diff options
Diffstat (limited to 'tests/progress')
-rw-r--r-- | tests/progress/buildfile | 7 | ||||
-rw-r--r-- | tests/progress/driver.cxx | 62 |
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); +} |