aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-12-09 12:57:02 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-12-09 12:57:02 +0200
commitffc931dfb8829c8ae36b171d47f3230e10b67cea (patch)
treedba7ed1adfcf18bae24c472055c723f5a7208dc9 /tests
parent5335c09efe07f01c64e8b24d9b6e00125f7438fe (diff)
Add support for calculating SHA1 checksums
Diffstat (limited to 'tests')
-rw-r--r--tests/sha1/buildfile8
-rw-r--r--tests/sha1/driver.cxx54
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/sha1/buildfile b/tests/sha1/buildfile
new file mode 100644
index 0000000..1d6cece
--- /dev/null
+++ b/tests/sha1/buildfile
@@ -0,0 +1,8 @@
+# file : tests/sha256/buildfile
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+import libs = libbutl%lib{butl}
+libs += $stdmod_lib
+
+exe{driver}: {hxx cxx}{*} $libs
diff --git a/tests/sha1/driver.cxx b/tests/sha1/driver.cxx
new file mode 100644
index 0000000..5f5bb69
--- /dev/null
+++ b/tests/sha1/driver.cxx
@@ -0,0 +1,54 @@
+// file : tests/sha1/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <cassert>
+
+#ifndef __cpp_lib_modules
+#include <string>
+#include <iostream>
+#endif
+
+// Other includes.
+
+#ifdef __cpp_modules
+#ifdef __cpp_lib_modules
+import std.core;
+import std.io;
+#endif
+import butl.sha1;
+#else
+#include <libbutl/sha1.mxx>
+#endif
+
+using namespace std;
+using namespace butl;
+
+int
+main ()
+{
+ assert (string (sha1 ().string ()) ==
+ "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+
+ assert (string (sha1 ("").string ()) !=
+ "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+
+ assert (string (sha1 ("123").string ()) ==
+ "cc320164df1a2130045a28f08d3b88bc5bbcc43a");
+
+ assert (string (sha1 ("123", 3).string ()) ==
+ "40bd001563085fc35165329ea1ff5c5ecbdbbeef");
+
+ {
+ sha1 h;
+ h.append ("1");
+ h.append (string ("2"));
+ h.append ("3", 1);
+
+ auto& b (h.binary ());
+ assert (b[0] == 0x58 && b[19] == 0xfd);
+
+ string s (h.string ());
+ assert (s == "58c596bafad8d007952934af1db9abc5401d4dfd");
+ }
+}