*** empty log message ***
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@60 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
ca9fff7cf4
commit
a0aa6b269f
13 changed files with 2054 additions and 0 deletions
109
tools/RegressionTest/FunctorTest.h
Normal file
109
tools/RegressionTest/FunctorTest.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Unit Test for Loki
|
||||
//
|
||||
// Copyright Terje Slettebø and Pavel Vozenilek 2002.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Last update: September 16, 2002
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef FUNCTORTEST_H
|
||||
#define FUNCTORTEST_H
|
||||
|
||||
#include <loki/Functor.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FunctorTest
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class FunctorTest : public Test
|
||||
{
|
||||
public:
|
||||
FunctorTest() : Test("Functor.h") {}
|
||||
|
||||
virtual void execute(TestResult &result)
|
||||
{
|
||||
printName(result);
|
||||
|
||||
using namespace Loki;
|
||||
|
||||
bool r;
|
||||
|
||||
TestFunctor testFunctor;
|
||||
TestClass testClass;
|
||||
|
||||
Functor<void,TYPELIST_1(bool &)> function(testFunction);
|
||||
Functor<void,TYPELIST_1(bool &)> functor(testFunctor);
|
||||
Functor<void,TYPELIST_1(bool &)> classFunctor(&testClass,&TestClass::member);
|
||||
Functor<void,TYPELIST_1(bool &)> functorCopy(function);
|
||||
Functor<void,NullType> bindFunctor(BindFirst(function,testResult));
|
||||
Functor<void> chainFunctor(Chain(bindFunctor,bindFunctor));
|
||||
|
||||
testResult=false;
|
||||
function(testResult);
|
||||
bool functionResult=testResult;
|
||||
|
||||
testResult=false;
|
||||
functor(testResult);
|
||||
bool functorResult=testResult;
|
||||
|
||||
testResult=false;
|
||||
classFunctor(testResult);
|
||||
bool classFunctorResult=testResult;
|
||||
|
||||
testResult=false;
|
||||
functorCopy(testResult);
|
||||
bool functorCopyResult=testResult;
|
||||
|
||||
testResult=false;
|
||||
bindFunctor();
|
||||
bool bindFunctorResult=testResult;
|
||||
|
||||
testResult=false;
|
||||
chainFunctor();
|
||||
bool chainFunctorResult=testResult;
|
||||
|
||||
r=functionResult && functorResult && classFunctorResult && functorCopyResult && bindFunctorResult &&
|
||||
chainFunctorResult;
|
||||
|
||||
testAssert("Functor",r,result);
|
||||
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
private:
|
||||
static bool testResult;
|
||||
|
||||
static void testFunction(bool &result)
|
||||
{
|
||||
result=true;
|
||||
}
|
||||
|
||||
class TestFunctor
|
||||
{
|
||||
public:
|
||||
void operator()(bool &result)
|
||||
{
|
||||
result=true;
|
||||
}
|
||||
};
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public:
|
||||
void member(bool &result)
|
||||
{
|
||||
result=true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
bool FunctorTest::testResult;
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue