src.dualinventive.com/dinet/libdi/tests/array.cpp

43 lines
842 B
C++

#include <di/array.h>
#include <gtest/gtest.h>
#define TEST_ARRAY_ITEMS 10U
static size_t test_items[TEST_ARRAY_ITEMS];
DI_ARRAY_DECL(test_array, test_items, size_t, TEST_ARRAY_ITEMS);
/**
* Test if DI_ARRAY_DECL initialize members correct
*/
TEST(array, DECL) {
ASSERT_EQ(TEST_ARRAY_ITEMS, test_array.size);
ASSERT_EQ(&test_items, test_array.begin);
}
/**
* Test if di_array_entry returns the correct address at element offset
* by writing the integer loop counter + 100
*/
TEST(array, entry) {
size_t *i;
for (size_t n = 0; n < test_array.size; n++) {
i = di_array_entry(test_array, n, size_t);
*i = n + 100;
}
for (size_t n = 0; n < test_array.size; n++)
ASSERT_EQ(n + 100, test_items[n]);
}
TEST(array, foreach) {
size_t n = 0;
di_array_foreach(test_array, i, size_t) {
ASSERT_EQ(n + 100, *i);
n++;
}
}