libamxc  1.10.3
C Generic Data Containers
test_amxc_array.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <amxc/amxc_array.h>
#include "test_amxc_array.h"
#include <amxc/amxc_macros.h>

Go to the source code of this file.

Functions

static void amxc_reset_test_array ()
 
static void amxc_check_array_it_delete (amxc_array_it_t *it)
 
int test_amxc_array_setup (UNUSED void **state)
 
int test_amxc_array_teardown (UNUSED void **state)
 
void test_amxc_array_new_delete_null (UNUSED void **state)
 
void test_amxc_array_init_clean_null (UNUSED void **state)
 
void test_amxc_array_init_clean (UNUSED void **state)
 
void test_amxc_array_clean_cb (UNUSED void **state)
 
void test_amxc_array_get_at_null (UNUSED void **state)
 
void test_amxc_array_get_at (UNUSED void **state)
 
void test_amxc_array_get_first_null (UNUSED void **state)
 
void test_amxc_array_get_first (UNUSED void **state)
 
void test_amxc_array_get_first_empty (UNUSED void **state)
 
void test_amxc_array_get_first_free_null (UNUSED void **state)
 
void test_amxc_array_get_first_free (UNUSED void **state)
 
void test_amxc_array_get_last_null (UNUSED void **state)
 
void test_amxc_array_get_last (UNUSED void **state)
 
void test_amxc_array_get_last_empty (UNUSED void **state)
 
void test_amxc_array_get_last_free_null (UNUSED void **state)
 
void test_amxc_array_get_last_free (UNUSED void **state)
 
void test_amxc_array_get_first_free_full (UNUSED void **state)
 
void test_amxc_array_get_last_free_full (UNUSED void **state)
 
void test_amxc_array_it_get_next_null (UNUSED void **state)
 
void test_amxc_array_it_get_next (UNUSED void **state)
 
void test_amxc_array_it_get_next_free_null (UNUSED void **state)
 
void test_amxc_array_it_get_next_free (UNUSED void **state)
 
void test_amxc_array_it_get_previous_null (UNUSED void **state)
 
void test_amxc_array_it_get_previous (UNUSED void **state)
 
void test_amxc_array_it_get_previous_free_null (UNUSED void **state)
 
void test_amxc_array_it_get_previous_free (UNUSED void **state)
 
void test_amxc_array_it_get_data_null (UNUSED void **state)
 
void test_amxc_array_it_get_data (UNUSED void **state)
 
void test_amxc_array_is_empty_null (UNUSED void **state)
 
void test_amxc_array_is_empty (UNUSED void **state)
 
void test_amxc_array_size_null (UNUSED void **state)
 
void test_amxc_array_size (UNUSED void **state)
 
void test_amxc_array_capacity_null (UNUSED void **state)
 
void test_amxc_array_capacity (UNUSED void **state)
 
void test_amxc_array_grow_null (UNUSED void **state)
 
void test_amxc_array_grow (UNUSED void **state)
 
void test_amxc_array_shrink_null (UNUSED void **state)
 
void test_amxc_array_shrink (UNUSED void **state)
 
void test_amxc_array_shift_null (UNUSED void **state)
 
void test_amxc_array_shift_left (UNUSED void **state)
 
void test_amxc_array_shift_left_all (UNUSED void **state)
 
void test_amxc_array_shift_right (UNUSED void **state)
 
void test_amxc_array_shift_right_all (UNUSED void **state)
 
void test_amxc_array_set_at_null (UNUSED void **state)
 
void test_amxc_array_set_at (UNUSED void **state)
 
void test_amxc_array_it_set_data_null (UNUSED void **state)
 
void test_amxc_array_it_set_data (UNUSED void **state)
 
void test_amxc_array_append_data_null (UNUSED void **state)
 
void test_amxc_array_append_data (UNUSED void **state)
 
void test_amxc_array_prepend_data_null (UNUSED void **state)
 
void test_amxc_array_prepend_data (UNUSED void **state)
 
void test_amxc_array_take_first_data_null (UNUSED void **state)
 
void test_amxc_array_take_first_data (UNUSED void **state)
 
void test_amxc_array_take_last_data_null (UNUSED void **state)
 
void test_amxc_array_take_last_data (UNUSED void **state)
 
void test_amxc_array_it_take_data_null (UNUSED void **state)
 
void test_amxc_array_it_take_data (UNUSED void **state)
 
void test_amxc_array_it_index_null (UNUSED void **state)
 
void test_amxc_array_it_index (UNUSED void **state)
 
static int test_cmp (amxc_array_it_t *it1, amxc_array_it_t *it2)
 
void test_amxc_array_sort (UNUSED void **state)
 

Variables

static int counter = 0
 
static amxc_array_tarray1 = NULL
 
char data [] = "abcdefghij"
 

Function Documentation

◆ amxc_check_array_it_delete()

static void amxc_check_array_it_delete ( amxc_array_it_t it)
static

Definition at line 79 of file test_amxc_array.c.

79  {
80  counter++;
81  assert_ptr_not_equal(it->data, NULL);
82 }
static int counter
static amxc_htable_it_t it[2000]

◆ amxc_reset_test_array()

static void amxc_reset_test_array ( )
static

Definition at line 71 of file test_amxc_array.c.

71  {
72  amxc_array_clean(array1, NULL);
77 }
amxc_array_it_t * amxc_array_set_data_at(amxc_array_t *const array, const unsigned int index, void *data)
Sets data at the given index.
Definition: amxc_array.c:474
int amxc_array_init(amxc_array_t *const array, const size_t items)
Initializes an array.
Definition: amxc_array.c:231
void amxc_array_clean(amxc_array_t *const array, amxc_array_it_delete_t func)
Removes all items from the array.
Definition: amxc_array.c:261
static amxc_array_t * array1
char data[]

◆ test_amxc_array_append_data()

void test_amxc_array_append_data ( UNUSED void **  state)

Definition at line 726 of file test_amxc_array.c.

