include/Tests/TestVectors.hpp

Go to the documentation of this file.
00001 #ifndef hpp_CPP_TestVectors_CPP_hpp
00002 #define hpp_CPP_TestVectors_CPP_hpp
00003 
00004 // We need String from BString lib
00005 #include "../Strings/BString.hpp"
00006 // We need stack too
00007 #include "../Tree/FIFO.hpp"
00008 // We need by ref
00009 #include "../Types/ByRef.hpp"
00010 
00011 #ifdef _MSC_VER
00012 // We don't care about the 255 name limit in debug symbols 
00013 #pragma warning(disable:4786)
00014 // There is a bug here with release build, as the compiler doesn't understand it should not inline the pointed method when taking the reference
00015 #if !defined(DEBUG) && !defined(_DEBUG)
00016     #define RefConstU U
00017 #else
00018     #define RefConstU const U &
00019 #endif
00020 #endif
00021 
00023 namespace Test
00024 {
00025     // We use String from BString
00026     using Bstrlib::String;
00027     struct Unit
00028     {
00029         String testName;
00030         virtual bool launchTest() = 0;
00031         virtual String getTestName(const String & str = "") const { return testName + str; }
00032 
00033         Unit(const String & name) : testName(name) {}
00034         virtual ~Unit() {}
00035     };
00036 
00038     template <typename T, typename U>
00039     class UnitImpl0 : public Unit
00040     {
00041     private:
00042         T & object;
00043         RefConstU  function;
00044 
00045     private:
00046         // The test method
00047         inline bool launchTest() { return (bool)(object.*function)();   }
00048 
00049     public:
00050         UnitImpl0(const String & name, T & obj, RefConstU func) : Unit(name), object(obj), function(func) {}
00051     };
00052 
00053     template <typename T, typename U>
00054     inline UnitImpl0<T, U> * MakeUnitTest(const String & name, T & object, const U & func) 
00055     {
00056         return new UnitImpl0<T, U>(name, object, func);
00057     }
00058 
00059 
00061     template <typename T, typename U, typename P1>
00062     class UnitImpl1 : public Unit
00063     {
00064     private:
00065         T & object;
00066         RefConstU function;
00067         const P1  param1;
00068 
00069     private:
00070         // The test method
00071         inline bool launchTest() { return (bool)(object.*function)(param1); }
00072 
00073     public:
00074         UnitImpl1(const String & name, T & obj, RefConstU func, const P1 & p1) : Unit(name), object(obj), function(func), param1(p1) {}
00075     };
00076 
00077     template <typename T, typename U, typename P1>
00078     inline UnitImpl1<T, U, P1> * MakeUnitTest(const String & name, T & object, const U & func, const P1 & p1) 
00079     {
00080         return new UnitImpl1<T, U, P1>(name, object, func, p1);
00081     }
00082 
00084     template <typename T, typename U, typename P1, typename P2>
00085     class UnitImpl2 : public Unit
00086     {
00087     private:
00088         T & object;
00089         RefConstU function;
00090         const P1  param1;
00091         const P2  param2;
00092 
00093     private:
00094         // The test method
00095         inline bool launchTest() { return (bool)(object.*function)(param1, param2); }
00096 
00097     public:
00098         UnitImpl2(const String & name, T & obj, RefConstU func, const P1 & p1, const P2 & p2) : Unit(name), object(obj), function(func), param1(p1), param2(p2) {}
00099     };
00100 
00101     template <typename T, typename U, typename P1, typename P2>
00102     inline UnitImpl2<T, U, P1, P2> * MakeUnitTest(const String & name, T & object, const U & func, const P1 & p1, const P2 & p2) 
00103     {
00104         return new UnitImpl2<T, U, P1, P2>(name, object, func, p1, p2);
00105     }
00106 
00108     template <typename T, typename U, typename P1, typename P2, typename P3>
00109     class UnitImpl3 : public Unit
00110     {
00111     private:
00112         T & object;
00113         RefConstU function;
00114         const P1  param1;
00115         const P2  param2;
00116         const P3  param3;
00117 
00118     private:
00119         // The test method
00120         inline bool launchTest() { return (bool)(object.*function)(param1, param2, param3); }
00121 
00122     public:
00123         UnitImpl3(const String & name, T & obj, RefConstU func, const P1 & p1, const P2 & p2, const P3 & p3) : Unit(name), object(obj), function(func), param1(p1), param2(p2), param3(p3) {}
00124     };
00125 
00126     template <typename T, typename U, typename P1, typename P2, typename P3>
00127     inline UnitImpl3<T, U, P1, P2, P3> * MakeUnitTest(const String & name, T & object, const U & func, const P1 & p1, const P2 & p2, const P3 & p3) 
00128     {
00129         return new UnitImpl3<T, U, P1, P2, P3>(name, object, func, p1, p2, p3);
00130     }
00131 
00133     template <typename T, typename U, typename P1, typename P2, typename P3, typename P4>
00134     class UnitImpl4 : public Unit
00135     {
00136     private:
00137         T & object;
00138         RefConstU function;
00139         const P1  param1;
00140         const P2  param2;
00141         const P3  param3;
00142         const P4  param4;
00143 
00144     private:
00145         // The test method
00146         inline bool launchTest() { return (bool)(object.*function)(param1, param2, param3, param4); }
00147 
00148     public:
00149         UnitImpl4(const String & name, T & obj, RefConstU func, const P1 & p1, const P2 & p2, const P3 & p3, const P4 & p4) : Unit(name), object(obj), function(func), param1(p1), param2(p2), param3(p3), param4(p4) {}
00150     };
00151 
00152     template <typename T, typename U, typename P1, typename P2, typename P3, typename P4>
00153     inline UnitImpl4<T, U, P1, P2, P3, P4> * MakeUnitTest(const String & name, T & object, const U & func, const P1 & p1, const P2 & p2, const P3 & p3, const P4 & p4) 
00154     {
00155         return new UnitImpl4<T, U, P1, P2, P3, P4>(name, object, func, p1, p2, p3, p4);
00156     }
00157 
00159     template <typename T, typename U, typename P1, typename P2, typename P3, typename P4, typename P5>
00160     class UnitImpl5 : public Unit
00161     {
00162     private:
00163         T & object;
00164         RefConstU function;
00165         const P1  param1;
00166         const P2  param2;
00167         const P3  param3;
00168         const P4  param4;
00169         const P5  param5;
00170 
00171     private:
00172         // The test method
00173         inline bool launchTest() { return (bool)(object.*function)(param1, param2, param3, param4, param5); }
00174 
00175     public:
00176         UnitImpl5(const String & name, T & obj, RefConstU func, const P1 & p1, const P2 & p2, const P3 & p3, const P4 & p4, const P5 & p5) : Unit(name), object(obj), function(func), param1(p1), param2(p2), param3(p3), param4(p4), param5(p5) {}
00177     };
00178 
00179     template <typename T, typename U, typename P1, typename P2, typename P3, typename P4, typename P5>
00180     inline UnitImpl5<T, U, P1, P2, P3, P4, P5> * MakeUnitTest(const String & name, T & object, const U & func, const P1 & p1, const P2 & p2, const P3 & p3, const P4 & p4, const P5 & p5) 
00181     {
00182         return new UnitImpl5<T, U, P1, P2, P3, P4, P5>(name, object, func, p1, p2, p3, p4, p5);
00183     }
00184 #define MakeTestName(X) String(__FILE__) + "(" + String().Format("%d", __LINE__) + ") : " + String( X )
00185     
00186 
00201     class Vector
00202     {
00203     private:
00205         ::Stack::WithClone::FIFO< Unit > vectorList;
00207         int unitSuccessful;
00209         int totalUnits;
00210 
00211     public:
00213         inline bool addUnitToTest(Unit * unit) { vectorList.Push(unit); return true; }
00215         inline String & testLastInsertedVectors(String & result) 
00216         {
00217             Unit *  unit = 0;
00218             totalUnits += vectorList.getSize();
00219             while ((unit = vectorList.Pop()) != NULL)
00220             {
00221                 bool bResult = false;
00222                 try { bResult = unit->launchTest(); } catch(...) { bResult = false; }
00223                 
00224                 if (!bResult)   result += unit->getTestName("\t[FAILED]\n");
00225                 else            { result += unit->getTestName("\t[  OK  ]\n"); unitSuccessful++; }
00226             }
00227             return result;
00228         }
00230         inline String testAllVectors(const String & previousResults = "") 
00231         {
00232             String result = previousResults;
00233             if (previousResults.getLength() == 0)   { unitSuccessful = 0; totalUnits = 0; }
00234             testLastInsertedVectors(result);
00235 
00236             result += String().Format("Tests finished : Successful tests %d/%d total\n", unitSuccessful, totalUnits);
00237             return result;
00238         }
00239 
00240         Vector() : unitSuccessful(0), totalUnits(0) {}
00241     };
00242 
00243     static bool OutputTestName()
00244     {
00245         return true;
00246     }
00247 
00248     struct LineDelimiter : public Unit
00249     {
00250         // The test method
00251         inline bool launchTest() { return true; }
00252         inline String getTestName(const String & = "") const { return testName + "\n"; }
00253         LineDelimiter(const String & name) : Unit(name) {}
00254     };
00255 
00256     inline LineDelimiter * MakeLineDelimiter(const String & name) { return new LineDelimiter(name); }
00257 
00258 }
00259 
00260 
00261 #endif

(C) An X-Ryl669 project 2007

This document describes Unlimited Zooming Interface source code. UZI stands for Unlimited Zooming Interface, and source code license is