xmlrpcvalue_base64.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include "xmlrpcpp/XmlRpcValue.h"
3 
4 #include <algorithm>
5 #include <string>
6 #include <sstream>
7 
8 int main(int argc, char **argv)
9 {
10  ::testing::InitGoogleTest(&argc, argv);
11  return RUN_ALL_TESTS();
12 }
13 
14 namespace XmlRpc
15 {
16 
17  XmlRpcValue base64Value(std::string const & data)
18  {
19  return XmlRpcValue(const_cast<char *>(&data[0]), data.size());
20  }
21 
22  XmlRpcValue fromXml(std::string const & data)
23  {
24  int offset = 0;
25  return XmlRpcValue(data, &offset);
26  }
27 
28  void removeNewlines(std::string & data)
29  {
30  data.erase(std::remove(data.begin(), data.end(), '\n'), data.end());
31  }
32 
33  void assertEncodeDecode(std::string const & raw, std::string const & base64)
34  {
35  XmlRpcValue value = base64Value(raw);
36  std::string xml ="<value><base64>" + base64 + "</base64></value>";
37  XmlRpcValue parsed_value = fromXml(xml);
38  std::string generated_xml = value.toXml();
39  removeNewlines(generated_xml);
40 
41  std::stringstream buffer;
42  value.write(buffer);
43  std::string streamed = buffer.str();
44  removeNewlines(streamed);
45  ASSERT_EQ(streamed, base64);
46 
47  ASSERT_EQ(generated_xml, "<value><base64>" + base64 + "</base64></value>");
48  ASSERT_EQ(parsed_value, value);
49  }
50 
51 
52  TEST(xmlrpcvalue_base64, empty_string)
53  {
54  assertEncodeDecode("", "");
55  }
56 
57  TEST(xmlrpcvalue_base64, hello_world)
58  {
59  assertEncodeDecode("Hello World!", "SGVsbG8gV29ybGQh");
60  assertEncodeDecode("Hello World!\n", "SGVsbG8gV29ybGQhCg==");
61  }
62 
63  TEST(xmlrpcvalue_base64, random)
64  {
66  std::string("\261", 1),
67  "sQ=="
68  );
70  std::string("\341\370", 2),
71  "4fg="
72  );
74  std::string("\206\262J", 3),
75  "hrJK"
76  );
78  std::string("|5Q%", 4),
79  "fDVRJQ=="
80  );
82  std::string("5\220,+X", 5),
83  "NZAsK1g="
84  );
86  std::string("\247\342\007M@\270", 6),
87  "p+IHTUC4"
88  );
90  std::string("\012\247e\013;\232*", 7),
91  "CqdlCzuaKg=="
92  );
94  std::string("U\374\336w\351-\2503", 8),
95  "Vfzed+ktqDM="
96  );
98  std::string("\264\204`\310\001\306\253g\026", 9),
99  "tIRgyAHGq2cW"
100  );
102  std::string("\224\307\217\336|J^\223\237v", 10),
103  "lMeP3nxKXpOfdg=="
104  );
106  std::string("~%\305\024\264P)\206\224\247N", 11),
107  "fiXFFLRQKYaUp04="
108  );
110  std::string("-4\355\215Q|\367\332j\013\027\006", 12),
111  "LTTtjVF899pqCxcG"
112  );
114  std::string("\026Q\304\204\244s%\203\023?\364\320\005", 13),
115  "FlHEhKRzJYMTP/TQBQ=="
116  );
118  std::string("G0\306B\251\351;mwM\312i(\000", 14),
119  "RzDGQqnpO213TcppKAA="
120  );
122  std::string("\031kpC)[t\205\026\230\343S\367\016\263", 15),
123  "GWtwQylbdIUWmONT9w6z"
124  );
126  std::string("B&\134a\013\246u^V\001\260a\247\231}U\3278\367=G\317g\020{\277\042\373", 28),
127  "QiZcYQumdV5WAbBhp5l9Vdc49z1Hz2cQe78i+w=="
128  );
130  std::string("[>\303\210`\270o\023FJ\004r\360\361\357\2517\345\204|\245\267P \247V\251v\025", 29),
131  "Wz7DiGC4bxNGSgRy8PHvqTflhHylt1Agp1apdhU="
132  );
134  std::string("\264\245\360=\273E%8\023\3138\227k\222WS\227uf\314\345Y\031\365Q\024\331.\210&", 30),
135  "tKXwPbtFJTgTyziXa5JXU5d1ZszlWRn1URTZLogm"
136  );
138  std::string("II\036\326\353\232T\221/\021\3265F}\2647A)O\2302CLY?\367O\261E\246\332\376\333\230\343\326_\373\303\225\343\351\354[\326~\264\034\305\035V\227\034\331[\012\263Y", 58),
139  "SUke1uuaVJEvEdY1Rn20N0EpT5gyQ0xZP/dPsUWm2v7bmOPWX/vDlePp7FvWfrQcxR1WlxzZWwqzWQ=="
140  );
142  std::string("\353\317\000-\333\230\2701\251\310&J\225\347+\221q\245tb\336\225\350\323\310\327*q\261&;\2448\033X\346\277\245GM\216Oz\365\025K1\341w\230\277\272*\365\343\204\376\334E", 59),
143  "688ALduYuDGpyCZKlecrkXGldGLelejTyNcqcbEmO6Q4G1jmv6VHTY5PevUVSzHhd5i/uir144T+3EU="
144  );
146  std::string("\235\232\352\362\304\351n\244\227\220\202hh\226\346\271\042\021d\362c\267\260\310`\000\034\247\215\350\013;#2\204(^_\333w\2233\374\337\205\253y\372\352\305F-\200v\034\331\216\205\011", 60),
147  "nZrq8sTpbqSXkIJoaJbmuSIRZPJjt7DIYAAcp43oCzsjMoQoXl/bd5Mz/N+Fq3n66sVGLX+AdhzZjoUJ"
148  );
149  }
150 }
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24
TEST(xmlrpcvalue_base64, empty_string)
int main(int argc, char **argv)
XmlRpcValue base64Value(std::string const &data)
std::string toXml() const
Encode the Value in xml.
std::ostream & write(std::ostream &os) const
Write the value (no xml encoding)
Definition: decode.h:15
void assertEncodeDecode(std::string const &raw, std::string const &base64)
XmlRpcValue fromXml(std::string const &data)
void removeNewlines(std::string &data)


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:33:22