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
|
/* xb_test_ndx.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 class xbIxNdx
// usage: xb_test_ndx QUITE|NORMAL|VERBOSE
#include "xbase.h"
using namespace xb;
#include "tstfuncs.cpp"
int main( int argCnt, char **av )
{
int iRc = 0;
int iRc2;
int iPo = 1; /* print option */
/* 0 - QUIET */
/* 1 - NORMAL */
/* 2 - VERBOSE */
xbString sMsg;
char c;
xbString s;
if( argCnt > 1 ) {
if( av[1][0] == 'Q' )
iPo = 0;
else if( av[1][0] == 'V' )
iPo = 2;
}
xbSchema MyV4Record[] =
{
{ "CITY", XB_CHAR_FLD, 100, 0 },
{ "STATE", XB_CHAR_FLD, 2, 0 },
{ "ZIP", XB_NUMERIC_FLD, 9, 0 },
{ "DATE1", XB_DATE_FLD, 8, 0 },
{ "",0,0,0 }
};
xbXBase x;
#ifdef XB_LOGGING_SUPPORT
x.EnableMsgLogging();
if( iPo ){
std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl;
}
sMsg.Sprintf( "Program [%s] initializing...", av[0] );
x.WriteLogMessage( sMsg );
#endif
x.SetDataDirectory( PROJECT_DATA_DIR );
x.EnableMsgLogging();
x.SetMultiUser( false );
InitTime();
if( iPo > 0 )
std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl;
xbFile f( &x );
xbIx *pIx;
void *pTag;
xbDate dt = "19890209";
xbString sKey;
xbDbf *V4DbfX1 = new xbDbf4( &x );
iRc2 = V4DbfX1->CreateTable( "TMDXDB01.DBF", "TestMdxX2", MyV4Record, XB_OVERLAY, XB_MULTI_USER );
iRc += TestMethod( iPo, "CreateTable(1)", iRc2, 0 );
/*
CreateTag( const xbString &sIxType, const xbString &sName, const xbString &sKey, const xbString &sFilter,
xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverLay, xbIx **xbIxOut, void **vpTagOut );
*/
iRc2 = V4DbfX1->CreateTag( "MDX", "CITY_TAGA", "CITY", "", 0, 0, XB_OVERLAY, &pIx, &pTag );
iRc += TestMethod( iPo, "CreateTag(1)", iRc2, 0 );
iRc2 = V4DbfX1->CreateTag( "MDX", "ZIP_TAG", "ZIP", "", xbTrue, 0, XB_OVERLAY, &pIx, &pTag );
iRc += TestMethod( iPo, "CreateTag(2)", iRc2, 0 );
iRc2 = V4DbfX1->CreateTag( "MDX", "DATE_TAG", "DATE1", "", 0, xbTrue, XB_OVERLAY, &pIx, &pTag );
iRc += TestMethod( iPo, "CreateTag(3)", iRc2, 0 );
// std::cout << "Cur Tag Name = " << V4DbfX1->GetCurTagName().Str() << "\n";
// xbDouble d = 4000;
// iRc2 = V4DbfX1->Find( d );
// std::cout << iRc2 << "\n";
// something in th following block of code causing issues
xbInt32 uZip = 10000;
for( xbUInt16 i = 0; i < 35; i++ ){
for( xbUInt16 j = 0; j < 14; j++ ){
c = j + 65;
s = c;
s.PadRight( c, (xbUInt32) i + 1 );
//std::cout << "*********** adding s=[" << s.Str() << "] length = " << s.Len() << "\n";
iRc2 = V4DbfX1->BlankRecord();
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "BlankRecord()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->PutField( "CITY", s );
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->PutLongField( "ZIP", uZip++ );
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->PutDateField( "DATE1", dt );
dt++;
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->AppendRecord();
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "AppendRecord()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->Commit();
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "Commit()", iRc2, XB_NO_ERROR );
}
}
iRc += TestMethod( iPo, "CheckTagIntegrity()", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR );
// attempt to add a dup key, should fail with XB_KEY_NOT_UNIQUE
iRc2 = V4DbfX1->BlankRecord();
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "BlankRecord()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->PutField( "CITY", "Tampa" );
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->PutLongField( "ZIP", uZip++ );
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR );
dt.Set( "19890209" );
iRc2 = V4DbfX1->PutDateField( "DATE1", dt );
dt++;
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "PutField()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->AppendRecord();
if( iRc2 != XB_KEY_NOT_UNIQUE )
iRc += TestMethod( iPo, "AppendRecord()", iRc2, XB_NO_ERROR );
iRc2 = V4DbfX1->Abort();
if( iRc2 != XB_NO_ERROR )
iRc += TestMethod( iPo, "Abort()", iRc2, XB_NO_ERROR );
iRc += TestMethod( iPo, "DeleteTag()", V4DbfX1->DeleteTag( "MDX", "CITY_TAGA" ), XB_NO_ERROR );
iRc += TestMethod( iPo, "CheckTagIntegrity()", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR );
iRc2 = V4DbfX1->CreateTag( "MDX", "CITY_TAGF", "CITY", ".NOT. DELETED()", 0, 0, XB_OVERLAY, &pIx, &pTag );
iRc += TestMethod( iPo, "CreateTag(4)", iRc2, 0 );
iRc2 = V4DbfX1->SetCurTag( "CITY_TAGF" );
iRc += TestMethod( iPo, "SetCurTag()", iRc2, XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurTagName()", V4DbfX1->GetCurTagName().Str(), "CITY_TAGF", 9 );
iRc += TestMethod( iPo, "CheckTagIntegrity()", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_INVALID_INDEX );
iRc2 = V4DbfX1->Reindex( 0 );
iRc += TestMethod( iPo, "Reindex( 0 )", iRc2, XB_NO_ERROR );
iRc += TestMethod( iPo, "CheckTagIntegrity()", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurTagName()", V4DbfX1->GetCurTagName().Str(), "CITY_TAGF", 9 );
iRc2 = V4DbfX1->Reindex( 1 );
iRc += TestMethod( iPo, "Reindex( 1 )", iRc2, XB_NO_ERROR );
iRc += TestMethod( iPo, "CheckTagIntegrity()", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR );
// delete everything, all keys should be removed from the filtered index
iRc += TestMethod( iPo, "DeleteAll(0)", V4DbfX1->DeleteAll( 0 ), XB_NO_ERROR );
iRc += TestMethod( iPo, "Commit()", V4DbfX1->Commit(), XB_NO_ERROR );
iRc += TestMethod( iPo, "CheckTagIntegrity()", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR );
// undelete everything, all keys should be added back into the filtered index
iRc += TestMethod( iPo, "DeleteAll(1)", V4DbfX1->DeleteAll( 1 ), XB_NO_ERROR );
iRc += TestMethod( iPo, "Commit()", V4DbfX1->Commit(), XB_NO_ERROR );
iRc += TestMethod( iPo, "CheckTagIntegrity()", V4DbfX1->CheckTagIntegrity( 1, 2 ), XB_NO_ERROR );
// std::cout << "Cur Tag Name = " << V4DbfX1->GetCurTagName().Str() << "\n";
sKey = "abc";
iRc += TestMethod( iPo, "Find()", V4DbfX1->Find( sKey ), XB_NOT_FOUND );
sKey = "EEEEE";
iRc += TestMethod( iPo, "Find()", V4DbfX1->Find( sKey ), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4DbfX1->GetCurRecNo(), (xbInt32) 61 );
iRc += TestMethod( iPo, "GetNextKey()", V4DbfX1->GetNextKey(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4DbfX1->GetCurRecNo(), (xbInt32) 75 );
iRc += TestMethod( iPo, "GetPrevKey()", V4DbfX1->GetPrevKey(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4DbfX1->GetCurRecNo(), (xbInt32) 61 );
iRc += TestMethod( iPo, "GetLastKey()", V4DbfX1->GetLastKey(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4DbfX1->GetCurRecNo(), (xbInt32) 490 );
iRc += TestMethod( iPo, "GetFirstKey()", V4DbfX1->GetFirstKey(), XB_NO_ERROR );
iRc += TestMethod( iPo, "GetCurRecNo()", (xbInt32) V4DbfX1->GetCurRecNo(), (xbInt32) 1 );
x.CloseAllTables();
delete V4DbfX1;
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 );
#endif
return iRc;
}
|