#include "wx/atomic.h"
#include "wx/thread.h"
#include "wx/dynarray.h"
+#include "wx/log.h"
+
WX_DEFINE_ARRAY_PTR(wxThread *, wxArrayThread);
// ----------------------------------------------------------------------------
public:
AtomicTestCase() { }
-private:
-
enum ETestType
{
IncAndDecMixed,
DecOnly
};
+private:
class MyThread : public wxThread
{
public:
CPPUNIT_TEST_SUITE( AtomicTestCase );
CPPUNIT_TEST( TestNoThread );
+ CPPUNIT_TEST( TestDecReturn );
CPPUNIT_TEST( TestTwoThreadsMix );
CPPUNIT_TEST( TestTenThreadsMix );
CPPUNIT_TEST( TestTwoThreadsSeparate );
CPPUNIT_TEST_SUITE_END();
void TestNoThread();
+ void TestDecReturn();
void TestTenThreadsMix() { TestWithThreads(10, IncAndDecMixed); }
void TestTwoThreadsMix() { TestWithThreads(2, IncAndDecMixed); }
void TestTenThreadsSeparate() { TestWithThreads(10, IncOnly); }
CPPUNIT_ASSERT( int2 == -10000000 );
}
+void AtomicTestCase::TestDecReturn()
+{
+ wxAtomicInt i(0);
+ wxAtomicInc(i);
+ wxAtomicInc(i);
+ CPPUNIT_ASSERT( i == 2 );
+
+ CPPUNIT_ASSERT( wxAtomicDec(i) > 0 );
+ CPPUNIT_ASSERT( wxAtomicDec(i) == 0 );
+}
+
void AtomicTestCase::TestWithThreads(int count, ETestType testType)
{
wxAtomicInt int1=0;