cleanup at unittest files

master
Denes Matetelki 13 years ago
parent c1fbd3bf9b
commit 0f69afd01d

@ -39,6 +39,11 @@ public:
return m_instance; return m_instance;
} }
static void destroy()
{
delete m_instance;
}
private: private:

@ -24,6 +24,11 @@ public:
return m_instance; return m_instance;
} }
static void destroy()
{
delete m_instance;
}
private: private:
static void do_init() static void do_init()

@ -33,6 +33,9 @@ void Thread::start()
void* Thread::join() const void* Thread::join() const
{ {
TRACE; TRACE;
if ( !m_isRunning )
return 0;
void* retVal; void* retVal;
pthread_join( m_threadHandler, &retVal ); pthread_join( m_threadHandler, &retVal );
return retVal; return retVal;

@ -18,20 +18,20 @@ if(CXXTEST_FOUND)
generated_main.cpp generated_main.cpp
Fixture.hpp Fixture.hpp
# test_ArgParse.hpp test_ArgParse.hpp
# test_Singelton_call_once.hpp test_Common.hpp
# test_Singleton.hpp test_ConditionalVariable.hpp
# test_Singleton_meyers.hpp test_Multiton.hpp
# test_Singleton_DCLP.hpp test_Mutex.hpp
# test_Mutex.hpp test_ScopedLock.hpp
# test_ScopedLock.hpp test_Semaphore.hpp
# test_ConditionalVariable.hpp test_Singleton_DCLP.hpp
test_Singleton_call_once.hpp
# test_Singleton.hpp Cannot test private member, Ficture.hpp loads it
test_Singleton_meyers.hpp
test_Thread.hpp test_Thread.hpp
# test_ThreadPool.hpp test_ThreadPool.hpp
# test_Semaphore.hpp # test_Timer.hpp Takes too much time&buggy
# test_Timer.hpp
# test_Common.hpp
# test_TimerThreadMultimap.hpp
) )
target_link_libraries(testCppUtils CppUtils gcov) target_link_libraries(testCppUtils CppUtils gcov)
endif() endif()

@ -65,8 +65,7 @@ valgrind \
$test | tee $test.out; retval=$PIPESTATUS $test | tee $test.out; retval=$PIPESTATUS
# NOTE to gen suppressions run: # NOTE to gen suppressions run:
# valgrind --leak-check=full --show-reachable=yes --show-below-main=no --track-origins=yes --num-callers=30 --malloc-fill=0xaa --free-fill=0xdd --gen-suppressions=yes ./test # valgrind --leak-check=full --show-reachable=yes --show-below-main=no --track-origins=yes --num-callers=30 --malloc-fill=0xaa --free-fill=0xdd --suppressions=valgrind.supp --gen-suppressions=yes ./testCppUtils
# retval is 0 on success # retval is 0 on success
# or the number of failed cases # or the number of failed cases

@ -1,35 +0,0 @@
#include <cxxtest/TestSuite.h>
#define private public // need to reach private variables
#include "Common.hpp"
#include "Fixture.hpp"
#include "Mutex.hpp"
class TestPThreadWrappers : public CxxTest::TestSuite
{
public:
void testMutexBasic( void )
{
TEST_HEADER;
Mutex m;
m.lock();
TS_ASSERT_EQUALS ( m.tryLock(0), 0 );
m.unlock();
}
void testMutexCreate( void )
{
TEST_HEADER;
Mutex m(PTHREAD_MUTEX_ERRORCHECK);
m.lock();
TS_ASSERT_EQUALS ( m.lock(), 1 );
m.unlock();
}
};

@ -34,6 +34,7 @@ private:
{ {
TRACE; TRACE;
} }
~ThreadClassWithSemaphore() { ~ThreadClassWithSemaphore() {
TRACE; TRACE;
} }
@ -94,6 +95,8 @@ public:
TS_ASSERT_EQUALS( t2->release(), true ); TS_ASSERT_EQUALS( t2->release(), true );
TS_ASSERT_EQUALS( semaphore.getCount(), 1 ); TS_ASSERT_EQUALS( semaphore.getCount(), 1 );
// t2 releases instead of the using t1
TS_ASSERT_EQUALS( t2->release(), true ); TS_ASSERT_EQUALS( t2->release(), true );
TS_ASSERT_EQUALS( semaphore.getCount(), 2 ); TS_ASSERT_EQUALS( semaphore.getCount(), 2 );
TS_ASSERT_EQUALS( t2->release(), false ); TS_ASSERT_EQUALS( t2->release(), false );
@ -102,6 +105,8 @@ public:
t2->stop(); t2->stop();
t1->join(); t1->join();
t2->join(); t2->join();
sleep(1);
delete t1; delete t1;
delete t2; delete t2;
} }

