Procházet zdrojové kódy

added unittest for CRC16 implementation

stefan před 9 měsíci
rodič
revize
dd087aa699

+ 2 - 0
makefile

@@ -79,6 +79,8 @@ UNITTEST_SOURCES := test/unittest/test_main.cpp
                     test/unittest/shellmatta/test_shellmatta_doInit.cpp                 \
                     test/unittest/shellmatta_crc/test_crc32Slow.cpp                     \
                     test/unittest/shellmatta_crc/test_crc32Fast.cpp                     \
+                    test/unittest/shellmatta_crc/test_crc16Slow.cpp                     \
+                    test/unittest/shellmatta_crc/test_crc16Fast.cpp                     \
                     test/unittest/shellmatta_ymodem/test_ymodem.cpp
 
 INTEGRATIONTEST_SOURCES :=  test/integrationtest/test_main.cpp                  \

+ 21 - 0
test/unittest/shellmatta_crc/test_crc16Fast.cpp

@@ -0,0 +1,21 @@
+#include "test/framework/catch.hpp"
+#include <string.h>
+
+#define SHELLMATTA_TRANSPORT
+#undef SHELLMATTA_YMODEM_CRC_NO_LOOKUP
+#include "test_crc_data.h"
+#include "src/shellmatta_crc.c"
+
+TEST_CASE( "shellmatta_crc crc16Fast" ) {
+
+    uint32_t crc = crc16Fast((char*)"123456789", 9, crc16Table);
+
+    REQUIRE(crc == 0x31C3u);
+}
+
+TEST_CASE( "shellmatta_crc crc16Fast - more data" ) {
+
+    uint32_t crc = crc16Fast((char*)data, sizeof(data), crc16Table);
+
+    REQUIRE(crc == data_crc_16);
+}

+ 21 - 0
test/unittest/shellmatta_crc/test_crc16Slow.cpp

@@ -0,0 +1,21 @@
+#include "test/framework/catch.hpp"
+#include <string.h>
+
+#define SHELLMATTA_TRANSPORT
+#define SHELLMATTA_YMODEM_CRC_NO_LOOKUP
+#include "test_crc_data.h"
+#include "src/shellmatta_crc.c"
+
+TEST_CASE("shellmatta_crc crc16Slow" ) {
+
+    uint32_t crc = crc16Slow((char*)"123456789", 9);
+
+    REQUIRE(crc == 0x31C3u);
+}
+
+TEST_CASE("shellmatta_crc crc16Slow - more data") {
+
+    uint32_t crc = crc16Slow((char*)data, sizeof(data));
+
+    REQUIRE(crc == data_crc_16);
+}

+ 2 - 2
test/unittest/shellmatta_crc/test_crc32Fast.cpp

@@ -3,7 +3,7 @@
 
 #define SHELLMATTA_TRANSPORT
 #undef SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP
-#include "test_crc32_data.h"
+#include "test_crc_data.h"
 #include "src/shellmatta_crc.c"
 
 TEST_CASE( "shellmatta_crc crc32Fast" ) {
@@ -17,5 +17,5 @@ TEST_CASE( "shellmatta_crc crc32Fast - more data" ) {
 
     uint32_t crc = crc32Fast((char*)data, sizeof(data), crc32Table);
 
-    REQUIRE(crc == data_crc);
+    REQUIRE(crc == data_crc_32);
 }

+ 2 - 2
test/unittest/shellmatta_crc/test_crc32Slow.cpp

@@ -3,7 +3,7 @@
 
 #define SHELLMATTA_TRANSPORT
 #define SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP
-#include "test_crc32_data.h"
+#include "test_crc_data.h"
 #include "src/shellmatta_crc.c"
 
 TEST_CASE( "shellmatta_crc crc32Slow" ) {
@@ -17,5 +17,5 @@ TEST_CASE( "shellmatta_crc crc32Slow - more data" ) {
 
     uint32_t crc = crc32Slow((char*)data, sizeof(data));
 
-    REQUIRE(crc == data_crc);
+    REQUIRE(crc == data_crc_32);
 }

+ 4 - 3
test/unittest/shellmatta_crc/test_crc32_data.h

@@ -1,5 +1,5 @@
-#ifndef _TEST_CRC32_DATA_H_
-#define _TEST_CRC32_DATA_H_
+#ifndef _TEST_CRC_DATA_H_
+#define _TEST_CRC_DATA_H_
 
 const uint8_t data[] = {
     0xB8, 0xCA, 0xFD, 0x92, 0x55, 0x6A, 0x2F, 0x22, 0x5B, 0xB3, 0x0F, 0xEE, 0x69, 0x4E, 0x83, 0x4A,
@@ -260,6 +260,7 @@ const uint8_t data[] = {
     0x14, 0x21, 0x4B, 0xDE, 0x6D, 0xC4, 0xE9, 0xC9, 0x75, 0xBA, 0x9C, 0x2D, 0x14, 0xD4, 0xB2, 0xFF
 };
 
-const uint32_t data_crc = 0x7322E75E;
+const uint32_t data_crc_16 = 0x5A57u;
+const uint32_t data_crc_32 = 0x7322E75Eu;
 
 #endif