726  {
728  assert_ptr_equal(it, NULL);
729  assert_int_equal(amxc_array_capacity(array1), 10);
730  assert_int_equal(amxc_array_size(array1), 3);
731  assert_int_equal(array1->last_used, 9);
732 
734  assert_ptr_not_equal(it, NULL);
735  assert_int_equal(amxc_array_capacity(array1), 13);
736  assert_int_equal(amxc_array_size(array1), 4);
737  assert_int_equal(array1->last_used, 10);
738 
740  assert_ptr_not_equal(it, NULL);
741  assert_int_equal(amxc_array_capacity(array1), 13);
742  assert_int_equal(amxc_array_size(array1), 5);
743  assert_int_equal(array1->last_used, 11);
744 
745  amxc_array_clean(array1, NULL);
746  assert_int_equal(amxc_array_capacity(array1), 0);
747 
749  assert_ptr_not_equal(it, NULL);
750  assert_int_equal(amxc_array_capacity(array1), 3);
751  assert_int_equal(amxc_array_size(array1), 1);
752  assert_int_equal(array1->last_used, 0);
753  assert_int_equal(array1->first_used, 0);
754 
756  assert_ptr_not_equal(it, NULL);
757  assert_int_equal(amxc_array_capacity(array1), 3);
758  assert_int_equal(amxc_array_size(array1), 2);
759  assert_int_equal(array1->last_used, 1);
760  assert_int_equal(array1->first_used, 0);
761 
763 }
AMXC_INLINE size_t amxc_array_capacity(const amxc_array_t *const array)
Gets the capacity of the array.
Definition: amxc_array.h:694
size_t amxc_array_size(const amxc_array_t *const array)
Calculates the number of used items in the array.
Definition: amxc_array.c:415
amxc_array_it_t * amxc_array_append_data(amxc_array_t *const array, void *data)
Adds an item after the last used item in the array.
Definition: amxc_array.c:429
The array iterator structure.
Definition: amxc_array.h:174
size_t last_used
Definition: amxc_array.h:165
size_t first_used
Definition: amxc_array.h:164
static void amxc_reset_test_array()

◆ test_amxc_array_append_data_null()

void test_amxc_array_append_data_null ( UNUSED void **  state)

Definition at line 722 of file test_amxc_array.c.

722  {
723  assert_ptr_equal(amxc_array_append_data(NULL, NULL), NULL);
724 }

◆ test_amxc_array_capacity()

void test_amxc_array_capacity ( UNUSED void **  state)

Definition at line 481 of file test_amxc_array.c.

481  {
482  assert_int_equal(amxc_array_capacity(array1), 10);
483 }

◆ test_amxc_array_capacity_null()

void test_amxc_array_capacity_null ( UNUSED void **  state)

Definition at line 477 of file test_amxc_array.c.

477  {
478  assert_int_equal(amxc_array_capacity(NULL), 0);
479 }

◆ test_amxc_array_clean_cb()

void test_amxc_array_clean_cb ( UNUSED void **  state)

Definition at line 144 of file test_amxc_array.c.

144  {
146 
147  // initialize array with 10 items
148  assert_int_equal(amxc_array_init(&array, 10), 0);
149  assert_ptr_not_equal(array.buffer, NULL);
150  assert_int_equal(array.items, 10);
151  counter = 0;
152  amxc_array_clean(&array, NULL);
153  assert_int_equal(counter, 0);
154  assert_int_equal(array.items, 0);
155 
156  // initialize array with 10 items
157  assert_int_equal(amxc_array_init(&array, 10), 0);
158  assert_ptr_not_equal(array.buffer, amxc_check_array_it_delete);
159  assert_int_equal(array.items, 10);
160  const char data[10] = "1234567890";
161  for(unsigned int index = 0; index < 10; index++) {
162  assert_ptr_equal(amxc_array_set_data_at(&array, index, (void*) &data[index]), &array.buffer[index]);
163  }
164  counter = 0;
166  assert_int_equal(array.items, 0);
167  assert_int_equal(counter, 10);
168 }
The array structure.
Definition: amxc_array.h:162
static void amxc_check_array_it_delete(amxc_array_it_t *it)
static unsigned int array[2006]

◆ test_amxc_array_get_at()

void test_amxc_array_get_at ( UNUSED void **  state)

Definition at line 185 of file test_amxc_array.c.

185  {
186  amxc_array_it_t* it = NULL;
187  for(int i = 0; i < 10; i++) {
189  assert_ptr_equal(it, &array1->buffer[i]);
190  assert_ptr_equal(it->array, array1);
191  if((i == 0) || ((i % 3) != 0)) {
192  assert_ptr_equal(it->data, NULL);
193  } else {
194  assert_ptr_equal(it->data, &data[i]);
195  }
196  }
197 }
amxc_array_it_t * amxc_array_get_at(const amxc_array_t *const array, const unsigned int index)
Gets the item iterator for the given index.
Definition: amxc_array.c:504
struct _amxc_array_it * buffer
Definition: amxc_array.h:166

◆ test_amxc_array_get_at_null()

void test_amxc_array_get_at_null ( UNUSED void **  state)

Definition at line 170 of file test_amxc_array.c.

170  {
171  amxc_array_t* array = NULL;
172  amxc_array_it_t* it = NULL;
173 
174  it = amxc_array_get_at(NULL, 5);
175  assert_ptr_equal(it, NULL);
176 
177  assert_int_equal(amxc_array_new(&array, 0), 0);
178  it = amxc_array_get_at(array, 0);
179  assert_ptr_equal(it, NULL);
180 
181  amxc_array_delete(&array, NULL);
182  assert_ptr_equal(array, NULL);
183 }
int8_t amxc_array_new(amxc_array_t **array, const size_t items)
Allocates an array.
Definition: amxc_array.c:179
void amxc_array_delete(amxc_array_t **array, const amxc_array_it_delete_t func)
Frees the previously allocated array.
Definition: amxc_array.c:213

◆ test_amxc_array_get_first()

void test_amxc_array_get_first ( UNUSED void **  state)

Definition at line 205 of file test_amxc_array.c.

205  {
206  amxc_array_it_t* it = NULL;
208  assert_ptr_equal(it, &array1->buffer[3]);
209  assert_ptr_equal(it->array, array1);
210  assert_ptr_equal(it->data, &data[3]);
211 }
amxc_array_it_t * amxc_array_get_first(const amxc_array_t *const array)
Gets the item iterator of the first used item in the array.
Definition: amxc_array.c:517

◆ test_amxc_array_get_first_empty()

void test_amxc_array_get_first_empty ( UNUSED void **  state)

Definition at line 213 of file test_amxc_array.c.

213  {
214  amxc_array_t* array = NULL;
215  assert_int_not_equal(amxc_array_new(&array, 10), -1);
216  assert_ptr_not_equal(array, NULL);
217  assert_ptr_not_equal(array->buffer, NULL);
218 
219  amxc_array_it_t* it = NULL;
221  assert_ptr_equal(it, NULL);
222 
223  amxc_array_delete(&array, NULL);
224 }

◆ test_amxc_array_get_first_free()

void test_amxc_array_get_first_free ( UNUSED void **  state)

Definition at line 232 of file test_amxc_array.c.

