#include <stdlib.h>
#include "XmlRpcValue.h"
#include <assert.h>
#include <iostream>
Go to the source code of this file.
Functions | |
void | testBoolean () |
void | testInt () |
void | testDouble () |
void | testString () |
void | testDateTime () |
void | testArray (XmlRpcValue const &d) |
void | testStruct () |
int | main (int argc, char *argv[]) |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 211 of file TestValues.cpp.
References testArray(), testBoolean(), testDateTime(), testDouble(), testInt(), testString(), and testStruct().
00212 { 00213 testBoolean(); 00214 00215 testInt(); 00216 00217 00218 testDouble(); 00219 00220 00221 testString(); 00222 00223 00224 testDateTime(); 00225 00226 00227 testArray(43.7); 00228 00229 00230 testStruct(); 00231 00232 return 0; 00233 }
void testArray | ( | XmlRpcValue const & | d | ) |
Definition at line 100 of file TestValues.cpp.
References XmlRpc::XmlRpcValue::setSize(), and deljobs::string.
Referenced by main().
00101 { 00102 // Array 00103 XmlRpcValue a; 00104 a.setSize(4); 00105 a[0] = 1; 00106 a[1] = std::string("two"); 00107 a[2] = 43.7; 00108 a[3] = "four"; 00109 assert(int(a[0]) == 1); 00110 assert(a[2] == d); 00111 00112 char csaXml[] = 00113 "<value><array>\n" 00114 " <data>\n" 00115 " <value><i4>1</i4></value> \n" 00116 " <value> <string>two</string></value>\n" 00117 " <value><double>43.7</double></value>\n" 00118 " <value>four</value>\n" 00119 " </data>\n" 00120 "</array></value>"; 00121 00122 int offset = 0; 00123 XmlRpcValue aXml(csaXml, &offset); 00124 assert(a == aXml); 00125 }
void testBoolean | ( | ) |
Definition at line 15 of file TestValues.cpp.
Referenced by main().
00016 { 00017 XmlRpcValue booleanFalse(false); 00018 XmlRpcValue booleanTrue(true); 00019 int offset = 0; 00020 XmlRpcValue booleanFalseXml("<value><boolean>0</boolean></value>", &offset); 00021 offset = 0; 00022 XmlRpcValue booleanTrueXml("<value><boolean>1</boolean></value>", &offset); 00023 assert(booleanFalse != booleanTrue); 00024 assert(booleanFalse == booleanFalseXml); 00025 assert(booleanFalse != booleanTrueXml); 00026 00027 if (bool(booleanFalse)) 00028 assert(false); 00029 00030 if ( ! bool(booleanTrue)) 00031 assert(false); 00032 }
void testDateTime | ( | ) |
Definition at line 90 of file TestValues.cpp.
References t().
Referenced by main().
00091 { 00092 // DateTime 00093 int offset = 0; 00094 XmlRpcValue dateTime("<value><dateTime.iso8601>19040101T03:12:35</dateTime.iso8601></value>", &offset); 00095 struct tm &t = dateTime; 00096 assert(t.tm_year == 1904 && t.tm_min == 12); 00097 }
void testDouble | ( | ) |
Definition at line 51 of file TestValues.cpp.
Referenced by main().
00052 { 00053 // Double 00054 XmlRpcValue d(43.7); 00055 int offset = 0; 00056 XmlRpcValue dXml("<value><double>56.3</double></value>", &offset); 00057 assert(double(d) + double(dXml) == 100.0); // questionable practice... 00058 }
void testInt | ( | ) |
Definition at line 35 of file TestValues.cpp.
Referenced by main().
00036 { 00037 XmlRpcValue int0(0); 00038 XmlRpcValue int1(1); 00039 XmlRpcValue int10(10); 00040 XmlRpcValue int_1(-1); 00041 int offset = 0; 00042 XmlRpcValue int0Xml("<value><int>0</int></value>", &offset); 00043 offset = 0; 00044 XmlRpcValue int9Xml("<value><i4>9</i4></value>", &offset); 00045 assert(int0 == int0Xml); 00046 assert(int(int10) - int(int1) == int(int9Xml)); 00047 assert(9 == int(int9Xml)); 00048 assert(int(int10) + int(int_1) == int(int9Xml)); 00049 }
void testString | ( | ) |
Definition at line 60 of file TestValues.cpp.
References s, deljobs::string, and XmlRpc::XmlRpcValue::toXml().
Referenced by main().
00061 { 00062 // String 00063 XmlRpcValue s("Now is the time <&"); 00064 char csxml[] = "<value><string>Now is the time <&</string></value>"; 00065 std::string ssxml = csxml; 00066 int offset = 0; 00067 XmlRpcValue vscXml(csxml, &offset); 00068 offset = 0; 00069 XmlRpcValue vssXml(ssxml, &offset); 00070 assert(s == vscXml); 00071 assert(s == vssXml); 00072 offset = 0; 00073 XmlRpcValue fromXml(vssXml.toXml(), &offset); 00074 assert(s == fromXml); 00075 00076 // Empty or blank strings with no <string> tags 00077 std::string emptyStringXml("<value></value>"); 00078 offset = 0; 00079 XmlRpcValue emptyStringVal1(emptyStringXml, &offset); 00080 XmlRpcValue emptyStringVal2(""); 00081 assert(emptyStringVal1 == emptyStringVal2); 00082 00083 emptyStringXml = "<value> </value>"; 00084 offset = 0; 00085 XmlRpcValue blankStringVal(emptyStringXml, &offset); 00086 assert(std::string(blankStringVal) == " "); 00087 }
void testStruct | ( | ) |
Definition at line 127 of file TestValues.cpp.
References EventModel::Gen::Event, genRecEmupikp::i, XmlRpc::XmlRpcValue::setSize(), delete_small_size::size, and deljobs::string.
Referenced by main().
00128 { 00129 // Struct 00130 XmlRpcValue struct1; 00131 struct1["i4"] = 1; 00132 struct1["str"] = "two"; 00133 struct1["d"] = 43.7; 00134 00135 XmlRpcValue a; 00136 a.setSize(4); 00137 a[0] = 1; 00138 a[1] = std::string("two"); 00139 a[2] = 43.7; 00140 a[3] = "four"; 00141 00142 assert(struct1["d"] == a[2]); 00143 00144 char csStructXml[] = 00145 "<value><struct>\n" 00146 " <member>\n" 00147 " <name>i4</name> \n" 00148 " <value><i4>1</i4></value> \n" 00149 " </member>\n" 00150 " <member>\n" 00151 " <name>d</name> \n" 00152 " <value><double>43.7</double></value>\n" 00153 " </member>\n" 00154 " <member>\n" 00155 " <name>str</name> \n" 00156 " <value> <string>two</string></value>\n" 00157 " </member>\n" 00158 "</struct></value>"; 00159 00160 int offset = 0; 00161 XmlRpcValue structXml(csStructXml, &offset); 00162 assert(struct1 == structXml); 00163 00164 XmlRpcValue astruct; 00165 astruct["array"] = a; 00166 assert(astruct["array"][2] == struct1["d"]); 00167 00168 for (int i=0; i<10; i++) { 00169 XmlRpcValue Event; 00170 Event["Name"] = "string"; 00171 00172 Event.clear(); 00173 00174 const int NELMTS = 100; 00175 int ii; 00176 00177 for (ii=0; ii< NELMTS; ++ii) { 00178 char buf[40]; 00179 sprintf(buf,"%d", ii); 00180 Event[std::string(buf)] = buf; 00181 } 00182 00183 Event.clear(); 00184 00185 for (ii=0; ii< NELMTS; ++ii) { 00186 char buf[40]; 00187 sprintf(buf,"%d", ii); 00188 if (ii != NELMTS/2) 00189 Event[std::string(buf)] = ii; 00190 else 00191 for (int jj=0; jj< NELMTS; ++jj) { 00192 char bufj[40]; 00193 sprintf(bufj,"%d", jj); 00194 Event[std::string(buf)][std::string(bufj)] = bufj; 00195 } 00196 } 00197 00198 for (ii=0; ii< NELMTS; ++ii) { 00199 char buf[40]; 00200 sprintf(buf,"%d", ii); 00201 if (ii != NELMTS/2) 00202 assert(Event[std::string(buf)] == XmlRpcValue(ii)); 00203 else 00204 assert(Event[std::string(buf)].size() == NELMTS); 00205 } 00206 } 00207 }