summaryrefslogtreecommitdiff
path: root/src/tests/xb_test_ndx2.cpp
blob: f406b052f8adc971a6aa9b37597c27f3d9f2d5ef (plain)
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
/* xb_test_ndx2.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:

    xb64-devel@lists.sourceforge.net
    xb64-users@lists.sourceforge.net

*/

// This program tests the class xbIxNdx

// usage:   xb_test_ndx QUITE|NORMAL|VERBOSE



// fix me - this program needs to test GetUnique

#include "xbase.h"

using namespace xb;

#include "tstfuncs.cpp"


int main( int argCnt, char **av )
{
  int iRc = 0;
  int iRc2 = 0;
  int 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 MyV3Record[] = 
  {
    { "CFLD",       XB_CHAR_FLD,     30, 0 },
    { "DFLD",       XB_DATE_FLD,      8, 0 },
    { "NFLD",       XB_NUMERIC_FLD,  12, 0 },
    { "",0,0,0 }
  };


  xbXBase x;
#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 );
  x.SetLogSize( 1000000 );
#endif

  x.SetDataDirectory( PROJECT_DATA_DIR );
  x.EnableMsgLogging();
//  x.DisableDefaultAutoLock();

  x.SetUniqueKeyOpt( XB_EMULATE_DBASE );
  InitTime();
  xbString s;
  iRc = 0;

  if( po > 0 )
    std::cout << "Default Data Directory is [" << x.GetDataDirectory().Str() << "]" << std::endl;

  xbDbf *V3Dbf = new xbDbf3( &x );
  xbIx *ixPtr;
  void *ndx;

  iRc2 = V3Dbf->CreateTable( "TestNdx.DBF", "TestNdx", MyV3Record, XB_OVERLAY, XB_MULTI_USER );
  iRc += TestMethod( po, "CreateTable()", (xbInt32) iRc2, XB_NO_ERROR );

  if( iRc2 )
    x.DisplayError( iRc2 );

  iRc2 = V3Dbf->CreateTag( "NDX", "TestNdxC.NDX", "CFLD", "", 0, xbTrue, XB_OVERLAY, &ixPtr, &ndx );
  iRc += TestMethod( po, "CreateTag()", (xbInt32) iRc2, XB_NO_ERROR );
  if( iRc2 )
    x.DisplayError( iRc2 );

  iRc2 = V3Dbf->AssociateIndex( "NDX", "TestNdxC.NDX", 0 );
  iRc += TestMethod( po, "Associate()", (xbInt32) iRc2, XB_NO_ERROR );


  iRc += TestMethod( po, "BlankRecord()",    V3Dbf->BlankRecord(),                     XB_NO_ERROR );
  iRc += TestMethod( po, "Putfield()",       V3Dbf->PutField( "CFLD", "AAA" ),         XB_NO_ERROR );
  iRc += TestMethod( po, "Putfield()",       V3Dbf->PutField( "DFLD", "19611109" ),    XB_NO_ERROR );
  iRc += TestMethod( po, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR );
  iRc += TestMethod( po, "AppendRecord()",   V3Dbf->AppendRecord(),                    XB_NO_ERROR );


  iRc += TestMethod( po, "BlankRecord()",    V3Dbf->BlankRecord(),                     XB_NO_ERROR );
  iRc += TestMethod( po, "Putfield()",       V3Dbf->PutField( "CFLD", "BBB" ),         XB_NO_ERROR );
  iRc += TestMethod( po, "Putfield()",       V3Dbf->PutField( "DFLD", "19611109" ),    XB_NO_ERROR );
  iRc += TestMethod( po, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR );
  iRc += TestMethod( po, "AppendRecord()",   V3Dbf->AppendRecord(),                    XB_NO_ERROR );

  iRc += TestMethod( po, "BlankRecord()",    V3Dbf->BlankRecord(),                     XB_NO_ERROR );
  iRc += TestMethod( po, "Putfield()",       V3Dbf->PutField( "CFLD", "BBB" ),         XB_NO_ERROR );
  iRc += TestMethod( po, "Putfield()",       V3Dbf->PutField( "DFLD", "19611109" ),    XB_NO_ERROR );
  iRc += TestMethod( po, "PutfieldDouble()", V3Dbf->PutDoubleField( "NFLD", 50 ), XB_NO_ERROR );
  iRc += TestMethod( po, "AppendRecord()",   V3Dbf->AppendRecord(),                    XB_NO_ERROR );


  xbIxList *ixl = V3Dbf->GetIxList();
  xbIxNdx *ix;
  xbString sTagName;
  while( ixl ){
    if( *ixl->sFmt == "NDX" ){
      ix = (xbIxNdx *) ixl->ix;
      //ix->GetTagName( 0, sTagName );
      sMsg.Sprintf( "CheckTagIntegrity() - [%s]", ix->GetTagName(ix->GetCurTag()).Str());
      iRc += TestMethod( po, sMsg, ix->CheckTagIntegrity( ix->GetCurTag(), 2 ), XB_NO_ERROR );
      ixl = ixl->next;
    }
  }

  iRc += TestMethod( po, "Close()", V3Dbf->Close(), XB_NO_ERROR );
  delete V3Dbf;

  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, 2 );
#endif

  return iRc;
}