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
|
/* xb_test_filter.cpp
XBase64 Software Library
Copyright (c) 1997,2003,2014,2020,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 class xbIxFilter
// usage: xb_test_filter QUITE|NORMAL|VERBOSE
#include "xbase.h"
using namespace xb;
#include "tstfuncs.cpp"
int main( int argCnt, char **av )
{
int iRc = 0;
int iRc2 = 0;
int iPo = 1; /* print option */
/* 0 - QUIET */
/* 1 - NORMAL */
/* 2 - VERBOSE */
if( argCnt > 1 ) {
if( av[1][0] == 'Q' )
iPo = 0;
else if( av[1][0] == 'V' )
iPo = 2;
}
xbSchema MyV4Record[] =
{
{ "CFLD", XB_CHAR_FLD, 6, 0 },
{ "NFLD", XB_NUMERIC_FLD, 6, 0 },
{ "ZFLD", XB_CHAR_FLD, 1, 0 },
{ "",0,0,0 }
};
xbXBase x;
#ifdef XB_LOGGING_SUPPORT
x.EnableMsgLogging();
if( iPo ){
std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl;
}
xbString sMsg;
sMsg.Sprintf( "Program [%s] initializing...", av[0] );
x.WriteLogMessage( sMsg );
x.SetLogSize( 1000000 );
#endif
x.SetDataDirectory( PROJECT_DATA_DIR );
x.EnableMsgLogging();
char c;
xbString s;
xbInt32 lRecCnt = 0;
iRc = 0;
if( iPo > 0 )
std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl;
xbDbf *V4Dbf = new xbDbf4( &x );
iRc2 = V4Dbf->CreateTable( "TestFilt.DBF", "TestFilter", MyV4Record, XB_OVERLAY, XB_MULTI_USER );
iRc += TestMethod( iPo, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR );
#ifdef XB_NDX_SUPPORT
xbIx *ixPtr;
void *ndx;
iRc2 = V4Dbf->CreateTag( "NDX", "TestFilt.NDX", "CFLD", "", 0, 0, XB_OVERLAY, &ixPtr, &ndx );
iRc += TestMethod( iPo, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR );
if( iRc2 )
x.DisplayError( iRc2 );
#endif // XB_NDX_SUPPORT
if( iRc2 )
x.DisplayError( iRc2 );
for( xbUInt16 i = 0; i < 5 && iRc == XB_NO_ERROR; i++ ){
// for( xbUInt16 j = 0; j < 26 && iRc == XB_NO_ERROR; j++ ){
for( xbInt16 j = 25; j >= 0 && iRc == XB_NO_ERROR; j-- ){
c = j + 65;
s = c;
s.PadRight( c, (xbUInt32) i + 1 );
V4Dbf->BlankRecord();
V4Dbf->PutField( "CFLD", s );
V4Dbf->PutLongField( "NFLD", ++lRecCnt );
iRc = V4Dbf->AppendRecord();
}
}
iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "" ), XB_NO_ERROR );
xbFilter f1( &x, V4Dbf );
xbString sMyFilterExpression = "LEFT( CFLD, 2 ) = 'YY'";
iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR );
iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "" ), XB_NO_ERROR );
iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 28 );
iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 54 );
iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 80 );
iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 106 );
iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 80 );
sMyFilterExpression = "LEFT( CFLD, 2 ) = 'CC'";
iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 50 );
iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 );
iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 102 );
iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 128 );
iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 102 );
#ifdef XB_NDX_SUPPORT
f1.SetLimit( 0 );
// change things up a bit
iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 32 ), XB_NO_ERROR );
iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 52 ), XB_NO_ERROR );
iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 76 ), XB_NO_ERROR );
iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetRecord()", V4Dbf->GetRecord( 103 ), XB_NO_ERROR );
iRc += TestMethod( iPo, "PutField()", V4Dbf->PutField( "ZFLD", "Z" ), XB_NO_ERROR );
iRc += TestMethod( iPo, "Commit()", V4Dbf->Commit(), XB_NO_ERROR );
iRc += TestMethod( iPo, "SetCurTag()", V4Dbf->SetCurTag( "TestFilt" ), XB_NO_ERROR );
sMyFilterExpression = "ZFLD = 'Z'";
iRc += TestMethod( iPo, "Set()", f1.Set( sMyFilterExpression ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetFirstRecord()", f1.GetFirstRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 52 );
iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 103 );
iRc += TestMethod( iPo, "GetNextRecord()", f1.GetNextRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 );
iRc += TestMethod( iPo, "GetLast()", f1.GetLastRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 32 );
iRc += TestMethod( iPo, "GetPrev()", f1.GetPrevRecord(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4Dbf->GetCurRecNo(), 76 );
#endif // XB_NDX_SUPPORT
iRc += TestMethod( iPo, "Close()", V4Dbf->Close(), XB_NO_ERROR );
delete V4Dbf;
if( iPo > 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, 2 );
#endif
return iRc;
}
|