33 #include <gtest/gtest.h> 40 EXPECT_EQ(
"<value><boolean>0</boolean></value>", v.
toXml());
44 v2[1] = std::string();
46 EXPECT_EQ(
"<value><array><data><value><i4>1</i4></value><value></" 47 "value><value><boolean>0</boolean></value></data></array></value>",
55 XmlRpcValue booleanFalseXml(
"<value><boolean>0</boolean></value>", &offset);
57 XmlRpcValue booleanTrueXml(
"<value><boolean>1</boolean></value>", &offset);
58 EXPECT_NE(booleanFalse, booleanTrue);
59 EXPECT_EQ(booleanFalse, booleanFalseXml);
60 EXPECT_NE(booleanFalse, booleanTrueXml);
62 EXPECT_FALSE(
bool(booleanFalse));
64 EXPECT_TRUE(
bool(booleanTrue));
69 EXPECT_EQ(
"0", ss.str());
71 std::stringstream ss2;
73 EXPECT_EQ(
"1", ss2.str());
91 XmlRpcValue int0Xml(
"<value><int>0</int></value>", &offset);
93 EXPECT_EQ(0,
int(int0Xml));
96 XmlRpcValue int9Xml(
"<value><i4>9</i4></value>", &offset);
98 EXPECT_EQ(9,
int(int9Xml));
100 EXPECT_EQ(int0, int0Xml);
101 EXPECT_EQ(
int(int10) -
int(int1),
int(int9Xml));
102 EXPECT_EQ(9,
int(int9Xml));
103 EXPECT_EQ(
int(int10) +
int(int_1),
int(int9Xml));
106 std::stringstream ss;
108 EXPECT_EQ(
"9", ss.str());
115 EXPECT_EQ(
"<value><double>43.700000000000003</double></value>", d.
toXml());
116 EXPECT_DOUBLE_EQ(43.7,
double(d));
119 XmlRpcValue dXml(
"<value><double>56.3</double></value>", &offset);
121 EXPECT_DOUBLE_EQ(56.3,
double(dXml));
123 EXPECT_DOUBLE_EQ(100.0,
double(d) +
double(dXml));
126 std::stringstream ss;
128 EXPECT_EQ(
"43.7", ss.str());
135 EXPECT_EQ(18, s.
size());
136 EXPECT_EQ(
"<value>Now is the time <&</value>", s.
toXml());
138 char csxml[] =
"<value><string>Now is the time <&</string></value>";
139 std::string ssxml = csxml;
143 EXPECT_EQ(s, vscXml);
147 EXPECT_EQ(s, vssXml);
154 std::string emptyStringXml(
"<value></value>");
156 XmlRpcValue emptyStringVal1(emptyStringXml, &offset);
158 EXPECT_EQ(emptyStringVal1, emptyStringVal2);
160 emptyStringXml =
"<value> </value>";
162 XmlRpcValue blankStringVal(emptyStringXml, &offset);
163 EXPECT_EQ(std::string(blankStringVal),
" ");
167 std::string tmp = s2;
169 EXPECT_EQ(
"", (std::string)s2);
172 std::stringstream ss;
174 EXPECT_EQ(
"Now is the time <&", ss.str());
182 "<value><dateTime.iso8601>19040503T03:12:35</dateTime.iso8601></value>",
185 struct tm t = dateTime;
186 EXPECT_EQ(t.tm_year, 1904);
187 EXPECT_EQ(t.tm_min, 12);
188 EXPECT_EQ(t.tm_sec, 35);
189 EXPECT_EQ(t.tm_hour, 3);
190 EXPECT_EQ(t.tm_mday, 3);
191 EXPECT_EQ(t.tm_mon, 5);
194 "<value><dateTime.iso8601>19040503T03:12:35</dateTime.iso8601></value>",
201 EXPECT_EQ(t.tm_year, 1904);
202 EXPECT_EQ(t.tm_min, 12);
208 EXPECT_EQ(t.tm_year, 0);
209 EXPECT_EQ(t.tm_min, 0);
212 std::stringstream ss;
214 EXPECT_EQ(
"19040503T03:12:35", ss.str());
217 EXPECT_EQ(dateTime, dateTime2);
220 dateTime3 = dateTime;
221 EXPECT_EQ(dateTime, dateTime3);
226 struct tm& tm2 = dateTime2;
229 EXPECT_NE(dateTime, dateTime2);
231 ASSERT_EQ(dateTime, dateTime2);
235 EXPECT_NE(dateTime, dateTime2);
237 ASSERT_EQ(dateTime, dateTime2);
241 EXPECT_NE(dateTime, dateTime2);
243 ASSERT_EQ(dateTime, dateTime2);
247 EXPECT_NE(dateTime, dateTime2);
249 ASSERT_EQ(dateTime, dateTime2);
253 EXPECT_NE(dateTime, dateTime2);
255 ASSERT_EQ(dateTime, dateTime2);
259 EXPECT_NE(dateTime, dateTime2);
268 a[1] = std::string(
"two");
272 EXPECT_EQ(
int(a[0]), 1);
275 char csaXml[] =
"<value><array>\n" 277 " <value><i4>1</i4></value> \n" 278 " <value> <string>two</string></value>\n" 279 " <value><double>43.7</double></value>\n" 280 " <value>four</value>\n" 292 for (
int i = 0; i < 3; i++) {
293 EXPECT_EQ(a[i], copy[i]);
302 std::stringstream ss;
304 EXPECT_EQ(
"{1,two,43.7,four}", ss.str());
311 struct1[
"str"] =
"two";
313 EXPECT_EQ(3, struct1.
size());
316 EXPECT_FALSE(struct1.
hasMember(
"nowhere"));
319 std::stringstream ss;
321 EXPECT_EQ(
"[d:43.7,i4:1,str:two]", ss.str());
326 a[1] = std::string(
"two");
330 EXPECT_EQ(struct1[
"d"], a[2]);
332 char csStructXml[] =
"<value><struct>\n" 334 " <name>i4</name> \n" 335 " <value><i4>1</i4></value> \n" 339 " <value><double>43.7</double></value>\n" 342 " <name>str</name> \n" 343 " <value> <string>two</string></value>\n" 349 EXPECT_EQ(struct1, structXml);
356 astruct[
"array"] = a;
357 EXPECT_EQ(astruct[
"array"][2], struct1[
"d"]);
359 for (
int i = 0; i < 10; i++) {
361 Event[
"Name"] =
"string";
365 const int NELMTS = 100;
368 for (ii = 0; ii < NELMTS; ++ii) {
370 sprintf(buf,
"%d", ii);
371 Event[std::string(buf)] = buf;
376 for (ii = 0; ii < NELMTS; ++ii) {
378 sprintf(buf,
"%d", ii);
379 if (ii != NELMTS / 2)
380 Event[std::string(buf)] = ii;
382 for (
int jj = 0; jj < NELMTS; ++jj) {
384 sprintf(bufj,
"%d", jj);
385 Event[std::string(buf)][std::string(bufj)] = bufj;
389 for (ii = 0; ii < NELMTS; ++ii) {
391 sprintf(buf,
"%d", ii);
392 if (ii != NELMTS / 2)
393 EXPECT_EQ(Event[std::string(buf)],
XmlRpcValue(ii));
395 EXPECT_EQ(Event[std::string(buf)].size(), NELMTS);
401 char data[] = {1, 2};
405 EXPECT_EQ(2, bin.
size());
411 EXPECT_EQ(
"<value><base64>AQI=\n</base64></value>", bin.
toXml());
414 std::stringstream ss;
416 EXPECT_EQ(
"AQI=\n", ss.str());
420 XmlRpcValue bin2(
"<value><base64>AQI=</base64></value>", &offset);
422 EXPECT_EQ(2, bin2.
size());
428 EXPECT_EQ(bin, bin2);
434 EXPECT_EQ(0, bin3.
size());
435 EXPECT_EQ(0u, d.size());
442 EXPECT_EQ(2, bin4.size());
452 EXPECT_FALSE(value.
valid());
453 EXPECT_EQ(
"", value.
toXml());
456 bool v = (bool)value;
483 EXPECT_FALSE(value.valid());
491 EXPECT_EQ(0, (
int)value);
503 EXPECT_EQ(1, value.size());
506 EXPECT_EQ(0, (
int)value[1]);
507 EXPECT_EQ(2, value.size());
515 int main(
int argc,
char **argv)
517 ::testing::InitGoogleTest(&argc, argv);
518 return RUN_ALL_TESTS();
const std::string & getMessage() const
Return the error message.
ValueStruct::iterator iterator
RPC method arguments and results are represented by Values.
void testArray(XmlRpcValue const &d)
int size() const
Return the size for string, base64, array, and struct values.
bool valid() const
Return true if the value has been set to something.
int getCode() const
Return the error code.
TEST(xmlrpcvalue_base64, empty_string)
Type const & getType() const
Return the type of the value stored.
void clear()
Erase the current value.
std::string toXml() const
Encode the Value in xml.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
bool hasMember(const std::string &name) const
Check for the existence of a struct member by name.
std::vector< char > BinaryData
int main(int argc, char **argv)
XmlRpcValue fromXml(std::string const &data)