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
|
/* xb_test_tblmgr.cpp
XBase64 Software Library
Copyright (c) 1997,2003,2014,2022,2023 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 table manager functions.
// usage: xb_test_tblmgr QUITE|NORMAL|VERBOSE
#include "xbase.h"
using namespace xb;
#include "tstfuncs.cpp"
int main( int argCnt, char **av )
{
int iRc = 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;
}
xbXBase x;
#ifdef XB_LOGGING_SUPPORT
x.SetLogDirectory( PROJECT_LOG_DIR );
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 );
#endif
InitTime();
if( iPo == 2 ){
std::cout << "DisplayError Test ==> ";
x.DisplayError( 0 );
#ifdef WIN32
std::cout << "WIN32 environment" << std::endl;
#else
std::cout << "Not WIN32 environment" << std::endl;
#endif
}
xbDbf * d1;
xbDbf * d2;
#if defined (XB_DBF3_SUPPORT )
d1 = new xbDbf3( &x );
#elif defined( XB_DBF4_SUPPORT )
d1 = new xbDbf4( &x );
#else
std::cout << "No dbf file support built into library" << std::endl;
return -1;
#endif
iRc += TestMethod( iPo, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableC" ), 0 );
iRc += TestMethod( iPo, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableA" ), 0 );
iRc += TestMethod( iPo, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableB" ), 0 );
iRc += TestMethod( iPo, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableD" ), 0 );
// Next line should generate an exception
iRc += TestMethod( iPo, "AddTblToTblLst()", x.AddTblToTblList( d1, "TestTableC" ), XB_DUP_TABLE_OR_ALIAS );
std::cout << "**** Next list should have one each of TestTableA, B, C, D sorted in alpha order ****" << std::endl;
x.DisplayTableList();
d2 = (xbDbf *) x.GetDbfPtr( "TestTableA" );
if( d2 )
std::cout << "[PASS] GetDbfPtr()" << std::endl;
else{
std::cout << "[FAIL] GetDbfPtr()" << std::endl;
iRc--;
}
std::cout << "cp0\n";
x.SetDataDirectory( "/ABCDEFG/" );
#ifdef WIN32
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG\\", 9 );
#else
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG/", 9 );
#endif
std::cout << "cp1\n";
x.SetDataDirectory( "/ABCDEFG" );
#ifdef WIN32
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG", 8 );
#else
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG", 8 );
#endif
x.SetDataDirectory( "\\ABCDEFG\\");
#ifdef WIN32
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG\\", 9 );
#else
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG/", 9 );
#endif
x.SetDataDirectory( "\\ABCDEFG" );
#ifdef WIN32
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "\\ABCDEFG", 8 );
#else
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "/ABCDEFG", 8 );
#endif
x.SetDataDirectory( "ABCDEFG" );
iRc += TestMethod( iPo, "Set/GetDataDirectory()", x.GetDataDirectory(), "ABCDEFG", 7 );
iRc += TestMethod( iPo, "RemoveTblFromDbList()", x.RemoveTblFromTblList( "TestTableB" ), 0 );
iRc += TestMethod( iPo, "RemoveTblFromDbList()", x.RemoveTblFromTblList( "TestTableB" ), XB_NOT_FOUND );
std::cout << "**** Next list should not have TestTableB in it ****" << std::endl;
x.DisplayTableList();
iRc += TestMethod( iPo, "RemoveTblFromDbList()", x.RemoveTblFromTblList( "TestTableA" ), 0 );
iRc += TestMethod( iPo, "RemoveTblFromDbList()", x.RemoveTblFromTblList( "TestTableC" ), 0 );
iRc += TestMethod( iPo, "RemoveTblFromDbList()", x.RemoveTblFromTblList( "TestTableD" ), 0 );
delete d1;
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;
}
|