6
6
https://developers.google.com/open-source/licenses/bsd
7
7
*/
8
8
9
- #include "record.h"
9
+ #include "test-lib.h"
10
+ #include "reftable/constants.h"
11
+ #include "reftable/record.h"
10
12
11
- #include "system.h"
12
- #include "basics.h"
13
- #include "constants.h"
14
- #include "test_framework.h"
15
- #include "reftable-tests.h"
16
-
17
- static void test_copy (struct reftable_record * rec )
13
+ static void t_copy (struct reftable_record * rec )
18
14
{
19
15
struct reftable_record copy ;
20
16
uint8_t typ ;
@@ -24,15 +20,12 @@ static void test_copy(struct reftable_record *rec)
24
20
reftable_record_copy_from (& copy , rec , GIT_SHA1_RAWSZ );
25
21
/* do it twice to catch memory leaks */
26
22
reftable_record_copy_from (& copy , rec , GIT_SHA1_RAWSZ );
27
- EXPECT (reftable_record_equal (rec , & copy , GIT_SHA1_RAWSZ ));
28
-
29
- puts ("testing print coverage:\n" );
30
- reftable_record_print (& copy , GIT_SHA1_RAWSZ );
23
+ check (reftable_record_equal (rec , & copy , GIT_SHA1_RAWSZ ));
31
24
32
25
reftable_record_release (& copy );
33
26
}
34
27
35
- static void test_varint_roundtrip (void )
28
+ static void t_varint_roundtrip (void )
36
29
{
37
30
uint64_t inputs [] = { 0 ,
38
31
1 ,
@@ -43,8 +36,8 @@ static void test_varint_roundtrip(void)
43
36
4096 ,
44
37
((uint64_t )1 << 63 ),
45
38
((uint64_t )1 << 63 ) + ((uint64_t )1 << 63 ) - 1 };
46
- int i = 0 ;
47
- for (i = 0 ; i < ARRAY_SIZE (inputs ); i ++ ) {
39
+
40
+ for (size_t i = 0 ; i < ARRAY_SIZE (inputs ); i ++ ) {
48
41
uint8_t dest [10 ];
49
42
50
43
struct string_view out = {
@@ -55,29 +48,26 @@ static void test_varint_roundtrip(void)
55
48
int n = put_var_int (& out , in );
56
49
uint64_t got = 0 ;
57
50
58
- EXPECT ( n > 0 );
51
+ check_int ( n , > , 0 );
59
52
out .len = n ;
60
53
n = get_var_int (& got , & out );
61
- EXPECT ( n > 0 );
54
+ check_int ( n , > , 0 );
62
55
63
- EXPECT (got == in );
56
+ check_int (got , = = , in );
64
57
}
65
58
}
66
59
67
60
static void set_hash (uint8_t * h , int j )
68
61
{
69
- int i = 0 ;
70
- for (i = 0 ; i < hash_size (GIT_SHA1_FORMAT_ID ); i ++ ) {
62
+ for (int i = 0 ; i < hash_size (GIT_SHA1_FORMAT_ID ); i ++ )
71
63
h [i ] = (j >> i ) & 0xff ;
72
- }
73
64
}
74
65
75
- static void test_reftable_ref_record_roundtrip (void )
66
+ static void t_reftable_ref_record_roundtrip (void )
76
67
{
77
68
struct strbuf scratch = STRBUF_INIT ;
78
- int i = 0 ;
79
69
80
- for (i = REFTABLE_REF_DELETION ; i < REFTABLE_NR_REF_VALUETYPES ; i ++ ) {
70
+ for (int i = REFTABLE_REF_DELETION ; i < REFTABLE_NR_REF_VALUETYPES ; i ++ ) {
81
71
struct reftable_record in = {
82
72
.type = BLOCK_TYPE_REF ,
83
73
};
@@ -107,19 +97,19 @@ static void test_reftable_ref_record_roundtrip(void)
107
97
}
108
98
in .u .ref .refname = xstrdup ("refs/heads/master" );
109
99
110
- test_copy (& in );
100
+ t_copy (& in );
111
101
112
- EXPECT (reftable_record_val_type (& in ) == i );
102
+ check_int (reftable_record_val_type (& in ), = = , i );
113
103
114
104
reftable_record_key (& in , & key );
115
105
n = reftable_record_encode (& in , dest , GIT_SHA1_RAWSZ );
116
- EXPECT ( n > 0 );
106
+ check_int ( n , > , 0 );
117
107
118
108
/* decode into a non-zero reftable_record to test for leaks. */
119
109
m = reftable_record_decode (& out , key , i , dest , GIT_SHA1_RAWSZ , & scratch );
120
- EXPECT ( n == m );
110
+ check_int ( n , = = , m );
121
111
122
- EXPECT (reftable_ref_record_equal (& in .u .ref , & out .u .ref ,
112
+ check (reftable_ref_record_equal (& in .u .ref , & out .u .ref ,
123
113
GIT_SHA1_RAWSZ ));
124
114
reftable_record_release (& in );
125
115
@@ -130,7 +120,7 @@ static void test_reftable_ref_record_roundtrip(void)
130
120
strbuf_release (& scratch );
131
121
}
132
122
133
- static void test_reftable_log_record_equal (void )
123
+ static void t_reftable_log_record_equal (void )
134
124
{
135
125
struct reftable_log_record in [2 ] = {
136
126
{
@@ -143,16 +133,15 @@ static void test_reftable_log_record_equal(void)
143
133
}
144
134
};
145
135
146
- EXPECT (!reftable_log_record_equal (& in [0 ], & in [1 ], GIT_SHA1_RAWSZ ));
136
+ check (!reftable_log_record_equal (& in [0 ], & in [1 ], GIT_SHA1_RAWSZ ));
147
137
in [1 ].update_index = in [0 ].update_index ;
148
- EXPECT (reftable_log_record_equal (& in [0 ], & in [1 ], GIT_SHA1_RAWSZ ));
138
+ check (reftable_log_record_equal (& in [0 ], & in [1 ], GIT_SHA1_RAWSZ ));
149
139
reftable_log_record_release (& in [0 ]);
150
140
reftable_log_record_release (& in [1 ]);
151
141
}
152
142
153
- static void test_reftable_log_record_roundtrip (void )
143
+ static void t_reftable_log_record_roundtrip (void )
154
144
{
155
- int i ;
156
145
struct reftable_log_record in [] = {
157
146
{
158
147
.refname = xstrdup ("refs/heads/master" ),
@@ -180,12 +169,12 @@ static void test_reftable_log_record_roundtrip(void)
180
169
}
181
170
};
182
171
struct strbuf scratch = STRBUF_INIT ;
172
+ set_hash (in [0 ].value .update .new_hash , 1 );
173
+ set_hash (in [0 ].value .update .old_hash , 2 );
174
+ set_hash (in [2 ].value .update .new_hash , 3 );
175
+ set_hash (in [2 ].value .update .old_hash , 4 );
183
176
184
- set_test_hash (in [0 ].value .update .new_hash , 1 );
185
- set_test_hash (in [0 ].value .update .old_hash , 2 );
186
- set_test_hash (in [2 ].value .update .new_hash , 3 );
187
- set_test_hash (in [2 ].value .update .old_hash , 4 );
188
- for (i = 0 ; i < ARRAY_SIZE (in ); i ++ ) {
177
+ for (size_t i = 0 ; i < ARRAY_SIZE (in ); i ++ ) {
189
178
struct reftable_record rec = { .type = BLOCK_TYPE_LOG };
190
179
struct strbuf key = STRBUF_INIT ;
191
180
uint8_t buffer [1024 ] = { 0 };
@@ -212,18 +201,18 @@ static void test_reftable_log_record_roundtrip(void)
212
201
213
202
rec .u .log = in [i ];
214
203
215
- test_copy (& rec );
204
+ t_copy (& rec );
216
205
217
206
reftable_record_key (& rec , & key );
218
207
219
208
n = reftable_record_encode (& rec , dest , GIT_SHA1_RAWSZ );
220
- EXPECT ( n >= 0 );
209
+ check_int ( n , >=, 0 );
221
210
valtype = reftable_record_val_type (& rec );
222
211
m = reftable_record_decode (& out , key , valtype , dest ,
223
212
GIT_SHA1_RAWSZ , & scratch );
224
- EXPECT ( n == m );
213
+ check_int ( n , = = , m );
225
214
226
- EXPECT (reftable_log_record_equal (& in [i ], & out .u .log ,
215
+ check (reftable_log_record_equal (& in [i ], & out .u .log ,
227
216
GIT_SHA1_RAWSZ ));
228
217
reftable_log_record_release (& in [i ]);
229
218
strbuf_release (& key );
@@ -233,7 +222,7 @@ static void test_reftable_log_record_roundtrip(void)
233
222
strbuf_release (& scratch );
234
223
}
235
224
236
- static void test_key_roundtrip (void )
225
+ static void t_key_roundtrip (void )
237
226
{
238
227
uint8_t buffer [1024 ] = { 0 };
239
228
struct string_view dest = {
@@ -252,21 +241,21 @@ static void test_key_roundtrip(void)
252
241
strbuf_addstr (& key , "refs/tags/bla" );
253
242
extra = 6 ;
254
243
n = reftable_encode_key (& restart , dest , last_key , key , extra );
255
- EXPECT (!restart );
256
- EXPECT ( n > 0 );
244
+ check (!restart );
245
+ check_int ( n , > , 0 );
257
246
258
247
strbuf_addstr (& roundtrip , "refs/heads/master" );
259
248
m = reftable_decode_key (& roundtrip , & rt_extra , dest );
260
- EXPECT ( n == m );
261
- EXPECT ( 0 == strbuf_cmp (& key , & roundtrip ));
262
- EXPECT (rt_extra == extra );
249
+ check_int ( n , = = , m );
250
+ check (! strbuf_cmp (& key , & roundtrip ));
251
+ check_int (rt_extra , = = , extra );
263
252
264
253
strbuf_release (& last_key );
265
254
strbuf_release (& key );
266
255
strbuf_release (& roundtrip );
267
256
}
268
257
269
- static void test_reftable_obj_record_roundtrip (void )
258
+ static void t_reftable_obj_record_roundtrip (void )
270
259
{
271
260
uint8_t testHash1 [GIT_SHA1_RAWSZ ] = { 1 , 2 , 3 , 4 , 0 };
272
261
uint64_t till9 [] = { 1 , 2 , 3 , 4 , 500 , 600 , 700 , 800 , 9000 };
@@ -289,9 +278,8 @@ static void test_reftable_obj_record_roundtrip(void)
289
278
},
290
279
};
291
280
struct strbuf scratch = STRBUF_INIT ;
292
- int i = 0 ;
293
281
294
- for (i = 0 ; i < ARRAY_SIZE (recs ); i ++ ) {
282
+ for (size_t i = 0 ; i < ARRAY_SIZE (recs ); i ++ ) {
295
283
uint8_t buffer [1024 ] = { 0 };
296
284
struct string_view dest = {
297
285
.buf = buffer ,
@@ -308,24 +296,24 @@ static void test_reftable_obj_record_roundtrip(void)
308
296
int n , m ;
309
297
uint8_t extra ;
310
298
311
- test_copy (& in );
299
+ t_copy (& in );
312
300
reftable_record_key (& in , & key );
313
301
n = reftable_record_encode (& in , dest , GIT_SHA1_RAWSZ );
314
- EXPECT ( n > 0 );
302
+ check_int ( n , > , 0 );
315
303
extra = reftable_record_val_type (& in );
316
304
m = reftable_record_decode (& out , key , extra , dest ,
317
305
GIT_SHA1_RAWSZ , & scratch );
318
- EXPECT ( n == m );
306
+ check_int ( n , = = , m );
319
307
320
- EXPECT (reftable_record_equal (& in , & out , GIT_SHA1_RAWSZ ));
308
+ check (reftable_record_equal (& in , & out , GIT_SHA1_RAWSZ ));
321
309
strbuf_release (& key );
322
310
reftable_record_release (& out );
323
311
}
324
312
325
313
strbuf_release (& scratch );
326
314
}
327
315
328
- static void test_reftable_index_record_roundtrip (void )
316
+ static void t_reftable_index_record_roundtrip (void )
329
317
{
330
318
struct reftable_record in = {
331
319
.type = BLOCK_TYPE_INDEX ,
@@ -350,33 +338,34 @@ static void test_reftable_index_record_roundtrip(void)
350
338
351
339
strbuf_addstr (& in .u .idx .last_key , "refs/heads/master" );
352
340
reftable_record_key (& in , & key );
353
- test_copy (& in );
341
+ t_copy (& in );
354
342
355
- EXPECT ( 0 == strbuf_cmp (& key , & in .u .idx .last_key ));
343
+ check (! strbuf_cmp (& key , & in .u .idx .last_key ));
356
344
n = reftable_record_encode (& in , dest , GIT_SHA1_RAWSZ );
357
- EXPECT ( n > 0 );
345
+ check_int ( n , > , 0 );
358
346
359
347
extra = reftable_record_val_type (& in );
360
348
m = reftable_record_decode (& out , key , extra , dest , GIT_SHA1_RAWSZ ,
361
349
& scratch );
362
- EXPECT ( m == n );
350
+ check_int ( m , = = , n );
363
351
364
- EXPECT (reftable_record_equal (& in , & out , GIT_SHA1_RAWSZ ));
352
+ check (reftable_record_equal (& in , & out , GIT_SHA1_RAWSZ ));
365
353
366
354
reftable_record_release (& out );
367
355
strbuf_release (& key );
368
356
strbuf_release (& scratch );
369
357
strbuf_release (& in .u .idx .last_key );
370
358
}
371
359
372
- int record_test_main (int argc , const char * argv [])
360
+ int cmd_main (int argc , const char * argv [])
373
361
{
374
- RUN_TEST (test_reftable_log_record_equal );
375
- RUN_TEST (test_reftable_log_record_roundtrip );
376
- RUN_TEST (test_reftable_ref_record_roundtrip );
377
- RUN_TEST (test_varint_roundtrip );
378
- RUN_TEST (test_key_roundtrip );
379
- RUN_TEST (test_reftable_obj_record_roundtrip );
380
- RUN_TEST (test_reftable_index_record_roundtrip );
381
- return 0 ;
362
+ TEST (t_reftable_log_record_equal (), "reftable_log_record_equal works" );
363
+ TEST (t_reftable_log_record_roundtrip (), "record operations work on log record" );
364
+ TEST (t_reftable_ref_record_roundtrip (), "record operations work on ref record" );
365
+ TEST (t_varint_roundtrip (), "put_var_int and get_var_int work" );
366
+ TEST (t_key_roundtrip (), "reftable_encode_key and reftable_decode_key work" );
367
+ TEST (t_reftable_obj_record_roundtrip (), "record operations work on obj record" );
368
+ TEST (t_reftable_index_record_roundtrip (), "record operations work on index record" );
369
+
370
+ return test_done ();
382
371
}
0 commit comments