232  {
233  amxc_array_it_t* it = NULL;
235  assert_ptr_equal(it, &array1->buffer[0]);
236  assert_ptr_equal(it->array, array1);
237  assert_ptr_equal(it->data, NULL);
238 }
amxc_array_it_t * amxc_array_get_first_free(const amxc_array_t *const array)
Gets the first free position in the array.
Definition: amxc_array.c:529

◆ test_amxc_array_get_first_free_full()

void test_amxc_array_get_first_free_full ( UNUSED void **  state)

Definition at line 282 of file test_amxc_array.c.

282  {
283  for(int i = 0; i < 10; i++) {
285  }
286 
288  assert_ptr_equal(it, NULL);
289 }

◆ test_amxc_array_get_first_free_null()

void test_amxc_array_get_first_free_null ( UNUSED void **  state)

Definition at line 226 of file test_amxc_array.c.

226  {
227  amxc_array_it_t* it = NULL;
229  assert_ptr_equal(it, NULL);
230 }

◆ test_amxc_array_get_first_null()

void test_amxc_array_get_first_null ( UNUSED void **  state)

Definition at line 199 of file test_amxc_array.c.

199  {
200  amxc_array_it_t* it = NULL;
201  it = amxc_array_get_first(NULL);
202  assert_ptr_equal(it, NULL);
203 }

◆ test_amxc_array_get_last()

void test_amxc_array_get_last ( UNUSED void **  state)

Definition at line 246 of file test_amxc_array.c.

246  {
247  amxc_array_it_t* it = NULL;
249  assert_ptr_equal(it, &array1->buffer[9]);
250  assert_ptr_equal(it->array, array1);
251  assert_ptr_equal(it->data, &data[9]);
252 }
amxc_array_it_t * amxc_array_get_last(const amxc_array_t *const array)
Gets the item iterator of the last used item in the array.
Definition: amxc_array.c:546

◆ test_amxc_array_get_last_empty()

void test_amxc_array_get_last_empty ( UNUSED void **  state)

Definition at line 254 of file test_amxc_array.c.

254  {
255  amxc_array_t* array = NULL;
256  assert_int_not_equal(amxc_array_new(&array, 10), -1);
257  assert_ptr_not_equal(array, NULL);
258  assert_ptr_not_equal(array->buffer, NULL);
259 
260  amxc_array_it_t* it = NULL;
262  assert_ptr_equal(it, NULL);
263 
264  amxc_array_delete(&array, NULL);
265 }

◆ test_amxc_array_get_last_free()

void test_amxc_array_get_last_free ( UNUSED void **  state)

Definition at line 273 of file test_amxc_array.c.

273  {
274  amxc_array_it_t* it = NULL;
276  assert_ptr_not_equal(it, NULL);
277  assert_ptr_equal(it, &array1->buffer[8]);
278  assert_ptr_equal(it->array, array1);
279  assert_ptr_equal(it->data, NULL);
280 }
amxc_array_it_t * amxc_array_get_last_free(const amxc_array_t *const array)
Gets the last free position in the array.
Definition: amxc_array.c:558

◆ test_amxc_array_get_last_free_full()

void test_amxc_array_get_last_free_full ( UNUSED void **  state)

Definition at line 291 of file test_amxc_array.c.

291  {
292  for(int i = 0; i < 10; i++) {
294  }
295 
297  assert_ptr_equal(it, NULL);
298 }

◆ test_amxc_array_get_last_free_null()

void test_amxc_array_get_last_free_null ( UNUSED void **  state)

Definition at line 267 of file test_amxc_array.c.

267  {
268  amxc_array_it_t* it = NULL;
270  assert_ptr_equal(it, NULL);
271 }

◆ test_amxc_array_get_last_null()

void test_amxc_array_get_last_null ( UNUSED void **  state)

Definition at line 240 of file test_amxc_array.c.

240  {
241  amxc_array_it_t* it = NULL;
242  it = amxc_array_get_last(NULL);
243  assert_ptr_equal(it, NULL);
244 }

◆ test_amxc_array_grow()

void test_amxc_array_grow ( UNUSED void **  state)

Definition at line 489 of file test_amxc_array.c.

489  {
490  assert_int_equal(amxc_array_grow(array1, 10), 0);
491  assert_int_equal(amxc_array_capacity(array1), 20);
492  assert_int_equal(array1->first_used, 3);
493  assert_int_equal(array1->last_used, 9);
494 
495  assert_int_equal(amxc_array_grow(array1, 0), 0);
496  assert_int_equal(amxc_array_capacity(array1), 20);
497  assert_int_equal(array1->first_used, 3);
498  assert_int_equal(array1->last_used, 9);
499 
500  assert_int_equal(amxc_array_shrink(array1, 10, NULL), 0);
501 }
int amxc_array_shrink(amxc_array_t *const array, const size_t items, amxc_array_it_delete_t func)
Shrinks the array.
Definition: amxc_array.c:298
int amxc_array_grow(amxc_array_t *const array, const size_t items)
Expands the array.
Definition: amxc_array.c:280

◆ test_amxc_array_grow_null()

void test_amxc_array_grow_null ( UNUSED void **  state)

Definition at line 485 of file test_amxc_array.c.

485  {
486  assert_int_equal(amxc_array_grow(NULL, 0), -1);
487 }

◆ test_amxc_array_init_clean()

void test_amxc_array_init_clean ( UNUSED void **  state)

Definition at line 126 of file test_amxc_array.c.

126  {
128 
129  // initialize array with 0 items
130  assert_int_equal(amxc_array_init(&array, 0), 0);
131  assert_ptr_equal(array.buffer, NULL);
132  assert_int_equal(array.items, 0);
133  amxc_array_clean(&array, NULL);
134  assert_int_equal(array.items, 0);
135 
136  // initialize array with 10 items
137  assert_int_equal(amxc_array_init(&array, 10), 0);
138  assert_ptr_not_equal(array.buffer, NULL);
139  assert_int_equal(array.items, 10);
140  amxc_array_clean(&array, NULL);
141  assert_int_equal(array.items, 0);
142 }

◆ test_amxc_array_init_clean_null()

void test_amxc_array_init_clean_null ( UNUSED void **  state)

Definition at line 120 of file test_amxc_array.c.

120  {
121  // passing NULL pointers should not lead to segfault
122  assert_int_equal(amxc_array_init(NULL, 0), -1);
123  amxc_array_clean(NULL, NULL);
124 }

◆ test_amxc_array_is_empty()

void test_amxc_array_is_empty ( UNUSED void **  state)

Definition at line 463 of file test_amxc_array.c.

