• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "XmlRpcUtil.h"
15 
16 using namespace XmlRpc;
17 
18 
main(int argc,char * argv[])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 
54