X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fstruct%2Fbitarray_test.c;h=b917d0f4d60ec89fbf51c576b2b0d020db674843;hb=f248bd5d8be37c741ef62386d82e4975723e09c3;hp=fa65c44a0791f625f47c3a0b40b26d043c0a99ab;hpb=4ac7a89ec44f465a12154d2ff695684eccf3bb77;p=bertos.git diff --git a/bertos/struct/bitarray_test.c b/bertos/struct/bitarray_test.c index fa65c44a..b917d0f4 100644 --- a/bertos/struct/bitarray_test.c +++ b/bertos/struct/bitarray_test.c @@ -41,19 +41,87 @@ #include #include -ALLOC_BITARRAY(test1, 128); -BitArray ctx; +#include + +#define TEST1_LEN 31 +#define TEST2_LEN 17 + +BITARRAY_ALLOC(test1, TEST1_LEN); +BITARRAY_ALLOC(test2, TEST2_LEN); + +BitArray bitx1; +BitArray bitx2; int bitarray_testSetup(void) { kdbg_init(); - init_bitarray(&ctx, test1, sizeof(test1)); + bitarray_init(&bitx1, TEST1_LEN, test1, sizeof(test1)); + bitarray_init(&bitx2, TEST2_LEN, test2, sizeof(test2)); return 0; } int bitarray_testRun(void) { + memset(test1, 0xaa, sizeof(test1)); + + bitarray_dump(&bitx1); + for (size_t i = 0; i < TEST1_LEN; i++) + { + if (!((bool)(i % 2) == bitarray_test(&bitx1,i))) + goto error; + } + + memset(test1, 0, sizeof(test1)); + for (size_t i = 0; i < TEST1_LEN; i++) + { + if ((i % 2) == 0) + bitarray_clear(&bitx1,i); + else + bitarray_set(&bitx1, i); + } + + bitarray_dump(&bitx1); + for (size_t i = 0; i < TEST1_LEN; i++) + { + if (!((bool)(i % 2) == bitarray_test(&bitx1, i))) + goto error; + } + + memset(test1, 0, sizeof(test1)); + bitarray_set(&bitx1, 0); + bitarray_dump(&bitx1); + if (!bitarray_test(&bitx1, 0)) + goto error; + + memset(test1, 0, sizeof(test1)); + bitarray_set(&bitx1, TEST1_LEN); + bitarray_dump(&bitx1); + if (!bitarray_test(&bitx1, TEST1_LEN)) + goto error; + + kprintf("Test 2\n"); + memset(test2, 0xFF, sizeof(test2)); + bitarray_dump(&bitx2); + if (!bitarray_isFull(&bitx2)) + goto error; + + memset(test2, 0xFF, sizeof(test2)); + bitarray_clear(&bitx2, 5); + bitarray_dump(&bitx2); + if (bitarray_isFull(&bitx2)) + goto error; + + memset(test2, 0xFF, sizeof(test2)); + bitarray_clear(&bitx2, 13); + bitarray_dump(&bitx2); + if (bitarray_isFull(&bitx2)) + goto error; + return 0; + +error: + kprintf("Error!\n"); + return -1; } int bitarray_testTearDown(void)