463  {
464  assert_int_equal(amxc_array_is_empty(array1), false);
465  amxc_array_clean(array1, NULL);
466  assert_int_equal(amxc_array_is_empty(array1), true);
467 }
bool amxc_array_is_empty(const amxc_array_t *const array)
Checks that the array is empty.
Definition: amxc_array.c:399

◆ test_amxc_array_is_empty_null()

void test_amxc_array_is_empty_null ( UNUSED void **  state)

Definition at line 459 of file test_amxc_array.c.

459  {
460  assert_int_equal(amxc_array_is_empty(NULL), true);
461 }

◆ test_amxc_array_it_get_data()

void test_amxc_array_it_get_data ( UNUSED void **  state)

Definition at line 444 of file test_amxc_array.c.

444  {
445  amxc_array_it_t* it = NULL;
447  assert_ptr_equal(amxc_array_it_get_data(it), NULL);
448 
450  assert_ptr_equal(amxc_array_it_get_data(it), NULL);
451 
453  assert_ptr_equal(amxc_array_it_get_data(it), NULL);
454 
456  assert_ptr_equal(amxc_array_it_get_data(it), &data[3]);
457 }
AMXC_INLINE void * amxc_array_it_get_data(const amxc_array_it_t *const it)
Gets the data pointer of array iterator.
Definition: amxc_array.h:729

◆ test_amxc_array_it_get_data_null()

void test_amxc_array_it_get_data_null ( UNUSED void **  state)

Definition at line 440 of file test_amxc_array.c.

440  {
441  assert_ptr_equal(amxc_array_it_get_data(NULL), NULL);
442 }

◆ test_amxc_array_it_get_next()

void test_amxc_array_it_get_next ( UNUSED void **  state)

Definition at line 306 of file test_amxc_array.c.

306  {
307  amxc_array_it_t* it = NULL;
309 
311  assert_ptr_equal(it, &array1->buffer[6]);
312  assert_ptr_equal(it->array, array1);
313  assert_ptr_equal(it->data, &data[6]);
314 
316  assert_ptr_equal(it, &array1->buffer[9]);
317  assert_ptr_equal(it->array, array1);
318  assert_ptr_equal(it->data, &data[9]);
319 
321  assert_ptr_equal(it, NULL);
322 }
amxc_array_it_t * amxc_array_it_get_next(const amxc_array_it_t *const reference)
Gets the next used item in the array, starting from the provided array iterator.
Definition: amxc_array_it.c:66

◆ test_amxc_array_it_get_next_free()

void test_amxc_array_it_get_next_free ( UNUSED void **  state)

Definition at line 330 of file test_amxc_array.c.

330  {
331  amxc_array_it_t* it = NULL;
333 
335  assert_ptr_equal(it, &array1->buffer[4]);
336  assert_ptr_equal(it->array, array1);
337  assert_ptr_equal(it->data, NULL);
338 
340  assert_ptr_equal(it, &array1->buffer[5]);
341  assert_ptr_equal(it->array, array1);
342  assert_ptr_equal(it->data, NULL);
343 
345  assert_ptr_equal(it, &array1->buffer[7]);
346  assert_ptr_equal(it->array, array1);
347  assert_ptr_equal(it->data, NULL);
348 
350  assert_ptr_equal(it, &array1->buffer[8]);
351  assert_ptr_equal(it->array, array1);
352  assert_ptr_equal(it->data, NULL);
353 
355  assert_ptr_equal(it, NULL);
356 }
amxc_array_it_t * amxc_array_it_get_next_free(const amxc_array_it_t *const reference)
Gets the next free item in the array, starting from the provided array iterator.
Definition: amxc_array_it.c:87

◆ test_amxc_array_it_get_next_free_null()

void test_amxc_array_it_get_next_free_null ( UNUSED void **  state)

Definition at line 324 of file test_amxc_array.c.

324  {
325  amxc_array_it_t* it = NULL;
327  assert_ptr_equal(it, NULL);
328 }

◆ test_amxc_array_it_get_next_null()

void test_amxc_array_it_get_next_null ( UNUSED void **  state)

Definition at line 300 of file test_amxc_array.c.

300  {
301  amxc_array_it_t* it = NULL;
302  it = amxc_array_it_get_next(NULL);
303  assert_ptr_equal(it, NULL);
304 }

◆ test_amxc_array_it_get_previous()

void test_amxc_array_it_get_previous ( UNUSED void **  state)

Definition at line 364 of file test_amxc_array.c.

364  {
365  amxc_array_it_t* it = NULL;
367 
369 
371  assert_ptr_equal(it, &array1->buffer[6]);
372  assert_ptr_equal(it->array, array1);
373  assert_ptr_equal(it->data, &data[6]);
374 
376  assert_ptr_equal(it, &array1->buffer[3]);
377  assert_ptr_equal(it->array, array1);
378  assert_ptr_equal(it->data, &data[3]);
379 
381  assert_ptr_equal(it, &array1->buffer[1]);
382  assert_ptr_equal(it->array, array1);
383  assert_ptr_equal(it->data, &data[1]);
384 
386  assert_ptr_equal(it, NULL);
387 
389 }
amxc_array_it_t * amxc_array_it_get_previous(const amxc_array_it_t *const reference)
Gets the previous used item in the array, starting from the provided array iterator.
void * amxc_array_it_take_data(amxc_array_it_t *const it)
Gets and removes a data pointer from the iterator.

◆ test_amxc_array_it_get_previous_free()

void test_amxc_array_it_get_previous_free ( UNUSED void **  state)

Definition at line 397 of file test_amxc_array.c.

397  {
398  amxc_array_it_t* it = NULL;
400 
402  assert_ptr_equal(it, &array1->buffer[8]);
403  assert_ptr_equal(it->array, array1);
404  assert_ptr_equal(it->data, NULL);
405 
407  assert_ptr_equal(it, &array1->buffer[7]);
408  assert_ptr_equal(it->array, array1);
409  assert_ptr_equal(it->data, NULL);
410 
412  assert_ptr_equal(it, &array1->buffer[5]);
413  assert_ptr_equal(it->array, array1);
414  assert_ptr_equal(it->data, NULL);
415 
417  assert_ptr_equal(it, &array1->buffer[4]);
418  assert_ptr_equal(it->array, array1);
419  assert_ptr_equal(it->data, NULL);
420 
422  assert_ptr_equal(it, &array1->buffer[2]);
423  assert_ptr_equal(it->array, array1);
424  assert_ptr_equal(it->data, NULL);
425 
427  assert_ptr_equal(it, &array1->buffer[1]);
428  assert_ptr_equal(it->array, array1);
429  assert_ptr_equal(it->data, NULL);
430 
432  assert_ptr_equal(it, &array1->buffer[0]);
433  assert_ptr_equal(it->array, array1);
434  assert_ptr_equal(it->data, NULL);
435 
437  assert_ptr_equal(it, NULL);
438 }
amxc_array_it_t * amxc_array_it_get_previous_free(const amxc_array_it_t *const reference)
Gets the previous free item in the array, starting from the provided array iterator.

