summaryrefslogtreecommitdiff
path: root/extras
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2013-10-09 02:01:06 +0000
committerTed Ross <tross@apache.org>2013-10-09 02:01:06 +0000
commit5b7b43548d94cc055a7ee4120a8798e99db71b37 (patch)
tree5c96b9f91b8c126d850156620d9b5282d7123367 /extras
parent1e946ac1fd59ce1aac25d27bfeabdd7c4c1c8c26 (diff)
downloadqpid-python-5b7b43548d94cc055a7ee4120a8798e99db71b37.tar.gz
QPID-5216 - Fixed a couple of bugs in the bitmask module.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1530481 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'extras')
-rw-r--r--extras/dispatch/src/bitmask.c6
-rw-r--r--extras/dispatch/tests/tool_test.c33
2 files changed, 36 insertions, 3 deletions
diff --git a/extras/dispatch/src/bitmask.c b/extras/dispatch/src/bitmask.c
index 5341f8d83a..88ba69dde1 100644
--- a/extras/dispatch/src/bitmask.c
+++ b/extras/dispatch/src/bitmask.c
@@ -33,7 +33,7 @@ ALLOC_DECLARE(dx_bitmask_t);
ALLOC_DEFINE(dx_bitmask_t);
#define MASK_INDEX(num) (num / 64)
-#define MASK_ONEHOT(num) (1 << (num % 64))
+#define MASK_ONEHOT(num) (((uint64_t) 1) << (num % 64))
#define FIRST_NONE -1
#define FIRST_UNKNOWN -2
@@ -81,7 +81,7 @@ void dx_bitmask_set_bit(dx_bitmask_t *b, int bitnum)
{
assert(bitnum < DX_BITMASK_BITS);
b->array[MASK_INDEX(bitnum)] |= MASK_ONEHOT(bitnum);
- if (b->first_set > bitnum)
+ if (b->first_set > bitnum || b->first_set < 0)
b->first_set = bitnum;
}
@@ -108,7 +108,7 @@ int dx_bitmask_first_set(dx_bitmask_t *b, int *bitnum)
for (int i = 0; i < DX_BITMASK_LONGS; i++)
if (b->array[i]) {
for (int j = 0; j < 64; j++)
- if ((1 << j) & b->array[i]) {
+ if ((((uint64_t) 1) << j) & b->array[i]) {
b->first_set = i * 64 + j;
break;
}
diff --git a/extras/dispatch/tests/tool_test.c b/extras/dispatch/tests/tool_test.c
index ba047d928c..2c90714b3d 100644
--- a/extras/dispatch/tests/tool_test.c
+++ b/extras/dispatch/tests/tool_test.c
@@ -21,6 +21,8 @@
#include <stdio.h>
#include <string.h>
#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/bitmask.h>
+#include "alloc_private.h"
typedef struct item_t {
DEQ_LINKS(struct item_t);
@@ -188,12 +190,43 @@ static char* test_deq_basic2(void *context)
}
+static char* test_bitmask(void *context)
+{
+ dx_bitmask_t *bm;
+ int num;
+
+ bm = dx_bitmask(0);
+ if (!bm) return "Can't allocate a bit mask";
+ if (dx_bitmask_first_set(bm, &num)) return "Expected no first set bit";
+
+ dx_bitmask_set_bit(bm, 3);
+ dx_bitmask_set_bit(bm, 500);
+
+ if (!dx_bitmask_first_set(bm, &num)) return "Expected first set bit";
+ if (num != 3) return "Expected first set bit to be 3";
+
+ dx_bitmask_clear_bit(bm, num);
+
+ if (!dx_bitmask_first_set(bm, &num)) return "Expected first set bit (2)";
+ if (num != 500) return "Expected first set bit to be 500";
+
+ dx_bitmask_clear_bit(bm, num);
+ if (dx_bitmask_first_set(bm, &num)) return "Expected no first set bit (2)";
+
+ dx_bitmask_free(bm);
+
+ return 0;
+}
+
+
int tool_tests(void)
{
int result = 0;
+ dx_alloc_initialize();
TEST_CASE(test_deq_basic, 0);
TEST_CASE(test_deq_basic2, 0);
+ TEST_CASE(test_bitmask, 0);
return result;
}