Navigation Menu

Skip to content

Commit

Permalink
add bitmap macro and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mir committed Aug 8, 2009
1 parent 40e8316 commit 56e3ca6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions driver.h
Expand Up @@ -95,6 +95,15 @@ typedef struct _mrn_record
#define MRN_HANDLER_NAME(obj_name) (obj_name - 2)
#define MRN_TABLE_NAME(name) (name + 2)

typedef unsigned char uchar;

#define MRN_IS_BIT(map,idx) \
(uint) (((uchar*)map)[(idx)/8] & (1 << ((idx)&7)))
#define MRN_SET_BIT(map,idx) \
(((uchar*)map)[(idx)/8] |= (1 << ((idx)&7)))
#define MRN_CLEAR_BIT(map,idx) \
(((uchar*)map)[(idx)/8] &= ~(1 << ((idx)&7)))

/* functions */
int mrn_init();
int mrn_deinit();
Expand Down
17 changes: 17 additions & 0 deletions test/unit/test-driver.c
Expand Up @@ -798,3 +798,20 @@ void test_mrn_rnd_next_cond()
cut_assert_equal_int(0, mrn_drop(ctx, "test/mrn_rnd_next_cond"));
mrn_deinit_obj_info(ctx, info);
}

void test_mrn_bitmap_macro()
{
uchar *a;
a = g_malloc(128);
memset(a,0,128);
int i;
for (i=0; i < 128*8; i++)
{
cut_assert_false(MRN_IS_BIT(a,i),"precheck: idx=%d",i);
MRN_SET_BIT(a,i);
cut_assert_true(MRN_IS_BIT(a,i),"after set: idx=%d",i);
MRN_CLEAR_BIT(a,i);
cut_assert_false(MRN_IS_BIT(a,i),"after clear: idx=%d",i);
}
g_free(a);
}

0 comments on commit 56e3ca6

Please sign in to comment.