tests/test_list.c

changeset 819
5da2ead43077
parent 818
2be8fe3d5a2d
child 831
7970eac1c598
equal deleted inserted replaced
818:2be8fe3d5a2d 819:5da2ead43077
48 heaparray[3] = 7; 48 heaparray[3] = 7;
49 heaparray[4] = 11; 49 heaparray[4] = 11;
50 size_t heaparray_size = 3; 50 size_t heaparray_size = 3;
51 size_t heaparray_capacity = 5; 51 size_t heaparray_capacity = 5;
52 int elem = 8, elem2 = 47; 52 int elem = 8, elem2 = 47;
53 enum cx_array_copy_result result; 53 enum cx_array_result result;
54 CX_TEST_DO { 54 CX_TEST_DO {
55 result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem, NULL); 55 result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem, NULL);
56 CX_TEST_ASSERT(result == CX_ARRAY_COPY_SUCCESS); 56 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS);
57 CX_TEST_ASSERT(stackarray[0] == 1); 57 CX_TEST_ASSERT(stackarray[0] == 1);
58 CX_TEST_ASSERT(stackarray[1] == 1); 58 CX_TEST_ASSERT(stackarray[1] == 1);
59 CX_TEST_ASSERT(stackarray[2] == 2); 59 CX_TEST_ASSERT(stackarray[2] == 2);
60 CX_TEST_ASSERT(stackarray[3] == 8); 60 CX_TEST_ASSERT(stackarray[3] == 8);
61 CX_TEST_ASSERT(stackarray[4] == 5); 61 CX_TEST_ASSERT(stackarray[4] == 5);
62 CX_TEST_ASSERT(stackarray_size == 4); 62 CX_TEST_ASSERT(stackarray_size == 4);
63 CX_TEST_ASSERT(stackarray_capacity == 5); 63 CX_TEST_ASSERT(stackarray_capacity == 5);
64 64
65 stackarray_size = 5; 65 stackarray_size = 5;
66 result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem2, NULL); 66 result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem2, NULL);
67 CX_TEST_ASSERT(result == CX_ARRAY_COPY_REALLOC_NOT_SUPPORTED); 67 CX_TEST_ASSERT(result == CX_ARRAY_REALLOC_NOT_SUPPORTED);
68 CX_TEST_ASSERT(stackarray[0] == 1); 68 CX_TEST_ASSERT(stackarray[0] == 1);
69 CX_TEST_ASSERT(stackarray[1] == 1); 69 CX_TEST_ASSERT(stackarray[1] == 1);
70 CX_TEST_ASSERT(stackarray[2] == 2); 70 CX_TEST_ASSERT(stackarray[2] == 2);
71 CX_TEST_ASSERT(stackarray[3] == 8); 71 CX_TEST_ASSERT(stackarray[3] == 8);
72 CX_TEST_ASSERT(stackarray[4] == 5); 72 CX_TEST_ASSERT(stackarray[4] == 5);
73 CX_TEST_ASSERT(stackarray_size == 5); 73 CX_TEST_ASSERT(stackarray_size == 5);
74 CX_TEST_ASSERT(stackarray_capacity == 5); 74 CX_TEST_ASSERT(stackarray_capacity == 5);
75 75
76 result = cx_array_add(&heaparray, &heaparray_size, &heaparray_capacity, sizeof(int), &elem, cx_array_default_reallocator); 76 result = cx_array_add(&heaparray, &heaparray_size, &heaparray_capacity, sizeof(int), &elem, cx_array_default_reallocator);
77 CX_TEST_ASSERT(result == CX_ARRAY_COPY_SUCCESS); 77 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS);
78 CX_TEST_ASSERT(heaparray[0] == 2); 78 CX_TEST_ASSERT(heaparray[0] == 2);
79 CX_TEST_ASSERT(heaparray[1] == 3); 79 CX_TEST_ASSERT(heaparray[1] == 3);
80 CX_TEST_ASSERT(heaparray[2] == 5); 80 CX_TEST_ASSERT(heaparray[2] == 5);
81 CX_TEST_ASSERT(heaparray[3] == 8); 81 CX_TEST_ASSERT(heaparray[3] == 8);
82 CX_TEST_ASSERT(heaparray[4] == 11); 82 CX_TEST_ASSERT(heaparray[4] == 11);
83 CX_TEST_ASSERT(heaparray_size == 4); 83 CX_TEST_ASSERT(heaparray_size == 4);
84 CX_TEST_ASSERT(heaparray_capacity == 5); 84 CX_TEST_ASSERT(heaparray_capacity == 5);
85 85
86 heaparray_size = 5; 86 heaparray_size = 5;
87 result = cx_array_add(&heaparray, &heaparray_size, &heaparray_capacity, sizeof(int), &elem2, cx_array_default_reallocator); 87 result = cx_array_add(&heaparray, &heaparray_size, &heaparray_capacity, sizeof(int), &elem2, cx_array_default_reallocator);
88 CX_TEST_ASSERT(result == CX_ARRAY_COPY_SUCCESS); 88 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS);
89 CX_TEST_ASSERT(heaparray[0] == 2); 89 CX_TEST_ASSERT(heaparray[0] == 2);
90 CX_TEST_ASSERT(heaparray[1] == 3); 90 CX_TEST_ASSERT(heaparray[1] == 3);
91 CX_TEST_ASSERT(heaparray[2] == 5); 91 CX_TEST_ASSERT(heaparray[2] == 5);
92 CX_TEST_ASSERT(heaparray[3] == 8); 92 CX_TEST_ASSERT(heaparray[3] == 8);
93 CX_TEST_ASSERT(heaparray[4] == 11); 93 CX_TEST_ASSERT(heaparray[4] == 11);

mercurial