aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-26 22:31:55 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-28 16:33:57 +0200
commit0f1bedc90f4cb71d965e99446cf3e72a45909346 (patch)
tree51da6f4ee75cffa160598b5425851a2cc5452933 /tests
parent68591ef78ceefb9a37eb1744be73e646f63e450b (diff)
Add utility function to compute crc32 check sums
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makemodule.am7
-rw-r--r--tests/crc32.c35
2 files changed, 40 insertions, 2 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 60312dc..e681a33 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -73,12 +73,15 @@ test_str_table_SOURCES = tests/str_table.c
test_str_table_LDADD = libutil.a
test_str_table_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests
+test_crc32_SOURCES = tests/crc32.c
+test_crc32_LDADD = libutil.a
+
check_PROGRAMS += test_canonicalize_name test_mknode_simple test_mknode_slink
check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table
check_PROGRAMS += test_add_by_path test_get_path test_fstree_sort
check_PROGRAMS += test_fstree_from_file test_fstree_init test_fstree_xattr
check_PROGRAMS += test_tar_ustar test_tar_pax test_tar_gnu test_tar_sparse_gnu
-check_PROGRAMS += test_tar_sparse_gnu1 test_tar_sparse_gnu2
+check_PROGRAMS += test_tar_sparse_gnu1 test_tar_sparse_gnu2 test_crc32
check_PROGRAMS += test_tar_xattr_bsd test_tar_xattr_schily test_str_table
TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink
@@ -87,6 +90,6 @@ TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file
TESTS += test_fstree_init test_fstree_xattr test_tar_ustar test_tar_pax
TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1
TESTS += test_tar_sparse_gnu2 test_tar_xattr_bsd test_tar_xattr_schily
-TESTS += test_str_table
+TESTS += test_str_table test_crc32
EXTRA_DIST += $(top_srcdir)/tests/tar $(top_srcdir)/tests/words.txt
diff --git a/tests/crc32.c b/tests/crc32.c
new file mode 100644
index 0000000..290f5cf
--- /dev/null
+++ b/tests/crc32.c
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "config.h"
+#include "util.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+static const struct {
+ const char *str;
+ uint32_t result;
+} test_vectors[] = {
+ { "", 0 },
+ { "Hello, World!", 0xEC4AC3D0 },
+ { "The quick brown fox jumps over the lazy dog", 0x414FA339 },
+};
+
+int main(void)
+{
+ uint32_t crc;
+ size_t i;
+
+ for (i = 0; i < sizeof(test_vectors) / sizeof(test_vectors[0]); ++i) {
+ crc = update_crc32(0, test_vectors[i].str,
+ strlen(test_vectors[i].str));
+
+ if (crc != test_vectors[i].result) {
+ fprintf(stderr, "Case %zu failed: %08X != %08X\n", i,
+ crc, test_vectors[i].result);
+ return EXIT_FAILURE;
+ }
+ }
+
+ return EXIT_SUCCESS;
+}