Debian Codegraph @

tests/unit/test_table_max_length.template

raw
1 /**
2 * This file is part of the Detox package.
3 *
4 * Copyright (c) Doug Harple <[email protected]>
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "table.h"
15
16 struct test_data {
17 int value;
18 char *data;
19 int max_length;
20 };
21
22 #define DATA_COUNT 13
23 static struct test_data data[DATA_COUNT] = {
24 {
25 .value = 0x0001,
26 .data = "a",
27 .max_length = 1
28 },
29 {
30 .value = 0x0002,
31 .data = "b",
32 .max_length = 1
33 },
34 {
35 .value = 0x0003,
36 .data = "c",
37 .max_length = 1
38 },
39 {
40 .value = 0x0004,
41 .data = "don't",
42 .max_length = 5
43 },
44 {
45 .value = 0x0005,
46 .data = "eat",
47 .max_length = 5
48 },
49 {
50 .value = 0x0006,
51 .data = "the",
52 .max_length = 5
53 },
54 {
55 .value = 0x0007,
56 .data = "joe o's",
57 .max_length = 7
58 },
59 {
60 .value = 0x0008,
61 .data = "k",
62 .max_length = 7
63 },
64 {
65 .value = 0x0009,
66 .data = "moo",
67 .max_length = 7
68 },
69 {
70 .value = 0x000A,
71 .data = "true",
72 .max_length = 7
73 },
74 {
75 .value = 0x000B,
76 .data = "insanity",
77 .max_length = 8
78 },
79 {
80 .value = 0x1001,
81 .data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed",
82 .max_length = 60,
83 },
84 {
85 .value = 0x1002,
86 .data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
87 .max_length = 123,
88 },
89 };
90
91 #test test_table_max_length
92 table_t *table;
93 int i;
94
95 table = table_init(DATA_COUNT * 10);
96
97 for (i = 0; i < DATA_COUNT; i++) {
98 table_put(table, data[i].value, data[i].data);
99 ck_assert_int_eq(table->max_data_length, data[i].max_length);
100 }
101
102 #test test_table_max_length_after_resize
103 table_t *table;
104 table_t *check_table;
105 int i, j;
106 int max_length, old_max_length;
107
108 table = table_init(DATA_COUNT * 10);
109
110 for (i = 0; i < DATA_COUNT; i++) {
111 table_put(table, data[i].value, data[i].data);
112 }
113
114 max_length = table->max_data_length;
115
116 //
117 // confirm that max length gets copied over to a resized table
118 //
119
120 for (j = 0; j < 2; j++) {
121 check_table = table_resize(table, table->length, j);
122 ck_assert_int_eq(check_table->max_data_length, max_length);
123 table_free(check_table);
124 }
125
126 //
127 // put "a" in all the values, so when we resize, the max length on the new
128 // table should be 1.
129 //
130
131 old_max_length = max_length;
132 max_length = 1;
133
134 for (i = 0; i < DATA_COUNT; i++) {
135 table_put(table, data[i].value, "a");
136 }
137
138 for (j = 0; j < 2; j++) {
139 check_table = table_resize(table, table->length, j);
140 ck_assert_int_eq(check_table->max_data_length, max_length);
141 table_free(check_table);
142 }
143
144 //
145 // put "" in all the values, so when we resize, the max length on the new
146 // table should be 0.
147 //
148
149 max_length = 0;
150
151 for (i = 0; i < DATA_COUNT; i++) {
152 table_put(table, data[i].value, "");
153 }
154
155 for (j = 0; j < 2; j++) {
156 check_table = table_resize(table, table->length, j);
157 ck_assert_int_eq(check_table->max_data_length, max_length);
158 table_free(check_table);
159 }
160
161 //
162
163 ck_assert_int_eq(table->max_data_length, old_max_length);