autoc 1.2 → 1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +4 -0
  3. data/README +3 -1
  4. data/doc/AutoC.html +23 -7
  5. data/doc/AutoC/Code.html +3 -3
  6. data/doc/AutoC/Collection.html +289 -76
  7. data/doc/AutoC/HashMap.html +44 -46
  8. data/doc/AutoC/HashSet.html +20 -17
  9. data/doc/AutoC/List.html +56 -92
  10. data/doc/AutoC/Module.html +2 -2
  11. data/doc/AutoC/Module/File.html +2 -2
  12. data/doc/AutoC/Module/Header.html +6 -4
  13. data/doc/AutoC/Module/Source.html +26 -26
  14. data/doc/AutoC/Priority.html +2 -2
  15. data/doc/AutoC/Queue.html +30 -92
  16. data/doc/AutoC/Reference.html +217 -61
  17. data/doc/AutoC/String.html +1393 -0
  18. data/doc/AutoC/Type.html +240 -128
  19. data/doc/AutoC/UserDefinedType.html +688 -47
  20. data/doc/AutoC/Vector.html +154 -62
  21. data/doc/_index.html +9 -2
  22. data/doc/class_list.html +1 -1
  23. data/doc/file.CHANGES.html +10 -2
  24. data/doc/file.README.html +5 -3
  25. data/doc/index.html +5 -3
  26. data/doc/method_list.html +235 -97
  27. data/doc/top-level-namespace.html +2 -2
  28. data/lib/autoc.rb +3 -1
  29. data/lib/autoc/code.rb +3 -2
  30. data/lib/autoc/collection.rb +36 -40
  31. data/lib/autoc/collection/hash_map.rb +10 -14
  32. data/lib/autoc/collection/hash_set.rb +12 -11
  33. data/lib/autoc/collection/list.rb +21 -11
  34. data/lib/autoc/collection/queue.rb +5 -8
  35. data/lib/autoc/collection/vector.rb +28 -12
  36. data/lib/autoc/string.rb +492 -0
  37. data/lib/autoc/type.rb +155 -66
  38. data/test/test.rb +157 -35
  39. data/test/test_char_string.rb +270 -0
  40. data/test/test_int_list.rb +35 -0
  41. data/test/test_int_vector.rb +34 -0
  42. data/test/test_value_hash_map.rb +162 -0
  43. data/test/test_value_hash_set.rb +173 -0
  44. data/test/test_value_list.rb +193 -0
  45. data/test/test_value_queue.rb +275 -0
  46. data/test/test_value_vector.rb +155 -0
  47. data/test/value.rb +80 -0
  48. metadata +15 -8
  49. data/test/test.c +0 -1041
  50. data/test/test.h +0 -41
  51. data/test/test_auto.c +0 -3407
  52. data/test/test_auto.h +0 -765
