standalone-tests/TestXml.cpp
Go to the documentation of this file.
1 // TestXml.cpp : Test XML encoding and decoding.
2 // The characters <>&'" are illegal in xml and must be encoded.
3 
4 
5 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
6 
7 #include <iostream>
8 // If you are using MSVC++6, you should update <string> to fix
9 // BUG: getline Template Function Reads Extra Character
10 #include <string>
11 #include <assert.h>
12 #include <stdlib.h>
13 
14 #include "xmlrpcpp/XmlRpcUtil.h"
15 
16 using namespace XmlRpc;
17 
18 
19 int main(int argc, char* argv[])
20 {
21  // Basic tests
22  std::string empty;
23  assert(empty == XmlRpcUtil::xmlEncode(empty));
24  assert(empty == XmlRpcUtil::xmlDecode(empty));
25  assert(empty == XmlRpcUtil::xmlEncode(""));
26  assert(empty == XmlRpcUtil::xmlDecode(""));
27 
28  std::string raw("<>&'\"");
29  assert(XmlRpcUtil::xmlDecode(XmlRpcUtil::xmlEncode(raw)) == raw);
30 
31  std::cout << "Basic tests passed.\n";
32 
33  // Interactive tests
34  std::string s;
35  for (;;) {
36  std::cout << "\nEnter line of raw text to encode:\n";
37  std::getline(std::cin, s);
38  if (s.empty()) break;
39 
40  std::cout << XmlRpcUtil::xmlEncode(s) << std::endl;
41  }
42 
43  for (;;) {
44  std::cout << "\nEnter line of xml-encoded text to decode:\n";
45  std::getline(std::cin, s);
46  if (s.empty()) break;
47 
48  std::cout << XmlRpcUtil::xmlDecode(s) << std::endl;
49  }
50 
51  return 0;
52 }
53 
XmlRpc::XmlRpcUtil::xmlEncode
static std::string xmlEncode(const std::string &raw)
Convert raw text to encoded xml.
Definition: XmlRpcUtil.cpp:299
s
XmlRpcServer s
Definition: HelloServer.cpp:11
main
int main(int argc, char *argv[])
Definition: standalone-tests/TestXml.cpp:19
XmlRpc
Definition: XmlRpcClient.h:20
XmlRpc::XmlRpcUtil::xmlDecode
static std::string xmlDecode(const std::string &encoded)
Convert encoded xml to raw text.
Definition: XmlRpcUtil.cpp:262
XmlRpcUtil.h


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:32