Commit c4b52c53 authored by berenger-bramas's avatar berenger-bramas

Change assert method into FAssertable::assert

(because the compiler is not enought smart to see the difference...)

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@151 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 28f9ad56
......@@ -30,7 +30,7 @@ public:
void push(const ParticleClass& particle){
if(particle.isTarget()) this->targets.push(particle);
else if(particle.isSource()) this->sources.push(particle);
else assert(false, "Error particle has undefined type.", __LINE__, __FILE__);
else FAssertable::assert(false, "Error particle has undefined type.", __LINE__, __FILE__);
}
/**
......
......@@ -39,7 +39,7 @@ template <int Capacity>
public:
// Constructor, set buffer to null
FBufferVector() : buffer(0), occuped(0) {
assert(Capacity > 0, "Capacity has to be positive", __LINE__, __FILE__);
FAssertable::assert(Capacity > 0, "Capacity has to be positive", __LINE__, __FILE__);
}
// Dealloc buffer if needed
......
......@@ -191,8 +191,8 @@ public:
*/
Iterator(FOctree* const inTarget)
: currentLocalIndex(0) , currentLocalLevel(0) {
assert(inTarget, "Target for Octree::Iterator cannot be null", __LINE__, __FILE__);
assert(inTarget->root.getRightLeafIndex() >= 0, "Octree seems to be empty, getRightLeafIndex == 0", __LINE__, __FILE__);
FAssertable::assert(inTarget, "Target for Octree::Iterator cannot be null", __LINE__, __FILE__);
FAssertable::assert(inTarget->root.getRightLeafIndex() >= 0, "Octree seems to be empty, getRightLeafIndex == 0", __LINE__, __FILE__);
// Start by the root
this->current.tree = &inTarget->root;
......
......@@ -133,13 +133,13 @@ public:
subOctreeHeight( inSubOctreeHeight ), subOctreePosition( inSubOctreePosition ), isLeafSubtree(inIsLeafSubtree) {
this->cells = new CellClass**[this->subOctreeHeight];
assert(this->cells, "Allocation failled", __LINE__, __FILE__);
FAssertable::assert(this->cells, "Allocation failled", __LINE__, __FILE__);
// We start at a sub-level - 8^1
long cellsAtlevel = 8;
for( int indexLevel = 0 ; indexLevel < this->subOctreeHeight ; ++indexLevel ){
this->cells[indexLevel] = new CellClass*[cellsAtlevel];
assert(this->cells[indexLevel], "Allocation failled", __LINE__, __FILE__);
FAssertable::assert(this->cells[indexLevel], "Allocation failled", __LINE__, __FILE__);
for( int indexCells = 0 ; indexCells < cellsAtlevel ; ++indexCells ){
this->cells[indexLevel][indexCells] = 0;
......@@ -212,7 +212,7 @@ public:
* @param level the level to access cells array (must be < subOctreeHeight)
* @return cells[level] */
CellClass** cellsAt(const int level) const{
assert(level < subOctreeHeight, "Level out of memory", __LINE__, __FILE__);
FAssertable::assert(level < subOctreeHeight, "Level out of memory", __LINE__, __FILE__);
return cells[level];
}
......@@ -294,7 +294,7 @@ public:
const long cellsAtLeafLevel = 1 << (3 * inSubOctreeHeight);
this->leafs = new LeafClass*[cellsAtLeafLevel];
assert(this->leafs, "Allocation failled", __LINE__, __FILE__);
FAssertable::assert(this->leafs, "Allocation failled", __LINE__, __FILE__);
for( long indexLeaf = 0 ; indexLeaf < cellsAtLeafLevel ; ++indexLeaf ){
this->leafs[indexLeaf] = 0;
......@@ -406,7 +406,7 @@ public:
const long cellsAtLeafLevel = 1 << (3 * inSubOctreeHeight);
this->subleafs = new FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>*[cellsAtLeafLevel];
assert(this->subleafs, "Allocation failled", __LINE__, __FILE__);
FAssertable::assert(this->subleafs, "Allocation failled", __LINE__, __FILE__);
for( int indexLeaf = 0 ; indexLeaf < cellsAtLeafLevel ; ++indexLeaf ){
this->subleafs[indexLeaf] = 0;
......
......@@ -39,8 +39,8 @@ public:
FFmmAlgorithm(OctreeClass* const inTree, KernelClass* const inKernels)
: tree(inTree) , kernels(inKernels), OctreeHeight(tree->getHeight()) {
assert(tree, "tree cannot be null", __LINE__, __FILE__);
assert(kernels, "kernels cannot be null", __LINE__, __FILE__);
FAssertable::assert(tree, "tree cannot be null", __LINE__, __FILE__);
FAssertable::assert(kernels, "kernels cannot be null", __LINE__, __FILE__);
FDEBUG(FDebug::Controller << "FFmmAlgorithm\n");
}
......
......@@ -53,7 +53,7 @@ public:
: tree(inTree) , kernels(0), iterArray(0), leafsNumber(0),
MaxThreads(omp_get_max_threads()), OctreeHeight(tree->getHeight()) {
assert(tree, "tree cannot be null", __LINE__, __FILE__);
FAssertable::assert(tree, "tree cannot be null", __LINE__, __FILE__);
this->kernels = new KernelClass*[MaxThreads];
for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
......@@ -96,7 +96,7 @@ public:
} while(octreeIterator.moveRight());
iterArray = new typename OctreeClass::Iterator[leafsNumber];
assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
FAssertable::assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
bottomPass();
upwardPass();
......
......@@ -86,7 +86,7 @@ public:
MaxThreads(omp_get_max_threads()), nbProcess(inApp.processCount()), idPorcess(inApp.processId()),
sendBuffer(0), OctreeHeight(tree->getHeight()) {
assert(tree, "tree cannot be null", __LINE__, __FILE__);
FAssertable::assert(tree, "tree cannot be null", __LINE__, __FILE__);
this->kernels = new KernelClass*[MaxThreads];
for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
......@@ -128,10 +128,10 @@ public:
} while(octreeIterator.moveRight());
iterArray = new typename OctreeClass::Iterator[leafs];
assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
FAssertable::assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
previousIterArray = new typename OctreeClass::Iterator[leafs];
assert(previousIterArray, "previousIterArray bad alloc", __LINE__, __FILE__);
FAssertable::assert(previousIterArray, "previousIterArray bad alloc", __LINE__, __FILE__);
// init offsets
for(int idxOff = 0 ; idxOff < OctreeHeight ; ++idxOff){
......
......@@ -50,7 +50,7 @@ public:
: tree(inTree) , kernels(0), iterArray(0),
MaxThreads(omp_get_max_threads()) , OctreeHeight(tree->getHeight()) {
assert(tree, "tree cannot be null", __LINE__, __FILE__);
FAssertable::assert(tree, "tree cannot be null", __LINE__, __FILE__);
this->kernels = new KernelClass*[MaxThreads];
for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
......@@ -83,7 +83,7 @@ public:
++numberOfLeafs;
} while(octreeIterator.moveRight());
iterArray = new typename OctreeClass::Iterator[numberOfLeafs];
assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
FAssertable::assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
bottomPass();
upwardPass();
......
......@@ -51,7 +51,7 @@ public:
: tree(inTree), kernels(0), iterArray(0),
MaxThreads(omp_get_max_threads()), OctreeHeight(tree->getHeight()) {
assert(tree, "tree cannot be null", __LINE__, __FILE__);
FAssertable::assert(tree, "tree cannot be null", __LINE__, __FILE__);
this->kernels = new KernelClass*[MaxThreads];
for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
......@@ -84,7 +84,7 @@ public:
++numberOfLeafs;
} while(octreeIterator.moveRight());
iterArray = new typename OctreeClass::Iterator[numberOfLeafs];
assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
FAssertable::assert(iterArray, "iterArray bad alloc", __LINE__, __FILE__);
for(int idxThread = 0 ; idxThread < MaxThreads ; ++idxThread){
this->kernels[idxThread]->init();
......
......@@ -43,8 +43,8 @@ public:
FFmmAlgorithmTsm(OctreeClass* const inTree, KernelClass* const inKernels)
: tree(inTree) , kernels(inKernels) , OctreeHeight(tree->getHeight()){
assert(tree, "tree cannot be null", __LINE__, __FILE__);
assert(kernels, "kernels cannot be null", __LINE__, __FILE__);
FAssertable::assert(tree, "tree cannot be null", __LINE__, __FILE__);
FAssertable::assert(kernels, "kernels cannot be null", __LINE__, __FILE__);
FDEBUG(FDebug::Controller << "FFmmAlgorithmTsm\n");
}
......
......@@ -29,12 +29,12 @@ protected:
* @param inLinePosition line number
* @param inFilePosition file name
*
* <code> assert(toto == titi, "problem : toto is not equal titi!", __LINE__, __FILE__); </code>
* <code> FAssertable::assert(toto == titi, "problem : toto is not equal titi!", __LINE__, __FILE__); </code>
*
* To prevent use from multiple thread we use a ostringstream before printing
*/
template <class Tmess, class Tline, class Tfile>
void assert(const bool inTest, const Tmess& inMessage, const Tline& inLinePosition, const Tfile& inFilePosition, const int inExitCode = 1) const {
void assert(const bool inTest, const Tmess& inMessage, const Tline& inLinePosition, const Tfile& inFilePosition, const int inExitCode = 1) const {
if(!inTest){
std::ostringstream oss;
oss << "Error in " << inFilePosition << " at line " << inLinePosition <<" :\n";
......
#ifndef UTESTER_HPP
#define UTESTER_HPP
// /!\ Please, you must read the license at the bottom of this page
#include <iostream>
#include <list>
#include <string>
#include <stdio.h>
#define TestClass(X)\
int main(void){\
X Controller;\
Controller.Run();\
return 0;\
}\
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* Please read the license
*
* This class is used to make simple unit test cases
*
* Please refer to testUTest.cpp to see an example
* @warning Create a derived class that implement SetTests() and use TestClass() macro
*/
template <class TestClass>
class FUTester{
// Test function pointer
typedef void (TestClass::*TestFunc)(void);
/** Test descriptor */
struct TestFuncDescriptor{
TestFunc func; //< Test adress
std::string name; //< Test name
};
std::list<TestFuncDescriptor> tests; //< all tests
int totalTests; //< number of tests
int currentTest; //< current processing test in the run
int currentStep; //< current processing step in the run
int failledSteps; //< number of failled step in the current test
int failledTests; //< number of failled tests
protected:
/** Constructor */
FUTester(){
totalTests = 0;
}
/** Callback before processing test */
virtual void Before(){}
/** Callback after processing test */
virtual void After(){}
/** Callback before each unit test */
virtual void PreTest(){}
/** Callback after each unit test */
virtual void PostTest(){}
/**
* This function has to add tests
* <code> AddTest(&MyTest::TestOne); </code>
*/
virtual void SetTests() = 0;
/**
* Add a test without giving a name
* @param inFunc test function address
*/
void AddTest(TestFunc inFunc){
char buff[256];
sprintf(buff,"Unamed Test number %d",totalTests+1);
AddTest(inFunc,buff);
}
/**
* Add a test with a name
* @param inFunc test function address
* @param inFuncName function name
*/
void AddTest(TestFunc inFunc, const std::string& inFuncName){
++totalTests;
TestFuncDescriptor desc;
desc.func = inFunc;
desc.name = inFuncName;
tests.push_back(desc);
}
/**
* To print a message manually in the test
* @param value a object that ostream can work on
*/
template <class Output>
void Print(const Output& value){
std::cout<< "--- Output from program : " << value << "\n";
}
/**
* To test
* @param result the test result
* if result is false test failled
*/
void assert(const bool result){
++currentStep;
if(!result){
std::cout << ">> Step " << currentStep << " Failled\n";
++failledSteps;
}
}
/**
* To test equality
* @param v1 value one
* @param v2 value 2
* if v1 is not equal v2 test failled
*/
template <class T>
void equal(const T& v1, const T& v2){
assert(v1 == v2);
}
/**
* To test equality
* @param v1 value one
* @param v2 value 2
* if v1 is equal v2 test failled
*/
template <class T>
void different(const T& v1, const T& v2){
assert(v1 != v2);
}
public :
/**
* Processing the test
*/
void Run(){
tests.clear();
// register tests
SetTests();
TestClass* const toTest = static_cast<TestClass*>(this);
currentTest = 0;
failledTests = 0;
Before();
// for each tests
const typename std::list<TestFuncDescriptor>::const_iterator end = tests.end();
for(typename std::list<TestFuncDescriptor>::iterator iter = tests.begin() ; iter != end ; ++iter){
currentStep = 0;
failledSteps = 0;
std::cout << "[Start] " << (*iter).name << "\n";
PreTest();
TestFunc ff = (*iter).func;
(toTest->*ff)();
PostTest();
if(failledSteps){
std::cout << "[Finished] FAILLED (" << failledSteps << "/" << currentStep<< " steps failled)\n";
++failledTests;
}
else{
std::cout << "[Finished] PASSED (" << currentStep << " steps)\n";
}
++currentTest;
}
After();
std::cout <<"Test is over, " << (totalTests-failledTests) << " Passed, " << failledTests << " Failled\n";
}
};
#endif
#ifndef UTESTER_HPP
#define UTESTER_HPP
// /!\ Please, you must read the license at the bottom of this page
#include <iostream>
#include <list>
#include <string>
#include <stdio.h>
#define TestClass(X)\
int main(void){\
X Controller;\
Controller.Run();\
return 0;\
}\
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* Please read the license
*
* This class is used to make simple unit test cases
*
* Please refer to testUTest.cpp to see an example
* @warning Create a derived class that implement SetTests() and use TestClass() macro
*/
template <class TestClass>
class FUTester{
// Test function pointer
typedef void (TestClass::*TestFunc)(void);
/** Test descriptor */
struct TestFuncDescriptor{
TestFunc func; //< Test adress
std::string name; //< Test name
};
std::list<TestFuncDescriptor> tests; //< all tests
int totalTests; //< number of tests
int currentTest; //< current processing test in the run
int currentStep; //< current processing step in the run
int failledSteps; //< number of failled step in the current test
int failledTests; //< number of failled tests
protected:
/** Constructor */
FUTester(){
totalTests = 0;
}
/** Callback before processing test */
virtual void Before(){}
/** Callback after processing test */
virtual void After(){}
/** Callback before each unit test */
virtual void PreTest(){}
/** Callback after each unit test */
virtual void PostTest(){}
/**
* This function has to add tests
* <code> AddTest(&MyTest::TestOne); </code>
*/
virtual void SetTests() = 0;
/**
* Add a test without giving a name
* @param inFunc test function address
*/
void AddTest(TestFunc inFunc){
char buff[256];
sprintf(buff,"Unamed Test number %d",totalTests+1);
AddTest(inFunc,buff);
}
/**
* Add a test with a name
* @param inFunc test function address
* @param inFuncName function name
*/
void AddTest(TestFunc inFunc, const std::string& inFuncName){
++totalTests;
TestFuncDescriptor desc;
desc.func = inFunc;
desc.name = inFuncName;
tests.push_back(desc);
}
/**
* To print a message manually in the test
* @param value a object that ostream can work on
*/
template <class Output>
void Print(const Output& value){
std::cout<< "--- Output from program : " << value << "\n";
}
/**
* To test
* @param result the test result
* if result is false test failled
*/
void assert(const bool result){
++currentStep;
if(!result){
std::cout << ">> Step " << currentStep << " Failled\n";
++failledSteps;
}
}
/**
* To test equality
* @param v1 value one
* @param v2 value 2
* if v1 is not equal v2 test failled
*/
template <class T>
void equal(const T& v1, const T& v2){
assert(v1 == v2);
}
/**
* To test equality
* @param v1 value one
* @param v2 value 2
* if v1 is equal v2 test failled
*/
template <class T>
void different(const T& v1, const T& v2){
assert(v1 != v2);
}
public :
/**
* Processing the test
*/
void Run(){
tests.clear();
// register tests
SetTests();
TestClass* const toTest = static_cast<TestClass*>(this);
currentTest = 0;
failledTests = 0;
Before();
// for each tests
const typename std::list<TestFuncDescriptor>::const_iterator end = tests.end();
for(typename std::list<TestFuncDescriptor>::iterator iter = tests.begin() ; iter != end ; ++iter){
currentStep = 0;
failledSteps = 0;
std::cout << "[Start] " << (*iter).name << "\n";
PreTest();
TestFunc ff = (*iter).func;
(toTest->*ff)();
PostTest();
if(failledSteps){
std::cout << "[Finished] FAILLED (" << failledSteps << "/" << currentStep<< " steps failled)\n";
++failledTests;
}
else{
std::cout << "[Finished] PASSED (" << currentStep << " steps)\n";
}
++currentTest;
}
After();
std::cout <<"Test is over, " << (totalTests-failledTests) << " Passed, " << failledTests << " Failled\n";
}
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment