1
1
forked from 0ad/0ad
0ad/source/lib/tests/test_allocators.h
janwas e0dfbe719d # add boatload of self-tests
(these are the old self-tests ripped out as well as new ones)
note: have not run yet; several would surely fail if they run (can't
anyway until cxxtest is installed)

This was SVN commit r3912.
2006-05-31 04:17:45 +00:00

45 lines
1.2 KiB
C++

#include <cxxtest/TestSuite.h>
class TestAllocators : public CxxTest::TestSuite
{
public:
void test_da()
{
DynArray da;
// basic test of functionality (not really meaningful)
TS_ASSERT_OK(da_alloc(&da, 1000));
TS_ASSERT_OK(da_set_size(&da, 1000));
TS_ASSERT_OK(da_set_prot(&da, PROT_NONE));
TS_ASSERT_OK(da_free(&da));
// test wrapping existing mem blocks for use with da_read
u8 data[4] = { 0x12, 0x34, 0x56, 0x78 };
TS_ASSERT_OK(da_wrap_fixed(&da, data, sizeof(data)));
u8 buf[4];
TS_ASSERT_OK(da_read(&da, buf, 4));
TS_ASSERT_EQUAL(read_le32(buf), 0x78563412); // read correct value
TS_ASSERT(da_read(&da, buf, 1) < 0); // no more data left
TS_ASSERT_OK(da_free(&da));
}
void test_expand()
{
}
void test_matrix()
{
// not much we can do here; allocate a matrix, write to it and
// make sure it can be freed.
// (note: can't check memory layout because "matrix" is int** -
// array of pointers. the matrix interface doesn't guarantee
// that data comes in row-major order after the row pointers)
int** m = (int**)matrix_alloc(3, 3, sizeof(int));
m[0][0] = 1;
m[0][1] = 2;
m[1][0] = 3;
m[2][2] = 4;
matrix_free((void**)m);
}
};