@@ -65,6 +65,31 @@ MU_TEST(test_check_bit) {
65
65
ba_free (ba );
66
66
}
67
67
68
+ /*******************************************************************************
69
+ * Test check and set bit
70
+ *******************************************************************************/
71
+ MU_TEST (test_check_and_set_bit ) {
72
+ bitarray_t ba = ba_init (125 ); /* bit array of length 125 */
73
+ int res ;
74
+ res = ba_set_bit (ba , 0 );
75
+ res = ba_set_bit (ba , 50 );
76
+ res = ba_set_bit (ba , 75 );
77
+
78
+ /* check out of bounds still caught */
79
+ res = ba_check_and_set_bit (ba , 125 );
80
+ mu_assert_int_eq (BITARRAY_INDEX_ERROR , res );
81
+
82
+ res = ba_check_and_set_bit (ba , 0 );
83
+ mu_assert_int_eq (BIT_SET , res );
84
+
85
+ res = ba_check_and_set_bit (ba , 55 );
86
+ mu_assert_int_eq (BIT_NOT_SET , res );
87
+
88
+ res = ba_check_and_set_bit (ba , 55 );
89
+ mu_assert_int_eq (BIT_SET , res );
90
+
91
+ ba_free (ba );
92
+ }
68
93
69
94
/*******************************************************************************
70
95
* Test clear bit
@@ -189,6 +214,7 @@ MU_TEST_SUITE(test_suite) {
189
214
MU_RUN_TEST (test_default_setup );
190
215
MU_RUN_TEST (test_set_bit );
191
216
MU_RUN_TEST (test_check_bit );
217
+ MU_RUN_TEST (test_check_and_set_bit );
192
218
MU_RUN_TEST (test_clear_bit );
193
219
MU_RUN_TEST (test_reset_bitarray );
194
220
MU_RUN_TEST (test_print_array );
0 commit comments