@ -1,35 +0,0 @@
#include <cxxtest/TestSuite.h>
#define private public // need to reach Singleton's private m_instance
#include "Common.hpp"
#include "Fixture.hpp"
#include "Singleton_DCLP.hpp"
class TestSingletonDCLPSuite : public CxxTest::TestSuite
{
private:
class BasicSingleton : public Singleton_DCLP<BasicSingleton>
{
public:
int getSeven()
{
TRACE;
return 7;
}
};
public:
void testBasic( void )
{
TEST_HEADER;
TS_ASSERT_EQUALS( BasicSingleton::getInstance()->getSeven(), 7 );
}
};

@ -29,6 +29,7 @@ public:
TEST_HEADER; TEST_HEADER;
TS_ASSERT_EQUALS( BasicSingleton::getInstance()->getSeven(), 7 ); TS_ASSERT_EQUALS( BasicSingleton::getInstance()->getSeven(), 7 );
BasicSingleton::destroy();
} }

@ -29,6 +29,7 @@ public:
TEST_HEADER; TEST_HEADER;
TS_ASSERT_EQUALS( BasicSingleton::getInstance()->getSeven(), 7 ); TS_ASSERT_EQUALS( BasicSingleton::getInstance()->getSeven(), 7 );
BasicSingleton::destroy();
} }

@ -34,18 +34,14 @@ public:
void testBasic( void ) void testBasic( void )
{ {
TEST_HEADER; TEST_HEADER;
ThreadClass *m = new ThreadClass; ThreadClass m;
m->start(); m.start();
void *retVal = m->join(); void *retVal = m.join();
TS_ASSERT_EQUALS ( *((int*)retVal) , 14 ); TS_ASSERT_EQUALS ( *((int*)retVal) , 14 );
free(retVal); free(retVal);
delete m;
} }
/**
* @note send a signal to a thread
*/
private: private:
@ -62,7 +58,6 @@ private:
TRACE; TRACE;
} }
private: private:
void* run( void ) { void* run( void ) {
@ -73,10 +68,9 @@ private:
*/ */
sleep(665); sleep(665);
// void* retVal = malloc(sizeof(int)); void* retVal = malloc(sizeof(int));
// *((int*)retVal) = 15; *((int*)retVal) = 15;
// return retVal; return retVal;
return 0;
} }
static void signal_handler(int sig) static void signal_handler(int sig)
@ -97,18 +91,17 @@ public:
void testSignalSend( void ) void testSignalSend( void )
{ {
TEST_HEADER; TEST_HEADER;
ThreadClassWithSignal *m2 = new ThreadClassWithSignal; ThreadClassWithSignal m2 ;
m2->start(); m2.start();
sleep(1); sleep(1);
m2->sendSignal(SIGINT); m2.sendSignal(SIGINT);
void *retVal = m2->join(); void *retVal = m2.join();
TS_ASSERT(retVal); TS_ASSERT(retVal);
if (retVal != 0 ) { if (retVal != 0 ) {
TS_ASSERT_EQUALS ( *((int*)retVal) , 16 ); TS_ASSERT_EQUALS ( *((int*)retVal) , 16 );
free((int*)retVal); free((int*)retVal);
} }
delete m2;
} }
@ -127,7 +120,7 @@ private:
public: public:
void testEmpty( void ) void eetestEmpty( void )
{ {
TEST_HEADER; TEST_HEADER;
@ -138,4 +131,17 @@ public:
void *retVal = e.join(); void *retVal = e.join();
TS_ASSERT_EQUALS ( retVal , (void *)0 ); TS_ASSERT_EQUALS ( retVal , (void *)0 );
} }
void testJoiningNotStartedThread( void )
{
TEST_HEADER;
EmptyThreadClass e;
e.stop();
e.join();
void *retVal = e.join();
TS_ASSERT_EQUALS ( retVal , (void *)0 );
}
}; };

@ -69,7 +69,18 @@
Memcheck:Leak Memcheck:Leak
fun:calloc fun:calloc
fun:_dl_allocate_tls fun:_dl_allocate_tls
fun:pthread_create@@GLIBC_*.*.* fun:pthread_create@@GLIBC_*
...
fun:main
}
{
create thread2
Memcheck:Leak
fun:calloc
fun:allocate_dtv
fun:_dl_allocate_tls
fun:pthread_create@@GLIBC_*
... ...
fun:main fun:main
} }

Loading…
Cancel
Save