summaryrefslogtreecommitdiffstats
path: root/akregator/src/mk4storage/metakit/tests/regress.cpp
blob: 2cd5f08410d7845637eb9b59fe4c09cf67e918b8 (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
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
// regress.cpp -- Regression test program, main code
// $Id$
// This is part of Metakit, the homepage is http://www.equi4.com/metakit/

#include "regress.h"

#if defined (macintosh)  
  #include <SIOUX.h>
  #ifdef DEBUG_NEW
    #include <DebugNew.cp>
    //#include "ZoneRanger.c"
  #if DEBUG_NEW >= 2 && !defined (q4_MAC_LEAK_CHECK)
    #define q4_MAC_LEAK_CHECK 1
  #endif
  #endif
#endif

#if __profile__
  #define q4_MWCW_PROFILER 1
  #include <profiler.h>
#endif

#if q4_NOTHROW
  const char* msg;
#endif

#if _WIN32_WCE

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int remove(const char* fn_)
{
  c4_Bytes buffer;
  int n = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fn_, -1, NULL, 0);
  wchar_t* w = (wchar_t*) buffer.SetBufferClear((n+1) * sizeof (wchar_t));
  MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, fn_, -1, w, n);
  return DeleteFile((wchar_t*) buffer.Contents()) ? 0 : -1;
}

#endif

int
#if _WIN32_WCE
_cdecl
#endif
main()
{
//  afxMemDF |= allocMemDF | checkAlwaysMemDF;

    // The M4STRING package sometimes keeps a spare empty string around.
    // By allocating it here, we avoid a few bogus memory leak reports.
  c4_String empty;

  #if q4_MAC_LEAK_CHECK
    DebugNewForgetLeaks();
  #endif

#if q4_MWCW_PROFILER
  if (!ProfilerInit(collectDetailed, bestTimeBase, 20, 5))
  {
#endif
    TestBasics1();
    TestBasics2();
    TestNotify();
    TestCustom1();
    TestCustom2();
    TestResize();
    TestStores1();
    TestStores2();
    TestStores3();
    TestStores4();
    TestStores5();
    TestDiffer();
    TestExtend();
    TestFormat();
    TestMapped();
    TestLimits();

#if q4_MWCW_PROFILER
    ProfilerDump("\pRegress.prof");
    ProfilerTerm();
  }
#endif

  #if defined (_DEBUG)
    fputs("\nPress return... ", stderr);
    getchar();
  #endif    
  #if q4_MAC_LEAK_CHECK
    if (DebugNewReportLeaks())
      fputs("    *** Memory leaks found ***\n", stderr);
  #endif
  #if defined (macintosh)  
    SIOUXSettings.asktosaveonclose = false;
  #endif
  
  fputs("Done.\n", stderr);
  return 0;
}

// Recursively display the entire view contents. The results shown do not
// depend on file tqlayout (free space, file positions, flat vs. on-demand).

static void ViewDisplay(const c4_View& v_, FILE* fp, int l_ =0)
{
  c4_String types;
  bool hasData = false, hasSubs = false;

    // display header info and collect all data types
  fprintf(fp, "%*s VIEW %5d rows =", l_, "", v_.GetSize());
  for (int n = 0; n < v_.NumProperties(); ++n)
  {
    c4_Property prop = v_.NthProperty(n);
    char t = prop.Type();

    fprintf(fp, " %s:%c", (const char*) prop.Name(), t);
    
    types += t;
  
    if (t == 'V')
      hasSubs = true;
    else
      hasData = true;
  }
  fprintf(fp, "\n");

  for (int j = 0; j < v_.GetSize(); ++j)
  {
    if (hasData)  // data properties are all shown on the same line
    {
      fprintf(fp, "%*s %4d:", l_, "", j);
      c4_RowRef r = v_[j];

      for (int k = 0; k < types.GetLength(); ++k)
      {
        c4_Property p = v_.NthProperty(k);

        switch (types[k])
        {
        case 'I':
          fprintf(fp, " %ld", (long) ((c4_IntProp&) p) (r));
          break;

#if !q4_TINY
        case 'F':
          fprintf(fp, " %g", (double) ((c4_FloatProp&) p) (r));
          break;

        case 'D':
          fprintf(fp, " %.12g", (double) ((c4_DoubleProp&) p) (r));
          break;
#endif

        case 'S':
          fprintf(fp, " '%s'", (const char*) ((c4_StringProp&) p) (r));
          break;

    case 'M': // backward compatibility
        case 'B':
          fprintf(fp, " (%db)", (p (r)).GetSize());
          break;

        default:
          if (types[k] != 'V')
            fprintf(fp, " (%c?)", types[k]);
        }
      }

      fprintf(fp, "\n");
    }

    if (hasSubs)  // subviews are then shown, each as a separate block
    {
      for (int k = 0; k < types.GetLength(); ++k)
      {
        if (types[k] == 'V')
        {
          c4_Property prop = v_.NthProperty(k);

          fprintf(fp, "%*s %4d: subview '%s'\n", l_, "", j,
              (const char*) prop.Name());

          c4_ViewProp& vp = (c4_ViewProp&) prop;

          ViewDisplay(vp (v_[j]), fp, l_ + 2);
        }
      }
    }
  }
}

void DumpFile(const char* in_, const char* out_)
{
  FILE* fp = fopen(out_, TEXTOUT);
  A(fp);

  c4_Storage store (in_, 0);

  ViewDisplay(store, fp);

  fclose(fp);
}

void Fail(const char* msg)
{ 
  #if q4_NOTHROW
    fprintf(stderr, "\t%s\n", msg);
    printf("*** %s ***\n", msg);
  #else
    throw msg;
  #endif
}

void FailExpr(const char* expr)
{
  char buffer [100];
  sprintf(buffer, "Failed: A(%s)", expr);
  Fail(buffer);
}

int StartTest(int mask_, const char* name_, const char* desc_)
{
  if (mask_)
  {
    #if q4_MFC && defined(_DEBUG)
      TRACE("%s - %-40s *** DISABLED ***\n", name_, desc_);
    #endif
    #if !q4_MWCW_PROFILER
      fprintf(stderr, "%s - %-40s   *** DISABLED ***\n", name_, desc_);
    #endif
    return false;
  }
  
  #if q4_MFC && defined(_DEBUG)
    TRACE("%s - %s\n", name_, desc_);
  #endif
  #if !q4_MWCW_PROFILER
    fprintf(stderr, "%s - %s\n", name_, desc_);
  #endif

  char buffer [50];
  sprintf(buffer, "%s%s.txt", TESTDIR, name_);
  #if _WIN32_WCE
    fclose(stdout);
    fopen(buffer, TEXTOUT);
  #else
    freopen(buffer, TEXTOUT, stdout);
  #endif
  printf(">>> %s\n", desc_);

  return true;
}

void CatchMsg(const char* msg)
{
  #if !q4_MWCW_PROFILER
    fprintf(stderr, "\t%s\n", msg);
  #endif
  printf("*** %s ***\n", msg);
}

void CatchOther()
{
  #if !q4_MWCW_PROFILER
    fputs("\tException!\n", stderr);
  #endif
  printf("*** Exception ***\n");
}