00001 /* 00002 * (c) Copyright 2008, IBM Corporation. 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 * 00015 */ 00016 #ifndef CONDVARTEST_H_ 00017 #define CONDVARTEST_H_ 00018 #include <cppunit/extensions/HelperMacros.h> 00019 #include <cppunit/TestAssert.h> 00020 #include "baseTest.h" 00021 #include "threadFactory.h" 00022 #include <amino/condition.h> 00023 #include <amino/mutex.h> 00024 #include <amino/thread.h> 00025 00026 using namespace amino; 00027 00028 namespace test{ 00029 00034 class ConditionTest : public CppUnit::TestFixture { 00035 CPPUNIT_TEST_SUITE(ConditionTest) 00036 ; 00037 CPPUNIT_TEST(testCondition); 00038 CPPUNIT_TEST_SUITE_END() 00039 ; 00040 00041 private: 00042 condition_variable * condVar; 00043 mutex fMutex; 00044 public: 00045 void setUp() { 00046 condVar = new condition_variable (); 00047 } 00048 00049 void reset() { 00050 delete condVar; 00051 condVar = new condition_variable(); 00052 } 00053 00054 void testCondition(); 00055 00056 void tearDown() { 00057 delete condVar; 00058 } 00059 }; 00060 00061 class ConditionThread : public Thread { 00062 private: 00063 condition_variable* fCondition; 00064 mutex * fMutex; 00065 public: 00066 ConditionThread(condition_variable * condVar, mutex * m) { 00067 fCondition = condVar; 00068 fMutex = m; 00069 } 00070 00071 void* run() { 00072 unique_lock<mutex> llock(*fMutex); 00073 fCondition->wait(llock); 00074 return NULL; 00075 } 00076 }; 00077 } 00078 #endif /*CONDVARTEST_H_*/