[Git][NTPsec/ntpsec][master] 4 commits: tests: add tests for get_lsb_short().

Gary E. Miller gitlab at mg.gitlab.com
Fri May 12 21:26:25 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
91d27f85 by Gary E. Miller at 2017-05-12T14:00:59-07:00
tests: add tests for get_lsb_short().

All tests pass, get_lsb_short() looks good.

- - - - -
e823e056 by Gary E. Miller at 2017-05-12T14:09:03-07:00
tests: add tests for get_msb_short)( and get_msb_long().

All tests pass and look good.

- - - - -
5fc17c07 by Gary E. Miller at 2017-05-12T14:12:45-07:00
tests: remove incorrect comment

- - - - -
5090b061 by Gary E. Miller at 2017-05-12T14:23:55-07:00
binio: remove 6 unused macros, 2 were broken.

6 macros I started to write tests for...

- - - - -


2 changed files:

- include/binio.h
- tests/libparse/binio.c


Changes:

=====================================
include/binio.h
=====================================
--- a/include/binio.h
+++ b/include/binio.h
@@ -17,19 +17,12 @@ void put_lsb_long (unsigned char **, long);
 
 #define get_lsb_int16( _x_ )   ((int16_t) get_lsb_short( _x_ ))
 #define get_lsb_uint16( _x_ )  ((uint16_t) get_lsb_short( _x_ ))
-#define get_lsb_int32( _x_ )   ((int32_t) get_lsb_long( _x_ ))
-#define get_lsb_uint32( _x_ )  ((uint32_t) get_lsb_long( _x_ ))
 
 long get_msb_short (unsigned char **);
 void put_msb_short (unsigned char **, long);
 long get_msb_long (unsigned char **);
 void put_msb_long (unsigned char **, long);
 
-#define get_msb_int16( _x_ )   ((int16_t) get_msb_short( _x_ ))
-#define get_msb_uint16( _x_ )  ((uint16_t) get_msb_short( _x_ ))
-#define get_msb_int32( _x_ )   ((int32_t) get_msb_long( _x_ ))
-#define get_msb_uint32( _x_ )  ((uint32_t) get_msb_long( _x_ ))
-
 #endif
 /*
  * History:


=====================================
tests/libparse/binio.c
=====================================
--- a/tests/libparse/binio.c
+++ b/tests/libparse/binio.c
@@ -17,6 +17,58 @@ TEST_SETUP(binio) {}
 
 TEST_TEAR_DOWN(binio) {}
 
+/* LSB tests */
+
+TEST(binio, get_lsb_short0) {
+        long ret;
+        unsigned char zero[2] = { 0, 0};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_short( &bp);
+
+        TEST_ASSERT_EQUAL_INT64( 0, ret );
+}
+
+TEST(binio, get_lsb_short1) {
+        long ret;
+        unsigned char zero[2] = { 1, 2};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x0201UL, ret );
+}
+
+TEST(binio, get_lsb_short2) {
+        long ret;
+        unsigned char zero[2] = { 2, 1};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x0102UL, ret );
+}
+
+TEST(binio, get_lsb_short3) {
+        long ret;
+        unsigned char zero[2] = { 0xff, 0xff};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( -1L, ret );
+}
+
+TEST(binio, get_lsb_short4) {
+        long ret;
+        unsigned char zero[2] = { 0, 0x80};
+        unsigned char *bp = &zero[0];
+
+        ret = get_lsb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( -0x8000L, ret );
+}
+
 
 TEST(binio, get_lsb_ulong0) {
         unsigned long ret;
@@ -25,7 +77,7 @@ TEST(binio, get_lsb_ulong0) {
 
         ret = get_lsb_ulong( &bp);
 
-        TEST_ASSERT_EQUAL_INT64( 0, (int64_t)ret );
+        TEST_ASSERT_EQUAL_UINT64( 0, ret );
 }
 
 
@@ -73,7 +125,121 @@ TEST(binio, get_lsb_ulong4) {
         TEST_ASSERT_EQUAL_HEX64( 0x080000000UL, ret );
 }
 
+/* MSB tests */
+
+TEST(binio, get_msb_short0) {
+        long ret;
+        unsigned char zero[2] = { 0, 0};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_short( &bp);
+
+        TEST_ASSERT_EQUAL_INT64( 0, ret );
+}
+
+TEST(binio, get_msb_short1) {
+        long ret;
+        unsigned char zero[2] = { 2, 1};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x0201UL, ret );
+}
+
+TEST(binio, get_msb_short2) {
+        long ret;
+        unsigned char zero[2] = { 1, 2};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x0102UL, ret );
+}
+
+TEST(binio, get_msb_short3) {
+        long ret;
+        unsigned char zero[2] = { 0xff, 0xff};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( -1L, ret );
+}
+
+TEST(binio, get_msb_short4) {
+        long ret;
+        unsigned char zero[2] = { 0x80, 0};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_short( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( -0x8000L, ret );
+}
+
+
+TEST(binio, get_msb_long0) {
+        long ret;
+        unsigned char zero[4] = { 0, 0, 0, 0};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_long( &bp);
+
+        TEST_ASSERT_EQUAL_UINT64( 0, ret );
+}
+
+
+TEST(binio, get_msb_long1) {
+        long ret;
+        unsigned char zero[4] = { 4, 3, 2, 1};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_long( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x04030201UL, ret );
+}
+
+
+TEST(binio, get_msb_long2) {
+        long ret;
+        unsigned char zero[4] = { 1, 2, 3, 4};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_long( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x01020304UL, ret );
+}
+
+
+TEST(binio, get_msb_long3) {
+        long ret;
+        unsigned char zero[4] = { 0xff, 0xff, 0xff, 0xff};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_long( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x0FFFFFFFFUL, ret );
+}
+
+
+TEST(binio, get_msb_long4) {
+        long ret;
+        unsigned char zero[4] = { 0x80, 0, 0, 0};
+        unsigned char *bp = &zero[0];
+
+        ret = get_msb_long( &bp);
+
+        TEST_ASSERT_EQUAL_HEX64( 0x080000000UL, ret );
+}
+
 TEST_GROUP_RUNNER(binio) {
+        /* LSB tests */
+        RUN_TEST_CASE(binio, get_lsb_short0);
+        RUN_TEST_CASE(binio, get_lsb_short1);
+        RUN_TEST_CASE(binio, get_lsb_short2);
+        RUN_TEST_CASE(binio, get_lsb_short3);
+        RUN_TEST_CASE(binio, get_lsb_short4);
+
         RUN_TEST_CASE(binio, get_lsb_ulong0);
         RUN_TEST_CASE(binio, get_lsb_ulong1);
         RUN_TEST_CASE(binio, get_lsb_ulong2);
@@ -81,4 +247,17 @@ TEST_GROUP_RUNNER(binio) {
         RUN_TEST_CASE(binio, get_lsb_ulong3);
         RUN_TEST_CASE(binio, get_lsb_ulong4);
         */
+
+        /* MSB tests */
+        RUN_TEST_CASE(binio, get_msb_short0);
+        RUN_TEST_CASE(binio, get_msb_short1);
+        RUN_TEST_CASE(binio, get_msb_short2);
+        RUN_TEST_CASE(binio, get_msb_short3);
+        RUN_TEST_CASE(binio, get_msb_short4);
+
+        RUN_TEST_CASE(binio, get_msb_long0);
+        RUN_TEST_CASE(binio, get_msb_long1);
+        RUN_TEST_CASE(binio, get_msb_long2);
+        RUN_TEST_CASE(binio, get_msb_long3);
+        RUN_TEST_CASE(binio, get_msb_long4);
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/95a1a1b1084571da46a628bc511728a365c59fcb...5090b0616a987ee581292a090db7a7bbc88952c8

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/95a1a1b1084571da46a628bc511728a365c59fcb...5090b0616a987ee581292a090db7a7bbc88952c8
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170512/c10598ec/attachment.html>


More information about the vc mailing list