summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2017-01-15 19:04:20 +0100
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-01-15 19:04:20 +0100
commit4be42017e51ff506da3fbdf6d2682e91a66f02c1 (patch)
tree727c24c687570c0a83bd7bf981aa561c0c57929f /src/lib
parent361e321f6c7011040805a7f3d3cbdd8dfae71c3f (diff)
parent164f943bb8af62c343a55d2b3f97c20d06fd7592 (diff)
downloadouroboros-4be42017e51ff506da3fbdf6d2682e91a66f02c1.tar.gz
ouroboros-4be42017e51ff506da3fbdf6d2682e91a66f02c1.zip
Merged in dstaesse/ouroboros/be-crc-test (pull request #348)
lib: Add test for crc32 function
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/tests/CMakeLists.txt1
-rw-r--r--src/lib/tests/crc32_test.c71
2 files changed, 72 insertions, 0 deletions
diff --git a/src/lib/tests/CMakeLists.txt b/src/lib/tests/CMakeLists.txt
index 92a4579a..85535399 100644
--- a/src/lib/tests/CMakeLists.txt
+++ b/src/lib/tests/CMakeLists.txt
@@ -4,6 +4,7 @@ get_filename_component(PARENT_DIR ${PARENT_PATH} NAME)
create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
# Add new tests here
bitmap_test.c
+ crc32_test.c
hashtable_test.c
sha3_test.c
)
diff --git a/src/lib/tests/crc32_test.c b/src/lib/tests/crc32_test.c
new file mode 100644
index 00000000..563d23b0
--- /dev/null
+++ b/src/lib/tests/crc32_test.c
@@ -0,0 +1,71 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2017
+ *
+ * Test of the CRC32 function
+ *
+ * Dimitri Staessens <dimitri.staessens@intec.ugent.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <ouroboros/crc32.h>
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+/*
+ * Test vectors calculated at
+ * https://www.lammertbies.nl/comm/info/crc-calculation.html
+ */
+
+int crc32_test(int argc,
+ char ** argv)
+{
+ uint32_t crc = 0;
+ int i = 0;
+
+ (void) argc;
+ (void) argv;
+
+ crc32(&crc, "0", 1);
+ if (crc != 0xF4DBDF21)
+ return -1;
+
+ crc = 0;
+
+ crc32(&crc, "123456789", 9);
+ if (crc != 0xCBF43926)
+ return -1;
+
+ crc = 0;
+
+ crc32(&crc, "987654321", 9);
+ if (crc != 0x015F0201)
+ return -1;
+
+ crc32(&crc, "123456789", 9);
+ if (crc != 0x806B60E3)
+ return -1;
+
+ crc = 0;
+
+ crc32(&crc, &i , 1);
+ if (crc != 0xD202EF8D)
+ return -1;
+
+ return 0;
+}