aboutsummaryrefslogtreecommitdiff
path: root/tests/progress
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-07-26 13:44:24 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2017-07-27 12:22:19 +0300
commit72450e72e400eb03325ca182f0e118fde8cd1705 (patch)
tree8e7d7c9fba4b99d047c1f770dcb85479b2c0ede1 /tests/progress
parent3fae4ef8b228374c865bc0afcb1041eabae5a111 (diff)
Add support for printing progress
Diffstat (limited to 'tests/progress')
-rw-r--r--tests/progress/buildfile7
-rw-r--r--tests/progress/driver.cxx62
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/progress/buildfile b/tests/progress/buildfile
new file mode 100644
index 0000000..19e85c0
--- /dev/null
+++ b/tests/progress/buildfile
@@ -0,0 +1,7 @@
+# file : tests/progress/buildfile
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+import libs = libbutl%lib{butl}
+
+exe{driver}: {hxx cxx}{*} $libs
diff --git a/tests/progress/driver.cxx b/tests/progress/driver.cxx
new file mode 100644
index 0000000..702319a
--- /dev/null
+++ b/tests/progress/driver.cxx
@@ -0,0 +1,62 @@
+// file : tests/progress/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef _WIN32
+# include <thread> // this_thread::sleep_for()
+#else
+# include <libbutl/win32-utility.hxx>
+#endif
+
+#include <cstddef> // size_t
+#include <iostream>
+
+#include <libbutl/diagnostics.hxx>
+
+using namespace std;
+using namespace butl;
+
+int
+main ()
+{
+ auto sleep = [] (size_t ms = 100)
+ {
+ // MINGW GCC 4.9 doesn't implement this_thread so use Win32 Sleep().
+ //
+#ifndef _WIN32
+ this_thread::sleep_for (chrono::milliseconds (ms));
+#else
+ Sleep (static_cast<DWORD> (ms));
+#endif
+ };
+
+ for (size_t i (100); i != 0; --i)
+ {
+ if (i % 10 == 0)
+ diag_stream_lock () << "Line " << i / 10 << endl;
+
+ {
+ diag_progress_lock l;
+ diag_progress = " " + to_string (i) + "%";
+ }
+
+ sleep ();
+ }
+
+ sleep (1000);
+
+ // Test that the progress line is restored by the diag_stream_lock.
+ //
+ diag_stream_lock () << "Printed to diag_stream" << endl;
+
+ sleep (1000);
+
+ // Test that the progress line is restored after printing to cerr.
+ //
+ {
+ cerr << "Printed to std::cerr" << endl;
+ diag_progress_lock ();
+ }
+
+ sleep (1000);
+}