aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-03-08 20:19:17 -0500
committerGavin Andresen <gavinandresen@gmail.com>2013-04-03 19:57:13 -0400
commit72f14d26ecc67a210a29d7914e580b8e67e45d8e (patch)
treea5c32b1a0b4690be8de680e1629a7d5d543dbaf0 /src/test
parent1b43bf0d3ae7b1fcde0c0e20c23c341540f4c8d2 (diff)
LoopForever and ThreadTrace helpers
Diffstat (limited to 'src/test')
-rw-r--r--src/test/util_tests.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 1b0ccad511..2d05794cc7 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -323,4 +323,62 @@ BOOST_AUTO_TEST_CASE(util_seed_insecure_rand)
}
}
+static int nCounter = 0;
+
+static void Count()
+{
+ ++nCounter;
+ MilliSleep(10);
+}
+
+static void CountWithArg(int arg)
+{
+ nCounter += arg;
+ MilliSleep(10);
+}
+
+BOOST_AUTO_TEST_CASE(util_loop_forever1)
+{
+ boost::thread_group threadGroup;
+
+ threadGroup.create_thread(boost::bind(&LoopForever<void (*)()>, "count", &Count, 1));
+ MilliSleep(1);
+ threadGroup.interrupt_all();
+ BOOST_CHECK_EQUAL(nCounter, 1);
+ nCounter = 0;
+}
+
+BOOST_AUTO_TEST_CASE(util_loop_forever2)
+{
+ boost::thread_group threadGroup;
+
+ boost::function<void()> f = boost::bind(&CountWithArg, 11);
+ threadGroup.create_thread(boost::bind(&LoopForever<boost::function<void()> >, "count11", f, 11));
+ MilliSleep(1);
+ threadGroup.interrupt_all();
+ BOOST_CHECK_EQUAL(nCounter, 11);
+ nCounter = 0;
+}
+
+BOOST_AUTO_TEST_CASE(util_threadtrace1)
+{
+ boost::thread_group threadGroup;
+
+ threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "count11", &Count));
+ threadGroup.join_all();
+ BOOST_CHECK_EQUAL(nCounter, 1);
+ nCounter = 0;
+}
+
+BOOST_AUTO_TEST_CASE(util_threadtrace2)
+{
+ boost::thread_group threadGroup;
+
+ boost::function<void()> f = boost::bind(&CountWithArg, 11);
+ threadGroup.create_thread(boost::bind(&TraceThread<boost::function<void()> >, "count11", f));
+ threadGroup.join_all();
+ BOOST_CHECK_EQUAL(nCounter, 11);
+ nCounter = 0;
+}
+
BOOST_AUTO_TEST_SUITE_END()