2005-10-24 20:35:12 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Unit Test for Loki
|
|
|
|
|
//
|
|
|
|
|
// Copyright Peter K<>mmel 2005
|
|
|
|
|
//
|
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
|
// purpose is hereby granted without fee, provided that this copyright and
|
|
|
|
|
// permissions notice appear in all copies and derivatives.
|
|
|
|
|
//
|
|
|
|
|
// This software is provided "as is" without express or implied warranty.
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
#ifndef THREADSTEST_H
|
|
|
|
|
#define THREADSTEST_H
|
|
|
|
|
|
2006-10-17 20:36:13 +00:00
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
2005-10-24 20:35:12 +00:00
|
|
|
|
#include <loki/Threads.h>
|
|
|
|
|
#include "UnitTest.h"
|
|
|
|
|
|
|
|
|
|
namespace ThreadsTestPrivate
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
class SingleLevel : public Loki::SingleThreaded<SingleLevel>
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
public:
|
|
|
|
|
void test()
|
|
|
|
|
{
|
|
|
|
|
Lock lock0;
|
|
|
|
|
Lock lock(*this);
|
|
|
|
|
Lock lockThis(this);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
};
|
2005-10-24 20:35:12 +00:00
|
|
|
|
|
2005-11-01 11:03:31 +00:00
|
|
|
|
#if defined(LOKI_CLASS_LEVEL_THREADING) || defined(LOKI_OBJECT_LEVEL_THREADING)
|
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
class ClassLevel : public Loki::ClassLevelLockable<ClassLevel>
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
public:
|
|
|
|
|
void test()
|
|
|
|
|
{
|
|
|
|
|
Lock lock0;
|
|
|
|
|
Lock lock(*this);
|
|
|
|
|
Lock lockThis(this);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
};
|
2005-10-24 20:35:12 +00:00
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
class ObjectLevel : public Loki::ObjectLevelLockable<ObjectLevel>
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
public:
|
|
|
|
|
void test()
|
|
|
|
|
{
|
|
|
|
|
//Lock lock0_must_not_compile;
|
|
|
|
|
Lock lock(*this);
|
|
|
|
|
Lock lockThis(this);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
};
|
2005-11-01 11:03:31 +00:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}//namespace Loki
|
|
|
|
|
|
2005-10-24 20:35:12 +00:00
|
|
|
|
|
|
|
|
|
class ThreadsTest : public Test
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ThreadsTest() : Test("Threads.h") {}
|
|
|
|
|
|
|
|
|
|
virtual void execute(TestResult &result)
|
|
|
|
|
{
|
|
|
|
|
printName(result);
|
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
bool r = true; // TODO some tests
|
2005-10-24 20:35:12 +00:00
|
|
|
|
|
|
|
|
|
testAssert("Threads",r,result);
|
|
|
|
|
|
|
|
|
|
std::cout << '\n';
|
|
|
|
|
}
|
|
|
|
|
} threadsTest;
|
|
|
|
|
|
|
|
|
|
#endif
|