[Git][NTPsec/ntpsec][master] 2 commits: tests: add tests for put_lsb_short()

Gary E. Miller gitlab at mg.gitlab.com
Sat May 13 02:47:36 UTC 2017


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


Commits:
aaeb7092 by Gary E. Miller at 2017-05-12T19:04:56-07:00
tests: add tests for put_lsb_short()

- - - - -
f3e7f450 by Gary E. Miller at 2017-05-12T19:17:58-07:00
binio: rename put_lsb_short(,long() to put_lsb_uint16(,uint16_t)

Shorts are not always 16 bits, it was always passed a uint16_t.
So now the function, and function name. is more tailored to the use.

All tests pass.

- - - - -


4 changed files:

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


Changes:

=====================================
include/binio.h
=====================================
--- a/include/binio.h
+++ b/include/binio.h
@@ -11,7 +11,7 @@
 #include "ntp_stdlib.h"
 
 int16_t get_lsb_int16 (unsigned char **);
-void put_lsb_short (unsigned char **, long);
+void put_lsb_uint16 (unsigned char **, uint16_t);
 int32_t get_lsb_int32 (unsigned char **);
 
 #define get_lsb_uint16( _x_ )  ((uint16_t) get_lsb_int16( _x_ ))


=====================================
libparse/binio.c
=====================================
--- a/libparse/binio.c
+++ b/libparse/binio.c
@@ -23,9 +23,9 @@ get_lsb_int16(
 }
 
 void
-put_lsb_short(
+put_lsb_uint16(
 	unsigned char **bufpp,
-	long val
+	uint16_t val
 	)
 {
   *((*bufpp)++) = (unsigned char) (val        & 0xFF);


=====================================
libparse/data_mbg.c
=====================================
--- a/libparse/data_mbg.c
+++ b/libparse/data_mbg.c
@@ -32,10 +32,10 @@ put_mbg_header(
 	GPS_MSG_HDR *headerp
 	)
 {
-  put_lsb_short(bufpp, headerp->cmd);
-  put_lsb_short(bufpp, headerp->len);
-  put_lsb_short(bufpp, headerp->data_csum);
-  put_lsb_short(bufpp, headerp->hdr_csum);
+  put_lsb_uint16(bufpp, headerp->cmd);
+  put_lsb_uint16(bufpp, headerp->len);
+  put_lsb_uint16(bufpp, headerp->data_csum);
+  put_lsb_uint16(bufpp, headerp->hdr_csum);
 }
 
 void


=====================================
tests/libparse/binio.c
=====================================
--- a/tests/libparse/binio.c
+++ b/tests/libparse/binio.c
@@ -124,6 +124,58 @@ TEST(binio, get_lsb_int324) {
         TEST_ASSERT_EQUAL_HEX32( 0x080000000UL, ret );
 }
 
+
+TEST(binio, put_lsb_uint160) {
+        unsigned char ret[2] = { 0, 0};
+        unsigned char exp[2] = { 0, 0};
+        unsigned char *bp = &ret[0];
+
+        put_lsb_uint16( &bp, 0);
+
+        TEST_ASSERT_EQUAL_HEX8_ARRAY( exp, ret, 2 );
+}
+
+TEST(binio, put_lsb_uint161) {
+        unsigned char ret[2] = { 0, 0};
+        unsigned char exp[2] = { 1, 0};
+        unsigned char *bp = &ret[0];
+
+        put_lsb_uint16( &bp, 1);
+
+        TEST_ASSERT_EQUAL_HEX8_ARRAY( exp, ret, 2 );
+}
+
+TEST(binio, put_lsb_uint162) {
+        unsigned char ret[2] = { 0, 0};
+        unsigned char exp[2] = { 0, 1};
+        unsigned char *bp = &ret[0];
+
+        put_lsb_uint16( &bp, 256);
+
+        TEST_ASSERT_EQUAL_HEX8_ARRAY( exp, ret, 2 );
+}
+
+TEST(binio, put_lsb_uint163) {
+        unsigned char ret[2] = { 0, 0};
+        unsigned char exp[2] = { 0xff, 0xff };
+        unsigned char *bp = &ret[0];
+
+        put_lsb_uint16( &bp, 0xffff);
+
+        TEST_ASSERT_EQUAL_HEX8_ARRAY( exp, ret, 2 );
+}
+
+TEST(binio, put_lsb_uint164) {
+        unsigned char ret[2] = { 0, 0};
+        unsigned char exp[2] = { 1, 0x80};
+        unsigned char *bp = &ret[0];
+
+        put_lsb_uint16( &bp, 0x8001);
+
+        TEST_ASSERT_EQUAL_HEX8_ARRAY( exp, ret, 2 );
+}
+
+
 /* LSB uint tests */
 
 TEST(binio, get_lsb_uint160) {
@@ -297,6 +349,12 @@ TEST_GROUP_RUNNER(binio) {
         RUN_TEST_CASE(binio, get_lsb_int323);
         RUN_TEST_CASE(binio, get_lsb_int324);
 
+        RUN_TEST_CASE(binio, put_lsb_uint160);
+        RUN_TEST_CASE(binio, put_lsb_uint161);
+        RUN_TEST_CASE(binio, put_lsb_uint162);
+        RUN_TEST_CASE(binio, put_lsb_uint163);
+        RUN_TEST_CASE(binio, put_lsb_uint164);
+
         /* LSB uint tests */
         RUN_TEST_CASE(binio, get_lsb_uint160);
         RUN_TEST_CASE(binio, get_lsb_uint161);



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/9d31f8bf9097063c2b447d4e6a17a6d6857130bb...f3e7f450c064bcfc90572b21b0ce5edbb812810e

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/9d31f8bf9097063c2b447d4e6a17a6d6857130bb...f3e7f450c064bcfc90572b21b0ce5edbb812810e
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/20170513/8411cc04/attachment.html>


More information about the vc mailing list