BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TestValuesWin32.cpp
Go to the documentation of this file.
1// TestValues.cpp : Test XML encoding and decoding of XmlRpcValues.
2
3#define _CRTDBG_MAP_ALLOC
4#include <crtdbg.h>
5#include <stdlib.h>
6
7#include "XmlRpcValue.h"
8
9#include <assert.h>
10#include <iostream>
11
12using namespace XmlRpc;
13
15 XmlRpcValue booleanFalse( false );
16 XmlRpcValue booleanTrue( true );
17 int offset = 0;
18 XmlRpcValue booleanFalseXml( "<value><boolean>0</boolean></value>", &offset );
19 offset = 0;
20 XmlRpcValue booleanTrueXml( "<value><boolean>1</boolean></value>", &offset );
21 assert( booleanFalse != booleanTrue );
22 assert( booleanFalse == booleanFalseXml );
23 assert( booleanFalse == booleanFalseXml );
24 if ( booleanFalse ) assert( false );
25
26 if ( booleanTrue ) assert( !false );
27 else assert( false );
28}
29
30// Int
31void testInt() {
32 XmlRpcValue int0( 0 );
33 XmlRpcValue int1( 1 );
34 XmlRpcValue int10( 10 );
35 XmlRpcValue int_1( -1 );
36 int offset = 0;
37 XmlRpcValue int0Xml( "<value><int>0</int></value>", &offset );
38 offset = 0;
39 XmlRpcValue int9Xml( "<value><i4>9</i4></value>", &offset );
40 assert( int0 == int0Xml );
41 assert( int( int10 ) - int( int1 ) == int( int9Xml ) );
42 assert( 9 == int( int9Xml ) );
43 assert( int( int10 ) + int( int_1 ) == int( int9Xml ) );
44}
45
46void testDouble() {
47 // Double
48 XmlRpcValue d( 43.7 );
49 int offset = 0;
50 XmlRpcValue dXml( "<value><double>56.3</double></value>", &offset );
51 assert( double( d ) + double( dXml ) == 100.0 ); // questionable practice...
52}
53
54void testString() {
55 // String
56 XmlRpcValue s( "Now is the time <&" );
57 char csxml[] = "<value><string>Now is the time &lt;&amp;</string></value>";
58 std::string ssxml = csxml;
59 int offset = 0;
60 XmlRpcValue vscXml( csxml, &offset );
61 offset = 0;
62 XmlRpcValue vssXml( ssxml, &offset );
63 assert( s == vscXml );
64 assert( s == vssXml );
65 offset = 0;
66 XmlRpcValue fromXml( vssXml.toXml(), &offset );
67 assert( s == fromXml );
68
69 // Empty or blank strings with no <string> tags
70 std::string emptyStringXml( "<value></value>" );
71 offset = 0;
72 XmlRpcValue emptyStringVal1( emptyStringXml, &offset );
73 XmlRpcValue emptyStringVal2( "" );
74 assert( emptyStringVal1 == emptyStringVal2 );
75
76 emptyStringXml = "<value> </value>";
77 offset = 0;
78 XmlRpcValue blankStringVal( emptyStringXml, &offset );
79 assert( std::string( blankStringVal ) == " " );
80}
81
83 // DateTime
84 int offset = 0;
85 XmlRpcValue dateTime(
86 "<value><dateTime.iso8601>19040101T03:12:35</dateTime.iso8601></value>", &offset );
87 struct tm& t = dateTime;
88 assert( t.tm_year == 1904 && t.tm_min == 12 );
89}
90
91void testArray( XmlRpcValue const& d ) {
92 // Array
94 a.setSize( 4 );
95 a[0] = 1;
96 a[1] = std::string( "two" );
97 a[2] = 43.7;
98 a[3] = "four";
99 assert( int( a[0] ) == 1 );
100 assert( a[2] == d );
101
102 char csaXml[] = "<value><array>\n"
103 " <data>\n"
104 " <value><i4>1</i4></value> \n"
105 " <value> <string>two</string></value>\n"
106 " <value><double>43.7</double></value>\n"
107 " <value>four</value>\n"
108 " </data>\n"
109 "</array></value>";
110
111 int offset = 0;
112 XmlRpcValue aXml( csaXml, &offset );
113 assert( a == aXml );
114}
115
117 // Struct
118 XmlRpcValue struct1;
119 struct1["i4"] = 1;
120 struct1["str"] = "two";
121 struct1["d"] = 43.7;
122
123 XmlRpcValue a;
124 a.setSize( 4 );
125 a[0] = 1;
126 a[1] = std::string( "two" );
127 a[2] = 43.7;
128 a[3] = "four";
129
130 assert( struct1["d"] == a[2] );
131
132 char csStructXml[] = "<value><struct>\n"
133 " <member>\n"
134 " <name>i4</name> \n"
135 " <value><i4>1</i4></value> \n"
136 " </member>\n"
137 " <member>\n"
138 " <name>d</name> \n"
139 " <value><double>43.7</double></value>\n"
140 " </member>\n"
141 " <member>\n"
142 " <name>str</name> \n"
143 " <value> <string>two</string></value>\n"
144 " </member>\n"
145 "</struct></value>";
146
147 int offset = 0;
148 XmlRpcValue structXml( csStructXml, &offset );
149 assert( struct1 == structXml );
150
151 XmlRpcValue astruct;
152 astruct["array"] = a;
153 assert( astruct["array"][2] == struct1["d"] );
154
155 for ( int i = 0; i < 10; i++ )
156 {
158 Event["Name"] = "string";
159
160 Event.clear();
161
162 const int NELMTS = 100;
163 int ii;
164
165 for ( ii = 0; ii < NELMTS; ++ii )
166 {
167 char buf[40];
168 sprintf( buf, "%d", ii );
169 Event[buf] = buf;
170 }
171
172 Event.clear();
173
174 for ( ii = 0; ii < NELMTS; ++ii )
175 {
176 char buf[40];
177 sprintf( buf, "%d", ii );
178 if ( ii != NELMTS / 2 ) Event[buf] = ii;
179 else
180 for ( int jj = 0; jj < NELMTS; ++jj )
181 {
182 char bufj[40];
183 sprintf( bufj, "%d", jj );
184 Event[buf][bufj] = bufj;
185 }
186 }
187
188 for ( ii = 0; ii < NELMTS; ++ii )
189 {
190 char buf[40];
191 sprintf( buf, "%d", ii );
192 if ( ii != NELMTS / 2 ) assert( Event[buf] == XmlRpcValue( ii ) );
193 else assert( Event[buf].size() == NELMTS );
194 }
195 }
196}
197
198int main( int argc, char* argv[] ) {
199 _CrtDumpMemoryLeaks();
200 _CrtCheckMemory();
201
202 testBoolean();
203 _CrtDumpMemoryLeaks();
204 _CrtCheckMemory();
205
206 testInt();
207 _CrtDumpMemoryLeaks();
208 _CrtCheckMemory();
209
210 testDouble();
211 _CrtDumpMemoryLeaks();
212 _CrtCheckMemory();
213
214 testString();
215 _CrtDumpMemoryLeaks();
216 _CrtCheckMemory();
217
218 testDateTime();
219 _CrtDumpMemoryLeaks();
220 _CrtCheckMemory();
221
222 testArray( 43.7 );
223 _CrtDumpMemoryLeaks();
224 _CrtCheckMemory();
225
226 testStruct();
227 _CrtDumpMemoryLeaks();
228 _CrtCheckMemory();
229
230 return 0;
231}
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
XmlRpcServer s
void testStruct()
void testDateTime()
void testString()
void testBoolean()
void testArray(XmlRpcValue const &d)
void testDouble()
void testInt()
RPC method arguments and results are represented by Values.
Definition XmlRpcValue.h:22
std::string toXml() const
Encode the Value in xml.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
int main()
Definition phokhara.cc:42
int t()
Definition t.c:1