20 #include <cppunit/ui/text/TestRunner.h> 21 #include <cppunit/TextOutputter.h> 22 #include <cppunit/extensions/TestFactoryRegistry.h> 23 #include <cppunit/extensions/HelperMacros.h> 24 #include <cppunit/TestAssert.h> 26 #include <coil/Condition.h> 27 #include <coil/Mutex.h> 28 #include <coil/Guard.h> 29 #include <coil/Task.h> 30 #include <coil/Async.h> 31 #include <coil/Time.h> 32 #include <coil/TimeValue.h> 68 : mutex(&aMutex), cond(&aCondition),
id(anId)
82 ConditionStatus +=
id;
84 return ConditionStatus;
102 int ConditionCheckTask::ConditionStatus(0);
106 :
public CppUnit::TestFixture
109 CPPUNIT_TEST(test_Condition_wait_and_signal);
110 CPPUNIT_TEST(test_Condition_wait_and_broadcast);
111 CPPUNIT_TEST(test_Condition_wait_with_time);
112 CPPUNIT_TEST_SUITE_END();
163 ConditionCheckTask::resteStatus();
172 CPPUNIT_ASSERT_EQUAL(0x00, ConditionCheckTask::getStatus());
183 CPPUNIT_ASSERT_EQUAL(id1, ConditionCheckTask::getStatus());
194 CPPUNIT_ASSERT_EQUAL(id1 + id2, ConditionCheckTask::getStatus());
209 ConditionCheckTask::resteStatus();
224 CPPUNIT_ASSERT_EQUAL(0, ConditionCheckTask::getStatus());
247 CPPUNIT_ASSERT_EQUAL(0x3f, ConditionCheckTask::getStatus());
249 CPPUNIT_ASSERT(
true);
264 result = cd.
wait(waitSec);
271 CPPUNIT_ASSERT(!result);
283 result = cd.
wait(waitSec);
291 CPPUNIT_ASSERT(result);
303 int main(
int argc,
char* argv[])
305 CppUnit::TextUi::TestRunner runner;
306 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
307 CppUnit::Outputter* outputter =
308 new CppUnit::TextOutputter(&runner.result(), std::cout);
309 runner.setOutputter(outputter);
314 #endif // Condition_cpp A(coil::Condition< coil::Mutex > &cond, coil::Mutex &mutex)
試験用タスク。起動するとwaitして、起こされると生成時に渡された値をConditionStatusに加算する。
int main(int argc, char **argv)
ConditionCheckTask(coil::Mutex &aMutex, coil::Condition< coil::Mutex > &aCondition, int anId)
virtual int svc()
Execute thread.
static int getStatus()
結果情報のConditionStatusの現在値を返す
virtual ~ConditionCheckTask()
void test_Condition_wait_and_broadcast()
wati with time.
void test_Condition_wait_and_signal()
wati with time.
virtual int wait(void)
Waiting for the thread terminate.
void test_Condition_wait_with_time()
wati with time.
~ConditionTests()
Destructor.
coil::Guard< coil::Mutex > Guard
virtual void setUp()
Test initialization.
coil::Condition< coil::Mutex > & m_cond
static void resteStatus()
結果情報のConditionStatusをクリアする
virtual void invoke()=0
Asynchronous invocation.
static int ConditionStatus
CPPUNIT_TEST_SUITE_REGISTRATION(Condition::ConditionTests)
ConditionTests()
Constructor.
virtual void tearDown()
Test finalization.
coil::Condition< coil::Mutex > * cond
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
virtual void activate()
Create a thread.
Async_t< Object, Func > * AsyncInvoker(Object *obj, Func func, bool auto_delete=false)
Helper function for async member function summons.