git.haldean.org ubik / cc6401c
remove obsolete unit test Haldean Brown 4 years ago
1 changed file(s) with 0 addition(s) and 118 deletion(s). Raw diff Collapse all Expand all
+0
-118
test/unit/load_save.c less more
0 /*
1 * load_save.c: run unit tests for loading and saving values
2 * Copyright (C) 2015, Haldean Brown
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stdlib.h>
20
21 #include "ubik/ubik.h"
22 #include "ubik/stream.h"
23 #include "unit.h"
24
25
26 test_t
27 load_save()
28 {
29 struct ubik_stream s;
30 struct ubik_value *u, *v;
31
32 assert(ubik_stream_buffer(&s, NULL) == OK);
33
34 /*
35 * 0
36 * / \
37 * W 1
38 * / \
39 * 2 W
40 * / \
41 * / \
42 * 3 4
43 * / \ / \
44 * 5 W W W
45 * / \
46 * W W
47 */
48 u = calloc(6, sizeof(struct ubik_value));
49 u[0].tag = TAG_VALUE | TAG_LEFT_WORD | TAG_RIGHT_NODE;
50 u[0].left.w = 0x1234567890123456;
51 u[0].right.t = &u[1];
52 u[1].tag = TAG_VALUE | TAG_LEFT_NODE | TAG_RIGHT_WORD;
53 u[1].left.t = &u[2];
54 u[1].right.w = 0x456789012345678;
55 u[2].tag = TAG_VALUE | TAG_LEFT_NODE | TAG_RIGHT_NODE;
56 u[2].left.t = &u[3];
57 u[2].right.t = &u[4];
58 u[3].tag = TAG_VALUE | TAG_LEFT_NODE | TAG_RIGHT_WORD;
59 u[3].left.t = &u[5];
60 u[3].right.w = 0x123123123123123;
61 u[4].tag = TAG_VALUE | TAG_LEFT_WORD | TAG_RIGHT_WORD;
62 u[4].left.w = 0x00424242424242;
63 u[4].right.w = 0x0000000000000001;
64 u[5].tag = TAG_VALUE | TAG_LEFT_WORD | TAG_RIGHT_WORD;
65 u[5].left.w = 0x0;
66 u[5].right.w = 0xFFFFFFFFFFFFFFFF;
67
68 assert(ubik_value_save(&s, u) == OK);
69
70 v = calloc(1, sizeof(struct ubik_value));
71 assert(ubik_value_load(v, &s) == OK);
72 assert(ubik_take(v) == OK);
73
74 /* make sure tags are correct. */
75 assert(v->tag == u[0].tag);
76 assert(v->right.t->tag == u[1].tag);
77 assert(v->right.t->left.t->tag == u[2].tag);
78 assert(v->right.t->left.t->left.t->tag == u[3].tag);
79 assert(v->right.t->left.t->right.t->tag == u[4].tag);
80 assert(v->right.t->left.t->left.t->left.t->tag == u[5].tag);
81
82 /* make sure refcounts are all 1 except the root. */
83 assert(v->refcount == 1);
84 assert(v->right.t->refcount == 1);
85 assert(v->right.t->left.t->refcount == 1);
86 assert(v->right.t->left.t->left.t->refcount == 1);
87 assert(v->right.t->left.t->right.t->refcount == 1);
88 assert(v->right.t->left.t->left.t->left.t->refcount == 1);
89
90 /* 0.left */
91 assert(v->left.w == u->left.w);
92 /* 5.left */
93 assert(v->right.t->left.t->left.t->left.t->left.w ==
94 u->right.t->left.t->left.t->left.t->left.w);
95 /* 5.right */
96 assert(v->right.t->left.t->left.t->left.t->right.w ==
97 u->right.t->left.t->left.t->left.t->right.w);
98 /* 3.right */
99 assert(v->right.t->left.t->left.t->right.w ==
100 u->right.t->left.t->left.t->right.w);
101 /* 4.left */
102 assert(v->right.t->left.t->right.t->left.w ==
103 u->right.t->left.t->right.t->left.w);
104 /* 4.right */
105 assert(v->right.t->left.t->right.t->right.w ==
106 u->right.t->left.t->right.t->right.w);
107 /* 1.right */
108 assert(v->right.t->right.w == u->right.t->right.w);
109
110 ubik_stream_close(&s);
111 free(u);
112 assert(ubik_release(v) == OK);
113
114 return ok;
115 }
116
117 run_single(load_save)