mirror of
https://github.com/tailix/libclayer.git
synced 2024-11-20 11:06:24 -05:00
Add tests
This commit is contained in:
parent
881f6ecb5b
commit
8197462089
1 changed files with 40 additions and 8 deletions
|
@ -3,19 +3,51 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define COUNT 1024
|
||||||
|
|
||||||
|
static char aaa[COUNT], bbb[COUNT];
|
||||||
|
|
||||||
|
#define memcmp LIBCLAYER(memcmp)
|
||||||
|
#define memcpy LIBCLAYER(memcpy)
|
||||||
|
#define memmove LIBCLAYER(memmove)
|
||||||
|
#define memchr LIBCLAYER(memchr)
|
||||||
|
#define memset LIBCLAYER(memset)
|
||||||
|
|
||||||
void test_main()
|
void test_main()
|
||||||
{
|
{
|
||||||
{
|
{ // memcmp
|
||||||
const size_t count = 1024;
|
for (size_t i = 0; i < COUNT; ++i) aaa[i] = bbb[i] = i * i;
|
||||||
char aaa[count];
|
assert(memcmp(aaa, bbb, COUNT) == 0);
|
||||||
char bbb[count];
|
|
||||||
for (size_t i = 0; i < count; ++i) aaa[i] = bbb[i] = i*i;
|
|
||||||
assert(LIBCLAYER(memcmp)(aaa, bbb, count) == 0);
|
|
||||||
aaa[123] = 1;
|
aaa[123] = 1;
|
||||||
bbb[123] = 2;
|
bbb[123] = 2;
|
||||||
assert(LIBCLAYER(memcmp)(aaa, bbb, count) == -1);
|
assert(memcmp(aaa, bbb, COUNT) == -1);
|
||||||
aaa[123] = 2;
|
aaa[123] = 2;
|
||||||
bbb[123] = 1;
|
bbb[123] = 1;
|
||||||
assert(LIBCLAYER(memcmp)(aaa, bbb, count) == 1);
|
assert(memcmp(aaa, bbb, COUNT) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // memcpy
|
||||||
|
for (size_t i = 0; i < COUNT; ++i) { aaa[i] = 0; bbb[i] = i * i; }
|
||||||
|
assert(memcpy(aaa, bbb, COUNT) == aaa);
|
||||||
|
for (size_t i = 0; i < COUNT; ++i) assert(aaa[i] == (char)(i * i));
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // memmove
|
||||||
|
for (size_t i = 0; i < COUNT; ++i) { aaa[i] = 0; bbb[i] = i * i; }
|
||||||
|
assert(memcpy(aaa, bbb, COUNT) == aaa);
|
||||||
|
for (size_t i = 0; i < COUNT; ++i) assert(aaa[i] == (char)(i * i));
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // memchr
|
||||||
|
for (size_t i = 0; i < COUNT; ++i) aaa[i] = 0;
|
||||||
|
aaa[256] = 'a';
|
||||||
|
assert(memchr(aaa, 'a', COUNT) == &aaa[256]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // memset
|
||||||
|
memset(&aaa[0], 'a', COUNT / 2);
|
||||||
|
memset(&aaa[COUNT / 2], 'b', COUNT / 2);
|
||||||
|
for (size_t i = 0; i < COUNT / 2; ++i) assert(aaa[i] == 'a');
|
||||||
|
for (size_t i = COUNT / 2; i < COUNT; ++i) assert(aaa[i] == 'b');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue