aboutsummaryrefslogtreecommitdiff
path: root/tests/crc32.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/crc32.c')
-rw-r--r--tests/crc32.c35
1 files changed, 35 insertions, 0 deletions
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;
+}