-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
166 lines (107 loc) · 3.17 KB
/
main.c
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
#include <stdio.h>
#include <conio.h>
#include "dmutil.h"
#include "dm.h"
#include "mem.h"
//#define TEST_MEM
//#define TEST_DM
#define TEST_HEIRARCHY_TRAVERSAL
int main(int argc, char **argv)
{
MEM_do_guard();
#ifdef TEST_HEIRARCHY_TRAVERSAL
ValveDataModel *vdm;
DMElement *parent, *child_1, *child_11, *child_12, *child_2, *child_21, *child_22, *child_23;
vdm = MEM_calloc(sizeof(ValveDataModel), "test datamodel");
DM_Init(vdm, "test datamodel", 1);
parent = DM_add_element(vdm, "parent", "parent");
child_1 = DM_add_element(vdm, "child_1", "plain_child");
child_2 = DM_add_element(vdm, "child_2", "plain_child");
child_11 = DM_add_element(vdm, "child_11", "plain_child");
child_12 = DM_add_element(vdm, "child_12", "plain_child");
child_21 = DM_add_element(vdm, "child_21", "plain_child");
child_22 = DM_add_element(vdm, "child_22", "array_child");
child_23 = DM_add_element(vdm, "child_23", "array_child");
DM_Release(vdm);
MEM_free(vdm);
MEM_printblocks(stdout);
_getch();
#endif
#ifdef TEST_DM
DMElement *ele;
DMEAttribute *attr;
DMEAttribute *ints;
DMEAttribute *vec4;
ValveDataModel dm;
char *s1 = "Wazzup!";
char *s2;
int vec[3] = {1, 2, 3};
int *vi;
float v4[4] = { 4, 3, 2, 1 };
char *sar1 = "Yah!";
char *sar2 = "Wooh!";
char *sar3 = "Bar!";
char *sar[3];
sar[0] = sar1;
sar[1] = sar2;
sar[2] = sar3;
char **sar_back;
VMatrix *vm = MEM_calloc(sizeof(VMatrix) * 1000, "test matrices");
VMatrix *back;
for (int c = 0; c < 1000; ++c)
for (int a = 0; a < 4; ++a)
for (int b = 0; b < 4; ++b)
vm[c].m[a][b] = (float) c - 2 + a + b - a * b;
DM_Init(&dm, "test", 0);
ele = DM_add_element(&dm, "element-name", "element-type");
MEM_printblocks(stdout);
attr = DME_add_attribute(ele, "FIRST", AT_FLOAT);
DMEA_SetFloat(attr, 1.3f);
ints = DME_add_attribute(ele, "SECOND", AT_INT_ARRAY);
DMEA_SetIntArray(ints, vec, 3);
vec4 = DME_add_attribute(ele, "THIRD", AT_VECTOR4);
DMEA_SetVec4(vec4, v4);
DMEAttribute *vmtx = DME_add_attribute(ele, "FOURTH", AT_VMATRIX_ARRAY);
DMEA_SetMtxArray(vmtx, vm, 1000);
DMEA_GetMtxArray(vmtx, &back);
DMEAttribute *str = DME_add_attribute(ele, "string-attr", AT_STRING);
DMEA_SetString(str, s1);
DMEAttribute *stringarray = DME_add_attribute(ele, "string array", AT_STRING_ARRAY);
DMEA_SetStringArray(stringarray, sar, 3);
MEM_printblocks(stdout);
printf("f: %f\n", DMEA_GetFloat(attr));
DMEA_GetIntArray(ints, (int **) &vi);
printf("ia: %d %d %d\n", vi[0], vi[1], vi[2]);
DME_remove_attribute(ele, attr);
DMEA_GetString(str, &s2);
sar_back = DMEA_GetStringArray(stringarray);
DM_remove_element(&dm, ele);
for (int i = 0; i < 3; ++i) {
printf("%s\n", sar_back[i]);
}
printf("%s\n", s2);
_getch();
DM_Release(&dm);
MEM_free(vi);
MEM_printblocks(stdout);
_getch();
#endif
#ifdef TEST_MEM
int *a = MEM_calloc(100, "ints");
float *t = MEM_malloc(3123, "floats");
MEM_printblocks(stdout);
_getch();
MEM_free(a);
MEM_printblocks(stdout);
MEM_free(t);
MEM_printblocks(stdout);
a = MEM_malloc(123, "FIRST");
a = MEM_malloc(11, "SECOND");
t = MEM_malloc(3, "THIRD");
MEM_printblocks(stdout);
MEM_free(a);
MEM_printblocks(stdout);
_getch();
#endif
return 0;
}