BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TestValues.cpp File Reference
#include <stdlib.h>
#include "XmlRpcValue.h"
#include <assert.h>
#include <iostream>

Go to the source code of this file.

Functions

void testBoolean ()
 
void testInt ()
 
void testDouble ()
 
void testString ()
 
void testDateTime ()
 
void testArray (XmlRpcValue const &d)
 
void testStruct ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 211 of file TestValues.cpp.

212{
213 testBoolean();
214
215 testInt();
216
217
218 testDouble();
219
220
221 testString();
222
223
224 testDateTime();
225
226
227 testArray(43.7);
228
229
230 testStruct();
231
232 return 0;
233}
void testStruct()
void testDateTime()
void testString()
void testBoolean()
void testArray(XmlRpcValue const &d)
void testDouble()
void testInt()

◆ testArray()

void testArray ( XmlRpcValue const & d)

Definition at line 100 of file TestValues.cpp.

101{
102 // Array
103 XmlRpcValue a;
104 a.setSize(4);
105 a[0] = 1;
106 a[1] = std::string("two");
107 a[2] = 43.7;
108 a[3] = "four";
109 assert(int(a[0]) == 1);
110 assert(a[2] == d);
111
112 char csaXml[] =
113 "<value><array>\n"
114 " <data>\n"
115 " <value><i4>1</i4></value> \n"
116 " <value> <string>two</string></value>\n"
117 " <value><double>43.7</double></value>\n"
118 " <value>four</value>\n"
119 " </data>\n"
120 "</array></value>";
121
122 int offset = 0;
123 XmlRpcValue aXml(csaXml, &offset);
124 assert(a == aXml);
125}
RPC method arguments and results are represented by Values.
Definition XmlRpcValue.h:22
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.

Referenced by main().

◆ testBoolean()

void testBoolean ( )

Definition at line 15 of file TestValues.cpp.

16{
17 XmlRpcValue booleanFalse(false);
18 XmlRpcValue booleanTrue(true);
19 int offset = 0;
20 XmlRpcValue booleanFalseXml("<value><boolean>0</boolean></value>", &offset);
21 offset = 0;
22 XmlRpcValue booleanTrueXml("<value><boolean>1</boolean></value>", &offset);
23 assert(booleanFalse != booleanTrue);
24 assert(booleanFalse == booleanFalseXml);
25 assert(booleanFalse != booleanTrueXml);
26
27 if (bool(booleanFalse))
28 assert(false);
29
30 if ( ! bool(booleanTrue))
31 assert(false);
32}

Referenced by main().

◆ testDateTime()

void testDateTime ( )

Definition at line 90 of file TestValues.cpp.

91{
92 // DateTime
93 int offset = 0;
94 XmlRpcValue dateTime("<value><dateTime.iso8601>19040101T03:12:35</dateTime.iso8601></value>", &offset);
95 struct tm &t = dateTime;
96 assert(t.tm_year == 1904 && t.tm_min == 12);
97}
TTree * t
Definition binning.cxx:23

Referenced by main().

◆ testDouble()

void testDouble ( )

Definition at line 51 of file TestValues.cpp.

52{
53 // Double
54 XmlRpcValue d(43.7);
55 int offset = 0;
56 XmlRpcValue dXml("<value><double>56.3</double></value>", &offset);
57 assert(double(d) + double(dXml) == 100.0); // questionable practice...
58}

Referenced by main().

◆ testInt()

void testInt ( )

Definition at line 35 of file TestValues.cpp.

36{
37 XmlRpcValue int0(0);
38 XmlRpcValue int1(1);
39 XmlRpcValue int10(10);
40 XmlRpcValue int_1(-1);
41 int offset = 0;
42 XmlRpcValue int0Xml("<value><int>0</int></value>", &offset);
43 offset = 0;
44 XmlRpcValue int9Xml("<value><i4>9</i4></value>", &offset);
45 assert(int0 == int0Xml);
46 assert(int(int10) - int(int1) == int(int9Xml));
47 assert(9 == int(int9Xml));
48 assert(int(int10) + int(int_1) == int(int9Xml));
49}