◆ test_amxc_array_it_get_previous_free_null()

void test_amxc_array_it_get_previous_free_null ( UNUSED void **  state)

Definition at line 391 of file test_amxc_array.c.

391  {
392  amxc_array_it_t* it = NULL;
394  assert_ptr_equal(it, NULL);
395 }

◆ test_amxc_array_it_get_previous_null()

void test_amxc_array_it_get_previous_null ( UNUSED void **  state)

Definition at line 358 of file test_amxc_array.c.

358  {
359  amxc_array_it_t* it = NULL;
361  assert_ptr_equal(it, NULL);
362 }

◆ test_amxc_array_it_index()

void test_amxc_array_it_index ( UNUSED void **  state)

Definition at line 893 of file test_amxc_array.c.

893  {
894  for(unsigned int index = 0; index < amxc_array_capacity(array1); index++) {
896  assert_int_equal(amxc_array_it_index(it), index);
897  }
898 }
unsigned int amxc_array_it_index(const amxc_array_it_t *const it)
Gets the index of the iterator in the array.

◆ test_amxc_array_it_index_null()

void test_amxc_array_it_index_null ( UNUSED void **  state)

Definition at line 889 of file test_amxc_array.c.

889  {
890  assert_int_equal(amxc_array_it_index(NULL), 0);
891 }

◆ test_amxc_array_it_set_data()

void test_amxc_array_it_set_data ( UNUSED void **  state)

Definition at line 699 of file test_amxc_array.c.

699  {
700  amxc_array_it_t* it = NULL;
701 
702  amxc_array_clean(array1, NULL);
704 
706  assert_int_equal(amxc_array_it_set_data(it, &data[0]), 0);
707  assert_int_equal(array1->first_used, 0);
708 
710  assert_int_equal(amxc_array_it_set_data(it, &data[2]), 0);
711  assert_int_equal(array1->first_used, 0);
712  assert_int_equal(array1->last_used, 2);
713 
714  assert_int_equal(amxc_array_grow(array1, 10), 0);
715  it = amxc_array_get_at(array1, 15);
716  assert_int_equal(amxc_array_it_set_data(it, &data[5]), 0);
717  assert_int_equal(array1->last_used, 15);
718 
720 }
int amxc_array_it_set_data(amxc_array_it_t *const it, void *data)
Sets the data pointer of an array iterator.

◆ test_amxc_array_it_set_data_null()

void test_amxc_array_it_set_data_null ( UNUSED void **  state)

Definition at line 688 of file test_amxc_array.c.

688  {
689  assert_int_equal(amxc_array_it_set_data(NULL, NULL), -1);
691  assert_int_equal(amxc_array_it_set_data(it, NULL), -1);
692  assert_int_equal(array1->first_used, 3);
693  assert_int_equal(amxc_array_grow(array1, 10), 0);
694  it = amxc_array_get_at(array1, 15);
695  assert_int_equal(amxc_array_it_set_data(it, NULL), -1);
696  assert_int_equal(array1->last_used, 9);
697 }

◆ test_amxc_array_it_take_data()

void test_amxc_array_it_take_data ( UNUSED void **  state)

Definition at line 864 of file test_amxc_array.c.

864  {
865  assert_ptr_equal(amxc_array_it_take_data(NULL), NULL);
867  assert_ptr_equal(amxc_array_it_take_data(it), &data[3]);
868  assert_int_equal(array1->first_used, 6);
869  assert_int_equal(array1->last_used, 9);
870 
872  assert_ptr_equal(amxc_array_it_take_data(it), NULL);
873  assert_int_equal(array1->first_used, 6);
874  assert_int_equal(array1->last_used, 9);
875 
877  assert_ptr_equal(amxc_array_it_take_data(it), &data[9]);
878  assert_int_equal(array1->first_used, 6);
879  assert_int_equal(array1->last_used, 6);
880 
882  assert_ptr_equal(amxc_array_it_take_data(it), &data[6]);
883  assert_int_equal(array1->first_used, 0);
884  assert_int_equal(array1->last_used, 0);
885 
886  assert_int_equal(amxc_array_is_empty(array1), true);
887 }

◆ test_amxc_array_it_take_data_null()

void test_amxc_array_it_take_data_null ( UNUSED void **  state)

Definition at line 860 of file test_amxc_array.c.

860  {
861  assert_int_equal(amxc_array_it_index(NULL), 0);
862 }

◆ test_amxc_array_new_delete_null()

void test_amxc_array_new_delete_null ( UNUSED void **  state)

Definition at line 111 of file test_amxc_array.c.

111  {
112  amxc_array_t* array = NULL;
113 
114  // passing NULL pointers should not lead to segfault
115  assert_int_not_equal(amxc_array_new(NULL, 0), 0);
116  assert_ptr_equal(array, NULL);
117  amxc_array_delete(NULL, NULL);
118 }

◆ test_amxc_array_prepend_data()

void test_amxc_array_prepend_data ( UNUSED void **  state)

Definition at line 769 of file test_amxc_array.c.

769  {
771  assert_ptr_equal(it, NULL);
772  assert_int_equal(amxc_array_capacity(array1), 10);
773  assert_int_equal(amxc_array_size(array1), 3);
774  assert_int_equal(array1->first_used, 3);
775 
777  assert_ptr_not_equal(it, NULL);
778  assert_int_equal(amxc_array_capacity(array1), 10);
779  assert_int_equal(amxc_array_size(array1), 4);
780  assert_int_equal(array1->first_used, 2);
781 
783  assert_ptr_not_equal(it, NULL);
784  assert_int_equal(amxc_array_capacity(array1), 10);
785  assert_int_equal(amxc_array_size(array1), 5);
786  assert_int_equal(array1->first_used, 1);
787 
788  amxc_array_clean(array1, NULL);
789  assert_int_equal(amxc_array_capacity(array1), 0);
790 
792  assert_ptr_not_equal(it, NULL);
793  assert_int_equal(amxc_array_capacity(array1), 3);
794  assert_int_equal(amxc_array_size(array1), 1);
795  assert_int_equal(array1->last_used, 0);
796  assert_int_equal(array1->first_used, 0);
797 
799  assert_ptr_not_equal(it, NULL);
800  assert_int_equal(amxc_array_capacity(array1), 6);
801  assert_int_equal(amxc_array_size(array1), 2);
802  assert_int_equal(array1->last_used, 3);
803  assert_int_equal(array1->first_used, 2);
804 
806 }
amxc_array_it_t * amxc_array_prepend_data(amxc_array_t *const array, void *data)
Adds an item before the first used item in the array.
Definition: amxc_array.c:449

