• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂412 (tree)
時間2012-04-09 22:04:18
作者ornse01

Log Message

copy arraybase_t fron bchan source.

Change Summary

差異

--- bchanf/trunk/src/coll/array.c (nonexistent)
+++ bchanf/trunk/src/coll/array.c (revision 412)
@@ -0,0 +1,230 @@
1+/*
2+ * array.c
3+ *
4+ * Copyright (c) 2010 project bchan
5+ *
6+ * This software is provided 'as-is', without any express or implied
7+ * warranty. In no event will the authors be held liable for any damages
8+ * arising from the use of this software.
9+ *
10+ * Permission is granted to anyone to use this software for any purpose,
11+ * including commercial applications, and to alter it and redistribute it
12+ * freely, subject to the following restrictions:
13+ *
14+ * 1. The origin of this software must not be misrepresented; you must not
15+ * claim that you wrote the original software. If you use this software
16+ * in a product, an acknowledgment in the product documentation would be
17+ * appreciated but is not required.
18+ *
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ *
22+ * 3. This notice may not be removed or altered from any source
23+ * distribution.
24+ *
25+ */
26+
27+#include <basic.h>
28+#include <bstdlib.h>
29+#include <bstdio.h>
30+#include <bsys/queue.h>
31+
32+#include "array.h"
33+
34+#ifdef BCHAN_CONFIG_DEBUG
35+# define DP(arg) printf arg
36+# define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err)
37+#else
38+# define DP(arg) /**/
39+# define DP_ER(msg, err) /**/
40+#endif
41+
42+LOCAL arraybase_datanode_t* arraybase_datanode_next(arraybase_datanode_t *node)
43+{
44+ return (arraybase_datanode_t *)node->queue.next;
45+}
46+
47+LOCAL arraybase_datanode_t* arraybase_datanode_prev(arraybase_datanode_t *node)
48+{
49+ return (arraybase_datanode_t *)node->queue.prev;
50+}
51+
52+LOCAL VOID arraybase_datanode_insert(arraybase_datanode_t *node, arraybase_datanode_t *que)
53+{
54+ QueInsert(&node->queue, &que->queue);
55+}
56+
57+LOCAL VOID arraybase_datanode_getunitbyindex(arraybase_datanode_t *node, W unitsize, W index, VP *p)
58+{
59+ /* comparing index and data lentgh is this user. */
60+ *p = (VP)(node->data + unitsize * index);
61+}
62+
63+LOCAL VOID arraybase_datanode_writebyindex(arraybase_datanode_t *node, W unitsize, W index, VP p)
64+{
65+ VP dest;
66+
67+ /* comparing index and data lentgh is this user. */
68+ arraybase_datanode_getunitbyindex(node, unitsize, index, &dest);
69+ memcpy(dest, p, unitsize);
70+}
71+
72+LOCAL W arraybase_datanode_initialize(arraybase_datanode_t *node, W unitsize, W denom)
73+{
74+ QueInit(&node->queue);
75+ node->data = (UB*)malloc(sizeof(UB)*unitsize*denom);
76+ if (node->data == NULL) {
77+ return -1; /* TODO */
78+ }
79+ return 0;
80+}
81+
82+LOCAL VOID arraybase_datanode_finalize(arraybase_datanode_t *node)
83+{
84+ free(node->data);
85+ QueRemove(&node->queue);
86+}
87+
88+LOCAL arraybase_datanode_t* arraybase_datanode_new(W unitsize, W denom)
89+{
90+ arraybase_datanode_t *node;
91+ W err;
92+
93+ node = (arraybase_datanode_t *)malloc(sizeof(arraybase_datanode_t));
94+ if (node == NULL) {
95+ return NULL;
96+ }
97+ err = arraybase_datanode_initialize(node, unitsize, denom);
98+ if (err < 0) {
99+ free(node);
100+ }
101+
102+ return node;
103+}
104+
105+LOCAL VOID arraybase_datanode_delete(arraybase_datanode_t *node)
106+{
107+ arraybase_datanode_finalize(node);
108+ free(node);
109+}
110+
111+EXPORT Bool arraybase_getunitbyindex(arraybase_t *arraybase, W index, VP *p)
112+{
113+ W i, i_num, i_data;
114+ arraybase_datanode_t *node;
115+
116+ if (index < 0) {
117+ return False;
118+ }
119+ if (index >= arraybase->datanum) {
120+ return False;
121+ }
122+
123+ i_num = index / arraybase->denom;
124+ i_data = index % arraybase->denom;
125+
126+ node = &arraybase->datalist;
127+ for (i = 0; i < i_num; i++) {
128+ node = arraybase_datanode_next(node);
129+ }
130+
131+ arraybase_datanode_getunitbyindex(node, arraybase->unitsize, i_data, p);
132+
133+ return True;
134+}
135+
136+EXPORT Bool arraybase_getunitfirst(arraybase_t *arraybase, VP *p)
137+{
138+ /* TODO: more efficient. */
139+ return arraybase_getunitbyindex(arraybase, 0, p);
140+}
141+
142+EXPORT Bool arraybase_getunitlast(arraybase_t *arraybase, VP *p)
143+{
144+ /* TODO: more efficient. */
145+ return arraybase_getunitbyindex(arraybase, arraybase->datanum - 1, p);
146+}
147+
148+EXPORT W arraybase_appendunit(arraybase_t *arraybase, VP p)
149+{
150+ arraybase_datanode_t *node;
151+ W i_data;
152+
153+ i_data = arraybase->datanum % arraybase->denom;
154+ if ((i_data == 0)&&(arraybase->datanum > 0)) {
155+ node = arraybase_datanode_new(arraybase->unitsize, arraybase->denom);
156+ if (node == NULL) {
157+ return -1; /* TODO */
158+ }
159+ arraybase_datanode_insert(node, &arraybase->datalist);
160+ } else {
161+ node = arraybase_datanode_prev(&arraybase->datalist);
162+ }
163+
164+ arraybase_datanode_writebyindex(node, arraybase->unitsize, i_data, p);
165+
166+ arraybase->datanum++;
167+
168+ return 0;
169+}
170+
171+EXPORT VOID arraybase_truncate(arraybase_t *arraybase, W newlength)
172+{
173+ W i, i_num;
174+ arraybase_datanode_t *node, *newlast;
175+
176+ if (newlength >= arraybase->datanum) {
177+ return;
178+ }
179+
180+ i_num = (newlength - 1) / arraybase->denom;
181+ node = &arraybase->datalist;
182+ for (i = 0; i < i_num; i++) {
183+ node = arraybase_datanode_next(node);
184+ }
185+ newlast = node;
186+
187+ for (;;) {
188+ node = arraybase_datanode_prev(&arraybase->datalist);
189+ if (node == newlast) {
190+ break;
191+ }
192+ arraybase_datanode_delete(node);
193+ }
194+
195+ arraybase->datanum = newlength;
196+}
197+
198+EXPORT W arraybase_length(arraybase_t *arraybase)
199+{
200+ return arraybase->datanum;
201+}
202+
203+EXPORT W arraybase_initialize(arraybase_t *arraybase, W unitsize, W denom)
204+{
205+ W err;
206+
207+ err = arraybase_datanode_initialize(&arraybase->datalist, unitsize, denom);
208+ if (err < 0) {
209+ return err;
210+ }
211+ arraybase->unitsize = unitsize;
212+ arraybase->denom = denom;
213+ arraybase->datanum = 0;
214+
215+ return 0;
216+}
217+
218+EXPORT VOID arraybase_finalize(arraybase_t *arraybase)
219+{
220+ arraybase_datanode_t *node;
221+
222+ for (;;) {
223+ node = arraybase_datanode_prev(&arraybase->datalist);
224+ if (node == &arraybase->datalist) {
225+ break;
226+ }
227+ arraybase_datanode_delete(node);
228+ }
229+ arraybase_datanode_finalize(&arraybase->datalist);
230+}
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
--- bchanf/trunk/src/coll/array.h (nonexistent)
+++ bchanf/trunk/src/coll/array.h (revision 412)
@@ -0,0 +1,56 @@
1+/*
2+ * array.h
3+ *
4+ * Copyright (c) 2010 project bchan
5+ *
6+ * This software is provided 'as-is', without any express or implied
7+ * warranty. In no event will the authors be held liable for any damages
8+ * arising from the use of this software.
9+ *
10+ * Permission is granted to anyone to use this software for any purpose,
11+ * including commercial applications, and to alter it and redistribute it
12+ * freely, subject to the following restrictions:
13+ *
14+ * 1. The origin of this software must not be misrepresented; you must not
15+ * claim that you wrote the original software. If you use this software
16+ * in a product, an acknowledgment in the product documentation would be
17+ * appreciated but is not required.
18+ *
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ *
22+ * 3. This notice may not be removed or altered from any source
23+ * distribution.
24+ *
25+ */
26+
27+#include <basic.h>
28+#include <bsys/queue.h>
29+
30+#ifndef __ARRAY_H__
31+#define __ARRAY_H__
32+
33+typedef struct arraybase_datanode_t_ arraybase_datanode_t;
34+struct arraybase_datanode_t_ {
35+ QUEUE queue;
36+ UB *data;
37+};
38+
39+typedef struct arraybase_t_ arraybase_t;
40+struct arraybase_t_ {
41+ W unitsize;
42+ W denom;
43+ W datanum;
44+ arraybase_datanode_t datalist;
45+};
46+
47+IMPORT W arraybase_initialize(arraybase_t *arraybase, W unitsize, W denom);
48+IMPORT VOID arraybase_finalize(arraybase_t *arraybase);
49+IMPORT Bool arraybase_getunitbyindex(arraybase_t *arraybase, W index, VP *p);
50+IMPORT Bool arraybase_getunitfirst(arraybase_t *arraybase, VP *p);
51+IMPORT Bool arraybase_getunitlast(arraybase_t *arraybase, VP *p);
52+IMPORT W arraybase_appendunit(arraybase_t *arraybase, VP p);
53+IMPORT VOID arraybase_truncate(arraybase_t *arraybase, W newlength);
54+IMPORT W arraybase_length(arraybase_t *arraybase);
55+
56+#endif
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
--- bchanf/trunk/src/coll/test_array.c (nonexistent)
+++ bchanf/trunk/src/coll/test_array.c (revision 412)
@@ -0,0 +1,849 @@
1+/*
2+ * test_array.c
3+ *
4+ * Copyright (c) 2010 project bchan
5+ *
6+ * This software is provided 'as-is', without any express or implied
7+ * warranty. In no event will the authors be held liable for any damages
8+ * arising from the use of this software.
9+ *
10+ * Permission is granted to anyone to use this software for any purpose,
11+ * including commercial applications, and to alter it and redistribute it
12+ * freely, subject to the following restrictions:
13+ *
14+ * 1. The origin of this software must not be misrepresented; you must not
15+ * claim that you wrote the original software. If you use this software
16+ * in a product, an acknowledgment in the product documentation would be
17+ * appreciated but is not required.
18+ *
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ *
22+ * 3. This notice may not be removed or altered from any source
23+ * distribution.
24+ *
25+ */
26+
27+#include <btron/btron.h>
28+#include <bstdio.h>
29+#include <tcode.h>
30+
31+#include "test.h"
32+
33+#include "array.h"
34+
35+LOCAL TEST_RESULT test_array_1()
36+{
37+ arraybase_t array;
38+ W i, err, *val;
39+ TEST_RESULT result = TEST_RESULT_PASS;
40+ Bool found;
41+
42+ err = arraybase_initialize(&array, sizeof(W), 100);
43+ if (err < 0) {
44+ return TEST_RESULT_FAIL;
45+ }
46+
47+ for (i = 0; i < 100; i++) {
48+ err = arraybase_appendunit(&array, (VP)&i);
49+ if (err < 0) {
50+ printf("arraybase_appendunit failure\n");
51+ result = TEST_RESULT_FAIL;
52+ }
53+ }
54+ for (i = 0; i < 100; i++) {
55+ found = arraybase_getunitbyindex(&array, i, (VP)&val);
56+ if (found != True) {
57+ printf("arraybase_getunitbyindex not found failure\n");
58+ result = TEST_RESULT_FAIL;
59+ }
60+ if (*val != i) {
61+ printf("arraybase_getunitbyindex unexpected value failure: %d:%d\n", i, *val);
62+ result = TEST_RESULT_FAIL;
63+ }
64+ }
65+
66+ arraybase_finalize(&array);
67+
68+ return result;
69+}
70+
71+LOCAL TEST_RESULT test_array_2()
72+{
73+ arraybase_t array;
74+ W i, err, *val;
75+ TEST_RESULT result = TEST_RESULT_PASS;
76+ Bool found;
77+
78+ err = arraybase_initialize(&array, sizeof(W), 100);
79+ if (err < 0) {
80+ return TEST_RESULT_FAIL;
81+ }
82+
83+ for (i = 0; i < 200; i++) {
84+ err = arraybase_appendunit(&array, (VP)&i);
85+ if (err < 0) {
86+ printf("arraybase_appendunit failure\n");
87+ result = TEST_RESULT_FAIL;
88+ }
89+ }
90+ for (i = 0; i < 200; i++) {
91+ found = arraybase_getunitbyindex(&array, i, (VP)&val);
92+ if (found != True) {
93+ printf("arraybase_getunitbyindex not found failure\n");
94+ result = TEST_RESULT_FAIL;
95+ }
96+ if (*val != i) {
97+ printf("arraybase_getunitbyindex unexpected value failure: %d:%d\n", i, *val);
98+ result = TEST_RESULT_FAIL;
99+ }
100+ }
101+
102+ arraybase_finalize(&array);
103+
104+ return result;
105+}
106+
107+LOCAL TEST_RESULT test_array_3()
108+{
109+ arraybase_t array;
110+ W i, err, *val;
111+ TEST_RESULT result = TEST_RESULT_PASS;
112+ Bool found;
113+
114+ err = arraybase_initialize(&array, sizeof(W), 100);
115+ if (err < 0) {
116+ return TEST_RESULT_FAIL;
117+ }
118+
119+ for (i = 0; i < 2000; i++) {
120+ err = arraybase_appendunit(&array, (VP)&i);
121+ if (err < 0) {
122+ printf("arraybase_appendunit failure\n");
123+ result = TEST_RESULT_FAIL;
124+ }
125+ }
126+ for (i = 0; i < 2000; i++) {
127+ found = arraybase_getunitbyindex(&array, i, (VP)&val);
128+ if (found != True) {
129+ printf("arraybase_getunitbyindex not found failure\n");
130+ result = TEST_RESULT_FAIL;
131+ }
132+ if (*val != i) {
133+ printf("arraybase_getunitbyindex unexpected value failure: %d:%d\n", i, *val);
134+ result = TEST_RESULT_FAIL;
135+ }
136+ }
137+
138+ arraybase_finalize(&array);
139+
140+ return result;
141+}
142+
143+LOCAL TEST_RESULT test_array_4()
144+{
145+ arraybase_t array;
146+ W i, err, *val;
147+ TEST_RESULT result = TEST_RESULT_PASS;
148+ Bool found;
149+
150+ err = arraybase_initialize(&array, sizeof(W), 100);
151+ if (err < 0) {
152+ return TEST_RESULT_FAIL;
153+ }
154+
155+ for (i = 0; i < 100; i++) {
156+ err = arraybase_appendunit(&array, (VP)&i);
157+ if (err < 0) {
158+ printf("arraybase_appendunit failure\n");
159+ result = TEST_RESULT_FAIL;
160+ }
161+ }
162+ for (i = 0; i < 200; i++) {
163+ found = arraybase_getunitbyindex(&array, i, (VP)&val);
164+ if (i < 100) {
165+ if (found != True) {
166+ printf("arraybase_getunitbyindex not found failure\n");
167+ result = TEST_RESULT_FAIL;
168+ }
169+ if (*val != i) {
170+ printf("arraybase_getunitbyindex unexpected value failure: %d:%d\n", i, *val);
171+ result = TEST_RESULT_FAIL;
172+ }
173+ } else {
174+ if (found != False) {
175+ printf("arraybase_getunitbyindex found failure\n");
176+ result = TEST_RESULT_FAIL;
177+ }
178+ }
179+ }
180+
181+ arraybase_finalize(&array);
182+
183+ return result;
184+}
185+
186+LOCAL TEST_RESULT test_array_5()
187+{
188+ arraybase_t array;
189+ W i, err, *val;
190+ TEST_RESULT result = TEST_RESULT_PASS;
191+ Bool found;
192+
193+ err = arraybase_initialize(&array, sizeof(W), 100);
194+ if (err < 0) {
195+ return TEST_RESULT_FAIL;
196+ }
197+
198+ for (i = 0; i < 50; i++) {
199+ err = arraybase_appendunit(&array, (VP)&i);
200+ if (err < 0) {
201+ printf("arraybase_appendunit failure\n");
202+ result = TEST_RESULT_FAIL;
203+ }
204+ }
205+ for (i = 0; i < 200; i++) {
206+ found = arraybase_getunitbyindex(&array, i, (VP)&val);
207+ if (i < 50) {
208+ if (found != True) {
209+ printf("arraybase_getunitbyindex not found failure\n");
210+ result = TEST_RESULT_FAIL;
211+ }
212+ if (*val != i) {
213+ printf("arraybase_getunitbyindex unexpected value failure: %d:%d\n", i, *val);
214+ result = TEST_RESULT_FAIL;
215+ }
216+ } else {
217+ if (found != False) {
218+ printf("arraybase_getunitbyindex found failure\n");
219+ result = TEST_RESULT_FAIL;
220+ }
221+ }
222+ }
223+
224+ arraybase_finalize(&array);
225+
226+ return result;
227+}
228+
229+LOCAL TEST_RESULT test_array_6()
230+{
231+ arraybase_t array;
232+ W i, err, *val;
233+ TEST_RESULT result = TEST_RESULT_PASS;
234+ Bool found;
235+
236+ err = arraybase_initialize(&array, sizeof(W), 100);
237+ if (err < 0) {
238+ return TEST_RESULT_FAIL;
239+ }
240+
241+ for (i = 0; i < 150; i++) {
242+ err = arraybase_appendunit(&array, (VP)&i);
243+ if (err < 0) {
244+ printf("arraybase_appendunit failure\n");
245+ result = TEST_RESULT_FAIL;
246+ }
247+ }
248+ for (i = 0; i < 200; i++) {
249+ found = arraybase_getunitbyindex(&array, i, (VP)&val);
250+ if (i < 150) {
251+ if (found != True) {
252+ printf("arraybase_getunitbyindex not found failure\n");
253+ result = TEST_RESULT_FAIL;
254+ }
255+ if (*val != i) {
256+ printf("arraybase_getunitbyindex unexpected value failure: %d:%d\n", i, *val);
257+ result = TEST_RESULT_FAIL;
258+ }
259+ } else {
260+ if (found != False) {
261+ printf("arraybase_getunitbyindex found failure\n");
262+ result = TEST_RESULT_FAIL;
263+ }
264+ }
265+ }
266+
267+ arraybase_finalize(&array);
268+
269+ return result;
270+}
271+
272+typedef struct {
273+ W a;
274+ W b;
275+ W c;
276+} test_array_dummydata;
277+
278+LOCAL TEST_RESULT test_array_7()
279+{
280+ arraybase_t array;
281+ W i, err;
282+ test_array_dummydata val, *val2;
283+ TEST_RESULT result = TEST_RESULT_PASS;
284+ Bool found;
285+
286+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), 100);
287+ if (err < 0) {
288+ return TEST_RESULT_FAIL;
289+ }
290+
291+ for (i = 0; i < 100; i++) {
292+ val.a = 100;
293+ val.b = i + 1234;
294+ val.c = i % 23 ;
295+ err = arraybase_appendunit(&array, (VP)&val);
296+ if (err < 0) {
297+ printf("arraybase_appendunit failure\n");
298+ result = TEST_RESULT_FAIL;
299+ }
300+ }
301+ for (i = 0; i < 100; i++) {
302+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
303+ if (found != True) {
304+ printf("arraybase_getunitbyindex not found failure\n");
305+ result = TEST_RESULT_FAIL;
306+ }
307+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
308+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
309+ result = TEST_RESULT_FAIL;
310+ }
311+ }
312+
313+ arraybase_finalize(&array);
314+
315+ return result;
316+}
317+
318+LOCAL TEST_RESULT test_array_8()
319+{
320+ arraybase_t array;
321+ W i, err;
322+ test_array_dummydata val, *val2;
323+ TEST_RESULT result = TEST_RESULT_PASS;
324+ Bool found;
325+
326+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), 100);
327+ if (err < 0) {
328+ return TEST_RESULT_FAIL;
329+ }
330+
331+ for (i = 0; i < 200; i++) {
332+ val.a = 100;
333+ val.b = i + 1234;
334+ val.c = i % 23 ;
335+ err = arraybase_appendunit(&array, (VP)&val);
336+ if (err < 0) {
337+ printf("arraybase_appendunit failure\n");
338+ result = TEST_RESULT_FAIL;
339+ }
340+ }
341+ for (i = 0; i < 200; i++) {
342+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
343+ if (found != True) {
344+ printf("arraybase_getunitbyindex not found failure\n");
345+ result = TEST_RESULT_FAIL;
346+ }
347+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
348+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
349+ result = TEST_RESULT_FAIL;
350+ }
351+ }
352+
353+ arraybase_finalize(&array);
354+
355+ return result;
356+}
357+
358+LOCAL TEST_RESULT test_array_9()
359+{
360+ arraybase_t array;
361+ W i, err;
362+ test_array_dummydata val, *val2;
363+ TEST_RESULT result = TEST_RESULT_PASS;
364+ Bool found;
365+
366+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), 100);
367+ if (err < 0) {
368+ return TEST_RESULT_FAIL;
369+ }
370+
371+ for (i = 0; i < 2000; i++) {
372+ val.a = 100;
373+ val.b = i + 1234;
374+ val.c = i % 23 ;
375+ err = arraybase_appendunit(&array, (VP)&val);
376+ if (err < 0) {
377+ printf("arraybase_appendunit failure\n");
378+ result = TEST_RESULT_FAIL;
379+ }
380+ }
381+ for (i = 0; i < 2000; i++) {
382+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
383+ if (found != True) {
384+ printf("arraybase_getunitbyindex not found failure\n");
385+ result = TEST_RESULT_FAIL;
386+ }
387+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
388+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
389+ result = TEST_RESULT_FAIL;
390+ }
391+ }
392+
393+ arraybase_finalize(&array);
394+
395+ return result;
396+}
397+
398+LOCAL TEST_RESULT test_array_10()
399+{
400+ arraybase_t array;
401+ W i, err;
402+ test_array_dummydata val, *val2;
403+ TEST_RESULT result = TEST_RESULT_PASS;
404+ Bool found;
405+
406+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), 100);
407+ if (err < 0) {
408+ return TEST_RESULT_FAIL;
409+ }
410+
411+ for (i = 0; i < 100; i++) {
412+ val.a = 100;
413+ val.b = i + 1234;
414+ val.c = i % 23 ;
415+ err = arraybase_appendunit(&array, (VP)&val);
416+ if (err < 0) {
417+ printf("arraybase_appendunit failure\n");
418+ result = TEST_RESULT_FAIL;
419+ }
420+ }
421+ for (i = 0; i < 200; i++) {
422+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
423+ if (i < 100) {
424+ if (found != True) {
425+ printf("arraybase_getunitbyindex not found failure\n");
426+ result = TEST_RESULT_FAIL;
427+ }
428+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
429+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
430+ result = TEST_RESULT_FAIL;
431+ }
432+ } else {
433+ if (found != False) {
434+ printf("arraybase_getunitbyindex found failure\n");
435+ result = TEST_RESULT_FAIL;
436+ }
437+ }
438+ }
439+
440+ arraybase_finalize(&array);
441+
442+ return result;
443+}
444+
445+LOCAL TEST_RESULT test_array_11()
446+{
447+ arraybase_t array;
448+ W i, err;
449+ test_array_dummydata val, *val2;
450+ TEST_RESULT result = TEST_RESULT_PASS;
451+ Bool found;
452+
453+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), 100);
454+ if (err < 0) {
455+ return TEST_RESULT_FAIL;
456+ }
457+
458+ for (i = 0; i < 50; i++) {
459+ val.a = 100;
460+ val.b = i + 1234;
461+ val.c = i % 23 ;
462+ err = arraybase_appendunit(&array, (VP)&val);
463+ if (err < 0) {
464+ printf("arraybase_appendunit failure\n");
465+ result = TEST_RESULT_FAIL;
466+ }
467+ }
468+ for (i = 0; i < 200; i++) {
469+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
470+ if (i < 50) {
471+ if (found != True) {
472+ printf("arraybase_getunitbyindex not found failure\n");
473+ result = TEST_RESULT_FAIL;
474+ }
475+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
476+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
477+ result = TEST_RESULT_FAIL;
478+ }
479+ } else {
480+ if (found != False) {
481+ printf("arraybase_getunitbyindex found failure\n");
482+ result = TEST_RESULT_FAIL;
483+ }
484+ }
485+ }
486+
487+ arraybase_finalize(&array);
488+
489+ return result;
490+}
491+
492+LOCAL TEST_RESULT test_array_12()
493+{
494+ arraybase_t array;
495+ W i, err;
496+ test_array_dummydata val, *val2;
497+ TEST_RESULT result = TEST_RESULT_PASS;
498+ Bool found;
499+
500+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), 100);
501+ if (err < 0) {
502+ return TEST_RESULT_FAIL;
503+ }
504+
505+ for (i = 0; i < 150; i++) {
506+ val.a = 100;
507+ val.b = i + 1234;
508+ val.c = i % 23 ;
509+ err = arraybase_appendunit(&array, (VP)&val);
510+ if (err < 0) {
511+ printf("arraybase_appendunit failure\n");
512+ result = TEST_RESULT_FAIL;
513+ }
514+ }
515+ for (i = 0; i < 200; i++) {
516+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
517+ if (i < 150) {
518+ if (found != True) {
519+ printf("arraybase_getunitbyindex not found failure\n");
520+ result = TEST_RESULT_FAIL;
521+ }
522+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
523+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
524+ result = TEST_RESULT_FAIL;
525+ }
526+ } else {
527+ if (found != False) {
528+ printf("arraybase_getunitbyindex found failure\n");
529+ result = TEST_RESULT_FAIL;
530+ }
531+ }
532+ }
533+
534+ arraybase_finalize(&array);
535+
536+ return result;
537+}
538+
539+LOCAL TEST_RESULT test_array_truncate_base(W denom, W testnum, W truncate, W checklen)
540+{
541+ arraybase_t array;
542+ W i, err, arraylen;
543+ test_array_dummydata val, *val2;
544+ TEST_RESULT result = TEST_RESULT_PASS;
545+ Bool found;
546+
547+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), denom);
548+ if (err < 0) {
549+ return TEST_RESULT_FAIL;
550+ }
551+
552+ for (i = 0; i < testnum; i++) {
553+ val.a = 100;
554+ val.b = i + 1234;
555+ val.c = i % 23 ;
556+ err = arraybase_appendunit(&array, (VP)&val);
557+ if (err < 0) {
558+ printf("arraybase_appendunit failure\n");
559+ result = TEST_RESULT_FAIL;
560+ }
561+ }
562+
563+ arraybase_truncate(&array, truncate);
564+
565+ if (truncate > testnum) {
566+ arraylen = testnum;
567+ } else {
568+ arraylen = truncate;
569+ }
570+
571+ for (i = 0; i < checklen; i++) {
572+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
573+ if (i < arraylen) {
574+ if (found != True) {
575+ printf("arraybase_getunitbyindex not found failure\n");
576+ result = TEST_RESULT_FAIL;
577+ }
578+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
579+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
580+ result = TEST_RESULT_FAIL;
581+ }
582+ } else {
583+ if (found != False) {
584+ printf("arraybase_getunitbyindex found failure\n");
585+ result = TEST_RESULT_FAIL;
586+ }
587+ }
588+ }
589+
590+ arraybase_finalize(&array);
591+
592+ return result;
593+}
594+
595+LOCAL TEST_RESULT test_array_13()
596+{
597+ return test_array_truncate_base(100, 100, 0, 200);
598+}
599+
600+LOCAL TEST_RESULT test_array_14()
601+{
602+ return test_array_truncate_base(100, 100, 50, 200);
603+}
604+
605+LOCAL TEST_RESULT test_array_15()
606+{
607+ return test_array_truncate_base(100, 100, 100, 200);
608+}
609+
610+LOCAL TEST_RESULT test_array_16()
611+{
612+ return test_array_truncate_base(100, 100, 200, 200);
613+}
614+
615+LOCAL TEST_RESULT test_array_17()
616+{
617+ return test_array_truncate_base(50, 100, 00, 200);
618+}
619+
620+LOCAL TEST_RESULT test_array_18()
621+{
622+ return test_array_truncate_base(50, 100, 50, 200);
623+}
624+
625+LOCAL TEST_RESULT test_array_19()
626+{
627+ return test_array_truncate_base(50, 100, 100, 200);
628+}
629+
630+LOCAL TEST_RESULT test_array_20()
631+{
632+ return test_array_truncate_base(50, 100, 200, 200);
633+}
634+
635+LOCAL TEST_RESULT test_array_21()
636+{
637+ return test_array_truncate_base(100, 500, 0, 1000);
638+}
639+
640+LOCAL TEST_RESULT test_array_22()
641+{
642+ return test_array_truncate_base(100, 500, 50, 1000);
643+}
644+
645+LOCAL TEST_RESULT test_array_23()
646+{
647+ return test_array_truncate_base(100, 500, 250, 1000);
648+}
649+
650+LOCAL TEST_RESULT test_array_24()
651+{
652+ return test_array_truncate_base(100, 500, 500, 1000);
653+}
654+
655+LOCAL TEST_RESULT test_array_25()
656+{
657+ return test_array_truncate_base(100, 500, 1000, 1000);
658+}
659+
660+LOCAL TEST_RESULT test_array_truncate_2_base(W denom, W testnum1, W truncate, W testnum2, W checklen)
661+{
662+ arraybase_t array;
663+ W i, err, arraylen;
664+ test_array_dummydata val, *val2;
665+ TEST_RESULT result = TEST_RESULT_PASS;
666+ Bool found;
667+
668+ err = arraybase_initialize(&array, sizeof(test_array_dummydata), denom);
669+ if (err < 0) {
670+ return TEST_RESULT_FAIL;
671+ }
672+
673+ for (i = 0; i < testnum1; i++) {
674+ val.a = 100;
675+ val.b = i + 1234;
676+ val.c = i % 23 ;
677+ err = arraybase_appendunit(&array, (VP)&val);
678+ if (err < 0) {
679+ printf("arraybase_appendunit failure\n");
680+ result = TEST_RESULT_FAIL;
681+ }
682+ }
683+
684+ arraybase_truncate(&array, truncate);
685+
686+ if (truncate > testnum1) {
687+ arraylen = testnum1;
688+ } else {
689+ arraylen = truncate;
690+ }
691+
692+ for (i = arraylen; i < arraylen + testnum2; i++) {
693+ val.a = 100;
694+ val.b = i + 1234;
695+ val.c = i % 23 ;
696+ err = arraybase_appendunit(&array, (VP)&val);
697+ if (err < 0) {
698+ printf("arraybase_appendunit failure\n");
699+ result = TEST_RESULT_FAIL;
700+ }
701+ }
702+
703+ arraylen += testnum2;
704+
705+ for (i = 0; i < checklen; i++) {
706+ found = arraybase_getunitbyindex(&array, i, (VP)&val2);
707+ if (i < arraylen) {
708+ if (found != True) {
709+ printf("arraybase_getunitbyindex not found failure\n");
710+ result = TEST_RESULT_FAIL;
711+ }
712+ if ((val2->a != 100)||(val2->b != i + 1234)||(val2->c != i % 23)) {
713+ printf("arraybase_getunitbyindex unexpected value failure: %d\n", i);
714+ result = TEST_RESULT_FAIL;
715+ }
716+ } else {
717+ if (found != False) {
718+ printf("arraybase_getunitbyindex found failure\n");
719+ result = TEST_RESULT_FAIL;
720+ }
721+ }
722+ }
723+
724+ arraybase_finalize(&array);
725+
726+ return result;
727+}
728+
729+LOCAL TEST_RESULT test_array_26()
730+{
731+ return test_array_truncate_2_base(100, 100, 0, 50, 200);
732+}
733+
734+LOCAL TEST_RESULT test_array_27()
735+{
736+ return test_array_truncate_2_base(100, 100, 50, 50, 200);
737+}
738+
739+LOCAL TEST_RESULT test_array_28()
740+{
741+ return test_array_truncate_2_base(100, 100, 100, 50, 200);
742+}
743+
744+LOCAL TEST_RESULT test_array_29()
745+{
746+ return test_array_truncate_2_base(100, 100, 200, 50, 200);
747+}
748+
749+LOCAL TEST_RESULT test_array_30()
750+{
751+ return test_array_truncate_2_base(50, 100, 00, 100, 200);
752+}
753+
754+LOCAL TEST_RESULT test_array_31()
755+{
756+ return test_array_truncate_2_base(50, 100, 50, 100, 200);
757+}
758+
759+LOCAL TEST_RESULT test_array_32()
760+{
761+ return test_array_truncate_2_base(50, 100, 100, 100, 200);
762+}
763+
764+LOCAL TEST_RESULT test_array_33()
765+{
766+ return test_array_truncate_2_base(50, 100, 200, 100, 200);
767+}
768+
769+LOCAL TEST_RESULT test_array_34()
770+{
771+ return test_array_truncate_2_base(100, 500, 0, 100, 1000);
772+}
773+
774+LOCAL TEST_RESULT test_array_35()
775+{
776+ return test_array_truncate_2_base(100, 500, 50, 100, 1000);
777+}
778+
779+LOCAL TEST_RESULT test_array_36()
780+{
781+ return test_array_truncate_2_base(100, 500, 250, 100, 1000);
782+}
783+
784+LOCAL TEST_RESULT test_array_37()
785+{
786+ return test_array_truncate_2_base(100, 500, 500, 100, 1000);
787+}
788+
789+LOCAL TEST_RESULT test_array_38()
790+{
791+ return test_array_truncate_2_base(100, 500, 1000, 100, 1000);
792+}
793+
794+LOCAL VOID test_array_printresult(TEST_RESULT (*proc)(), B *test_name)
795+{
796+ TEST_RESULT result;
797+
798+ printf("test_array: %s\n", test_name);
799+ printf("---------------------------------------------\n");
800+ result = proc();
801+ if (result == TEST_RESULT_PASS) {
802+ printf("--pass---------------------------------------\n");
803+ } else {
804+ printf("--fail---------------------------------------\n");
805+ }
806+ printf("---------------------------------------------\n");
807+}
808+
809+EXPORT VOID test_array_main()
810+{
811+ test_array_printresult(test_array_1, "test_array_1");
812+ test_array_printresult(test_array_2, "test_array_2");
813+ test_array_printresult(test_array_3, "test_array_3");
814+ test_array_printresult(test_array_4, "test_array_4");
815+ test_array_printresult(test_array_5, "test_array_5");
816+ test_array_printresult(test_array_6, "test_array_6");
817+ test_array_printresult(test_array_7, "test_array_7");
818+ test_array_printresult(test_array_8, "test_array_8");
819+ test_array_printresult(test_array_9, "test_array_9");
820+ test_array_printresult(test_array_10, "test_array_10");
821+ test_array_printresult(test_array_11, "test_array_11");
822+ test_array_printresult(test_array_12, "test_array_12");
823+ test_array_printresult(test_array_13, "test_array_13");
824+ test_array_printresult(test_array_14, "test_array_14");
825+ test_array_printresult(test_array_15, "test_array_15");
826+ test_array_printresult(test_array_16, "test_array_16");
827+ test_array_printresult(test_array_17, "test_array_17");
828+ test_array_printresult(test_array_18, "test_array_18");
829+ test_array_printresult(test_array_19, "test_array_19");
830+ test_array_printresult(test_array_20, "test_array_20");
831+ test_array_printresult(test_array_21, "test_array_21");
832+ test_array_printresult(test_array_22, "test_array_22");
833+ test_array_printresult(test_array_23, "test_array_23");
834+ test_array_printresult(test_array_24, "test_array_24");
835+ test_array_printresult(test_array_25, "test_array_25");
836+ test_array_printresult(test_array_26, "test_array_26");
837+ test_array_printresult(test_array_27, "test_array_27");
838+ test_array_printresult(test_array_28, "test_array_28");
839+ test_array_printresult(test_array_29, "test_array_29");
840+ test_array_printresult(test_array_30, "test_array_30");
841+ test_array_printresult(test_array_31, "test_array_31");
842+ test_array_printresult(test_array_32, "test_array_32");
843+ test_array_printresult(test_array_33, "test_array_33");
844+ test_array_printresult(test_array_34, "test_array_34");
845+ test_array_printresult(test_array_35, "test_array_35");
846+ test_array_printresult(test_array_36, "test_array_36");
847+ test_array_printresult(test_array_37, "test_array_37");
848+ test_array_printresult(test_array_38, "test_array_38");
849+}
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Show on old repository browser