aboutsummaryrefslogtreecommitdiff
path: root/old-tests/depdb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-12-01 12:07:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-12-01 12:07:18 +0200
commit0ed86c76239d4f2904ea4ae1a77902a9e0db2a6d (patch)
tree5e8e1d43a0140f5739b21be7cbe120ebb9360d4f /old-tests/depdb
parent12fc75188cc1f0a8c4c443c04e7a022131198c36 (diff)
Move old tests to old-tests/
Diffstat (limited to 'old-tests/depdb')
-rw-r--r--old-tests/depdb/buildfile8
-rw-r--r--old-tests/depdb/driver.cxx166
2 files changed, 174 insertions, 0 deletions
diff --git a/old-tests/depdb/buildfile b/old-tests/depdb/buildfile
new file mode 100644
index 0000000..53e9cd3
--- /dev/null
+++ b/old-tests/depdb/buildfile
@@ -0,0 +1,8 @@
+# file : tests/depdb/buildfile
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+import libs = libbutl%lib{butl}
+
+exe{driver}: cxx{driver ../../build2/{depdb}} $libs
+exe{driver}: test.arguments = $out_base/test.d
diff --git a/old-tests/depdb/driver.cxx b/old-tests/depdb/driver.cxx
new file mode 100644
index 0000000..f156991
--- /dev/null
+++ b/old-tests/depdb/driver.cxx
@@ -0,0 +1,166 @@
+// file : tests/depdb/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+
+#include <butl/filesystem>
+
+#include <build2/types>
+#include <build2/utility>
+
+#include <build2/depdb>
+
+using namespace std;
+using namespace build2;
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " <db-file>" << endl;
+ return 1;
+ }
+
+ path p (argv[1]);
+ auto rm = [&p] () {try_rmfile (p);};
+
+ // Create empty database.
+ //
+ {
+ rm ();
+
+ {
+ depdb d (p);
+ assert (d.writing ());
+ d.close ();
+ }
+
+ {
+ depdb d (p);
+ assert (d.reading ());
+ assert (!d.more ());
+ assert (d.read () == nullptr);
+ d.close ();
+ }
+ }
+
+ // No close/end marker.
+ //
+ {
+ rm ();
+
+ {
+ depdb d (p);
+ assert (d.writing ());
+ // No close.
+ }
+
+ {
+ depdb d (p);
+ assert (d.writing ());
+ d.close ();
+ }
+
+ {
+ depdb d (p);
+ assert (d.reading ());
+ }
+ }
+
+ // Overwrite/append/truncate.
+ //
+ {
+ rm ();
+
+ {
+ depdb d (p);
+ d.write ("foo");
+ d.close ();
+ }
+
+ {
+ depdb d (p);
+ assert (*d.read () == "foo");
+ assert (!d.more ());
+ d.close ();
+ }
+
+ {
+ depdb d (p);
+ assert (*d.read () == "foo");
+ assert (!d.more ());
+ d.write ("FOO");
+ d.close ();
+ }
+
+ {
+ depdb d (p);
+ assert (*d.read () == "FOO");
+ assert (!d.more ());
+ assert (d.read () == nullptr);
+ assert (d.read () == nullptr);
+ d.write ("BAR");
+ d.close ();
+ }
+
+ {
+ depdb d (p);
+ assert (*d.read () == "FOO");
+ assert (d.more ());
+ d.write ("foo");
+ d.close (); // Truncate.
+ }
+
+ {
+ depdb d (p);
+ assert (*d.read () == "foo");
+ assert (!d.more ());
+ }
+
+ // Stray end marker.
+ //
+ {
+ depdb d (p);
+ assert (*d.read () == "foo");
+ d.write ("fox");
+ // No close.
+ }
+
+ {
+ depdb d (p);
+ assert (d.more ());
+ assert (*d.read () == "fox");
+ assert (!d.more ());
+ }
+ }
+
+ // Read/truncate.
+ //
+ {
+ rm ();
+
+ {
+ depdb d (p);
+ d.write ("foo");
+ d.write ("bar");
+ d.close ();
+ }
+
+ {
+ depdb d (p);
+ assert (*d.read () == "foo");
+ assert (d.more ());
+ d.close (); // Truncate bar.
+ }
+
+ {
+ depdb d (p);
+ assert (*d.read () == "foo");
+ assert (!d.more ());
+ }
+ }
+
+ rm ();
+}