File: TestXml.cpp

package info (click to toggle)
flxmlrpc 0.1.4-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,056 kB
  • sloc: sh: 11,511; cpp: 3,648; makefile: 63
file content (106 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// TestXml.cpp : Test XML encoding and decoding.

// The characters <>&'" are illegal in xml and must be encoded.





#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers



#include <iostream>

// If you are using MSVC++6, you should update <string> to fix

// BUG: getline Template Function Reads Extra Character

#include <string>

#include <assert.h>

#include <stdlib.h>



#include "XmlRpcUtil.h"



using namespace XmlRpc;





int main(int argc, char* argv[])

{

  // Basic tests

  std::string empty;

  assert(empty == XmlRpcUtil::xmlEncode(empty));

  assert(empty == XmlRpcUtil::xmlDecode(empty));

  assert(empty == XmlRpcUtil::xmlEncode(""));

  assert(empty == XmlRpcUtil::xmlDecode(""));



  std::string raw("<>&'\"");

  assert(XmlRpcUtil::xmlDecode(XmlRpcUtil::xmlEncode(raw)) == raw);

  

  std::cout << "Basic tests passed.\n";



  // Interactive tests

  std::string s;

  for (;;) {

    std::cout << "\nEnter line of raw text to encode:\n";

    std::getline(std::cin, s);

    if (s.empty()) break;



    std::cout << XmlRpcUtil::xmlEncode(s) << std::endl;

  }



  for (;;) {

    std::cout << "\nEnter line of xml-encoded text to decode:\n";

    std::getline(std::cin, s);

    if (s.empty()) break;



    std::cout << XmlRpcUtil::xmlDecode(s) << std::endl;

  }



  return 0;

}