BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
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#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
5
6#include <iostream>
7// If you are using MSVC++6, you should update <string> to fix
8// BUG: getline Template Function Reads Extra Character
9#include <assert.h>
10#include <stdlib.h>
11#include <string>
12
13#include "XmlRpcUtil.h"
14
15using namespace XmlRpc;
16
17int main( int argc, char* argv[] ) {
18 // Basic tests
19 std::string empty;
20 assert( empty == XmlRpcUtil::xmlEncode( empty ) );
21 assert( empty == XmlRpcUtil::xmlDecode( empty ) );
22 assert( empty == XmlRpcUtil::xmlEncode( "" ) );
23 assert( empty == XmlRpcUtil::xmlDecode( "" ) );
24
25 std::string raw( "<>&'\"" );
26 assert( XmlRpcUtil::xmlDecode( XmlRpcUtil::xmlEncode( raw ) ) == raw );
27
28 std::cout << "Basic tests passed.\n";
29
30 // Interactive tests
31 std::string s;
32 for ( ;; )
33 {
34 std::cout << "\nEnter line of raw text to encode:\n";
35 std::getline( std::cin, s );
36 if ( s.empty() ) break;
37
38 std::cout << XmlRpcUtil::xmlEncode( s ) << std::endl;
39 }
40
41 for ( ;; )
42 {
43 std::cout << "\nEnter line of xml-encoded text to decode:\n";
44 std::getline( std::cin, s );
45 if ( s.empty() ) break;
46
47 std::cout << XmlRpcUtil::xmlDecode( s ) << std::endl;
48 }
49
50 return 0;
51}
XmlRpcServer s
static std::string xmlEncode(const std::string &raw)
Convert raw text to encoded xml.
static std::string xmlDecode(const std::string &encoded)
Convert encoded xml to raw text.
int main()
Definition phokhara.cc:42