Referenced by main().

◆ testString()

void testString ( )

Definition at line 60 of file TestValues.cpp.

61{
62 // String
63 XmlRpcValue s("Now is the time <&");
64 char csxml[] = "<value><string>Now is the time &lt;&amp;</string></value>";
65 std::string ssxml = csxml;
66 int offset = 0;
67 XmlRpcValue vscXml(csxml, &offset);
68 offset = 0;
69 XmlRpcValue vssXml(ssxml, &offset);
70 assert(s == vscXml);
71 assert(s == vssXml);
72 offset = 0;
73 XmlRpcValue fromXml(vssXml.toXml(), &offset);
74 assert(s == fromXml);
75
76 // Empty or blank strings with no <string> tags
77 std::string emptyStringXml("<value></value>");
78 offset = 0;
79 XmlRpcValue emptyStringVal1(emptyStringXml, &offset);
80 XmlRpcValue emptyStringVal2("");
81 assert(emptyStringVal1 == emptyStringVal2);
82
83 emptyStringXml = "<value> </value>";
84 offset = 0;
85 XmlRpcValue blankStringVal(emptyStringXml, &offset);
86 assert(std::string(blankStringVal) == " ");
87}
XmlRpcServer s

Referenced by main().

◆ testStruct()

void testStruct ( )

Definition at line 127 of file TestValues.cpp.

128{
129 // Struct
130 XmlRpcValue struct1;
131 struct1["i4"] = 1;
132 struct1["str"] = "two";
133 struct1["d"] = 43.7;
134
135 XmlRpcValue a;
136 a.setSize(4);
137 a[0] = 1;
138 a[1] = std::string("two");
139 a[2] = 43.7;
140 a[3] = "four";
141
142 assert(struct1["d"] == a[2]);
143
144 char csStructXml[] =
145 "<value><struct>\n"
146 " <member>\n"
147 " <name>i4</name> \n"
148 " <value><i4>1</i4></value> \n"
149 " </member>\n"
150 " <member>\n"
151 " <name>d</name> \n"
152 " <value><double>43.7</double></value>\n"
153 " </member>\n"
154 " <member>\n"
155 " <name>str</name> \n"
156 " <value> <string>two</string></value>\n"
157 " </member>\n"
158 "</struct></value>";
159
160 int offset = 0;
161 XmlRpcValue structXml(csStructXml, &offset);
162 assert(struct1 == structXml);
163
164 XmlRpcValue astruct;
165 astruct["array"] = a;
166 assert(astruct["array"][2] == struct1["d"]);
167
168 for (int i=0; i<10; i++) {
170 Event["Name"] = "string";
171
172 Event.clear();
173
174 const int NELMTS = 100;
175 int ii;
176
177 for (ii=0; ii< NELMTS; ++ii) {
178 char buf[40];
179 sprintf(buf,"%d", ii);
180 Event[std::string(buf)] = buf;
181 }
182
183 Event.clear();
184
185 for (ii=0; ii< NELMTS; ++ii) {
186 char buf[40];
187 sprintf(buf,"%d", ii);
188 if (ii != NELMTS/2)
189 Event[std::string(buf)] = ii;
190 else
191 for (int jj=0; jj< NELMTS; ++jj) {
192 char bufj[40];
193 sprintf(bufj,"%d", jj);
194 Event[std::string(buf)][std::string(bufj)] = bufj;
195 }
196 }
197
198 for (ii=0; ii< NELMTS; ++ii) {
199 char buf[40];
200 sprintf(buf,"%d", ii);
201 if (ii != NELMTS/2)
202 assert(Event[std::string(buf)] == XmlRpcValue(ii));
203 else
204 assert(Event[std::string(buf)].size() == NELMTS);
205 }
206 }
207}
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)
Definition Event.h:21

Referenced by main().