-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.c
More file actions
260 lines (215 loc) · 6.61 KB
/
test.c
File metadata and controls
260 lines (215 loc) · 6.61 KB
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
// this technically compiles without standard.h, but takes forever to link
// gatui_tree_select_in_model_by_path makes this extremely expensive
#include "standard.h"
#include "atomtree.h"
#include "atui.h"
#include "gatui_private.h"
#include "yaabe_gtk4.h"
// landing is in main
static struct error error = {}; // error handling
inline static void
gatui_leaf_test_memory(
GATUILeaf* const leaf
) {
if (gatui_leaf_has_textable_value(leaf)) {
char* value_text = NULL;
value_text = gatui_leaf_value_to_text(leaf, false);
gatui_leaf_set_value_from_text(leaf, value_text, false);
free(value_text);
value_text = NULL;
value_text = gatui_leaf_value_to_text(leaf, true);
gatui_leaf_set_value_from_text(leaf, value_text, true);
free(value_text);
}
}
inline static void
gatui_node_test_memory(
GATUINode* const node,
GATUITree* const root
) {
size_t bios_size = 0;
void const* const bios = gatui_tree_get_bios_pointer(root, &bios_size);
atui_node const* const atui = _gatui_node_get_atui(node);
bool success = false;
char* b64_text = NULL;
GVariant* val = NULL;
void* oldmem = NULL;
if (atui->num_bytes) {
oldmem = cralloc(atui->num_bytes);
memcpy(oldmem, atui->data.input, atui->num_bytes);
error_assert(&error, ERROR_CRASH, NULL,
bios <= atui->data.input
);
error_assert(&error, ERROR_CRASH, NULL,
(atui->data.input + atui->num_bytes - 1)
<= (bios + bios_size)
);
val = gatui_node_get_contiguous_data(node);
success = gatui_node_set_contiguous_data(node, val);
error_assert(&error, ERROR_CRASH, NULL, success);
success = gatui_node_set_value(node, val);
error_assert(&error, ERROR_CRASH, NULL, success);
g_variant_unref(val);
val = NULL;
val = gatui_node_get_value(node);
success = gatui_node_set_value(node, val);
error_assert(&error, ERROR_CRASH, NULL, success);
g_variant_unref(val);
val = NULL;
b64_text = gatui_node_to_base64(node, GATUI_NODE_B64_CONTIGUOUS);
success = gatui_node_from_base64(node, b64_text, NULL);
error_assert(&error, ERROR_CRASH, NULL, success);
free(b64_text);
b64_text = NULL;
b64_text = gatui_node_to_base64(node, GATUI_NODE_B64_VALUE);
success = gatui_node_from_base64(node, b64_text, NULL);
error_assert(&error, ERROR_CRASH, NULL, success);
free(b64_text);
b64_text = NULL;
success = 0 == memcmp(oldmem, atui->data.input, atui->num_bytes);
error_assert(&error, ERROR_CRASH, NULL, success);
}
if (atui->num_copyable_leaves) {
uint16_t num_copyable_leaves = 0;
val = NULL;
gatui_node_get_leaves_package(node, &val, &num_copyable_leaves);
success = gatui_node_set_leaves_memory_package(
node, val, num_copyable_leaves
);
error_assert(&error, ERROR_CRASH, NULL, success);
g_variant_unref(val);
val = NULL;
b64_text = gatui_node_to_base64(node, GATUI_NODE_B64_LEAVES_PACKAGE);
success = gatui_node_from_base64(node, b64_text, NULL);
error_assert(&error, ERROR_CRASH, NULL, success);
free(b64_text);
b64_text = NULL;
success = 0 == memcmp(oldmem, atui->data.input, atui->num_bytes);
error_assert(&error, ERROR_CRASH, NULL, success);
}
if (GATUI_IS_LEAF(node)) {
gatui_leaf_test_memory(GATUI_LEAF(node));
success = 0 == memcmp(oldmem, atui->data.input, atui->num_bytes);
error_assert(&error, ERROR_CRASH, NULL, success);
}
free(oldmem);
}
inline static char*
gatui_node_test_path(
GATUINode* const node,
GATUITree* const root
) {
char* const path = gatui_node_to_path(node);
bool success;
int16_t branch_index = -1;
int16_t leaf_index = -1;
success = gatui_tree_select_in_model_by_path(
root, path, &branch_index, &leaf_index, NULL
);
error_assert(&error, ERROR_CRASH, NULL,
success
);
GATUINode* node_via_roundabout = NULL;
GListModel* const branch_model = G_LIST_MODEL(
gatui_tree_create_trunk_model(root)
);
GtkTreeListRow* const branch_row = GTK_TREE_LIST_ROW(
g_list_model_get_item(branch_model, branch_index)
);
GATUIBranch* const owning_branch = GATUI_BRANCH(
gtk_tree_list_row_get_item(branch_row)
);
g_object_unref(branch_row);
g_object_unref(branch_model);
if (GATUI_IS_LEAF(node)) {
GListModel* const leaves_model = G_LIST_MODEL(
gatui_branch_get_leaves_model(owning_branch)
);
GtkTreeListRow* const leaf_row = GTK_TREE_LIST_ROW(
g_list_model_get_item(leaves_model, leaf_index)
);
node_via_roundabout = GATUI_NODE(gtk_tree_list_row_get_item(leaf_row));
g_object_unref(leaf_row);
//g_object_unref(leaves_model); // does not get ref'd
g_object_unref(owning_branch);
} else {
node_via_roundabout = GATUI_NODE(owning_branch);
}
error_assert(&error, ERROR_CRASH, NULL,
node == node_via_roundabout // test uniqueness
);
g_object_unref(node_via_roundabout);
return path;
}
static void
gatui_node_test(
GATUINode* const node
) {
atui_node const* const atui = _gatui_node_get_atui(node);
GATUITree* const root = gatui_node_get_root(node);
bool success;
bool const is_leaf = GATUI_IS_LEAF(node);
error_assert(&error, ERROR_CRASH, NULL,
is_leaf == atui->is_leaf
);
error_assert(&error, ERROR_CRASH, NULL,
strlen(atui->name) < sizeof(atui->name)
);
char* const path = gatui_node_test_path(node, root); // free later for debug
success = gatui_tree_select_in_model_by_path(root, path, NULL,NULL,NULL);
error_assert(&error, ERROR_CRASH, NULL,
success
);
gatui_node_test_memory(node, root);
if (atui->leaves.count) {
struct atui_children const* const leaves = &(atui->leaves);
GATUILeaf* const* const leaves_array = _gatui_node_get_leaf_array(node);
for (uint16_t i=0; i < leaves->count; i++) {
gatui_node_test(GATUI_NODE(leaves_array[i]));
}
}
if (! is_leaf) {
struct atui_children const* const branches = &(atui->branch.branches);
GATUIBranch* const* const branches_array = (
_gatui_branch_get_branches_array(GATUI_BRANCH(node))
);
for (uint16_t i=0; i < branches->count; i++) {
gatui_node_test(GATUI_NODE(branches_array[i]));
}
}
free(path);
}
int
main(
int const argc,
char const* const* const argv
) {
enum error_severity ret_val = NO_ERROR;
GATUITree* root = NULL;
setjmp(error.env);
ret_val = error.severity;
if (error.severity) {
return ret_val;
}
if (argc > 1) {
GError* ferror = NULL;
root = gatui_tree_new_from_path(argv[1], &ferror);
if (ferror) {
printf("%s\n", ferror->message);
g_error_free(ferror);
return 1;
}
}
if (root) {
error_assert(&error, ERROR_CRASH, NULL,
gatui_tree_get_atom_tree(root)
);
GATUINode* const trunk = GATUI_NODE(gatui_tree_get_trunk(root));
GtkSelectionModel* const model = gatui_tree_create_trunk_model(root);
gatui_node_test(trunk);
g_assert_finalize_object(model);
g_assert_finalize_object(trunk);
g_assert_finalize_object(root);
}
return ret_val;
}