@@ -0,0 +1,155 @@
1
+ require "value"
2
+
3
+
4
+ type_test(AutoC::Vector, :ValueVector, Value) do
5
+
6
+ setup %~#{type} t;~
7
+ cleanup %~#{dtor}(&t);~
8
+
9
+ test :createSmallest, %~
10
+ #{ctor}(&t, 1);
11
+ TEST_EQUAL( #{size}(&t), 1 );
12
+ ~
13
+
14
+ test :createLarge, %~
15
+ #{ctor}(&t, 1024);
16
+ TEST_EQUAL( #{size}(&t), 1024 );
17
+ ~
18
+
19
+ setup %~
20
+ #{type} t;
21
+ #{element.type} e;
22
+ int i, c = 3;
23
+ #{ctor}(&t, c);
24
+ for(i = 0; i < c; ++i) {
25
+ #{element.ctorEx}(e, i);
26
+ #{set}(&t, i, e);
27
+ #{element.dtor}(e);
28
+ }
29
+ ~
30
+ cleanup %~#{dtor}(&t);~
31
+
32
+
33
+ test :get, %~
34
+ #{element.type} e2;
35
+ #{element.ctorEx}(e, 2);
36
+ e2 = #{get}(&t, 2);
37
+ TEST_TRUE( #{element.equal}(e, e2) );
38
+ #{element.dtor}(e);
39
+ #{element.dtor}(e2);
40
+ ~
41
+
42
+ test :set, %~
43
+ #{element.type} e2;
44
+ #{element.ctorEx}(e, -1);
45
+ #{set}(&t, 2, e);
46
+ e2 = #{get}(&t, 2);
47
+ TEST_TRUE( #{element.equal}(e, e2) );
48
+ #{element.dtor}(e);
49
+ #{element.dtor}(e2);
50
+ ~
51
+
52
+ test :within, %~
53
+ TEST_TRUE( #{within}(&t, 0) );
54
+ TEST_TRUE( #{within}(&t, 2) );
55
+ TEST_FALSE( #{within}(&t, 3) );
56
+ ~
57
+
58
+ test :iterateForward, %~
59
+ #{it} it;
60
+ #{itCtor}(&it, &t);
61
+ i = 0;
62
+ while(#{itMove}(&it)) {
63
+ e = #{itGet}(&it);
64
+ TEST_EQUAL( #{element.get}(e), i++ );
65
+ #{element.dtor}(e);
66
+ }
67
+ ~
68
+
69
+ test :iterateExactForward, %~
70
+ #{it} it;
71
+ #{itCtorEx}(&it, &t, 1);
72
+ i = 0;
73
+ while(#{itMove}(&it)) {
74
+ e = #{itGet}(&it);
75
+ TEST_EQUAL( #{element.get}(e), i++ );
76
+ #{element.dtor}(e);
77
+ }
78
+ ~
79
+
80
+ test :iterateBackward, %~
81
+ #{it} it;
82
+ #{itCtorEx}(&it, &t, 0);
83
+ i = c-1;
84
+ while(#{itMove}(&it)) {
85
+ e = #{itGet}(&it);
86
+ TEST_EQUAL( #{element.get}(e), i-- );
87
+ #{element.dtor}(e);
88
+ }
89
+ ~
90
+
91
+ setup %~
92
+ #{type} t1, t2;
93
+ #{element.type} e;
94
+ int i, c = 3;
95
+ #{ctor}(&t1, c);
96
+ #{ctor}(&t2, c);
97
+ TEST_TRUE( #{equal}(&t1, &t2) );
98
+ for(i = 0; i < c; ++i) {
99
+ #{element.ctorEx}(e, i);
100
+ #{set}(&t1, i, e);
101
+ #{set}(&t2, i, e);
102
+ #{element.dtor}(e);
103
+ }
104
+ TEST_TRUE( #{equal}(&t1, &t2) );
105
+ ~
106
+ cleanup %~
107
+ #{dtor}(&t1);
108
+ #{dtor}(&t2);
109
+ ~
110
+
111
+ test :size, %~
112
+ TEST_EQUAL( #{size}(&t1), 3 );
113
+ TEST_EQUAL( #{size}(&t1), #{size}(&t2) );
114
+ #{resize}(&t2, 1);
115
+ TEST_EQUAL( #{size}(&t2), 1 );
116
+ TEST_NOT_EQUAL( #{size}(&t1), #{size}(&t2) );
117
+ ~
118
+
119
+ test :equal, %~
120
+ #{element.ctorEx}(e, -1);
121
+ #{set}(&t1, 0, e);
122
+ #{element.dtor}(e);
123
+ TEST_FALSE( #{equal}(&t1, &t2) );
124
+ ~
125
+
126
+ test :resizeShrink, %~
127
+ #{resize}(&t2, 2);
128
+ TEST_EQUAL( #{size}(&t2), 2 );
129
+ TEST_FALSE( #{equal}(&t1, &t2) );
130
+ ~
131
+
132
+ test :resizeExpand, %~
133
+ #{resize}(&t2, 4);
134
+ TEST_EQUAL( #{size}(&t2), 4 );
135
+ TEST_FALSE( #{equal}(&t1, &t2) );
136
+ e = #{get}(&t2, 3);
137
+ TEST_EQUAL( #{element.get}(e), 0 );
138
+ TEST_NOT_EQUAL( #{element.get}(e), 1 );
139
+ #{element.dtor}(e);
140
+ ~
141
+
142
+ test :sort, %~
143
+ #{sort}(&t2);
144
+ TEST_TRUE( #{equal}(&t1, &t2) );
145
+ e = #{get}(&t2, 0);
146
+ TEST_EQUAL( #{element.get}(e), 0 );
147
+ #{element.dtor}(e);
148
+ #{sortEx}(&t2, 0);
149
+ TEST_FALSE( #{equal}(&t1, &t2) );
150
+ e = #{get}(&t2, 0);
151
+ TEST_EQUAL( #{element.get}(e), 2 );
152
+ #{element.dtor}(e);
153
+ ~
154
+
155
+ end
@@ -0,0 +1,80 @@
1
+ require "autoc"
2
+
3
+
4
+ Value = Class.new(AutoC::UserDefinedType) do
5
+ def write_intf(stream)
6
+ super
7
+ stream << %~
8
+ typedef struct {
9
+ int* value;
10
+ } Value;
11
+ #define ValueCtor(self) _ValueCtor(&self)
12
+ #define ValueCtorEx(self, v) _ValueCtorEx(&self, v)
13
+ #define ValueDtor(self) _ValueDtor(&self)
14
+ #define ValueCopy(dst, src) _ValueCopy(&dst, &src)
15
+ #define ValueEqual(lt, rt) _ValueEqual(&lt, &rt)
16
+ #define ValueLess(lt, rt) _ValueLess(&lt, &rt)
17
+ #define ValueIdentify(self) _ValueIdentify(&self)
18
+ #define ValueGet(self) *(self).value
19
+ #define ValueSet(self, x) *(self).value = (x)
20
+ void _ValueCtor(Value*);
21
+ void _ValueCtorEx(Value*, int);
22
+ void _ValueDtor(Value*);
23
+ void _ValueCopy(Value*, Value*);
24
+ int _ValueEqual(Value*, Value*);
25
+ int _ValueLess(Value*, Value*);
26
+ size_t _ValueIdentify(Value*);
27
+ ~
28
+ end
29
+ def write_defs(stream)
30
+ super
31
+ stream << %~
32
+ void _ValueCtor(Value* self) {
33
+ #{assert}(self);
34
+ self->value = #{calloc}(1, sizeof(int)); #{assert}(self->value);
35
+ }
36
+ void _ValueCtorEx(Value* self, int value) {
37
+ #{assert}(self);
38
+ ValueCtor(*self);
39
+ *self->value = value;
40
+ }
41
+ void _ValueDtor(Value* self) {
42
+ #{assert}(self);
43
+ #{free}(self->value);
44
+ }
45
+ void _ValueCopy(Value* dst, Value* src) {
46
+ #{assert}(src);
47
+ #{assert}(dst);
48
+ #{assert}(src->value);
49
+ ValueCtorEx(*dst, *src->value);
50
+ }
51
+ int _ValueEqual(Value* lt, Value* rt) {
52
+ #{assert}(lt);
53
+ #{assert}(rt);
54
+ #{assert}(lt->value);
55
+ #{assert}(rt->value);
56
+ return *lt->value == *rt->value;
57
+ }
58
+ int _ValueLess(Value* lt, Value* rt) {
59
+ #{assert}(lt);
60
+ #{assert}(rt);
61
+ #{assert}(lt->value);
62
+ #{assert}(rt->value);
63
+ return *lt->value < *rt->value;
64
+ }
65
+ size_t _ValueIdentify(Value* self) {
66
+ #{assert}(self);
67
+ #{assert}(self->value);
68
+ return *self->value ^ 0xAAAA;
69
+ }
70
+ ~
71
+ end
72
+ end.new(
73
+ :type => :Value,
74
+ :ctor => :ValueCtor,
75
+ :dtor => :ValueDtor,
76
+ :copy => :ValueCopy,
77
+ :equal => :ValueEqual,
78
+ :less => :ValueLess,
79
+ :identify => :ValueIdentify
80
+ )
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoc
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg A. Khlybov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-22 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  AutoC is a collection of Ruby modules related to automatic C source code generation:
15
15
  1) Multi-file C module generator.
16
- 2) Generators for strongly-typed generic collections similar to those from the C++ standard template library.
16
+ 2) Generators for strongly-typed generic collections (Vector, List, Set etc.).
17
17
  email: fougas@mail.ru
18
18
  executables: []
19
19
  extensions: []
@@ -35,6 +35,7 @@ files:
35
35
  - doc/AutoC/Priority.html
36
36
  - doc/AutoC/Queue.html
37
37
  - doc/AutoC/Reference.html
38
+ - doc/AutoC/String.html
38
39
  - doc/AutoC/Type.html
39
40
  - doc/AutoC/UserDefinedType.html
40
41
  - doc/AutoC/Vector.html
@@ -61,12 +62,18 @@ files:
61
62
  - lib/autoc/collection/list.rb
62
63
  - lib/autoc/collection/queue.rb
63
64
  - lib/autoc/collection/vector.rb
65
+ - lib/autoc/string.rb
64
66
  - lib/autoc/type.rb
65
- - test/test.c
66
- - test/test.h
67
67
  - test/test.rb
68
- - test/test_auto.c
69
- - test/test_auto.h
68
+ - test/test_char_string.rb
69
+ - test/test_int_list.rb
70
+ - test/test_int_vector.rb
71
+ - test/test_value_hash_map.rb
72
+ - test/test_value_hash_set.rb
73
+ - test/test_value_list.rb
74
+ - test/test_value_queue.rb
75
+ - test/test_value_vector.rb
76
+ - test/value.rb
70
77
  homepage: http://autoc.sourceforge.net/
71
78
  licenses:
72
79
  - BSD
@@ -87,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
94
  version: '0'
88
95
  requirements: []
89
96
  rubyforge_project:
90
- rubygems_version: 2.2.2
97
+ rubygems_version: 2.4.5.1
91
98
  signing_key:
92
99
  specification_version: 4
93
100
  summary: A host of Ruby modules related to automatic C source code generation
@@ -1,1041 +0,0 @@
1
- /*
2
- * This test is intended to be run under memory debugger such as Valgrind or Dr.Memory.
3
- * Normally it should complete without errors and should exhibit no memory-related issues.
4
- * The test should be compilable with any ANSI C compiler.
5
- *
6
- * > cc test.c test_auto.c
7
- */
8
-
9
-
10
- #include <assert.h>
11
- #include <memory.h>
12
- #include <stdio.h>
13
-
14
-
15
- #include "test.h"
16
- #include "test_auto.h"
17
-
18
-
19
- #define SIZE 16
20
- void ValueTypeCtorEx(ValueType* self, int value) {
21
- assert(self);
22
- self->value = value;
23
- self->block = malloc(SIZE); assert(self->block);
24
- }
25
-
26
-
27
- void ValueTypeCtorRef(ValueType* self) {
28
- ValueTypeCtorEx(self, 0);
29
- }
30
-
31
-
32
- void ValueTypeDtorRef(ValueType* self) {
33
- assert(self);
34
- free(self->block);
35
- }
36
-
37
-
38
- void ValueTypeCopyRef(ValueType* dst, ValueType* src) {
39
- assert(src);
40
- assert(dst);
41
- dst->block = malloc(SIZE); assert(dst->block);
42
- dst->value = src->value;
43
- memcpy(dst->block, src->block, SIZE);
44
- }
45
-
46
-
47
- int ValueTypeEqualRef(ValueType* lt, ValueType* rt) {
48
- assert(lt);
49
- assert(rt);
50
- return lt->value == rt->value;
51
- }
52
-
53
-
54
- int ValueTypeLessRef(ValueType* lt, ValueType* rt) {
55
- assert(lt);
56
- assert(rt);
57
- return lt->value < rt->value;
58
- }
59
-
60
-
61
- size_t ValueTypeIdentifyRef(ValueType* self) {
62
- assert(self);
63
- return (size_t)self->value;
64
- }
65
-
66
-
67
- #undef element
68
- #define element(x) ValueType##x
69
-
70
-
71
- #undef Type
72
- #define Type ValueTypeVector
73
- #undef TypeIt
74
- #define TypeIt ValueTypeVectorIt
75
- #undef type
76
- #define type(x) ValueTypeVector##x
77
- #undef it
78
- #define it(x) ValueTypeVectorIt##x
79
-
80
-
81
- static void type(Test)() {
82
- ValueType e1, e2;
83
- Type c1, c2;
84
- TypeIt it;
85
-
86
- type(Ctor)(&c1, 3);
87
- type(Copy)(&c2, &c1);
88
-
89
- type(Resize)(&c1, 5);
90
- type(Size)(&c1);
91
- type(Equal)(&c1, &c2);
92
- type(Resize)(&c1, 3);
93
- type(Size)(&c1);
94
- type(Equal)(&c1, &c2);
95
-
96
- type(Within)(&c1, 0);
97
- type(Within)(&c1, 10);
98
-
99
- element(CtorEx)(&e1, -1);
100
- element(CtorEx)(&e2, +1);
101
- type(Set)(&c1, 2, e1);
102
- type(Set)(&c1, 0, e2);
103
- element(Dtor)(e1);
104
- element(Dtor)(e2);
105
-
106
- it(Ctor)(&it, &c1);
107
- while(it(Move)(&it)) {
108
- ValueType e = it(Get)(&it);
109
- element(Dtor)(e);
110
- }
111
-
112
- it(CtorEx)(&it, &c2, 0);
113
- while(it(Move)(&it)) {
114
- ValueType e = it(Get)(&it);
115
- element(Dtor)(e);
116
- }
117
-
118
- type(Sort)(&c1);
119
- type(Sort)(&c2);
120
-
121
- type(Identify)(&c1);
122
- type(Identify)(&c2);
123
-
124
- type(Dtor)(&c1);
125
- type(Dtor)(&c2);
126
- }
127
-
128
-
129
- #undef Type
130
- #define Type ValueTypeList
131
- #undef TypeIt
132
- #define TypeIt ValueTypeListIt
133
- #undef type
134
- #define type(x) ValueTypeList##x
135
- #undef it
136
- #define it(x) ValueTypeListIt##x
137
-
138
-
139
- static void type(Test)() {
140
- ValueType e1, e2, e3;
141
- Type c1, c2;
142
- TypeIt it;
143
-
144
- type(Ctor)(&c1);
145
- type(Copy)(&c2, &c1);
146
-
147
- type(Equal)(&c1, &c2);
148
- type(Empty)(&c1);
149
-
150
- it(Ctor)(&it, &c1);
151
- while(it(Move)(&it)) {
152
- ValueType e = it(Get)(&it);
153
- element(Dtor)(e);
154
- }
155
-
156
- element(CtorEx)(&e1, -1);
157
- element(CtorEx)(&e2, +1);
158
-
159
- type(Push)(&c1, e1);
160
- type(Push)(&c2, e2);
161
- type(Contains)(&c1, e1);
162
- type(Contains)(&c2, e1);
163
- type(Push)(&c1, e2);
164
- type(Push)(&c2, e1);
165
- type(Empty)(&c1);
166
-
167
- element(Dtor)(e1);
168
- element(Dtor)(e2);
169
-
170
- e1 = type(Peek)(&c1);
171
- e2 = type(Peek)(&c2);
172
- element(Dtor)(e1);
173
- element(Dtor)(e2);
174
-
175
- it(Ctor)(&it, &c1);
176
- while(it(Move)(&it)) {
177
- ValueType e = it(Get)(&it);
178
- element(Dtor)(e);
179
- }
180
-
181
- type(Identify)(&c1);
182
- type(Identify)(&c2);
183
-
184
- e1 = type(Pop)(&c1);
185
- e2 = type(Pop)(&c2);
186
- element(Dtor)(e1);
187
- element(Dtor)(e2);
188
-
189
- type(Purge)(&c1);
190
- type(Purge)(&c2);
191
-
192
- element(CtorEx)(&e1, 3);
193
- element(CtorEx)(&e2, -3);
194
- element(Copy)(e3, e2);
195
- type(Push)(&c1, e1);
196
- type(Push)(&c1, e2);
197
- type(Push)(&c1, e1);
198
- type(Push)(&c2, e2);
199
- type(Push)(&c2, e2);
200
- type(Push)(&c2, e2);
201
- type(Replace)(&c2, e3);
202
- type(ReplaceAll)(&c2, e3);
203
- type(Remove)(&c1, e2);
204
- type(Remove)(&c1, e1);
205
- type(Remove)(&c2, e1);
206
- type(RemoveAll)(&c2, e2);
207
- element(Dtor)(e1);
208
- element(Dtor)(e2);
209
- element(Dtor)(e3);
210
-
211
- type(Dtor)(&c1);
212
- type(Dtor)(&c2);
213
- }
214
-
215
-
216
- #undef Type
217
- #define Type ValueTypeQueue
218
- #undef TypeIt
219
- #define TypeIt ValueTypeQueueIt
220
- #undef type
221
- #define type(x) ValueTypeQueue##x
222
- #undef it
223
- #define it(x) ValueTypeQueueIt##x
224
-
225
-
226
- /*
227
- * Queue is a non-strict superset of List
228
- * so the test case for the latter can be reused as-is
229
- */
230
- static void type(Test)() {
231
- ValueType e1, e2, e3;
232
- Type c1, c2;
233
- TypeIt it;
234
-
235
- type(Ctor)(&c1);
236
- type(Copy)(&c2, &c1);
237
-
238
- type(Equal)(&c1, &c2);
239
- type(Empty)(&c1);
240
-
241
- it(Ctor)(&it, &c1);
242
- while(it(Move)(&it)) {
243
- ValueType e = it(Get)(&it);
244
- element(Dtor)(e);
245
- }
246
-
247
- element(CtorEx)(&e1, -1);
248
- element(CtorEx)(&e2, +1);
249
-
250
- type(Push)(&c1, e1);
251
- type(Push)(&c2, e2);
252
- type(Contains)(&c1, e1);
253
- type(Contains)(&c2, e1);
254
- type(Push)(&c1, e2);
255
- type(Push)(&c2, e1);
256
- type(Empty)(&c1);
257
-
258
- element(Dtor)(e1);
259
- element(Dtor)(e2);
260
-
261
- e1 = type(Peek)(&c1);
262
- e2 = type(Peek)(&c2);
263
- element(Dtor)(e1);
264
- element(Dtor)(e2);
265
-
266
- it(Ctor)(&it, &c1);
267
- while(it(Move)(&it)) {
268
- ValueType e = it(Get)(&it);
269
- element(Dtor)(e);
270
- }
271
-
272
- type(Identify)(&c1);
273
- type(Identify)(&c2);
274
-
275
- e1 = type(Pop)(&c1);
276
- e2 = type(Pop)(&c2);
277
- element(Dtor)(e1);
278
- element(Dtor)(e2);
279
-
280
- type(Purge)(&c1);
281
- type(Purge)(&c2);
282
-
283
- element(CtorEx)(&e1, 3);
284
- element(CtorEx)(&e2, -3);
285
- element(Copy)(e3, e2);
286
- type(Push)(&c1, e1);
287
- type(Push)(&c1, e2);
288
- type(Push)(&c1, e1);
289
- type(Push)(&c2, e2);
290
- type(Push)(&c2, e2);
291
- type(Push)(&c2, e2);
292
- type(Replace)(&c2, e3);
293
- type(ReplaceAll)(&c2, e3);
294
- type(Remove)(&c1, e2);
295
- type(Remove)(&c1, e1);
296
- type(Remove)(&c2, e1);
297
- type(RemoveAll)(&c2, e2);
298
- element(Dtor)(e1);
299
- element(Dtor)(e2);
300
- element(Dtor)(e3);
301
-
302
- type(Dtor)(&c1);
303
- type(Dtor)(&c2);
304
- }
305
-
306
-
307
- #undef Type
308
- #define Type ValueTypeSet
309
- #undef TypeIt
310
- #define TypeIt ValueTypeSetIt
311
- #undef type
312
- #define type(x) ValueTypeSet##x
313
- #undef it
314
- #define it(x) ValueTypeSetIt##x
315
-
316
-
317
- static void type(Test)() {
318
- ValueType e1, e2, e3;
319
- Type c1, c2, cc1, cc2;
320
- TypeIt it;
321
-
322
- type(Ctor)(&c1);
323
- type(Copy)(&c2, &c1);
324
-
325
- it(Ctor)(&it, &c1);
326
- while(it(Move)(&it)) {
327
- ValueType e = it(Get)(&it);
328
- element(Dtor)(e);
329
- }
330
-
331
- type(Equal)(&c1, &c2);
332
- type(Empty)(&c1);
333
- type(Size)(&c1);
334
-
335
- element(CtorEx)(&e1, -1);
336
- element(CtorEx)(&e2, +1);
337
- element(CtorEx)(&e3, 0);
338
-
339
- type(Put)(&c1, e1);
340
- type(Put)(&c2, e1);
341
- type(Equal)(&c1, &c2);
342
- type(Put)(&c1, e2);
343
- type(Put)(&c2, e3);
344
- type(Equal)(&c1, &c2);
345
- type(Contains)(&c1, e1);
346
- type(Contains)(&c2, e2);
347
- {
348
- ValueType e = type(Get)(&c2, e3);
349
- element(Dtor)(e);
350
- }
351
- type(Replace)(&c1, e2);
352
-
353
- type(Put)(&c2, e1);
354
- type(Put)(&c2, e2);
355
- type(Put)(&c2, e3);
356
-
357
- element(Dtor)(e1);
358
- element(Dtor)(e2);
359
- element(Dtor)(e3);
360
-
361
- {
362
- int i;
363
- ValueType e;
364
- for(i = 0; i < 100; ++i) {
365
- element(CtorEx)(&e, i);
366
- type(Put)(&c1, e);
367
- element(Dtor)(e);
368
- }
369
- for(i = 0; i < 100; i += 2) {
370
- element(CtorEx)(&e, i);
371
- type(Remove)(&c1, e);
372
- element(Dtor)(e);
373
- }
374
- it(Ctor)(&it, &c1);
375
- while(it(Move)(&it)) {
376
- ValueType e = it(Get)(&it);
377
- element(Dtor)(e);
378
- }
379
- }
380
-
381
- {
382
- type(Copy)(&cc1, &c1);
383
- type(Copy)(&cc2, &c2);
384
- type(Retain)(&cc1, &cc2);
385
- type(Dtor)(&cc1);
386
- type(Dtor)(&cc2);
387
- }
388
-
389
- {
390
- type(Copy)(&cc1, &c1);
391
- type(Copy)(&cc2, &c2);
392
- type(Retain)(&cc2, &cc1);
393
- type(Dtor)(&cc1);
394
- type(Dtor)(&cc2);
395
- }
396
-
397
- {
398
- type(Copy)(&cc1, &c1);
399
- type(Copy)(&cc2, &c2);
400
- type(Include)(&cc1, &cc2);
401
- type(Dtor)(&cc1);
402
- type(Dtor)(&cc2);
403
- }
404
-
405
- {
406
- type(Copy)(&cc1, &c1);
407
- type(Copy)(&cc2, &c2);
408
- type(Include)(&cc2, &cc1);
409
- type(Dtor)(&cc1);
410
- type(Dtor)(&cc2);
411
- }
412
-
413
- {
414
- type(Copy)(&cc1, &c1);
415
- type(Copy)(&cc2, &c2);
416
- type(Exclude)(&cc1, &cc2);
417
- type(Dtor)(&cc1);
418
- type(Dtor)(&cc2);
419
- }
420
-
421
- {
422
- type(Copy)(&cc1, &c1);
423
- type(Copy)(&cc2, &c2);
424
- type(Exclude)(&cc2, &cc1);
425
- type(Dtor)(&cc1);
426
- type(Dtor)(&cc2);
427
- }
428
-
429
- {
430
- type(Copy)(&cc1, &c1);
431
- type(Copy)(&cc2, &c2);
432
- type(Invert)(&cc1, &cc2);
433
- type(Dtor)(&cc1);
434
- type(Dtor)(&cc2);
435
- }
436
-
437
- {
438
- type(Copy)(&cc1, &c1);
439
- type(Copy)(&cc2, &c2);
440
- type(Invert)(&cc2, &cc1);
441
- type(Dtor)(&cc1);
442
- type(Dtor)(&cc2);
443
- }
444
-
445
- type(Identify)(&c1);
446
- type(Identify)(&c2);
447
-
448
- type(Purge)(&c1);
449
- type(Dtor)(&c1);
450
- type(Dtor)(&c2);
451
- }
452
-
453
-
454
- #undef Type
455
- #define Type ValueTypeMap
456
- #undef TypeIt
457
- #define TypeIt ValueTypeMapIt
458
- #undef type
459
- #define type(x) ValueTypeMap##x
460
- #undef it
461
- #define it(x) ValueTypeMapIt##x
462
-
463
-
464
- static void type(Test)() {
465
- ValueType e1, e2, e3;
466
- Type c1, c2;
467
- TypeIt it;
468
-
469
- element(CtorEx)(&e1, -1);
470
- element(CtorEx)(&e2, +1);
471
- element(CtorEx)(&e3, 0);
472
-
473
- type(Ctor)(&c1);
474
- type(Put)(&c1, e1, e3);
475
- type(Put)(&c1, e2, e3);
476
- type(Copy)(&c2, &c1);
477
-
478
- type(Put)(&c1, e1, e2);
479
- type(Put)(&c2, e2, e1);
480
-
481
- {
482
- int i;
483
- ValueType e;
484
- for(i = 0; i < 100; ++i) {
485
- element(CtorEx)(&e, i);
486
- type(Put)(&c1, e, e);
487
- element(Dtor)(e);
488
- }
489
- for(i = 0; i < 100; i += 2) {
490
- element(CtorEx)(&e, i);
491
- type(Remove)(&c1, e);
492
- element(Dtor)(e);
493
- }
494
- for(i = 1; i < 10; ++i) {
495
- ValueType k;
496
- element(CtorEx)(&k, i);
497
- element(CtorEx)(&e, -i);
498
- type(Replace)(&c1, k, e);
499
- element(Dtor)(k);
500
- element(Dtor)(e);
501
- }
502
- }
503
-
504
- it(Ctor)(&it, &c1);
505
- while(it(Move)(&it)) {
506
- ValueType k = it(GetKey)(&it), e = it(GetElement)(&it);
507
- element(Dtor)(k);
508
- element(Dtor)(e);
509
- }
510
-
511
- element(Dtor)(e1);
512
- element(Dtor)(e2);
513
- element(Dtor)(e3);
514
-
515
- type(Equal)(&c1, &c2);
516
- type(Empty)(&c1);
517
- type(Size)(&c1);
518
-
519
- type(Identify)(&c1);
520
- type(Identify)(&c2);
521
-
522
- type(Purge)(&c1);
523
- type(Dtor)(&c1);
524
- type(Dtor)(&c2);
525
- }
526
-
527
-
528
- #undef Type
529
- #define Type IntSet
530
- #undef TypeIt
531
- #define TypeIt IntSetIt
532
- #undef type
533
- #define type(x) IntSet##x
534
- #undef it
535
- #define it(x) IntSetIt##x
536
-
537
-
538
- /* {1,2,3} & {2,3,4} == {2,3} */
539
- static void type(TestAnd)() {
540
- Type r, c1, c2, cc1, cc2;
541
-
542
- type(Ctor)(&r);
543
- type(Ctor)(&c1);
544
- type(Ctor)(&c2);
545
-
546
- assert(type(Empty)(&r));
547
- assert(type(Empty)(&c1));
548
- assert(type(Empty)(&c2));
549
-
550
- type(Put)(&c1, 1); type(Put)(&c1, 3);
551
- type(Put)(&c1, 2);
552
- type(Put)(&c1, 3); type(Put)(&c1, 1);
553
-
554
- assert(type(Size)(&c1) == 3);
555
-
556
- type(Copy)(&cc1, &c1);
557
-
558
- type(Put)(&c2, 2);
559
- type(Put)(&c2, 3);
560
- type(Put)(&c2, 4);
561
-
562
- assert(type(Size)(&c2) == 3);
563
-
564
- type(Copy)(&cc2, &c2);
565
-
566
- assert(!type(Equal)(&c1, &c2));
567
- assert(!type(Equal)(&c2, &c1));
568
-
569
- type(Retain)(&c1, &c2);
570
- type(Retain)(&cc2, &cc1);
571
-
572
- assert(type(Size)(&c1) == 2);
573
- assert(type(Size)(&cc2) == 2);
574
-
575
- type(Put)(&r, 3);
576
- type(Put)(&r, 2);
577
-
578
- assert(type(Size)(&r) == 2);
579
-
580
- assert(!type(Empty)(&r));
581
- assert(!type(Empty)(&c1));
582
- assert(!type(Empty)(&c2));
583
-
584
- assert(type(Equal)(&c1, &r));
585
- assert(type(Equal)(&r, &c1));
586
-
587
- assert(type(Equal)(&cc2, &c1));
588
- assert(type(Equal)(&c1, &cc2));
589
-
590
- type(Dtor)(&r);
591
- type(Dtor)(&c1);
592
- type(Dtor)(&c2);
593
- type(Dtor)(&cc1);
594
- type(Dtor)(&cc2);
595
- }
596
-
597
-
598
- /* {1,2,3} | {2,3,4} == {1,2,3,4} */
599
- static void type(TestOr)() {
600
- Type r, c1, c2, cc1, cc2;
601
-
602
- type(Ctor)(&r);
603
- type(Ctor)(&c1);
604
- type(Ctor)(&c2);
605
-
606
- assert(type(Empty)(&r));
607
- assert(type(Empty)(&c1));
608
- assert(type(Empty)(&c2));
609
-
610
- type(Put)(&c1, 1); type(Put)(&c1, 3);
611
- type(Put)(&c1, 2);
612
- type(Put)(&c1, 3); type(Put)(&c1, 1);
613
-
614
- assert(type(Size)(&c1) == 3);
615
-
616
- type(Copy)(&cc1, &c1);
617
-
618
- type(Put)(&c2, 2);
619
- type(Put)(&c2, 3);
620
- type(Put)(&c2, 4);
621
-
622
- assert(type(Size)(&c2) == 3);
623
-
624
- type(Copy)(&cc2, &c2);
625
-
626
- assert(!type(Equal)(&c1, &c2));
627
- assert(!type(Equal)(&c2, &c1));
628
-
629
- type(Include)(&c1, &c2);
630
- type(Include)(&cc2, &cc1);
631
-
632
- assert(type(Size)(&c1) == 4);
633
- assert(type(Size)(&cc2) == 4);
634
-
635
- type(Put)(&r, 3);
636
- type(Put)(&r, 2);
637
- type(Put)(&r, 1);
638
- type(Put)(&r, 4);
639
-
640
- assert(type(Size)(&r) == 4);
641
-
642
- assert(!type(Empty)(&r));
643
- assert(!type(Empty)(&c1));
644
- assert(!type(Empty)(&c2));
645
-
646
- assert(type(Equal)(&c1, &r));
647
- assert(type(Equal)(&r, &c1));
648
-
649
- assert(type(Equal)(&cc2, &c1));
650
- assert(type(Equal)(&c1, &cc2));
651
-
652
- type(Dtor)(&r);
653
- type(Dtor)(&c1);
654
- type(Dtor)(&c2);
655
- type(Dtor)(&cc1);
656
- type(Dtor)(&cc2);
657
- }
658
-
659
-
660
- /* {1,2,3} ^ {2,3,4} == {1,4} */
661
- static void type(TestXor)() {
662
- Type r, c1, c2, cc1, cc2;
663
-
664
- type(Ctor)(&r);
665
- type(Ctor)(&c1);
666
- type(Ctor)(&c2);
667
-
668
- assert(type(Empty)(&r));
669
- assert(type(Empty)(&c1));
670
- assert(type(Empty)(&c2));
671
-
672
- type(Put)(&c1, 1); type(Put)(&c1, 3);
673
- type(Put)(&c1, 2);
674
- type(Put)(&c1, 3); type(Put)(&c1, 1);
675
-
676
- assert(type(Size)(&c1) == 3);
677
-
678
- type(Copy)(&cc1, &c1);
679
-
680
- type(Put)(&c2, 2);
681
- type(Put)(&c2, 3);
682
- type(Put)(&c2, 4);
683
-
684
- assert(type(Size)(&c2) == 3);
685
-
686
- type(Copy)(&cc2, &c2);
687
-
688
- assert(!type(Equal)(&c1, &c2));
689
- assert(!type(Equal)(&c2, &c1));
690
-
691
- type(Invert)(&c1, &c2);
692
- type(Invert)(&cc2, &cc1);
693
-
694
- assert(type(Size)(&c1) == 2);
695
- assert(type(Size)(&cc2) == 2);
696
-
697
- type(Put)(&r, 4);
698
- type(Put)(&r, 1);
699
-
700
- assert(type(Size)(&r) == 2);
701
-
702
- assert(!type(Empty)(&r));
703
- assert(!type(Empty)(&c1));
704
- assert(!type(Empty)(&c2));
705
-
706
- assert(type(Equal)(&c1, &r));
707
- assert(type(Equal)(&r, &c1));
708
-
709
- assert(type(Equal)(&cc2, &c1));
710
- assert(type(Equal)(&c1, &cc2));
711
-
712
- type(Dtor)(&r);
713
- type(Dtor)(&c1);
714
- type(Dtor)(&c2);
715
- type(Dtor)(&cc1);
716
- type(Dtor)(&cc2);
717
- }
718
-
719
-
720
- /* {1,2,3} - {2,3,4} == {1} */
721
- static void type(TestNot1)() {
722
- Type r, c1, c2, cc1, cc2;
723
-
724
- type(Ctor)(&r);
725
- type(Ctor)(&c1);
726
- type(Ctor)(&c2);
727
-
728
- assert(type(Empty)(&r));
729
- assert(type(Empty)(&c1));
730
- assert(type(Empty)(&c2));
731
-
732
- type(Put)(&c1, 1); type(Put)(&c1, 3);
733
- type(Put)(&c1, 2);
734
- type(Put)(&c1, 3); type(Put)(&c1, 1);
735
-
736
- assert(type(Size)(&c1) == 3);
737
-
738
- type(Copy)(&cc1, &c1);
739
-
740
- type(Put)(&c2, 2);
741
- type(Put)(&c2, 3);
742
- type(Put)(&c2, 4);
743
-
744
- assert(type(Size)(&c2) == 3);
745
-
746
- type(Copy)(&cc2, &c2);
747
-
748
- assert(!type(Equal)(&c1, &c2));
749
- assert(!type(Equal)(&c2, &c1));
750
-
751
- type(Exclude)(&c1, &c2);
752
- type(Exclude)(&cc2, &cc1);
753
-
754
- assert(type(Size)(&c1) == 1);
755
- assert(type(Size)(&cc2) == 1);
756
-
757
- type(Put)(&r, 1);
758
-
759
- assert(type(Size)(&r) == 1);
760
-
761
- assert(!type(Empty)(&r));
762
- assert(!type(Empty)(&c1));
763
- assert(!type(Empty)(&c2));
764
-
765
- assert(type(Equal)(&c1, &r));
766
- assert(type(Equal)(&r, &c1));
767
-
768
- assert(!type(Equal)(&cc2, &c1));
769
- assert(!type(Equal)(&c1, &cc2));
770
-
771
- type(Dtor)(&r);
772
- type(Dtor)(&c1);
773
- type(Dtor)(&c2);
774
- type(Dtor)(&cc1);
775
- type(Dtor)(&cc2);
776
- }
777
-
778
-
779
- /* {1,2,3} - {1,2,3,4} == {} */
780
- static void type(TestNot2)() {
781
- Type r, c1, c2;
782
-
783
- type(Ctor)(&r);
784
- type(Ctor)(&c1);
785
- type(Ctor)(&c2);
786
-
787
- assert(type(Empty)(&r));
788
- assert(type(Empty)(&c1));
789
- assert(type(Empty)(&c2));
790
-
791
- type(Put)(&c1, 1); type(Put)(&c1, 3);
792
- type(Put)(&c1, 2);
793
- type(Put)(&c1, 3); type(Put)(&c1, 1);
794
-
795
- assert(type(Size)(&c1) == 3);
796
-
797
- type(Put)(&c2, 1);
798
- type(Put)(&c2, 2);
799
- type(Put)(&c2, 3);
800
- type(Put)(&c2, 4);
801
-
802
- assert(type(Size)(&c2) == 4);
803
-
804
- assert(!type(Equal)(&c1, &c2));
805
- assert(!type(Equal)(&c2, &c1));
806
-
807
- type(Exclude)(&c1, &c2);
808
-
809
- assert(type(Size)(&c1) == 0);
810
-
811
- assert(type(Size)(&r) == 0);
812
-
813
- assert(type(Empty)(&r));
814
- assert(type(Empty)(&c1));
815
- assert(!type(Empty)(&c2));
816
-
817
- assert(type(Equal)(&c1, &r));
818
- assert(type(Equal)(&r, &c1));
819
-
820
- type(Dtor)(&r);
821
- type(Dtor)(&c1);
822
- type(Dtor)(&c2);
823
- }
824
-
825
-
826
- #undef Type
827
- #define Type IntStrMap
828
- #undef TypeIt
829
- #define TypeIt IntStrMapIt
830
- #undef type
831
- #define type(x) IntStrMap##x
832
- #undef it
833
- #define it(x) IntStrMapIt##x
834
-
835
-
836
- static const char* zero = "zero";
837
- static const char* one = "one";
838
- static const char* two = "two";
839
-
840
-
841
- static void type(Test)() {
842
- Type c1, c2;
843
- TypeIt it;
844
- int i;
845
-
846
- type(Ctor)(&c1);
847
- type(Ctor)(&c2);
848
-
849
- assert(type(Empty)(&c1));
850
- assert(type(Empty)(&c2));
851
- assert(type(Equal)(&c1, &c2));
852
-
853
- assert(type(Put)(&c1, 0, zero));
854
- assert(type(Put)(&c1, 1, one));
855
- assert(type(Put)(&c1, 2, two));
856
- assert(!type(Put)(&c1, 2, two));
857
-
858
- assert(type(Put)(&c2, 2, two));
859
- assert(type(Put)(&c2, 0, zero));
860
- assert(type(Put)(&c2, 1, one));
861
- assert(!type(Put)(&c2, 0, zero));
862
-
863
- assert(!type(Empty)(&c1));
864
- assert(!type(Empty)(&c2));
865
- assert(type(Size)(&c1) == type(Size)(&c2));
866
- assert(type(Equal)(&c1, &c2));
867
-
868
- assert(type(ContainsKey)(&c1, 0));
869
- assert(type(Remove)(&c1, 0));
870
- assert(!type(Remove)(&c1, 0));
871
- assert(!type(ContainsKey)(&c1, 0));
872
- assert(type(ContainsKey)(&c2, 2));
873
- assert(type(Remove)(&c2, 2));
874
- assert(!type(ContainsKey)(&c2, 2));
875
- assert(type(Size)(&c1) == type(Size)(&c2));
876
- assert(!type(Equal)(&c1, &c2));
877
-
878
- type(Purge)(&c1);
879
-
880
- assert(type(Put)(&c1, 0, zero));
881
- assert(type(Put)(&c1, 1, one));
882
- assert(type(Put)(&c1, 2, two));
883
-
884
- assert(type(Replace)(&c1, 0, two));
885
- assert(type(Replace)(&c1, 2, zero));
886
-
887
- assert(type(Get)(&c1, 0) == two);
888
- assert(type(Get)(&c1, 2) == zero);
889
- assert(type(Get)(&c1, 1) == one);
890
-
891
- i = 0;
892
- it(Ctor)(&it, &c1);
893
- while(it(Move)(&it)) {
894
- int k;
895
- const char* e;
896
- k = it(GetKey)(&it);
897
- e = it(Get)(&it);
898
- ++i;
899
- }
900
- assert(i == 3);
901
-
902
- type(Purge)(&c2);
903
- type(Dtor)(&c1);
904
- type(Dtor)(&c2);
905
- }
906
-
907
-
908
- #undef Type
909
- #define Type ListIntSet
910
- #undef TypeIt
911
- #define TypeIt ListIntSetIt
912
- #undef type
913
- #define type(x) ListIntSet##x
914
- #undef it
915
- #define it(x) ListIntSetIt##x
916
- #undef Element
917
- #define Element IntSet
918
- #undef element
919
- #define element(x) IntSet##x
920
-
921
-
922
- static void type(Test)() {
923
- Type c1, c2;
924
- Element e;
925
-
926
- type(Ctor)(&c1);
927
- type(Ctor)(&c2);
928
-
929
- element(Ctor)(&e);
930
- type(Push)(&c1, e);
931
- element(Put)(&e, 3);
932
- element(Put)(&e, 2);
933
- element(Put)(&e, 1);
934
- type(Push)(&c2, e);
935
- element(Dtor)(&e);
936
-
937
- type(Dtor)(&c1);
938
- type(Dtor)(&c2);
939
- }
940
-
941
-
942
- #undef Type
943
- #define Type Int
944
- #undef type
945
- #define type(x) Int##x
946
-
947
-
948
- static void PIntTest() {
949
- int *c1, *c2;
950
- c1 = type(New)(); *c1 = 1;
951
- c2 = type(New)(); *c2 = 2;
952
- assert(*c1 != *c2);
953
- type(Free)(c2);
954
- c2 = type(Ref)(c1);
955
- assert(*c1 == *c2);
956
- type(Free)(c1);
957
- type(Free)(c2);
958
- }
959
-
960
-
961
- #undef Type
962
- #define Type ValueType
963
- #undef type
964
- #define type(x) ValueType##x
965
-
966
-
967
- static void PValueTypeTest() {
968
- ValueType *c1, *c2;
969
- c1 = type(New)();
970
- c2 = type(New)();
971
- type(Free)(c2);
972
- c2 = type(Ref)(c1);
973
- type(Free)(c1);
974
- type(Free)(c2);
975
- }
976
-
977
-
978
- /* List<Vector<ValueType*>*> */
979
- #undef Type
980
- #define Type ListPVectorValue
981
- #undef TypeIt
982
- #define TypeIt ListPVectorValueIt
983
- #undef type
984
- #define type(x) ListPVectorValue##x
985
- #undef it
986
- #define it(x) ListPVectorValueIt##x
987
- #undef Element
988
- #define Element PVectorValue
989
- #undef element
990
- #define element(x) PVectorValue##x
991
-
992
-
993
- static void type(Test)() {
994
- Type c1, c2;
995
- Element *e1, *e2;
996
- ValueType *v1, *v2;
997
-
998
- type(Ctor)(&c1);
999
- type(Ctor)(&c2);
1000
-
1001
- e1 = element(New)(3);
1002
-
1003
- element(Set)(e1, 1, v1 = ValueTypeNew());
1004
-
1005
- e2 = element(Ref)(e1);
1006
-
1007
- assert(element(Equal)(e1, e2));
1008
-
1009
- element(Set)(e2, 0, v2 = ValueTypeRef(v1));
1010
-
1011
- type(Push)(&c1, e1);
1012
-
1013
- element(Free)(e1);
1014
- element(Free)(e2);
1015
-
1016
- type(Dtor)(&c1);
1017
- type(Dtor)(&c2);
1018
-
1019
- ValueTypeFree(v1);
1020
- ValueTypeFree(v2);
1021
- }
1022
-
1023
-
1024
- int main(int argc, char** argv) {
1025
- ValueTypeVectorTest();
1026
- ValueTypeListTest();
1027
- ValueTypeQueueTest();
1028
- ValueTypeSetTest();
1029
- ValueTypeMapTest();
1030
- IntSetTestAnd();
1031
- IntSetTestOr();
1032
- IntSetTestXor();
1033
- IntSetTestNot1();
1034
- IntSetTestNot2();
1035
- IntStrMapTest();
1036
- ListIntSetTest();
1037
- PIntTest();
1038
- PValueTypeTest();
1039
- ListPVectorValueTest();
1040
- return 0;
1041
- }