diff options
Diffstat (limited to 'contrib/ntp/tests/libntp/tsafememcmp.c')
-rw-r--r-- | contrib/ntp/tests/libntp/tsafememcmp.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/contrib/ntp/tests/libntp/tsafememcmp.c b/contrib/ntp/tests/libntp/tsafememcmp.c new file mode 100644 index 0000000..7bd9158 --- /dev/null +++ b/contrib/ntp/tests/libntp/tsafememcmp.c @@ -0,0 +1,85 @@ +#include "config.h" + +#include "ntp_stdlib.h" +#include "isc/string.h" + +#include "unity.h" + +/* Basisc test for timingsafe_memcmp() */ + +void test_Empty(void); +void test_Equal(void); +void test_FirstByte(void); +void test_LastByte(void); +void test_MiddleByte(void); +void test_MiddleByteUpLo(void); + +void test_Empty(void) +{ + static const char dummy[1]; + TEST_ASSERT_EQUAL_INT(0, isc_tsmemcmp(NULL , NULL , 0)); + TEST_ASSERT_EQUAL_INT(0, isc_tsmemcmp(dummy, dummy, 0)); +} + +void test_Equal(void) +{ + static const char dummy[2][4] = { + "blob", "blob" + }; + TEST_ASSERT_EQUAL_INT(0, isc_tsmemcmp(dummy[0], + dummy[1], + sizeof(dummy[0]))); +} + +void test_FirstByte(void) +{ + static const char dummy[2][4] = { + "Blob", "Clob" + }; + TEST_ASSERT_EQUAL_INT(-1, isc_tsmemcmp(dummy[0], + dummy[1], + sizeof(dummy[0]))); + TEST_ASSERT_EQUAL_INT( 1, isc_tsmemcmp(dummy[1], + dummy[0], + sizeof(dummy[0]))); +} + +void test_LastByte(void) +{ + static const char dummy[2][4] = { + "Blob", "Bloc" + }; + TEST_ASSERT_EQUAL_INT(-1, isc_tsmemcmp(dummy[0], + dummy[1], + sizeof(dummy[0]))); + TEST_ASSERT_EQUAL_INT( 1, isc_tsmemcmp(dummy[1], + dummy[0], + sizeof(dummy[0]))); +} + +void test_MiddleByte(void) +{ + static const char dummy[2][4] = { + "Blob", "Blpb" + }; + TEST_ASSERT_EQUAL_INT(-1, isc_tsmemcmp(dummy[0], + dummy[1], + sizeof(dummy[0]))); + TEST_ASSERT_EQUAL_INT( 1, isc_tsmemcmp(dummy[1], + dummy[0], + sizeof(dummy[0]))); +} + +void test_MiddleByteUpLo(void) +{ + static const char dummy[2][4] = { + "Blob", "Blpa" + }; + TEST_ASSERT_EQUAL_INT(-1, isc_tsmemcmp(dummy[0], + dummy[1], + sizeof(dummy[0]))); + TEST_ASSERT_EQUAL_INT( 1, isc_tsmemcmp(dummy[1], + dummy[0], + sizeof(dummy[0]))); +} + |