◆ test_amxc_array_prepend_data_null()

void test_amxc_array_prepend_data_null ( UNUSED void **  state)

Definition at line 765 of file test_amxc_array.c.

765  {
766  assert_ptr_equal(amxc_array_prepend_data(NULL, NULL), NULL);
767 }

◆ test_amxc_array_set_at()

void test_amxc_array_set_at ( UNUSED void **  state)

Definition at line 639 of file test_amxc_array.c.

639  {
640  assert_ptr_equal(amxc_array_set_data_at(array1, 2, NULL), &array1->buffer[2]);
641  assert_int_equal(array1->first_used, 3);
642  assert_int_equal(array1->last_used, 9);
643  assert_int_equal(amxc_array_is_empty(array1), false);
644  assert_int_equal(amxc_array_size(array1), 3);
645 
646  assert_ptr_equal(amxc_array_set_data_at(array1, 9, NULL), &array1->buffer[9]);
647  assert_int_equal(array1->first_used, 3);
648  assert_int_equal(array1->last_used, 6);
649  assert_int_equal(amxc_array_is_empty(array1), false);
650  assert_int_equal(amxc_array_size(array1), 2);
651 
652  assert_ptr_equal(amxc_array_set_data_at(array1, 3, NULL), &array1->buffer[3]);
653  assert_int_equal(array1->first_used, 6);
654  assert_int_equal(array1->last_used, 6);
655  assert_int_equal(amxc_array_is_empty(array1), false);
656  assert_int_equal(amxc_array_size(array1), 1);
657 
658  assert_ptr_equal(amxc_array_set_data_at(array1, 6, NULL), &array1->buffer[6]);
659  assert_int_equal(array1->first_used, 0);
660  assert_int_equal(array1->last_used, 0);
661  assert_int_equal(amxc_array_is_empty(array1), true);
662  assert_int_equal(amxc_array_size(array1), 0);
663 
664  assert_ptr_equal(amxc_array_set_data_at(array1, 7, &data[7]), &array1->buffer[7]);
665  assert_int_equal(array1->first_used, 7);
666  assert_int_equal(array1->last_used, 7);
667  assert_int_equal(amxc_array_is_empty(array1), false);
668  assert_int_equal(amxc_array_size(array1), 1);
669 
670  assert_ptr_equal(amxc_array_set_data_at(array1, 2, &data[2]), &array1->buffer[2]);
671  assert_int_equal(array1->first_used, 2);
672  assert_int_equal(array1->last_used, 7);
673  assert_int_equal(amxc_array_is_empty(array1), false);
674  assert_int_equal(amxc_array_size(array1), 2);
675 
676  assert_ptr_equal(amxc_array_set_data_at(array1, 5, &data[5]), &array1->buffer[5]);
677  assert_int_equal(array1->first_used, 2);
678  assert_int_equal(array1->last_used, 7);
679  assert_int_equal(amxc_array_is_empty(array1), false);
680  assert_int_equal(amxc_array_size(array1), 3);
681 
682  assert_ptr_equal(amxc_array_set_data_at(array1, 10, NULL), NULL);
683  assert_ptr_equal(amxc_array_set_data_at(array1, 11, NULL), NULL);
684 
686 }

◆ test_amxc_array_set_at_null()

void test_amxc_array_set_at_null ( UNUSED void **  state)

Definition at line 635 of file test_amxc_array.c.

635  {
636  assert_ptr_equal(amxc_array_set_data_at(NULL, 0, NULL), NULL);
637 }

◆ test_amxc_array_setup()

int test_amxc_array_setup ( UNUSED void **  state)

Definition at line 84 of file test_amxc_array.c.

84  {
85  assert_int_equal(amxc_array_new(&array1, 10), 0);
86  assert_ptr_not_equal(array1, NULL);
87  assert_ptr_not_equal(array1->buffer, NULL);
88 
90  assert_int_equal(array1->first_used, 3);
91  assert_int_equal(array1->last_used, 3);
92 
94  assert_int_equal(array1->first_used, 3);
95  assert_int_equal(array1->last_used, 6);
96 
98  assert_int_equal(array1->first_used, 3);
99  assert_int_equal(array1->last_used, 9);
100 
101  return 0;
102 }

◆ test_amxc_array_shift_left()

void test_amxc_array_shift_left ( UNUSED void **  state)

Definition at line 544 of file test_amxc_array.c.

544  {
545  assert_int_equal(amxc_array_shift_left(array1, 15, NULL), -1);
546  assert_int_equal(amxc_array_shift_left(array1, 0, NULL), 0);
547 
548  assert_int_equal(amxc_array_shift_left(array1, 1, NULL), 0);
549  assert_int_equal(amxc_array_capacity(array1), 10);
550  assert_int_equal(amxc_array_size(array1), 3);
551  assert_int_equal(array1->first_used, 2);
552  assert_int_equal(array1->last_used, 8);
553  assert_ptr_equal(array1->buffer[2].data, &data[3]);
554  assert_ptr_equal(array1->buffer[3].data, NULL);
555  assert_ptr_equal(array1->buffer[5].data, &data[6]);
556  assert_ptr_equal(array1->buffer[6].data, NULL);
557  assert_ptr_equal(array1->buffer[8].data, &data[9]);
558  assert_ptr_equal(array1->buffer[9].data, NULL);
559 
560  assert_int_equal(amxc_array_shift_left(array1, 3, NULL), 0);
561  assert_int_equal(amxc_array_capacity(array1), 10);
562  assert_int_equal(amxc_array_size(array1), 2);
563  assert_ptr_equal(array1->buffer[2].data, &data[6]);
564  assert_ptr_equal(array1->buffer[5].data, &data[9]);
565  assert_ptr_equal(array1->buffer[8].data, NULL);
566  assert_int_equal(array1->first_used, 2);
567  assert_int_equal(array1->last_used, 5);
568 
569  assert_int_equal(amxc_array_shift_left(array1, 6, NULL), 0);
570  assert_int_equal(amxc_array_capacity(array1), 10);
571  assert_int_equal(amxc_array_size(array1), 0);
572  assert_int_equal(array1->first_used, 0);
573  assert_int_equal(array1->last_used, 0);
574 }
int amxc_array_shift_left(amxc_array_t *const array, const size_t items, amxc_array_it_delete_t func)
Shift all items to the left in the array.
Definition: amxc_array.c:361

