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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/* xb_test_funcs.cpp
XBase64 Software Library
Copyright (c) 1997,2003,2014,2022 Gary A Kunkel
The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
Email Contact:
XDB-devel@lists.sourceforge.net
XDB-users@lists.sourceforge.net
*/
// This program tests the xb functions
// usage: xb_test_funcs QUITE|NORMAL|VERBOSE
#include "xbase.h"
using namespace xb;
#include "tstfuncs.cpp"
/**************************************************************************/
int main( int argCnt, char **av )
{
xbInt16 iRc = 0;
xbInt16 rc2 = 0;
xbInt16 po = 1; /* print option */
/* 0 - QUIET */
/* 1 - NORMAL */
/* 2 - VERBOSE */
if( argCnt > 1 ) {
if( av[1][0] == 'Q' )
po = 0;
else if( av[1][0] == 'V' )
po = 2;
}
xbSchema MyRecord[] =
{
{ "NUM1", XB_NUMERIC_FLD, 9, 2 },
{ "DATE1", XB_DATE_FLD, 8, 0 },
{ "DATE2", XB_DATE_FLD, 8, 0 },
{ "",0,0,0 }
};
xbXBase x;
xbDbf * MyFile;
xbDate d;
xbString sResult;
xbDate dtResult;
xbDouble dResult;
xbBool bResult;
xbDate dtIn( "19890209" );
#ifdef XB_LOGGING_SUPPORT
x.EnableMsgLogging();
if( po ){
std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl;
}
xbString sMsg;
sMsg.Sprintf( "Program [%s] initializing...", av[0] );
x.WriteLogMessage( sMsg );
#endif
x.SetDataDirectory( PROJECT_DATA_DIR );
x.EnableMsgLogging();
InitTime();
if( po > 0 ){
std::cout << "XBase Expression testing program.." << std::endl;
std::cout << "This program tests the XBase expression logic." << std::endl;
std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl;
}
#ifdef XB_DBF4_SUPPORT
MyFile = new xbDbf4( &x ); /* version 4 dbf file */
#else
MyFile = new xbDbf3( &x ); /* version 3 dbf file */
#endif
rc2 = MyFile->CreateTable( "Functest.DBF", "ExpTest", MyRecord, XB_OVERLAY, XB_MULTI_USER );
iRc += TestMethod( po, "CreateTable()", rc2, XB_NO_ERROR );
iRc += TestMethod( po, "PutField()", MyFile->PutFloatField( "NUM1", 5 ), XB_NO_ERROR );
iRc += TestMethod( po, "PutField()", MyFile->PutField( "DATE1", "19890303" ), XB_NO_ERROR );
iRc += TestMethod( po, "PutField()", MyFile->PutField ( "DATE2", "20120708" ), XB_NO_ERROR );
#ifdef XB_LOCKING_SUPPORT
MyFile->SetAutoLock( xbFalse );
#endif // XB_LOCKING_SUPPORT
iRc += TestMethod( po, "AppendRecord()", MyFile->AppendRecord(), XB_NO_ERROR );
iRc += TestMethod( po, "ABS( -222, dResult )", x.ABS( -222, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "ABS( -222, dResult )", -222, -222 );
iRc += TestMethod( po, "ABS( 333, dResult )", x.ABS( 333, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "ABS( 333, dResult )", 333, 333 );
iRc += TestMethod( po, "x.ALLTRIM( \" zzz \", sResult )", x.ALLTRIM( " zzz ", sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.ALLTRIM( \" zzz \", sResult )", sResult, "zzz", 3 );
iRc += TestMethod( po, "ASC( \"A\", dResult )", x.ASC( "A", dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "ASC( \"A\" )", dResult, (xbDouble) 65 );
iRc += TestMethod( po, "ASC( \"B\", dResult )", x.ASC( "B", dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "ASC( \"B\" )", dResult, (xbDouble) 66 );
iRc += TestMethod( po, "AT( \"ABC\", \"XYZABC\", 4 )", x.AT( "ABC", "XYZABC", dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "AT( \"ABC\", \"XYZABC\", 4 )", dResult, (xbDouble) 4 );
iRc += TestMethod( po, "CDOW( dtIn, sResult )", x.CDOW( dtIn, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "CDOW( dtIn, sResult )", sResult, "Thursday", 8 );
iRc += TestMethod( po, "CHR( 101, sResult )", x.CHR( 101, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "CHR( 101, sResult )", sResult, "e", 1 );
dtIn = "19870103";
iRc += TestMethod( po, "CMONTH( dtIn, sResult )", x.CMONTH( dtIn, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "CMONTH( dtIn, sResult )", sResult, "January", 7 );
iRc += TestMethod( po, "CTOD( \"01\\03\\87\", dtResult )", x.CTOD( "01\\03\\87", dtResult ), XB_NO_ERROR );
iRc += TestMethod( po, "CTOD( \"01\\03\\87\", dtResult )", dtResult.Str(), "19870103", 8 );
iRc += TestMethod( po, "DATE( dtResult )", x.DATE( dtResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DATE( dtResult )", dtResult.Str(), d.Str(), 8 );
iRc += TestMethod( po, "DAY(\"19870103\", dResult )", x.DAY( "19870103", dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DAY(\"19870103\", dResult )", dResult, (xbDouble) 3 );
iRc += TestMethod( po, "DEL( MyFile, sResult )", x.DEL( MyFile, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DEL( MyFile, sResult )", sResult, " ", 1 );
iRc += TestMethod( po, "DELETED( MyFile, bResult )", x.DELETED( MyFile, bResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DELETED( MyFile, bResult )", (xbInt32) bResult, xbFalse );
iRc += TestMethod( po, "DeleteRecord()", MyFile->DeleteRecord(), XB_NO_ERROR );
iRc += TestMethod( po, "DEL( MyFile, sResult )", x.DEL( MyFile, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DEL( MyFile, sResult )", sResult, "*", 1 );
iRc += TestMethod( po, "DELETED( MyFile, bResult )", x.DELETED( MyFile, bResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DELETED( MyFile, bResult )", (xbInt32) bResult, xbTrue );
iRc += TestMethod( po, "UndeleteRecord()", MyFile->UndeleteRecord(), XB_NO_ERROR );
iRc += TestMethod( po, "DESCEND(\"ABCDE\", sResult )", x.DESCEND( "ABCDE", sResult ), XB_NO_ERROR );
char sDescendResult[6]; // = "¾½¼»º";
sDescendResult[0] = (char) 0xBE;
sDescendResult[1] = (char) 0xBD;
sDescendResult[2] = (char) 0xBC;
sDescendResult[3] = (char) 0xBB;
sDescendResult[4] = (char) 0xBA;
sDescendResult[5] = (char) 0x00;
iRc += TestMethod( po, "DESCEND(\"ABCDE\", sResult )", sResult, sDescendResult, 5 );
iRc += TestMethod( po, "DESCEND( 12345, dResult )", x.DESCEND( 12345, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DESCEND( 12345, dResult )", dResult, (xbDouble) -12345 );
dtIn = "19890303";
iRc += TestMethod( po, "DESCEND( dtIn, dtResult )", x.DESCEND( dtIn, dtResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DESCEND( dtIn, dtResult )", dtResult.Str(), "29101031", 8 );
dtIn = "20120708";
iRc += TestMethod( po, "DESCEND( dtIn, dtResult )", x.DESCEND( dtIn, dtResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DESCEND( dtIn, dtResult )", dtResult.Str(), "28870625" , 8 );
dtIn = "20171014";
iRc += TestMethod( po, "DOW( dtIn, dResult )", x.DOW( dtIn, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DOW(\"20171015\", dResult )", dResult, (xbDouble) 0 );
dtIn++;
iRc += TestMethod( po, "DOW( dtIn, dResult )", x.DOW( dtIn, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DOW(\"20171016\", dResult )", dResult, (xbDouble) 1 );
dtIn++;
iRc += TestMethod( po, "DOW( dtIn, dResult )", x.DOW( dtIn, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DOW(\"20171021\", dResult )", dResult, (xbDouble) 2 );
dtIn = "20000101";
iRc += TestMethod( po, "DTOC( dtIn, sResult )", x.DTOC( dtIn, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DTOC( dtIn, sResult )", sResult, "01/01/00", 8 );
iRc += TestMethod( po, "DTOS( dtIn, sResult )", x.DTOS( dtIn, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "DTOS( dtIn, sResult )", sResult, "20000101", 8 );
iRc += TestMethod( po, "EXP( 1, dResult )", x.EXP( 1, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "EXP( 1, dResult )", dResult, 2.71828, .001 );
iRc += TestMethod( po, "x.INT( 621.5, dResult )", x.INT( 621.5, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.INT( 621.5, dResult )", dResult, (xbDouble) 621 );
iRc += TestMethod( po, "x.ISALPHA( \"1\", bResult )", x.ISALPHA( "1", bResult ), 0 );
iRc += TestMethod( po, "x.ISALPHA( \"1\", bResult )", (xbInt32) bResult, xbFalse );
iRc += TestMethod( po, "x.ISALPHA( \"A\", bResult )", x.ISALPHA( "A", bResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.ISALPHA( \"A\", bResult )", (xbInt32) bResult, xbTrue );
iRc += TestMethod( po, "x.ISLOWER( \"A\", bResult )", x.ISLOWER( "A", bResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.ISLOWER( \"A\", bResult )", bResult, xbFalse );
iRc += TestMethod( po, "x.ISLOWER( \"a\", bResult )", x.ISLOWER( "a", bResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.ISLOWER( \"a\", bResult )", bResult, xbTrue );
iRc += TestMethod( po, "x.ISUPPER( \"A\", bResult )", x.ISUPPER( "A", bResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.ISUPPER( \"A\", bResult )", bResult, xbTrue );
iRc += TestMethod( po, "x.ISUPPER( \"a\", bResult )", x.ISUPPER( "a", bResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.ISUPPER( \"a\", bResult )", bResult, xbFalse );
iRc += TestMethod( po, "x.LEFT( \"STRING\", 3, sResult )", x.LEFT( "STRING", 3, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.LEFT( \"STRING\", 3, sResult )", sResult, "STR", 3 );
iRc += TestMethod( po, "x.LEN( \"AAAAA\", dResult )", x.LEN( "AAAAA", dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.LEN( \"AAAAA\", dResult )", dResult, (xbDouble) 5 );
iRc += TestMethod( po, "x.LOG( 2, dResult )", x.LOG( 2, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.LOG( 2, dResult )", dResult, (xbDouble) 0.69314700, .0001 );
iRc += TestMethod( po, "x.LOWER( \"AAAA\", sResult )", x.LOWER( "AAAA", sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.LOWER( \"AAAA\", sResult )", sResult, "aaaa", 4 );
iRc += TestMethod( po, "x.LTRIM( \" xxxxxx\" )", x.LTRIM( " xxxxxx", sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.LTRIM( \" xxxxxx\" )", sResult, "xxxxxx", 6 );
iRc += TestMethod( po, "x.MAX( 10, 27, dResult )", x.MAX( 10, 27, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.MAX( 10, 27, dResult )", dResult, (xbDouble) 27 );
iRc += TestMethod( po, "x.MIN( 10, 5, dResult )", x.MIN( 10, 5, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.MIN( 10, 5, dResult )", dResult, (xbDouble) 5 );
iRc += TestMethod( po, "x.MONTH( dtIn, dResult )", x.MONTH( dtIn, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.MONTH( dtIn, dResult )", dResult, (xbDouble) 1 );
iRc += TestMethod( po, "x.RECCOUNT( MyFile, dResult)", x.RECNO( MyFile, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.RECCOUNT( MyFile, dResult)", dResult, (xbDouble) 1 );
iRc += TestMethod( po, "x.RECNO( MyFile, dResult)", x.RECNO( MyFile, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.RECNO( MyFile, dResult)", dResult, (xbDouble) 1 );
iRc += TestMethod( po, "x.REPLICATE( \"abc\", 3, sResult )", x.REPLICATE( "abc", 3, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.REPLICATE( \"abc\", 3, sResult )", sResult, "abcabcabc", 9 );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", x.RIGHT( "STRING", 3, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", sResult, "ING", 3 );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", x.RIGHT( "STRING", 5, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", sResult, "TRING", 5 );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", x.RIGHT( "STRING", 6, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", sResult, "STRING", 6 );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", x.RIGHT( "STRING", 7, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.RIGHT( \"STRING\", 3, sResult )", sResult, "STRING", 6 );
iRc += TestMethod( po, "x.RTRIM( \"zzz \", sResult )", x.RTRIM( "zzz ", sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.RTRIM( \"zzz \", sResult )", sResult, "zzz", 3 );
iRc += TestMethod( po, "x.TRIM( \"aaa \", sResult )", x.TRIM( "aaa ", sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.TRIM( \"aaa \", sResult )", sResult, "aaa", 3 );
iRc += TestMethod( po, "x.SPACE( 3, sResult )", x.SPACE( 3, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.SPACE( 3, sResult )", sResult, " ", 3 );
iRc += TestMethod( po, "x.SQRT( 9, dResult )", x.SQRT( 9, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.SQRT( 9, dResult )", dResult, (xbDouble) 3 );
iRc += TestMethod( po, "x.STOD( \"20000101\", dtResult )", x.STOD( "20000101", dtResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STOD( \"20000101\", dtResult )",dtResult.Str(), "20000101", 8 );
xbString sPadChar = " ";
iRc += TestMethod( po, "x.STR( 2001, 4, 0, sPadChar, sResult )", x.STR( 2001, 4, 0, sPadChar, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( 2001, 4, 0, sPadChar, sResult )", sResult, "2001", 4 );
iRc += TestMethod( po, "x.STR( 2002, 3, 0, sPadChar, sResult )", x.STR( 2002, 3, 0, sPadChar, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( 2002, 3, 0, sPadChar, sResult )", sResult, "***", 3 );
iRc += TestMethod( po, "x.STR( 203.2, 6, 2, sPadChar, sResult )", x.STR( 203.2, 6, 2, sPadChar, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( 203.2, 6, 2, sPadChar, sResult )", sResult, "203.20", 6 );
iRc += TestMethod( po, "x.STR( 204.11, 8, 2, sPadChar, sResult )", x.STR( 204.11, 8, 2, sPadChar, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( 204.11, 8, 2, sPadChar, sResult )", sResult, " 204.11", 8 );
iRc += TestMethod( po, "x.STR( -205.45, 8, 2, sPadChar, sResult )", x.STR( -205.45, 8, 2, sPadChar, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( -205.45, 8, 2, sPadChar, sResult )", sResult, " -205.45", 8 );
iRc += TestMethod( po, "x.STR( -306.45, 8, 2, sPadChar, sResult )", x.STR( -306.45, 8, 2, sPadChar, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( -306.45, 8, 2, sPadChar, sResult )", sResult, " -306.45", 8 );
iRc += TestMethod( po, "x.STR( 6.56, 5, 0, sResult )", x.STR( 6.56, 5, 0, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( 6.56, 5, 0, sResult )", sResult, " 7", 5 );
iRc += TestMethod( po, "x.STR( 7.77, 5, sResult )", x.STR( 7.77, 5, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( 7.77, 5, sResult )", sResult, " 8", 5 );
iRc += TestMethod( po, "x.STR( 8, sResult )", x.STR( 8, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( 8, sResult )", sResult, " 8", 10 );
sPadChar = "0";
iRc += TestMethod( po, "x.STR( -5.2, 10, 2, sPadChar, sResult )", x.STR( -5.2, 10, 2, sPadChar, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STR( -5.2, 10, 2, sPadChar, sResult )", sResult, "00000-5.20", 10 );
iRc += TestMethod( po, "x.STRZERO( 8, 8, 0, sResult )", x.STRZERO( 8, 8, 0, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STRZERO( 8, 8, 0, sResult )", sResult, "00000008", 8 );
iRc += TestMethod( po, "x.STRZERO( -8, 8, 0, sResult )", x.STRZERO( -8, 8, 0, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STRZERO( -8, 8, 0, sResult )", sResult, "-0000008", 8 );
iRc += TestMethod( po, "x.STRZERO( -205.45, 10, 3 )", x.STRZERO( -205.45, 10, 3, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STRZERO( -205.45, 10, 3 )", sResult, "-00205.450", 10 );
iRc += TestMethod( po, "x.STRZERO( -205.45, 3, 1 )", x.STRZERO( -205.45, 3, 1, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.STRZERO( -205.45, 3, 1 )", sResult, "***", 3 );
iRc += TestMethod( po, "x.SUBSTR( \"TESTSTRING\", 5, 2, sResult )", x.SUBSTR( "TESTSTRING", 5, 2, sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.SUBSTR( \"TESTSTRING\", 5, 2, sResult )", sResult, "ST", 2 );
iRc += TestMethod( po, "x.UPPER( \"abababa\", sResult )", x.UPPER( "abababa", sResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.UPPER( \"abababa\", sResult )", sResult, "ABABABA", 7 );
iRc += TestMethod( po, "x.VAL( \"65\", dResult )", x.VAL( "65", dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.VAL( \"65\", dResult )", dResult, (xbDouble) 65 );
iRc += TestMethod( po, "x.YEAR( dtIn, dResult )", x.YEAR( dtIn, dResult ), XB_NO_ERROR );
iRc += TestMethod( po, "x.YEAR( dtIn, dResult )", dResult, (xbDouble) 2000 );
iRc += TestMethod( po, "Close()", MyFile->Close(), XB_NO_ERROR );
delete MyFile;
if( po > 0 || iRc < 0 )
fprintf( stdout, "Total Errors = %d\n", iRc * -1 );
#ifdef XB_LOGGING_SUPPORT
sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], iRc * -1 );
x.WriteLogMessage( sMsg );
#endif
return iRc;
}
|