summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-01-13 20:39:01 +0700
committerhathach <[email protected]>2013-01-13 20:39:01 +0700
commitf9914751833deb1b135568b7c09271261f356a06 (patch)
treee64aae9020e1682cc2dace9a99472451c9e5b535
parentb7b9531b9bb6e9a2fb6f85ae586c91bd29ef92e5 (diff)
add assert_hex & assert_hex_within
-rw-r--r--tests/test/test_assertion.c43
-rw-r--r--tinyusb/common/assertion.h19
2 files changed, 60 insertions, 2 deletions
diff --git a/tests/test/test_assertion.c b/tests/test/test_assertion.c
index 300a28859..7f2394093 100644
--- a/tests/test/test_assertion.c
+++ b/tests/test/test_assertion.c
@@ -106,3 +106,46 @@ void test_assert_int_within_greater(void)
ASSERT_INT_WITHIN (1, 5, 10, (void) 0);
TEST_FAIL();
}
+
+//--------------------------------------------------------------------+
+// HEX
+//--------------------------------------------------------------------+
+void test_assert_hex_equal(void)
+{
+ ASSERT_HEX (0xffee, 0xffee, (void) 0);
+ ASSERT_HEX_EQUAL (0xffee, 0xffee, (void) 0);
+
+ uint32_t x = 0xf0f0;
+ uint32_t y = 0xf0f0;
+ ASSERT_HEX (x++, y++, (void) 0); // test side effect
+ TEST_ASSERT_EQUAL(0xf0f1, x);
+ TEST_ASSERT_EQUAL(0xf0f1, y);
+
+ ASSERT_HEX(0x1234, 0x4321, (void) 0);
+
+ TEST_FAIL();
+}
+
+void test_assert_hex_within_succeed(void)
+{
+ ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff11, (void) 0);
+ ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff00, (void) 0);
+ ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xffff, (void) 0);
+}
+
+void test_assert_hex_within_less(void)
+{
+ ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xeeee, (void) 0);
+ TEST_FAIL();
+}
+
+void test_assert_hex_within_greater(void)
+{
+ ASSERT_HEX_WITHIN (0xff00, 0xffff, 0x1eeee, (void) 0);
+ TEST_FAIL();
+}
+
+
+
+
+
diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h
index 26dad566a..8fc19289a 100644
--- a/tinyusb/common/assertion.h
+++ b/tinyusb/common/assertion.h
@@ -105,8 +105,6 @@ extern "C"
//--------------------------------------------------------------------+
// Integer Assert
//--------------------------------------------------------------------+
-#define TEST_INT_EQUAL
-
#define ASSERT_INT(...) ASSERT_INT_EQUAL(__VA_ARGS__)
#define ASSERT_INT_EQUAL(expected, actual, error) \
ASSERT_DEFINE(\
@@ -122,6 +120,23 @@ extern "C"
error,\
"expected within %d-%d, actual %d", low, up, act)
+//--------------------------------------------------------------------+
+// Hex Assert
+//--------------------------------------------------------------------+
+#define ASSERT_HEX(...) ASSERT_HEX_EQUAL(__VA_ARGS__)
+#define ASSERT_HEX_EQUAL(expected, actual, error) \
+ ASSERT_DEFINE(\
+ uint32_t exp = (expected); uint32_t act = (actual),\
+ exp==act,\
+ error,\
+ "expected 0x%x, actual 0x%x", exp, act)
+
+#define ASSERT_HEX_WITHIN(lower, upper, actual, error) \
+ ASSERT_DEFINE(\
+ uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\
+ (low <= act) && (act <= up),\
+ error,\
+ "expected within 0x%x-0x%x, actual 0x%x", low, up, act)
#ifdef __cplusplus
}