◆ test_amxc_array_shift_left_all()

void test_amxc_array_shift_left_all ( UNUSED void **  state)

Definition at line 576 of file test_amxc_array.c.

576  {
577  assert_int_equal(amxc_array_shift_left(array1, 10, NULL), 0);
578  assert_int_equal(amxc_array_capacity(array1), 10);
579  assert_int_equal(amxc_array_size(array1), 0);
580  assert_int_equal(array1->first_used, 0);
581  assert_int_equal(array1->last_used, 0);
582  assert_ptr_equal(array1->buffer[3].data, NULL);
583  assert_ptr_equal(array1->buffer[6].data, NULL);
584  assert_ptr_equal(array1->buffer[9].data, NULL);
585 
587 }

◆ test_amxc_array_shift_null()

void test_amxc_array_shift_null ( UNUSED void **  state)

Definition at line 539 of file test_amxc_array.c.

539  {
540  assert_int_equal(amxc_array_shift_left(NULL, 0, NULL), -1);
541  assert_int_equal(amxc_array_shift_right(NULL, 0, NULL), -1);
542 }
int amxc_array_shift_right(amxc_array_t *const array, const size_t items, amxc_array_it_delete_t func)
Shift all items to the right in the array.
Definition: amxc_array.c:323

◆ test_amxc_array_shift_right()

void test_amxc_array_shift_right ( UNUSED void **  state)

Definition at line 589 of file test_amxc_array.c.

589  {
590  assert_int_equal(amxc_array_shift_right(array1, 15, NULL), -1);
591  assert_int_equal(amxc_array_shift_right(array1, 0, NULL), 0);
592 
593  assert_int_equal(amxc_array_shift_right(array1, 1, NULL), 0);
594  assert_int_equal(amxc_array_capacity(array1), 10);
595  assert_int_equal(amxc_array_size(array1), 2);
596  assert_int_equal(array1->first_used, 4);
597  assert_int_equal(array1->last_used, 7);
598  assert_ptr_equal(array1->buffer[4].data, &data[3]);
599  assert_ptr_equal(array1->buffer[3].data, NULL);
600  assert_ptr_equal(array1->buffer[7].data, &data[6]);
601  assert_ptr_equal(array1->buffer[6].data, NULL);
602  assert_ptr_equal(array1->buffer[9].data, NULL);
603 
604  assert_int_equal(amxc_array_shift_right(array1, 3, NULL), 0);
605  assert_int_equal(amxc_array_capacity(array1), 10);
606  assert_int_equal(amxc_array_size(array1), 1);
607  assert_ptr_equal(array1->buffer[7].data, &data[3]);
608  assert_ptr_equal(array1->buffer[4].data, NULL);
609  assert_int_equal(array1->first_used, 7);
610  assert_int_equal(array1->last_used, 7);
611 
612  assert_int_equal(amxc_array_shift_right(array1, 3, NULL), 0);
613  assert_int_equal(amxc_array_capacity(array1), 10);
614  assert_int_equal(amxc_array_size(array1), 0);
615  assert_int_equal(array1->first_used, 0);
616  assert_int_equal(array1->last_used, 0);
617 
619 }

◆ test_amxc_array_shift_right_all()

void test_amxc_array_shift_right_all ( UNUSED void **  state)

Definition at line 621 of file test_amxc_array.c.

621  {
622  assert_int_equal(amxc_array_shift_right(array1, 10, NULL), 0);
623  assert_int_equal(amxc_array_capacity(array1), 10);
624  assert_int_equal(amxc_array_size(array1), 0);
625  assert_int_equal(array1->first_used, 0);
626  assert_int_equal(array1->last_used, 0);
627  assert_ptr_equal(array1->buffer[3].data, NULL);
628  assert_ptr_equal(array1->buffer[6].data, NULL);
629  assert_ptr_equal(array1->buffer[9].data, NULL);
630 
632 }

◆ test_amxc_array_shrink()

void test_amxc_array_shrink ( UNUSED void **  state)

Definition at line 507 of file test_amxc_array.c.

507  {
508  assert_int_equal(amxc_array_shrink(array1, 15, NULL), -1);
509 
510  assert_int_equal(amxc_array_shrink(array1, 5, NULL), 0);
511  assert_int_equal(amxc_array_capacity(array1), 5);
512  assert_int_equal(array1->first_used, 3);
513  assert_int_equal(array1->last_used, 3);
514 
515  assert_int_equal(amxc_array_shrink(array1, 3, NULL), 0);
516  assert_int_equal(amxc_array_capacity(array1), 2);
517  assert_int_equal(array1->first_used, 0);
518  assert_int_equal(array1->last_used, 0);
519 
520  assert_int_equal(amxc_array_shrink(array1, 2, NULL), 0);
521  assert_int_equal(amxc_array_capacity(array1), 0);
522  assert_int_equal(array1->first_used, 0);
523  assert_int_equal(array1->last_used, 0);
524 
525  assert_int_equal(amxc_array_grow(array1, 10), 0);
527  assert_int_equal(array1->first_used, 3);
528  assert_int_equal(array1->last_used, 3);
529 
531  assert_int_equal(array1->first_used, 3);
532  assert_int_equal(array1->last_used, 6);
533 
535  assert_int_equal(array1->first_used, 3);
536  assert_int_equal(array1->last_used, 9);
537 }

◆ test_amxc_array_shrink_null()

void test_amxc_array_shrink_null ( UNUSED void **  state)

Definition at line 503 of file test_amxc_array.c.

503  {
504  assert_int_equal(amxc_array_shrink(NULL, 0, NULL), -1);
505 }

◆ test_amxc_array_size()

void test_amxc_array_size ( UNUSED void **  state)

Definition at line 473 of file test_amxc_array.c.

473  {
474  assert_int_equal(amxc_array_size(array1), 3);
475 }

◆ test_amxc_array_size_null()

void test_amxc_array_size_null ( UNUSED void **  state)

Definition at line 469 of file test_amxc_array.c.

469  {
470  assert_int_equal(amxc_array_size(NULL), 0);
471 }

◆ test_amxc_array_sort()

void test_amxc_array_sort ( UNUSED void **  state)

Definition at line 913 of file test_amxc_array.c.

