static void test(ck_bitmap_t *bits, unsigned int n_length, bool initial) { unsigned int i; CK_BITMAP_INSTANCE(8) u; CK_BITMAP_INIT(&u, 8, false); CK_BITMAP_SET(&u, 1); CK_BITMAP_SET(&u, 4); for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == !initial) { ck_error("[0] ERROR [%u]: Expected %u got %u\n", i, initial, !initial); } } for (i = 0; i < n_length; i++) { ck_bitmap_set(bits, i); if (ck_bitmap_test(bits, i) == false) { ck_error("[1] ERROR: Expected bit to be set: %u\n", i); } ck_bitmap_reset(bits, i); if (ck_bitmap_test(bits, i) == true) { ck_error("[2] ERROR: Expected bit to be cleared: %u\n", i); } ck_bitmap_set(bits, i); if (ck_bitmap_test(bits, i) == false) { ck_error("[3] ERROR: Expected bit to be set: %u\n", i); } check_iteration(bits, i, initial); } for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == false) { ck_error("[4] ERROR: Expected bit to be set: %u\n", i); } } ck_bitmap_clear(bits); for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == true) { ck_error("[4] ERROR: Expected bit to be reset: %u\n", i); } } ck_bitmap_union(bits, CK_BITMAP(&u)); if (ck_bitmap_test(bits, 1) == false || ck_bitmap_test(bits, 4) == false) { ck_error("ERROR: Expected union semantics.\n"); } return; }
int main(int argc, char *argv[]) { unsigned int bytes, base; if (argc >= 2) { length = atoi(argv[1]); } base = ck_bitmap_base(length); bytes = ck_bitmap_size(length); fprintf(stderr, "Configuration: %u bytes\n", bytes); g_bits = malloc(bytes); memset(g_bits->map, 0xFF, base); ck_bitmap_init(g_bits, length, false); test(g_bits, length, false); memset(g_bits->map, 0x00, base); ck_bitmap_init(g_bits, length, true); test(g_bits, length, true); ck_bitmap_test(g_bits, length - 1); CK_BITMAP_INSTANCE(STATIC_LENGTH) sb; fprintf(stderr, "Static configuration: %zu bytes\n", sizeof(sb)); memset(CK_BITMAP_BUFFER(&sb), 0xFF, ck_bitmap_base(STATIC_LENGTH)); CK_BITMAP_INIT(&sb, STATIC_LENGTH, false); test(CK_BITMAP(&sb), STATIC_LENGTH, false); memset(CK_BITMAP_BUFFER(&sb), 0x00, ck_bitmap_base(STATIC_LENGTH)); CK_BITMAP_INIT(&sb, STATIC_LENGTH, true); test(CK_BITMAP(&sb), STATIC_LENGTH, true); CK_BITMAP_CLEAR(&sb); if (CK_BITMAP_TEST(&sb, 1) == true) { fprintf(stderr, "ERROR: Expected bit to be reset.\n"); exit(EXIT_FAILURE); } CK_BITMAP_SET_MPMC(&sb, 1); if (CK_BITMAP_TEST(&sb, 1) == false) { fprintf(stderr, "ERROR: Expected bit to be set.\n"); exit(EXIT_FAILURE); } CK_BITMAP_RESET_MPMC(&sb, 1); if (CK_BITMAP_TEST(&sb, 1) == true) { fprintf(stderr, "ERROR: Expected bit to be reset.\n"); exit(EXIT_FAILURE); } return 0; }
static void test(ck_bitmap_t *bits, unsigned int n_length, bool initial) { unsigned int i; for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == !initial) { fprintf(stderr, "[0] ERROR [%u]: Expected %u got %u\n", i, initial, !initial); exit(EXIT_FAILURE); } } for (i = 0; i < n_length; i++) { ck_bitmap_set_mpmc(bits, i); if (ck_bitmap_test(bits, i) == false) { fprintf(stderr, "[1] ERROR: Expected bit to be set: %u\n", i); exit(EXIT_FAILURE); } ck_bitmap_reset_mpmc(bits, i); if (ck_bitmap_test(bits, i) == true) { fprintf(stderr, "[2] ERROR: Expected bit to be cleared: %u\n", i); exit(EXIT_FAILURE); } ck_bitmap_set_mpmc(bits, i); if (ck_bitmap_test(bits, i) == false) { fprintf(stderr, "[3] ERROR: Expected bit to be set: %u\n", i); exit(EXIT_FAILURE); } check_iteration(bits, i, initial); } for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == false) { fprintf(stderr, "[4] ERROR: Expected bit to be set: %u\n", i); exit(EXIT_FAILURE); } } ck_bitmap_clear(bits); for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == true) { fprintf(stderr, "[4] ERROR: Expected bit to be reset: %u\n", i); exit(EXIT_FAILURE); } } return; }