Skip to content

Commit eb5c867

Browse files
committed
Merge branch 'sk/unit-tests-0130' into seen
* sk/unit-tests-0130: t/unit-tests: convert strcmp-offset test to clar framework t/unit-tests: convert strbuf test to clar framework t/unit-tests: adapt example decorate test to clar framework t/unit-tests: convert hashmap test to clar framework
2 parents a9c4744 + 8bf4f0a commit eb5c867

File tree

9 files changed

+362
-353
lines changed

9 files changed

+362
-353
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,18 +1353,20 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%
13531353
THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
13541354

13551355
CLAR_TEST_SUITES += u-ctype
1356+
CLAR_TEST_SUITES += u-example-decorate
13561357
CLAR_TEST_SUITES += u-hash
1358+
CLAR_TEST_SUITES += u-hashmap
13571359
CLAR_TEST_SUITES += u-mem-pool
13581360
CLAR_TEST_SUITES += u-prio-queue
13591361
CLAR_TEST_SUITES += u-reftable-tree
1362+
CLAR_TEST_SUITES += u-strbuf
1363+
CLAR_TEST_SUITES += u-strcmp-offset
13601364
CLAR_TEST_SUITES += u-strvec
13611365
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
13621366
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
13631367
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
13641368
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13651369

1366-
UNIT_TEST_PROGRAMS += t-example-decorate
1367-
UNIT_TEST_PROGRAMS += t-hashmap
13681370
UNIT_TEST_PROGRAMS += t-oid-array
13691371
UNIT_TEST_PROGRAMS += t-oidmap
13701372
UNIT_TEST_PROGRAMS += t-oidtree
@@ -1376,8 +1378,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader
13761378
UNIT_TEST_PROGRAMS += t-reftable-readwrite
13771379
UNIT_TEST_PROGRAMS += t-reftable-record
13781380
UNIT_TEST_PROGRAMS += t-reftable-stack
1379-
UNIT_TEST_PROGRAMS += t-strbuf
1380-
UNIT_TEST_PROGRAMS += t-strcmp-offset
13811381
UNIT_TEST_PROGRAMS += t-trailer
13821382
UNIT_TEST_PROGRAMS += t-urlmatch-normalization
13831383
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))

t/meson.build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
clar_test_suites = [
22
'unit-tests/u-ctype.c',
3+
'unit-tests/u-example-decorate.c',
34
'unit-tests/u-hash.c',
5+
'unit-tests/u-hashmap.c',
46
'unit-tests/u-mem-pool.c',
57
'unit-tests/u-prio-queue.c',
68
'unit-tests/u-reftable-tree.c',
9+
'unit-tests/u-strbuf.c',
10+
'unit-tests/u-strcmp-offset.c',
711
'unit-tests/u-strvec.c',
812
]
913

@@ -44,8 +48,6 @@ clar_unit_tests = executable('unit-tests',
4448
test('unit-tests', clar_unit_tests)
4549

4650
unit_test_programs = [
47-
'unit-tests/t-example-decorate.c',
48-
'unit-tests/t-hashmap.c',
4951
'unit-tests/t-oid-array.c',
5052
'unit-tests/t-oidmap.c',
5153
'unit-tests/t-oidtree.c',
@@ -57,8 +59,6 @@ unit_test_programs = [
5759
'unit-tests/t-reftable-readwrite.c',
5860
'unit-tests/t-reftable-record.c',
5961
'unit-tests/t-reftable-stack.c',
60-
'unit-tests/t-strbuf.c',
61-
'unit-tests/t-strcmp-offset.c',
6262
'unit-tests/t-trailer.c',
6363
'unit-tests/t-urlmatch-normalization.c',
6464
]

t/unit-tests/t-example-decorate.c

Lines changed: 0 additions & 74 deletions
This file was deleted.

t/unit-tests/t-strbuf.c

Lines changed: 0 additions & 122 deletions
This file was deleted.

t/unit-tests/t-strcmp-offset.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

t/unit-tests/u-example-decorate.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
3+
#include "unit-test.h"
4+
#include "object.h"
5+
#include "decorate.h"
6+
#include "repository.h"
7+
8+
struct test_vars {
9+
struct object *one, *two, *three;
10+
struct decoration n;
11+
int decoration_a, decoration_b;
12+
};
13+
14+
static struct test_vars vars;
15+
16+
void test_example_decorate__add(void)
17+
{
18+
void *ret = add_decoration(&vars.n, vars.one, &vars.decoration_a);
19+
cl_assert(ret == NULL);
20+
ret = add_decoration(&vars.n, vars.two, NULL);
21+
cl_assert(ret == NULL);
22+
}
23+
24+
void test_example_decorate__readd(void)
25+
{
26+
void *ret;
27+
28+
cl_assert(add_decoration(&vars.n, vars.one, &vars.decoration_a) == NULL);
29+
cl_assert(add_decoration(&vars.n, vars.two, NULL) == NULL);
30+
31+
ret = add_decoration(&vars.n, vars.one, NULL);
32+
cl_assert(ret == &vars.decoration_a);
33+
ret = add_decoration(&vars.n, vars.two, &vars.decoration_b);
34+
cl_assert(ret == NULL);
35+
}
36+
37+
void test_example_decorate__lookup(void)
38+
{
39+
void *ret;
40+
41+
add_decoration(&vars.n, vars.two, &vars.decoration_b);
42+
add_decoration(&vars.n, vars.one, NULL);
43+
44+
ret = lookup_decoration(&vars.n, vars.two);
45+
cl_assert(ret == &vars.decoration_b);
46+
ret = lookup_decoration(&vars.n, vars.one);
47+
cl_assert(ret == NULL);
48+
}
49+
50+
void test_example_decorate__loop(void)
51+
{
52+
int objects_noticed = 0;
53+
54+
add_decoration(&vars.n, vars.one, &vars.decoration_a);
55+
add_decoration(&vars.n, vars.two, &vars.decoration_b);
56+
57+
for (size_t i = 0; i < vars.n.size; i++) {
58+
if (vars.n.entries[i].base)
59+
objects_noticed++;
60+
}
61+
cl_assert_equal_i(objects_noticed, 2);
62+
}
63+
64+
void test_example_decorate__initialize(void)
65+
{
66+
struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } };
67+
68+
vars.one = lookup_unknown_object(the_repository, &one_oid);
69+
vars.two = lookup_unknown_object(the_repository, &two_oid);
70+
vars.three = lookup_unknown_object(the_repository, &three_oid);
71+
}
72+
73+
void test_example_decorate__cleanup(void)
74+
{
75+
clear_decoration(&vars.n, NULL);
76+
}

0 commit comments

Comments
 (0)