913  {
915  const char data[16] = "KRATELEPUIMQCXOS";
916  const char sorted[16] = "ACEEIKLMOPQRSTUX";
917 
918  const char data_sets[6][3] = {
919  "ABC", "BCA", "CAB", "CBA", "BAC", "ACB"
920  };
921 
922  // initialize array with 10 items
923  assert_int_equal(amxc_array_init(&array, 20), 0);
924  for(unsigned int index = 0; index < 16; index++) {
925  assert_ptr_equal(amxc_array_set_data_at(&array, index, (void*) &data[index]), &array.buffer[index]);
926  }
927 
928  assert_int_equal(amxc_array_sort(&array, test_cmp), 0);
929  for(unsigned int index = 0; index < 16; index++) {
930  char* d = amxc_array_it_get_data(amxc_array_get_at(&array, index));
931  printf("%c\n", d[0]);
932  assert_int_equal(d[0], sorted[index]);
933  }
934  amxc_array_clean(&array, NULL);
935 
936  assert_int_equal(amxc_array_init(&array, 40), 0);
937  for(unsigned int index = 0; index < 32; index += 2) {
938  assert_ptr_equal(amxc_array_set_data_at(&array, index, (void*) &data[index / 2]), &array.buffer[index]);
939  }
940 
941  assert_int_equal(amxc_array_sort(&array, test_cmp), 0);
942  for(unsigned int index = 0; index < 16; index++) {
943  char* d = amxc_array_it_get_data(amxc_array_get_at(&array, index));
944  printf("%c\n", d[0]);
945  assert_int_equal(d[0], sorted[index]);
946  }
947  assert_int_equal(amxc_array_size(&array), 16);
948  amxc_array_clean(&array, NULL);
949 
950  for(int sets = 0; sets < 6; sets++) {
951  printf("\n %d - ", sets);
952  assert_int_equal(amxc_array_init(&array, 20), 0);
953  for(unsigned int index = 0; index < 3; index++) {
954  assert_ptr_equal(amxc_array_set_data_at(&array, index, (void*) &data_sets[sets][index]), &array.buffer[index]);
955  }
956 
957  assert_int_equal(amxc_array_sort(&array, test_cmp), 0);
958  for(unsigned int index = 0; index < 3; index++) {
959  char* d = amxc_array_it_get_data(amxc_array_get_at(&array, index));
960  printf("%c", d[0]);
961  }
962  amxc_array_clean(&array, NULL);
963  }
964  printf("\n");
965 
966  assert_int_not_equal(amxc_array_sort(NULL, test_cmp), 0);
967  assert_int_equal(amxc_array_init(&array, 20), 0);
968  assert_int_not_equal(amxc_array_sort(&array, NULL), 0);
969  assert_int_equal(amxc_array_sort(&array, test_cmp), 0);
970  amxc_array_clean(&array, NULL);
971  assert_int_equal(amxc_array_init(&array, 0), 0);
972  assert_int_equal(amxc_array_sort(&array, test_cmp), 0);
973  amxc_array_clean(&array, NULL);
974 }
int amxc_array_sort(amxc_array_t *const array, amxc_array_it_cmp_t cmp)
Sorts the content of the array.
Definition: amxc_array.c:596
static int test_cmp(amxc_array_it_t *it1, amxc_array_it_t *it2)

◆ test_amxc_array_take_first_data()

void test_amxc_array_take_first_data ( UNUSED void **  state)

Definition at line 812 of file test_amxc_array.c.

812  {
814  assert_ptr_equal(d, &data[3]);
815  assert_int_equal(amxc_array_capacity(array1), 10);
816  assert_int_equal(amxc_array_size(array1), 2);
817  assert_int_equal(array1->first_used, 6);
818 
820  assert_ptr_equal(d, &data[6]);
821  assert_int_equal(amxc_array_capacity(array1), 10);
822  assert_int_equal(amxc_array_size(array1), 1);
823  assert_int_equal(array1->first_used, 9);
824 
826  assert_ptr_equal(d, &data[9]);
827  assert_int_equal(amxc_array_capacity(array1), 10);
828  assert_int_equal(amxc_array_size(array1), 0);
829  assert_int_equal(array1->first_used, 0);
830 
832 }
void * amxc_array_take_first_data(amxc_array_t *const array)
Takes the data pointer from the first used item in the array.
Definition: amxc_array.c:576

◆ test_amxc_array_take_first_data_null()

void test_amxc_array_take_first_data_null ( UNUSED void **  state)

Definition at line 808 of file test_amxc_array.c.

808  {
809  assert_ptr_equal(amxc_array_take_first_data(NULL), NULL);
810 }

◆ test_amxc_array_take_last_data()

void test_amxc_array_take_last_data ( UNUSED void **  state)

Definition at line 838 of file test_amxc_array.c.

838  {
840  assert_ptr_equal(d, &data[9]);
841  assert_int_equal(amxc_array_capacity(array1), 10);
842  assert_int_equal(amxc_array_size(array1), 2);
843  assert_int_equal(array1->last_used, 6);
844 
846  assert_ptr_equal(d, &data[6]);
847  assert_int_equal(amxc_array_capacity(array1), 10);
848  assert_int_equal(amxc_array_size(array1), 1);
849  assert_int_equal(array1->last_used, 3);
850 
852  assert_ptr_equal(d, &data[3]);
853  assert_int_equal(amxc_array_capacity(array1), 10);
854  assert_int_equal(amxc_array_size(array1), 0);
855  assert_int_equal(array1->first_used, 0);
856 
858 }
void * amxc_array_take_last_data(amxc_array_t *const array)
Takes the data pointer from the last used item in the array.
Definition: amxc_array.c:586

◆ test_amxc_array_take_last_data_null()

void test_amxc_array_take_last_data_null ( UNUSED void **  state)

Definition at line 834 of file test_amxc_array.c.

834  {
835  assert_ptr_equal(amxc_array_take_last_data(NULL), NULL);
836 }

◆ test_amxc_array_teardown()

int test_amxc_array_teardown ( UNUSED void **  state)

Definition at line 104 of file test_amxc_array.c.

104  {
105  amxc_array_delete(&array1, NULL);
106 
107  return 0;
108 }

◆ test_cmp()

static int test_cmp ( amxc_array_it_t it1,
amxc_array_it_t it2 
)
static

Definition at line 900 of file test_amxc_array.c.

900  {
901  char* d1 = amxc_array_it_get_data(it1);
902  char* d2 = amxc_array_it_get_data(it2);
903 
904  if(d1[0] < d2[0]) {
905  return -1;
906  } else if(d1[0] > d2[0]) {
907  return 1;
908  }
909 
910  return 0;
911 }
static amxc_llist_it_t it2
static amxc_llist_it_t it1

Variable Documentation

◆ array1

amxc_array_t* array1 = NULL
static

Definition at line 68 of file test_amxc_array.c.

◆ counter

int counter = 0
static

Definition at line 66 of file test_amxc_array.c.

◆ data

char data[] = "abcdefghij"

Definition at line 69 of file test_amxc_array.c.