chiark / gitweb /
test: add a simple smoke test for string_hashsum()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 5 Feb 2018 08:48:38 +0000 (09:48 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:53:59 +0000 (07:53 +0200)
This is enough to show memory leakages pointed out by Stef Bon <stefbon@gmail.com>.

(cherry picked from commit bd181f27d4d0c16c500c9f49394213d1fbad1f09)

src/test/meson.build
src/test/test-gcrypt-util.c [new file with mode: 0644]

index 72fb33d9aec69cee1d0da4fc8e150cd3f378d228..12dfcf5adafd280b60a04f7c3f795a889b53c9e5 100644 (file)
@@ -409,6 +409,17 @@ tests += [
 #           libblkid]],
 #endif // 0
 
+        [['src/test/test-watch-pid.c',
+          'src/test/test-helper.c'],
+         [libcore,
+          libshared],
+         [libmount,
+          threads,
+          librt,
+          libseccomp,
+          libselinux,
+          libblkid]],
+
         [['src/test/test-hashmap.c',
           'src/test/test-hashmap-plain.c',
           test_hashmap_ordered_c],
@@ -434,6 +445,10 @@ tests += [
          [],
          []],
 
+        [['src/test/test-procfs-util.c'],
+         [],
+         []],
+
         [['src/test/test-unaligned.c'],
          [],
          []],
@@ -681,6 +696,11 @@ tests += [
          [],
          []],
 
+        [['src/test/test-gcrypt-util.c'],
+         [],
+         [],
+         'HAVE_GCRYPT'],
+
 #if 0 /// UNNEEDED in elogind
 #         [['src/test/test-nss.c'],
 #          [],
diff --git a/src/test/test-gcrypt-util.c b/src/test/test-gcrypt-util.c
new file mode 100644 (file)
index 0000000..9f0ed21
--- /dev/null
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: LGPL-2.1+
+ * Copyright 2018 Zbigniew Jędrzejewski-Szmek
+ */
+
+//#include "alloc-util.h"
+//#include "gcrypt-util.h"
+//#include "macro.h"
+//#include "string-util.h"
+
+static void test_string_hashsum(void) {
+        _cleanup_free_ char *out1 = NULL, *out2 = NULL, *out3 = NULL, *out4 = NULL;
+
+        assert_se(string_hashsum("asdf", 4, GCRY_MD_SHA224, &out1) == 0);
+        /* echo -n 'asdf' | sha224sum - */
+        assert_se(streq(out1, "7872a74bcbf298a1e77d507cd95d4f8d96131cbbd4cdfc571e776c8a"));
+
+        assert_se(string_hashsum("asdf", 4, GCRY_MD_SHA256, &out2) == 0);
+        /* echo -n 'asdf' | sha256sum - */
+        assert_se(streq(out2, "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"));
+
+        assert_se(string_hashsum("", 0, GCRY_MD_SHA224, &out3) == 0);
+        /* echo -n '' | sha224sum - */
+        assert_se(streq(out3, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"));
+
+        assert_se(string_hashsum("", 0, GCRY_MD_SHA256, &out4) == 0);
+        /* echo -n '' | sha256sum - */
+        assert_se(streq(out4, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
+}
+
+int main(int argc, char **argv) {
+        test_string_hashsum();
+
+        return 0;
+}