35 #include <gtest/gtest.h> 42 EXPECT_EQ(
"<value><boolean>0</boolean></value>", v.
toXml());
46 v2[1] = std::string();
48 EXPECT_EQ(
"<value><array><data><value><i4>1</i4></value><value></" 49 "value><value><boolean>0</boolean></value></data></array></value>",
57 XmlRpcValue booleanFalseXml(
"<value><boolean>0</boolean></value>", &offset);
59 XmlRpcValue booleanTrueXml(
"<value><boolean>1</boolean></value>", &offset);
60 EXPECT_NE(booleanFalse, booleanTrue);
61 EXPECT_EQ(booleanFalse, booleanFalseXml);
62 EXPECT_NE(booleanFalse, booleanTrueXml);
64 EXPECT_FALSE(
bool(booleanFalse));
66 EXPECT_TRUE(
bool(booleanTrue));
71 EXPECT_EQ(
"0", ss.str());
73 std::stringstream ss2;
75 EXPECT_EQ(
"1", ss2.str());
93 XmlRpcValue int0Xml(
"<value><int>0</int></value>", &offset);
95 EXPECT_EQ(0,
int(int0Xml));
98 XmlRpcValue int9Xml(
"<value><i4>9</i4></value>", &offset);
100 EXPECT_EQ(9,
int(int9Xml));
102 EXPECT_EQ(int0, int0Xml);
103 EXPECT_EQ(
int(int10) -
int(int1),
int(int9Xml));
104 EXPECT_EQ(9,
int(int9Xml));
105 EXPECT_EQ(
int(int10) +
int(int_1),
int(int9Xml));
108 std::stringstream ss;
110 EXPECT_EQ(
"9", ss.str());
117 EXPECT_EQ(
"<value><double>43.700000000000003</double></value>", d.
toXml());
118 EXPECT_DOUBLE_EQ(43.7,
double(d));
121 XmlRpcValue dXml(
"<value><double>56.3</double></value>", &offset);
123 EXPECT_DOUBLE_EQ(56.3,
double(dXml));
125 EXPECT_DOUBLE_EQ(100.0,
double(d) +
double(dXml));
128 std::stringstream ss;
130 EXPECT_EQ(
"43.7", ss.str());
140 EXPECT_EQ(
" 2.0000000000", ss.str());
145 EXPECT_EQ(
"2.00000000000000000000000000000000", ss.str());
153 " 2.000000000", ss.str());
158 EXPECT_EQ(
"2.000000000000000000000000000000" 159 "00000000000000000000000000000000" 160 "00000000000000000000000000000000" 161 "000000000000000000000000000000000", ss.str());
171 EXPECT_EQ(18, s.
size());
172 EXPECT_EQ(
"<value>Now is the time <&</value>", s.
toXml());
174 char csxml[] =
"<value><string>Now is the time <&</string></value>";
175 std::string ssxml = csxml;
179 EXPECT_EQ(s, vscXml);
183 EXPECT_EQ(s, vssXml);
190 std::string emptyStringXml(
"<value></value>");
192 XmlRpcValue emptyStringVal1(emptyStringXml, &offset);
194 EXPECT_EQ(emptyStringVal1, emptyStringVal2);
196 emptyStringXml =
"<value> </value>";
198 XmlRpcValue blankStringVal(emptyStringXml, &offset);
199 EXPECT_EQ(std::string(blankStringVal),
" ");
203 std::string tmp = s2;
205 EXPECT_EQ(
"", (std::string)s2);
208 std::stringstream ss;
210 EXPECT_EQ(
"Now is the time <&", ss.str());
216 std::string xml =
"<tag><nexttag>";
217 xml += std::string(INT_MAX,
'a');
218 xml +=
"a</nexttag></tag>";
223 EXPECT_EQ(offset, 0);
227 EXPECT_EQ(offset, 0);
231 EXPECT_EQ(offset, 0);
235 EXPECT_EQ(offset, 0);
237 catch (std::bad_alloc& err) {
239 GTEST_SKIP() <<
"Unable to allocate memory to run test\n";
241 std::cerr <<
"[ SKIPPED ] XmlRpc.testOversizeString Unable to allocate memory to run test\n";
251 EXPECT_EQ(offset, 0);
255 EXPECT_EQ(offset, 0);
260 EXPECT_EQ(offset, 20);
265 EXPECT_EQ(offset, 0);
269 EXPECT_EQ(offset, 0);
273 EXPECT_EQ(offset, 14);
281 EXPECT_EQ(offset, 0);
285 EXPECT_EQ(offset, 0);
290 EXPECT_EQ(offset, 20);
295 EXPECT_EQ(offset, 13);
303 EXPECT_EQ(offset, 0);
307 EXPECT_EQ(offset, 0);
312 EXPECT_EQ(offset, 20);
317 EXPECT_EQ(offset, 5);
322 EXPECT_EQ(offset, 11);
327 EXPECT_EQ(offset, 0);
335 EXPECT_EQ(offset, 0);
340 EXPECT_EQ(offset, 20);
345 EXPECT_EQ(offset, 5);
350 EXPECT_EQ(offset, 11);
355 EXPECT_EQ(offset, 0);
361 EXPECT_EQ(offset, 4);
366 EXPECT_EQ(offset, 2);
375 EXPECT_EQ(offset, 0);
379 EXPECT_EQ(offset, 0);
384 EXPECT_EQ(offset, 20);
389 EXPECT_EQ(offset, 11);
394 EXPECT_EQ(offset, 14);
399 EXPECT_EQ(offset, 17);
404 EXPECT_EQ(offset, 0);
409 EXPECT_EQ(offset, 0);
414 EXPECT_EQ(offset, 0);
422 "<value><dateTime.iso8601>19040503T03:12:35</dateTime.iso8601></value>",
425 struct tm t = dateTime;
426 EXPECT_EQ(t.tm_year, 1904);
427 EXPECT_EQ(t.tm_min, 12);
428 EXPECT_EQ(t.tm_sec, 35);
429 EXPECT_EQ(t.tm_hour, 3);
430 EXPECT_EQ(t.tm_mday, 3);
431 EXPECT_EQ(t.tm_mon, 5);
434 "<value><dateTime.iso8601>19040503T03:12:35</dateTime.iso8601></value>",
441 EXPECT_EQ(t.tm_year, 1904);
442 EXPECT_EQ(t.tm_min, 12);
448 EXPECT_EQ(t.tm_year, 0);
449 EXPECT_EQ(t.tm_min, 0);
452 std::stringstream ss;
454 EXPECT_EQ(
"19040503T03:12:35", ss.str());
457 EXPECT_EQ(dateTime, dateTime2);
460 dateTime3 = dateTime;
461 EXPECT_EQ(dateTime, dateTime3);
466 struct tm& tm2 = dateTime2;
469 EXPECT_NE(dateTime, dateTime2);
471 ASSERT_EQ(dateTime, dateTime2);
475 EXPECT_NE(dateTime, dateTime2);
477 ASSERT_EQ(dateTime, dateTime2);
481 EXPECT_NE(dateTime, dateTime2);
483 ASSERT_EQ(dateTime, dateTime2);
487 EXPECT_NE(dateTime, dateTime2);
489 ASSERT_EQ(dateTime, dateTime2);
493 EXPECT_NE(dateTime, dateTime2);
495 ASSERT_EQ(dateTime, dateTime2);
499 EXPECT_NE(dateTime, dateTime2);
508 a[1] = std::string(
"two");
512 EXPECT_EQ(
int(a[0]), 1);
515 char csaXml[] =
"<value><array>\n" 517 " <value><i4>1</i4></value> \n" 518 " <value> <string>two</string></value>\n" 519 " <value><double>43.7</double></value>\n" 520 " <value>four</value>\n" 532 for (
int i = 0; i < 3; i++) {
533 EXPECT_EQ(a[i], copy[i]);
542 std::stringstream ss;
544 EXPECT_EQ(
"{1,two,43.7,four}", ss.str());
551 struct1[
"str"] =
"two";
553 EXPECT_EQ(3, struct1.
size());
556 EXPECT_FALSE(struct1.
hasMember(
"nowhere"));
559 std::stringstream ss;
561 EXPECT_EQ(
"[d:43.7,i4:1,str:two]", ss.str());
566 a[1] = std::string(
"two");
570 EXPECT_EQ(struct1[
"d"], a[2]);
572 char csStructXml[] =
"<value><struct>\n" 574 " <name>i4</name> \n" 575 " <value><i4>1</i4></value> \n" 579 " <value><double>43.7</double></value>\n" 582 " <name>str</name> \n" 583 " <value> <string>two</string></value>\n" 589 EXPECT_EQ(struct1, structXml);
596 astruct[
"array"] = a;
597 EXPECT_EQ(astruct[
"array"][2], struct1[
"d"]);
599 for (
int i = 0; i < 10; i++) {
601 Event[
"Name"] =
"string";
605 const int NELMTS = 100;
608 for (ii = 0; ii < NELMTS; ++ii) {
610 sprintf(buf,
"%d", ii);
611 Event[std::string(buf)] = buf;
616 for (ii = 0; ii < NELMTS; ++ii) {
618 sprintf(buf,
"%d", ii);
619 if (ii != NELMTS / 2)
620 Event[std::string(buf)] = ii;
622 for (
int jj = 0; jj < NELMTS; ++jj) {
624 sprintf(bufj,
"%d", jj);
625 Event[std::string(buf)][std::string(bufj)] = bufj;
629 for (ii = 0; ii < NELMTS; ++ii) {
631 sprintf(buf,
"%d", ii);
632 if (ii != NELMTS / 2)
633 EXPECT_EQ(Event[std::string(buf)],
XmlRpcValue(ii));
635 EXPECT_EQ(Event[std::string(buf)].size(), NELMTS);
641 char data[] = {1, 2};
645 EXPECT_EQ(2, bin.
size());
651 EXPECT_EQ(
"<value><base64>AQI=\n</base64></value>", bin.
toXml());
654 std::stringstream ss;
656 EXPECT_EQ(
"AQI=\n", ss.str());
660 XmlRpcValue bin2(
"<value><base64>AQI=</base64></value>", &offset);
662 EXPECT_EQ(2, bin2.
size());
668 EXPECT_EQ(bin, bin2);
674 EXPECT_EQ(0, bin3.
size());
675 EXPECT_EQ(0u, d.size());
682 EXPECT_EQ(2, bin4.size());
692 EXPECT_FALSE(value.
valid());
693 EXPECT_EQ(
"", value.
toXml());
696 bool v = (bool)value;
723 EXPECT_FALSE(value.valid());
731 EXPECT_EQ(0, (
int)value);
743 EXPECT_EQ(1, value.size());
746 EXPECT_EQ(0, (
int)value[1]);
747 EXPECT_EQ(2, value.size());
761 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
766 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
767 EXPECT_EQ(offset, 20);
772 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
773 EXPECT_EQ(offset, 0);
777 val.
fromXml(
"<value>", &offset);
778 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
779 EXPECT_EQ(offset, 0);
783 val.
fromXml(
"<value><invalid></invalid></value>", &offset);
784 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
785 EXPECT_EQ(offset, 0);
789 val.
fromXml(
"<value></value>", &offset);
790 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeString);
791 EXPECT_EQ(offset, 15);
792 EXPECT_EQ(static_cast<std::string>(val),
"");
801 val.
fromXml(
"<value><boolean></boolean></value>", &offset);
802 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
803 EXPECT_EQ(offset, 0);
807 val.
fromXml(
"<value><boolean></value>", &offset);
808 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
809 EXPECT_EQ(offset, 0);
813 val.
fromXml(
"<value><boolean>foo</boolean></value>", &offset);
814 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
815 EXPECT_EQ(offset, 0);
819 val.
fromXml(
"<value><boolean>25</boolean></value>", &offset);
820 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
821 EXPECT_EQ(offset, 0);
826 val.
fromXml(
"<value><boolean>1foo</boolean></value>", &offset);
827 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeBoolean);
828 EXPECT_EQ(offset, 38);
829 EXPECT_EQ(static_cast<bool>(val),
true);
834 val.
fromXml(
"<value><boolean>1</value>", &offset);
835 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeBoolean);
836 EXPECT_EQ(offset, 25);
837 EXPECT_EQ(static_cast<bool>(val),
true);
841 val.
fromXml(
"<value><boolean>0</boolean></value>", &offset);
842 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeBoolean);
843 EXPECT_EQ(offset, 35);
844 EXPECT_EQ(static_cast<bool>(val),
false);
848 val.
fromXml(
"<value><boolean>1</boolean></value>", &offset);
849 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeBoolean);
850 EXPECT_EQ(offset, 35);
851 EXPECT_EQ(static_cast<bool>(val),
true);
860 val.
fromXml(
"<value><i4></i4></value>", &offset);
861 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
862 EXPECT_EQ(offset, 0);
866 val.
fromXml(
"<value><i4></value>", &offset);
867 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
868 EXPECT_EQ(offset, 0);
872 val.
fromXml(
"<value><i4>foo</i4></value>", &offset);
873 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
874 EXPECT_EQ(offset, 0);
878 val.
fromXml(
"<value><i4>25</i4></value>", &offset);
879 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInt);
880 EXPECT_EQ(offset, 26);
881 EXPECT_EQ(static_cast<int>(val), 25);
886 val.
fromXml(
"<value><i4>1foo</i4></value>", &offset);
887 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInt);
888 EXPECT_EQ(offset, 28);
889 EXPECT_EQ(static_cast<int>(val), 1);
894 val.
fromXml(
"<value><i4>99</value>", &offset);
895 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInt);
896 EXPECT_EQ(offset, 21);
897 EXPECT_EQ(static_cast<int>(val), 99);
906 val.
fromXml(
"<value><int></int></value>", &offset);
907 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
908 EXPECT_EQ(offset, 0);
912 val.
fromXml(
"<value><int></value>", &offset);
913 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
914 EXPECT_EQ(offset, 0);
918 val.
fromXml(
"<value><int>foo</int></value>", &offset);
919 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
920 EXPECT_EQ(offset, 0);
924 val.
fromXml(
"<value><int>25</int></value>", &offset);
925 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInt);
926 EXPECT_EQ(offset, 28);
927 EXPECT_EQ(static_cast<int>(val), 25);
932 val.
fromXml(
"<value><int>1foo</int></value>", &offset);
933 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInt);
934 EXPECT_EQ(offset, 30);
935 EXPECT_EQ(static_cast<int>(val), 1);
940 val.
fromXml(
"<value><int>99</value>", &offset);
941 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInt);
942 EXPECT_EQ(offset, 22);
943 EXPECT_EQ(static_cast<int>(val), 99);
952 val.
fromXml(
"<value><double></double></value>", &offset);
953 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
954 EXPECT_EQ(offset, 0);
958 val.
fromXml(
"<value><double></value>", &offset);
959 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
960 EXPECT_EQ(offset, 0);
964 val.
fromXml(
"<value><double>foo</double></value>", &offset);
965 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
966 EXPECT_EQ(offset, 0);
970 val.
fromXml(
"<value><double>25</double></value>", &offset);
971 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeDouble);
972 EXPECT_EQ(offset, 34);
973 EXPECT_EQ(static_cast<double>(val), 25.0);
977 val.
fromXml(
"<value><double>25.876</double></value>", &offset);
978 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeDouble);
979 EXPECT_EQ(offset, 38);
980 EXPECT_NEAR(static_cast<double>(val), 25.876, 0.01);
985 val.
fromXml(
"<value><double>1foo</double></value>", &offset);
986 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeDouble);
987 EXPECT_EQ(offset, 36);
988 EXPECT_EQ(static_cast<double>(val), 1);
997 val.
fromXml(
"<value><foo></foo></value>", &offset);
998 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
999 EXPECT_EQ(offset, 0);
1003 val.
fromXml(
"<value>foo</value>", &offset);
1004 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeString);
1005 EXPECT_EQ(offset, 18);
1006 EXPECT_EQ(static_cast<std::string>(val),
"foo");
1007 EXPECT_EQ(val.
size(), 3);
1016 val.
fromXml(
"<value><string>", &offset);
1017 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1018 EXPECT_EQ(offset, 0);
1023 val.
fromXml(
"<value><string></value>", &offset);
1024 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeString);
1025 EXPECT_EQ(offset, 23);
1026 EXPECT_EQ(static_cast<std::string>(val),
"");
1027 EXPECT_EQ(val.
size(), 0);
1031 val.
fromXml(
"<value><string>foo</string></value>", &offset);
1032 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeString);
1033 EXPECT_EQ(offset, 35);
1034 EXPECT_EQ(static_cast<std::string>(val),
"foo");
1035 EXPECT_EQ(val.
size(), 3);
1041 struct tm expected{};
1046 val.
fromXml(
"<value><dateTime.iso8601></dateTime.iso8601></value>", &offset);
1047 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1048 EXPECT_EQ(offset, 0);
1052 val.
fromXml(
"<value><dateTime.iso8601>", &offset);
1053 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1054 EXPECT_EQ(offset, 0);
1058 val.
fromXml(
"<value><dateTime.iso8601></value>", &offset);
1059 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1060 EXPECT_EQ(offset, 0);
1064 val.
fromXml(
"<value><dateTime.iso8601>0000000T00:00<dateTime.iso8601></value>", &offset);
1065 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1066 EXPECT_EQ(offset, 0);
1070 val.
fromXml(
"<value><dateTime.iso8601>000000T00:00:00<dateTime.iso8601></value>", &offset);
1071 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1072 EXPECT_EQ(offset, 0);
1078 val.
fromXml(
"<value><dateTime.iso8601>0000000T00:00:00</value>", &offset);
1079 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeDateTime);
1080 EXPECT_EQ(offset, 49);
1081 returned =
static_cast<struct tm
>(val);
1082 EXPECT_EQ(returned.tm_sec, expected.tm_sec);
1083 EXPECT_EQ(returned.tm_min, expected.tm_min);
1084 EXPECT_EQ(returned.tm_hour, expected.tm_hour);
1085 EXPECT_EQ(returned.tm_mday, expected.tm_mday);
1086 EXPECT_EQ(returned.tm_mon, expected.tm_mon);
1087 EXPECT_EQ(returned.tm_year, expected.tm_year);
1088 EXPECT_EQ(returned.tm_isdst, -1);
1093 val.
fromXml(
"<value><dateTime.iso8601>0000000T00:00:0<dateTime.iso8601></value>", &offset);
1094 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeDateTime);
1095 EXPECT_EQ(offset, 66);
1096 returned =
static_cast<struct tm
>(val);
1097 EXPECT_EQ(returned.tm_sec, expected.tm_sec);
1098 EXPECT_EQ(returned.tm_min, expected.tm_min);
1099 EXPECT_EQ(returned.tm_hour, expected.tm_hour);
1100 EXPECT_EQ(returned.tm_mday, expected.tm_mday);
1101 EXPECT_EQ(returned.tm_mon, expected.tm_mon);
1102 EXPECT_EQ(returned.tm_year, expected.tm_year);
1103 EXPECT_EQ(returned.tm_isdst, -1);
1108 val.
fromXml(
"<value><dateTime.iso8601>0000000T00:00:00<dateTime.iso8601></value>", &offset);
1109 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeDateTime);
1110 EXPECT_EQ(offset, 67);
1111 returned =
static_cast<struct tm
>(val);
1112 EXPECT_EQ(returned.tm_sec, expected.tm_sec);
1113 EXPECT_EQ(returned.tm_min, expected.tm_min);
1114 EXPECT_EQ(returned.tm_hour, expected.tm_hour);
1115 EXPECT_EQ(returned.tm_mday, expected.tm_mday);
1116 EXPECT_EQ(returned.tm_mon, expected.tm_mon);
1117 EXPECT_EQ(returned.tm_year, expected.tm_year);
1118 EXPECT_EQ(returned.tm_isdst, -1);
1127 val.
fromXml(
"<value><base64>", &offset);
1128 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1129 EXPECT_EQ(offset, 0);
1133 val.
fromXml(
"<value><base64></base64></value>", &offset);
1134 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeBase64);
1135 EXPECT_EQ(offset, 32);
1137 EXPECT_EQ(val.
size(), 0);
1142 val.
fromXml(
"<value><base64>____</base64></value>", &offset);
1143 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeBase64);
1144 EXPECT_EQ(offset, 36);
1146 EXPECT_EQ(val.
size(), 0);
1151 val.
fromXml(
"<value><base64>aGVsbG8=</base64></value>", &offset);
1152 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeBase64);
1153 EXPECT_EQ(offset, 40);
1154 EXPECT_EQ(static_cast<const XmlRpc::XmlRpcValue::BinaryData &>(val), expected);
1155 EXPECT_EQ(val.
size(), 5);
1164 val.
fromXml(
"<value><array>", &offset);
1165 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1166 EXPECT_EQ(offset, 0);
1170 val.
fromXml(
"<value><array></array></value>", &offset);
1171 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeInvalid);
1172 EXPECT_EQ(offset, 0);
1176 val.
fromXml(
"<value><array><data></data></array></value>", &offset);
1177 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeArray);
1178 EXPECT_EQ(offset, 43);
1179 EXPECT_EQ(val.
size(), 0);
1183 val.
fromXml(
"<value><array><data><value><boolean>1</boolean></value></data></array></value>", &offset);
1184 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeArray);
1185 EXPECT_EQ(offset, 78);
1186 EXPECT_EQ(val.
size(), 1);
1187 EXPECT_EQ(static_cast<bool>(val[0]),
true);
1192 val.
fromXml(
"<value><array><data><value><boolean>1</boolean></value></array></value>", &offset);
1193 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeArray);
1194 EXPECT_EQ(offset, 71);
1195 EXPECT_EQ(val.
size(), 1);
1196 EXPECT_EQ(static_cast<bool>(val[0]),
true);
1200 val.
fromXml(
"<value><array><data><value><boolean>1</boolean></value><value><double>23.4</double></value></data></array></value>", &offset);
1201 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeArray);
1202 EXPECT_EQ(offset, 114);
1203 EXPECT_EQ(val.
size(), 2);
1204 EXPECT_EQ(static_cast<bool>(val[0]),
true);
1205 EXPECT_NEAR(static_cast<double>(val[1]), 23.4, 0.01);
1215 val.
fromXml(
"<value><struct>", &offset);
1216 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeStruct);
1217 EXPECT_EQ(offset, 15);
1218 EXPECT_EQ(val.
size(), 0);
1223 val.
fromXml(
"<value><struct><member><value><boolean>1</value>", &offset);
1224 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeStruct);
1225 EXPECT_EQ(offset, 48);
1226 EXPECT_EQ(val.
size(), 1);
1227 EXPECT_EQ(static_cast<bool>(val[
""]),
true);
1232 val.
fromXml(
"<value><struct><member><value><boolean>1</boolean></value></member></struct></value>", &offset);
1233 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeStruct);
1234 EXPECT_EQ(offset, 84);
1235 EXPECT_EQ(val.
size(), 1);
1236 EXPECT_EQ(static_cast<bool>(val[
""]),
true);
1241 val.
fromXml(
"<value><struct><member><name></name><value><boolean>1</boolean></value></member></struct></value>", &offset);
1242 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeStruct);
1243 EXPECT_EQ(offset, 97);
1244 EXPECT_EQ(val.
size(), 1);
1245 EXPECT_EQ(static_cast<bool>(val[
""]),
true);
1249 val.
fromXml(
"<value><struct><member><name>foo</name><value><boolean>1</boolean></value></member></struct></value>", &offset);
1250 EXPECT_EQ(val.
getType(), XmlRpcValue::Type::TypeStruct);
1251 EXPECT_EQ(offset, 100);
1252 EXPECT_EQ(val.
size(), 1);
1253 EXPECT_EQ(static_cast<bool>(val[
"foo"]),
true);
1258 ::testing::InitGoogleTest(&argc, argv);
1259 return RUN_ALL_TESTS();
int size() const
Return the size for string, base64, array, and struct values.
ValueStruct::iterator iterator
RPC method arguments and results are represented by Values.
static std::string nextTagData(const char *tag, std::string const &xml, int *offset)
void testArray(XmlRpcValue const &d)
static std::string getNextTag(std::string const &xml, int *offset)
static std::string parseTag(const char *tag, std::string const &xml, int *offset)
bool valid() const
Return true if the value has been set to something.
static bool findTag(const char *tag, std::string const &xml, int *offset)
Returns true if the tag is found and updates offset to the char after the tag.
const std::string & getMessage() const
Return the error message.
TEST(xmlrpcvalue_base64, empty_string)
void clear()
Erase the current value.
Type const & getType() const
Return the type of the value stored.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
static void setDoubleFormat(const char *f)
Specify the format used to write double values.
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
int getCode() const
Return the error code.
std::string toXml() const
Encode the Value in xml.
std::vector< char > BinaryData
static std::string const & getDoubleFormat()
Return the format used to write double values.
int main(int argc, char **argv)
XmlRpcValue fromXml(std::string const &data)
bool hasMember(const std::string &name) const
Check for the existence of a struct member by name.
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)