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

#include "regress.h"

void TestStores1()
{
  B(s00, Simple storage, 0) W(s00a);
  {
    c4_Storage s1 ("s00a", 1);
    s1.SetStructure("a[p1:I]");
    s1.Commit();
  } D(s00a); R(s00a); E;

  B(s01, Integer storage, 0) W(s01a);
  {
    c4_IntProp p1 ("p1");
    c4_Storage s1 ("s01a", 1);
    s1.SetStructure("a[p1:I]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 [123]);
      v1.Add(p1 [456]);
      v1.InsertAt(1, p1 [789]);
        A(v1.GetSize() == 3);
    s1.Commit();
        A(v1.GetSize() == 3);
  } D(s01a); R(s01a); E;

#if !q4_TINY
  B(s02, Float storage, 0) W(s02a);
  {
    c4_FloatProp p1 ("p1");
    c4_Storage s1 ("s02a", 1);
    s1.SetStructure("a[p1:F]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 [12.3]);
      v1.Add(p1 [45.6]);
      v1.InsertAt(1, p1 [78.9]);
    s1.Commit();
  } D(s02a); R(s02a); E;
#endif

  B(s03, String storage, 0) W(s03a);
  {
    c4_StringProp p1 ("p1");
    c4_Storage s1 ("s03a", 1);
    s1.SetStructure("a[p1:S]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 ["one"]);
      v1.Add(p1 ["two"]);
      v1.InsertAt(1, p1 ["three"]);
    s1.Commit();
  } D(s03a); R(s03a); E;

  B(s04, View storage, 0) W(s04a);
  {
    c4_StringProp p1 ("p1");
    c4_ViewProp p2 ("p2");
    c4_IntProp p3 ("p3");
    c4_Storage s1 ("s04a", 1);
    s1.SetStructure("a[p1:S,p2[p3:I]]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 ["one"]);
      v1.Add(p1 ["two"]);
      c4_View v2 = p2 (v1[0]);
      v2.Add(p3 [1]);
      v2 = p2 (v1[1]);
      v2.Add(p3 [11]);
      v2.Add(p3 [22]);
      v1.InsertAt(1, p1 ["three"]);
      v2 = p2 (v1[1]);
      v2.Add(p3 [111]);
      v2.Add(p3 [222]);
      v2.Add(p3 [333]);
      s1.Commit();
  } D(s04a); R(s04a); E;

  B(s05, Store and reload, 0) W(s05a);
  {
    c4_IntProp p1 ("p1");
    {
      c4_Storage s1 ("s05a", 1);
      s1.SetStructure("a[p1:I]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 [123]);
      s1.Commit();
    }
    {
      c4_Storage s1 ("s05a", 0);
      c4_View v1 = s1.View("a");
        A(v1.GetSize() == 1);
        A(p1 (v1[0]) == 123);
    }
  } D(s05a); R(s05a); E;

  B(s06, Commit twice, 0) W(s06a);
  {
    c4_IntProp p1 ("p1");
    {
      c4_Storage s1 ("s06a", 1);
      s1.SetStructure("a[p1:I]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 [123]);
      s1.Commit();
      v1.Add(p1 [234]);
      s1.Commit();
    }
    {
      c4_Storage s1 ("s06a", 0);
      c4_View v1 = s1.View("a");
        A(v1.GetSize() == 2);
        A(p1 (v1[0]) == 123);
        A(p1 (v1[1]) == 234);
    }
  } D(s06a); R(s06a); E;

  B(s07, Commit modified, 0) W(s07a);
  {
    c4_IntProp p1 ("p1");
    {
      c4_Storage s1 ("s07a", 1);
      s1.SetStructure("a[p1:I]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 [123]);
      s1.Commit();
      p1 (v1[0]) = 234;
      s1.Commit();
    }
    {
      c4_Storage s1 ("s07a", 0);
      c4_View v1 = s1.View("a");
        A(v1.GetSize() == 1);
        A(p1 (v1[0]) == 234);
    }
  } D(s07a); R(s07a); E;

  B(s08, View after storage, 0) W(s08a);
  {
    c4_IntProp p1 ("p1");
    {
      c4_Storage s1 ("s08a", 1);
      s1.SetStructure("a[p1:I]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 [123]);
      s1.Commit();
    }
    c4_View v1;
    {
      c4_Storage s1 ("s08a", 0);
      v1 = s1.View("a");
    }
        // 19990916 - semantics changed, view now 1 row, but 0 props
      A(v1.GetSize() == 1);
      A(v1.NumProperties() == 0);
    v1.InsertAt(0, p1 [234]);
      A(v1.GetSize() == 2);
      A(p1 (v1[0]) == 234);
      A(p1 (v1[1]) == 0); // the original value is gone
  } D(s08a); R(s08a); E;

  B(s09, Copy storage, 0) W(s09a); W(s09b);
  {
    c4_IntProp p1 ("p1");
    {
      c4_Storage s1 ("s09a", 1);
      s1.SetStructure("a[p1:I]");
      c4_View v1 = s1.View("a");
      v1.Add(p1 [123]);
      s1.Commit();
    }
    {
      c4_Storage s1 ("s09a", 0);
      c4_Storage s2 ("s09b", 1);
      s2.SetStructure("a[p1:I]");
      s2.View("a") = s1.View("a");
      s2.Commit();
    }
  } D(s09a); D(s09b); R(s09a); R(s09b); E;
}