-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_ug_jfc_xml.pas
250 lines (218 loc) · 7.63 KB
/
test_ug_jfc_xml.pas
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
{=============================================================================
| _________ _______ _______ ______ _______ Get out of the |
| /___ ___// _____/ / _____/ / __ / / _____/ Mainstream... |
| / / / /__ / / ___ / /_/ / / /____ Jump into the |
| / / / ____/ / / / / / __ / /____ / Jetstream |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Virtually Everything IT(tm) info@jegas.com |
==============================================================================
Copyright(c)2016 Jegas, LLC
=============================================================================}
//=============================================================================
{ }
// Testing the uxxg_jfc_xml.pp Unit
program test_ug_jfc_xml;
//=============================================================================
//=============================================================================
// Global Directives
//=============================================================================
{$INCLUDE i_jegas_splash.pp}
{$INCLUDE i_jegas_macros.pp}
{$SMARTLINK ON}
{$MODE objfpc}
{$PACKRECORDS 4}
//=============================================================================
//=============================================================================
uses
//=============================================================================
ug_jfc_xml,
ug_misc,
sysutils,
ug_common;
//=============================================================================
var gsaFileName: ansistring;
//=============================================================================
function bTest_JFC_XML_From_File(p_safile:ansistring): boolean;
//=============================================================================
var
XML: JFC_XML;
bOk: boolean;
saXML: ansistring;
begin
XML:=JFC_XML.Create;
bOk:=fileexists(p_safile);
if not bOk then
begin
writeln('file not found: ',p_saFile);
end;
if bOk then
begin
bOk:=bLoadTextFile(p_safile, saXML);
if not bOk then
begin
writeln('bLoadTextFile failed.');
end;
end;
if bOk then
begin
writeln('Loaded XML, Now On to Tokenizing it.');
bOk:=XML.bParseXML(saXML);
if bOk then
begin
writeln('BEGIN ---- XML RENDER');
writeln(XML.saXML(false,false));
writeln('END ---- XML RENDER');
end;
writeln('XML.ListCount:',XML.ListCount);
if xml.movefirst then
begin
repeat
writeln('Name:'+xml.Item_saName+' Value:'+XML.Item_saValue+' lpPtr:',uint(XML.Item_lpPtr));
until not XML.MoveNext;
end;
end;
writeln('XML.saLastError:'+XML.saLastError);
XML.Destroy;
result:=bOk;
end;
//=============================================================================
//=============================================================================
function bTest_JFC_XML_From_Scratch: boolean;
//=============================================================================
var
XML: JFC_XML;
XMLNode: JFC_XML;
bOk: boolean;
begin
bOk:=true;
XML:=JFC_XML.Create;
XML.appenditem_saName('jmenu');
XMLNode:=JFC_XML.Create;
XMLNode.AppendItem_saName_N_saValue('test','data');
//JFC_XMLITEM(XMLNode.lpItem).Attr.AppendItem_saName_N_saValue('attrib','some value');
XML.Item_lpPtr:=XMLNode;
writeln(XML.saXML(false,false));
XML.Destroy;
result:=bOk;
end;
//=============================================================================
{
<synchronize>
<entitylist>
<entity name="task">
<upload>yes</upload>
<download>yes</download>
<transactional>no</transactional>
</entity>
<entity name="calls">
<upload>yes</upload>
<download>yes</download>
<transactional>no</transactional>
</entity>
<entity name="meetings">
<upload>yes</upload>
<download>yes</download>
<transactional>no</transactional>
</entity>
</entitylist>
</synchronize>
}
//=============================================================================
function bTest_JFC_XML_SpecificData: boolean;
//=============================================================================
var
XML: JFC_XML;
bOk: boolean;
saXML: ansistring;
begin
XML:=JFC_XML.Create;
//saXML:='<synchronize><entitylist><entity name="task"><upload>yes</upload><download>yes</download><transactional>no</transactional></entity>'+
// '<entity name="calls"><upload>yes</upload><download>yes</download><transactional>no</transactional></entity><entity name="meetings">'+
// '<upload>yes</upload><download>yes</download><transactional>no</transactional></entity></entitylist></synchronize>';
saXML:='<xml>'+csCRLF+
' <updates>'+csCRLF+
' <program name="jegasedit" version="0" revision="68" />'+csCRLF+
' <program name="springlitimer" version="0" revision="2" />'+csCRLF+
' </updates>'+csCRLF+
'</xml>'+csCRLF;
bOk:=XML.bParseXML(saXML);
if bOk then
begin
writeln('BEGIN ---- XML RENDER');
writeln(XML.saXML(false,false));
writeln('END ---- XML RENDER');
end;
writeln('XML.ListCount:',XML.ListCount);
if xml.movefirst then
begin
repeat
writeln('Name:'+xml.Item_saName+' Value:'+XML.Item_saValue+' lpPtr:',uint(XML.Item_lpPtr));
until not XML.MoveNext;
end;
writeln('XML.saLastError:'+XML.saLastError);
XML.Destroy;
result:=bOk;
end;
//=============================================================================
//=============================================================================
// Main Program Starts Here
//=============================================================================
var bGood: boolean;
Begin
bGood:=true;
if bGood then
begin
bGood:=bTest_JFC_XML_From_Scratch;
if not bGood then
begin
writeln('failed: bTest_JFC_XML_From_Scratch');
end;
end;
if bGood then
begin
bGood:=bTest_JFC_XML_SpecificData;
if not bGood then
begin
writeln('failed: bTest_JFC_XML_SpecificData')
end;
end;
if bGood then
begin
gsaFilename:='.'+DOSSLASH+'data'+DOSSLASH+'test.xml';
Writeln('Testing bTest_JFC_XML_From_File('''+gsaFilename+''')');
bGood:=bTest_JFC_XML_From_File(gsaFilename);
if not bGood then
begin
writeln('failed: bTest_JFC_XML_From_File('''+gsaFilename+''')');
end;
end;
if bGood then
begin
gsaFilename:='.'+DOSSLASH+'data'+DOSSLASH+'test2.xml';
Writeln('Testing bTest_JFC_XML_From_File('''+gsaFilename+''')');
bGood:=bTest_JFC_XML_From_File(gsaFilename);
if not bGood then
begin
writeln('failed: bTest_JFC_XML_From_File('''+gsaFilename+''')');
end;
end;
if bGood then
begin
gsaFilename:='.'+DOSSLASH+'data'+DOSSLASH+'testbig.xml';
Writeln('Testing bTest_JFC_XML_From_File('''+gsaFilename+''')');
bGood:=bTest_JFC_XML_From_File(gsaFilename);
if not bGood then
begin
writeln('failed: bTest_JFC_XML_From_File('''+gsaFilename+''')');
end;
end;
if bGood then
begin
Writeln('All Tests PASSED!');
end;
End.
//=============================================================================
//*****************************************************************************
// eof
//*****************************************************************************