aboutsummaryrefslogtreecommitdiff
path: root/tests/sha256
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-07-10 09:20:25 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2018-07-10 14:58:50 +0300
commit16b63f8cdf5b488ab2f4b0e029478b01a2d6b8a8 (patch)
tree78509ede9ae2652e8c82f01ec91b35eba3c3c7e4 /tests/sha256
parent681ca375fd5af01501a91a78214ab7a26ad67ac7 (diff)
Add support for hashing ifdstream
Diffstat (limited to 'tests/sha256')
-rw-r--r--tests/sha256/driver.cxx32
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/sha256/driver.cxx b/tests/sha256/driver.cxx
index 5653e05..908b6ec 100644
--- a/tests/sha256/driver.cxx
+++ b/tests/sha256/driver.cxx
@@ -6,7 +6,7 @@
#ifndef __cpp_lib_modules
#include <string>
-#include <iostream>
+#include <cstddef> // size_t
#endif
// Other includes.
@@ -14,11 +14,16 @@
#ifdef __cpp_modules
#ifdef __cpp_lib_modules
import std.core;
-import std.io;
#endif
+import butl.path;
import butl.sha256;
+import butl.fdstream;
+import butl.filesystem;
#else
+#include <libbutl/path.mxx>
#include <libbutl/sha256.mxx>
+#include <libbutl/fdstream.mxx>
+#include <libbutl/filesystem.mxx> // auto_rmfile
#endif
using namespace std;
@@ -37,6 +42,29 @@ main ()
"a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3");
{
+ string s;
+ for (size_t i (0); i < 1024; ++i)
+ s += "0123456789";
+
+ path p (path::temp_path ("butl-sha256"));
+
+ auto_rmfile pr; // Always remove the file after the stream is closed.
+ ofdstream os (p);
+ pr = auto_rmfile (p);
+
+ os << s;
+ os.close ();
+
+ ifdstream is (p);
+
+ assert (string (sha256 (is).string ()) ==
+ sha256 (s.c_str (), s.size ()).string ());
+
+ assert (is.eof ());
+ is.close ();
+ }
+
+ {
sha256 h ("123");
assert (string (h.string ()) ==