Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "gate/tests.h" | ||
2 | #include "test_blobs.h" | ||
3 | #include "gate/blobs.h" | ||
4 | |||
5 | static char static_bytes[] = "Hello World"; | ||
6 | |||
7 | 1 | GATE_TEST_FUNCTION(test_blobs) | |
8 | { | ||
9 | gate_blob_t blob; | ||
10 | gate_blob_t blob_copy; | ||
11 | gate_blob_t blob_clone; | ||
12 | gate_blob_t blob_dup; | ||
13 | |||
14 | (void)blob_copy; | ||
15 | |||
16 | 1 | GATE_TEST_UNIT_BEGIN(test_blobs); | |
17 | |||
18 | /* test empty: */ | ||
19 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_empty(&blob), &blob); |
20 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(blob.buffer, NULL); |
21 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), NULL); |
22 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), 0U); |
23 | 1 | gate_blob_release(&blob); | |
24 | |||
25 | /* test static: */ | ||
26 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_static(&blob, static_bytes, sizeof(static_bytes)), &blob); |
27 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(blob.buffer, NULL); |
28 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), &static_bytes[0]); |
29 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), sizeof(static_bytes)); |
30 |
1/2✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(gate_blob_data(&blob), &static_bytes[0], gate_blob_length(&blob)), 0); |
31 | 1 | gate_blob_release(&blob); | |
32 | |||
33 | /* test duplicate: */ | ||
34 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_static(&blob, static_bytes, sizeof(static_bytes)), &blob); |
35 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_duplicate(&blob_dup, &blob), &blob_dup); |
36 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(blob_dup.buffer, NULL); |
37 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob_dup), &static_bytes[0]); |
38 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob_dup), sizeof(static_bytes)); |
39 | 1 | gate_blob_release(&blob_dup); | |
40 | 1 | gate_blob_release(&blob); | |
41 | |||
42 | /* test dynamic: */ | ||
43 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob); |
44 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_NOT_EQUAL(blob.buffer, NULL); |
45 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_NOT_EQUAL(gate_blob_data(&blob), &static_bytes[0]); |
46 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), sizeof(static_bytes)); |
47 |
1/2✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(gate_blob_data(&blob), &static_bytes[0], gate_blob_length(&blob)), 0); |
48 | 1 | gate_blob_release(&blob); | |
49 | |||
50 | /* test copy: */ | ||
51 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob); |
52 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_copy(&blob_copy, &blob), &blob_copy); |
53 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), gate_blob_length(&blob_copy)); |
54 |
1/2✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(gate_blob_data(&blob), gate_blob_data(&blob_copy), gate_blob_length(&blob)), 0); |
55 | 1 | gate_blob_release(&blob_copy); | |
56 | 1 | gate_blob_release(&blob); | |
57 | |||
58 | /* test ref-clone: */ | ||
59 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob); |
60 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_clone(&blob_clone, &blob), &blob_clone); |
61 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), gate_blob_length(&blob_clone)); |
62 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), gate_blob_data(&blob_clone)); |
63 | 1 | gate_blob_release(&blob_clone); | |
64 | 1 | gate_blob_release(&blob); | |
65 | |||
66 | /* test subset: */ | ||
67 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_static(&blob, static_bytes, sizeof(static_bytes)), &blob); |
68 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create_subset(&blob_dup, &blob, 0, sizeof(static_bytes) / 2), &blob_dup); |
69 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), gate_blob_data(&blob_dup)); |
70 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob_dup), sizeof(static_bytes) / 2); |
71 | 1 | gate_blob_release(&blob_dup); | |
72 | 1 | gate_blob_release(&blob); | |
73 | |||
74 | /* test set/get */ | ||
75 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob); |
76 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_blob_set_byte(&blob, 0, 'A')); |
77 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_blob_set_byte(&blob, 1, 'B')); |
78 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_blob_set_byte(&blob, 2, 'C')); |
79 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_get_byte(&blob, 0), 'A'); |
80 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_get_byte(&blob, 1), 'B'); |
81 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_blob_get_byte(&blob, 2), 'C'); |
82 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_RESULT(gate_blob_set_byte(&blob, sizeof(static_bytes), 'X'), GATE_RESULT_OUTOFBOUNDS); |
83 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_RESULT(gate_blob_get_byte(&blob, sizeof(static_bytes)), 0); |
84 | 1 | gate_blob_release(&blob); | |
85 | |||
86 | 1 | GATE_TEST_UNIT_END; | |
87 | } | ||
88 |