Fennel: CalcExtMathTest Class Reference (original) (raw)

Inheritance diagram for CalcExtMathTest:

List of all members.

Public Member Functions
CalcExtMathTest ()
virtual ~CalcExtMathTest ()
TestSuite * releaseTestSuite ()
void beforeTestCase (std::string testCaseName)
void afterTestCase (std::string testCaseName)
virtual void testCaseSetUp ()
Equivalent to JUnit TestCase.setUp; this is called before each test case method is invoked.
virtual void testCaseTearDown ()
Equivalent to JUnit TestCase.tearDown; this is called after each test case method is invoked.
virtual void notifyTrace (std::string source, TraceLevel level, std::string message)
Receives notification when a trace event occurs.
virtual TraceLevel getSourceTraceLevel (std::string source)
Gets the level at which a particular source should be traced.
virtual void initTraceSource (SharedTraceTarget pTraceTarget, std::string name)
For use when initialization has to be deferred until after construction.
void trace (TraceLevel level, std::string message) const
Records a trace message.
bool isTracing () const
**Returns:**true iff tracing is enabled for this source
bool isTracingLevel (TraceLevel level) const
Determines whether a particular level is being traced.
TraceTarget & getTraceTarget () const
**Returns:**the TraceTarget for this source
SharedTraceTarget getSharedTraceTarget () const
**Returns:**the SharedTraceTarget for this source
std::string getTraceSourceName () const
Gets the name of this source.
void setTraceSourceName (std::string const &n)
Sets the name of this source.
TraceLevel getMinimumTraceLevel () const
void disableTracing ()
Static Public Member Functions
static void readParams (int argc, char **argv)
Parses the command line.
Static Public Attributes
static ParamName paramTestSuiteName
static ParamName paramTraceFileName
static ParamName paramDictionaryFileName
static ParamName paramTraceLevel
static ParamName paramStatsFileName
static ParamName paramTraceStdout
static ParamName paramDegreeOfParallelism
static ConfigMap configMap
Configuration parameters.
Protected Member Functions
void snooze (uint nSeconds)
Protected Attributes
TestSuite * pTestSuite
Boost test suite.
boost::shared_ptr< TestBase > pTestObj
std::ofstream traceStream
Output file stream for tracing.
StrictMutex traceMutex
Protects traceStream.
std::string testName
Name of test.
TraceLevel traceLevel
Level at which to trace test execution.
FileStatsTarget statsTarget
Output for stats.
StatsTimer statsTimer
Timer for stats collection.
bool traceStdout
Copy trace output to stdout.
bool traceFile
Copy trace output to file.
TestCaseGroup defaultTests
TestCaseGroup extraTests
Static Protected Attributes
static bool runAll
Run all test cases, including the extra tests.
static std::string runSingle
Run only the test case of this name.
Private Member Functions
void checkWarnings (Calculator &calc, string expected)
void testCalcExtMathLogarithms ()
void testCalcExtMathLogarithmsFails ()
void testCalcExtMathPow ()
void testCalcExtMathPowFails ()
void testCalcExtMathAbs ()
void printOutput (TupleData const &tup, Calculator const &calc)
Private Attributes
string mProgramPower

Detailed Description

Definition at line 43 of file CalcExtMathTest.cpp.


Constructor & Destructor Documentation

| CalcExtMathTest::CalcExtMathTest | ( | | ) | [inline, explicit] | | -------------------------------- | - | | - | -------------------- |

Definition at line 59 of file CalcExtMathTest.cpp.

References CalcInit::instance(), mProgramPower, testCalcExtMathAbs(), testCalcExtMathLogarithms(), testCalcExtMathLogarithmsFails(), testCalcExtMathPow(), and testCalcExtMathPowFails().

00060 : TraceSource(shared_from_this(),"CalcExtMathTest") 00061 { 00062 srand(time(NULL)); 00063 CalcInit::instance(); 00064 FENNEL_UNIT_TEST_CASE(CalcExtMathTest, testCalcExtMathLogarithms); 00065 FENNEL_UNIT_TEST_CASE(CalcExtMathTest, testCalcExtMathLogarithmsFails); 00066 FENNEL_UNIT_TEST_CASE(CalcExtMathTest, testCalcExtMathAbs); 00067 FENNEL_UNIT_TEST_CASE(CalcExtMathTest, testCalcExtMathPow); 00068 FENNEL_UNIT_TEST_CASE(CalcExtMathTest, testCalcExtMathPowFails); 00069 00070 00071
00072 ostringstream pg; 00073 00074 pg << "O d;" << endl; 00075 pg << "L d;" << endl; 00076 pg << "C %s, %s;" << endl; 00077 pg << "V %s, %s;" << endl; 00078 pg << "T;" << endl; 00079 pg << "CALL 'POW(L0, C0, C1);" << endl; 00080 pg << "REF O0, L0;" << endl; 00081 00082 mProgramPower = pg.str(); 00083 }

| virtual CalcExtMathTest::~CalcExtMathTest | ( | | ) | [inline, virtual] | | ------------------------------------------ | - | | - | ------------------- |


Member Function Documentation

void CalcExtMathTest::checkWarnings ( Calculator & calc,
string expected
) [private]

| void CalcExtMathTest::testCalcExtMathLogarithms | ( | | ) | [private] | | ----------------------------------------------- | - | | - | ----------- |

Definition at line 127 of file CalcExtMathTest.cpp.

References Calculator::assemble(), Calculator::bind(), Calculator::exec(), Calculator::getInputRegisterDescriptor(), FennelExcn::getMessage(), Calculator::getOutputRegisterDescriptor(), and printOutput().

Referenced by CalcExtMathTest().

00128 { 00129 ostringstream pg(""); 00130 00131 pg << "O d, d;" << endl; 00132 pg << "L d, d;" << endl; 00133 pg << "C d, d;" << endl; 00134 pg << "V 2.71828, 10.0;" << endl; 00135 pg << "T;" << endl; 00136 pg << "CALL 'LN(L0, C0);" << endl; 00137 pg << "CALL 'LOG10(L1, C1);" << endl; 00138 pg << "REF O0, L0;" << endl; 00139 pg << "REF O1, L1;" << endl; 00140 00141 Calculator calc(0); 00142 00143 try { 00144 calc.assemble(pg.str().c_str()); 00145 } catch (FennelExcn& ex) { 00146 BOOST_FAIL("Assemble exception " << ex.getMessage()<< pg.str()); 00147 } 00148 00149 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00150 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00151 00152 calc.bind(&inTuple, &outTuple); 00153 calc.exec(); 00154 printOutput(outTuple, calc); 00155 00156 for (int i = 0; i < 2; i++) { 00157 BOOST_CHECK( 00158 fabs( 00159 *(reinterpret_cast<double*> 00160 (const_cast(outTuple[i].pData))) - 1.0) 00161 < 0.0001); 00162 } 00163 }

| void CalcExtMathTest::testCalcExtMathLogarithmsFails | ( | | ) | [private] | | ---------------------------------------------------- | - | | - | ----------- |

Definition at line 167 of file CalcExtMathTest.cpp.

References checkWarnings(), FennelExcn::getMessage(), and FennelExcn::what().

Referenced by CalcExtMathTest().

00168 { 00169 char buff[1024]; 00170 const char* pg = 00171 "O d;\n" 00172 "L d;\n" 00173 "C %s;\n" 00174 "V %s;\n" 00175 "T;\n" 00176 "CALL '%s(L0, C0);\n" 00177 "REF O0, L0;\n"; 00178 00179 const char* tests[][3] = { 00180 { "LN", "s8", "0" }, 00181 { "LN", "d", "0.0" }, 00182 { "LN", "s8", "-1" }, 00183 { "LN", "d", "-1.0" }, 00184 { "LOG10", "s8", "0" }, 00185 { "LOG10", "d", "0.0" }, 00186 { "LOG10", "s8", "-1" }, 00187 { "LOG10", "d", "-1.0" }, 00188 }; 00189 00190 int n = sizeof(tests) / sizeof(tests[0]); 00191 for (int i = 0; i < n; i++) { 00192 Calculator calc(0); 00193 sprintf(buff, pg, tests[i][1], tests[i][2], tests[i][0]); 00194 try { 00195 calc.assemble(buff); 00196 } catch (FennelExcn& ex) { 00197 BOOST_FAIL("Assemble exception " << ex.getMessage() << ex.what()); 00198 } 00199 00200 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00201 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00202 00203 calc.bind(&inTuple, &outTuple); 00204 checkWarnings(calc,"22023"); 00205 if (!outTuple.containsNull()) { 00206 BOOST_FAIL("Result should be NULL"); 00207 } 00208 } 00209 }

| void CalcExtMathTest::testCalcExtMathPow | ( | | ) | [private] | | ---------------------------------------- | - | | - | ----------- |

Definition at line 292 of file CalcExtMathTest.cpp.

References Calculator::assemble(), Calculator::bind(), Calculator::exec(), Calculator::getInputRegisterDescriptor(), FennelExcn::getMessage(), Calculator::getOutputRegisterDescriptor(), mProgramPower, printOutput(), and FennelExcn::what().

Referenced by CalcExtMathTest().

00293 { 00294 char buff[1024]; 00295 00296 00297 const char* tests[][4] = { 00298 { "d", "d", "2.0", "2.2" }, 00299 { "d", "d", "2.0", "-2.2" }, 00300 { "d", "d", "-2.0", "2.0" }, 00301 }; 00302 00303 double results[] = { 4.5947934, 0.21763764, 4}; 00304 int n = sizeof(results) / sizeof(results[0]); 00305 assert(n == (sizeof(tests) / sizeof(tests[0]))); 00306 for (int i = 0; i < n; i++) { 00307 sprintf( 00308 buff, mProgramPower.c_str(), 00309 tests[i][0], tests[i][1], tests[i][2], tests[i][3]); 00310 00311 Calculator calc(0); 00312 try { 00313 calc.assemble(buff); 00314 } catch (FennelExcn& ex) { 00315 BOOST_FAIL( 00316 "Assemble exception " << ex.getMessage() << ex.what() << buff); 00317 } 00318 00319 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00320 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00321 00322 calc.bind(&inTuple, &outTuple); 00323 calc.exec(); 00324 printOutput(outTuple, calc); 00325 00326 BOOST_CHECK( 00327 fabs( 00328 *(reinterpret_cast<double*>( 00329 const_cast(outTuple[0].pData))) - results[i]) 00330 < 0.00001); 00331 } 00332 }

| void CalcExtMathTest::testCalcExtMathPowFails | ( | | ) | [private] | | --------------------------------------------- | - | | - | ----------- |

Definition at line 335 of file CalcExtMathTest.cpp.

References checkWarnings(), FennelExcn::getMessage(), mProgramPower, and FennelExcn::what().

Referenced by CalcExtMathTest().

00336 { 00337 char buff[1024]; 00338 00339 const char* tests[][4] = { 00340 { "d", "d", "0.0", "-1.0" }, 00341 { "d", "d", "-2.0", "2.2" }, 00342 { "d", "d", "-2.0", "-2.2" }, 00343 }; 00344 00345 int n = sizeof(tests) / sizeof(tests[0]); 00346 for (int i = 0; i < n; i++) { 00347 Calculator calc(0); 00348 sprintf( 00349 buff, mProgramPower.c_str(), 00350 tests[i][0], tests[i][1], tests[i][2], tests[i][3]); 00351 00352 try { 00353 calc.assemble(buff); 00354 } catch (FennelExcn& ex) { 00355 BOOST_FAIL("Assemble exception " << ex.getMessage() << ex.what()); 00356 } 00357 00358 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00359 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00360 00361 calc.bind(&inTuple, &outTuple); 00362 checkWarnings(calc,"22023"); 00363 if (!outTuple.containsNull()) { 00364 BOOST_FAIL("Result should be NULL"); 00365 } 00366 } 00367 }

| void CalcExtMathTest::testCalcExtMathAbs | ( | | ) | [private] | | ---------------------------------------- | - | | - | ----------- |

Definition at line 212 of file CalcExtMathTest.cpp.

References Calculator::assemble(), Calculator::bind(), Calculator::exec(), Calculator::getInputRegisterDescriptor(), FennelExcn::getMessage(), Calculator::getOutputRegisterDescriptor(), and printOutput().

Referenced by CalcExtMathTest().

00213 { 00214 ostringstream pg(""); 00215 00216 pg << "O d, d, d, s8, s8, s8;" << endl; 00217 pg << "L d, d, d, s8, s8, s8;" << endl; 00218 pg << "C d, d, d, s8, s8, s8;" << endl; 00219
00220 pg << "V 0.0, -1234567890123.0, 1234567890123.0,";; 00221 pg << "0, 9223372036854775807, -9223372036854775807;" << endl; 00222 pg << "T;" << endl; 00223 pg << "CALL 'ABS(L0, C0);" << endl; 00224 pg << "CALL 'ABS(L1, C1);" << endl; 00225 pg << "CALL 'ABS(L2, C2);" << endl; 00226 pg << "CALL 'ABS(L3, C3);" << endl; 00227 pg << "CALL 'ABS(L4, C4);" << endl; 00228 pg << "CALL 'ABS(L5, C5);" << endl; 00229 pg << "REF O0, L0;" << endl; 00230 pg << "REF O1, L1;" << endl; 00231 pg << "REF O2, L2;" << endl; 00232 pg << "REF O3, L3;" << endl; 00233 pg << "REF O4, L4;" << endl; 00234 pg << "REF O5, L5;" << endl; 00235 00236
00237 00238 Calculator calc(0); 00239 00240 try { 00241 calc.assemble(pg.str().c_str()); 00242 } catch (FennelExcn& ex) { 00243 BOOST_FAIL("Assemble exception " << ex.getMessage() << pg.str()); 00244 } 00245 00246 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00247 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00248 00249 calc.bind(&inTuple, &outTuple); 00250 calc.exec(); 00251 printOutput(outTuple, calc); 00252 00253 00254 double epsilon = 0.000001; 00255 00256 BOOST_CHECK( 00257 fabs( 00258 *(reinterpret_cast<double*> 00259 (const_cast(outTuple[0].pData))) - 00260 0) 00261 < epsilon); 00262 00263 BOOST_CHECK( 00264 fabs( 00265 *(reinterpret_cast<double*> 00266 (const_cast(outTuple[1].pData))) - 00267 1234567890123.0) 00268 < epsilon); 00269 00270 BOOST_CHECK( 00271 fabs( 00272 *(reinterpret_cast<double*> 00273 (const_cast(outTuple[2].pData))) - 00274 1234567890123.0) 00275 < epsilon); 00276 00277 BOOST_CHECK_EQUAL( 00278 *(reinterpret_cast<uint64_t*> 00279 (const_cast(outTuple[3].pData))),0); 00280 00281 BOOST_CHECK_EQUAL( 00282 *(reinterpret_cast<uint64_t*>( 00283 const_cast(outTuple[4].pData))), 00284 9223372036854775807LL); 00285 BOOST_CHECK_EQUAL( 00286 *(reinterpret_cast<uint64_t*>( 00287 const_cast(outTuple[5].pData))), 00288 9223372036854775807LL); 00289 }

void TestBase::snooze ( uint nSeconds ) [protected, inherited]
void TestBase::readParams ( int argc,
char ** argv
) [static, inherited]

Parses the command line.

format: [-v] [-t TEST | -all] {param=val}* [CONFIGFILE | -] Normally, the test program runs the default test cases. With the option "-all", runs the extra test cases as well. With the option "-t TEST", runs only the single test case named TEST. CONFIGFILE is read to load configuration parameters. Configuration parameters can also be set ad hoc, from the command line, as pairs name=val. These take precedence.

Definition at line 108 of file TestBase.cpp.

References TestBase::configMap, ConfigMap::dumpParams(), ConfigMap::isParamSet(), ConfigMap::mergeFrom(), TestBase::paramDictionaryFileName, ConfigMap::readParams(), TestBase::runAll, TestBase::runSingle, ConfigMap::setStringParam(), and verbose.

00109 { 00110 bool verbose = false; 00111 ConfigMap adhocMap; 00112 00113 for (int i = 1; i < argc; ++i) { 00114 std::string arg = argv[i]; 00115 if (argv[i][0] == '-') { 00116 if (arg == "-v") { 00117 verbose = true; 00118 } else if (arg == "-") { 00119 configMap.readParams(std::cin); 00120 } else if (arg == "-all") { 00121 runAll = true; 00122 } else if (arg == "-t") {
00123 permAssert(i + 1 < argc); 00124 runSingle = argv[++i]; 00125 } else if (arg[1] == 't') { 00126 runSingle = arg.substr(2); 00127 } 00128 } else { 00129 int i = arg.find("="); 00130 if ((0 < i) && (i < arg.size())) { 00131
00132 std::string key = arg.substr(0,i); 00133 std::string val = arg.substr(i + 1); 00134 adhocMap.setStringParam(key,val); 00135 } else { 00136
00137 std::ifstream configFile(arg.c_str()); 00138 assert(configFile.good()); 00139 configMap.readParams(configFile); 00140 } 00141 } 00142 } 00143 configMap.mergeFrom(adhocMap); 00144 00145
00146
00147 if (configMap.isParamSet(paramDictionaryFileName)) { 00148 std::string dictFileName = "dictWords"; 00149 configMap.setStringParam(paramDictionaryFileName,dictFileName); 00150 } 00151 00152 if (verbose) { 00153 configMap.dumpParams(std::cout); 00154 } 00155 }

| TestSuite * TestBase::releaseTestSuite | ( | | ) | [inherited] | | ---------------------------------------------------------------------------------------------- | - | | - | ------------- |

void TestBase::beforeTestCase ( std::string testCaseName ) [inherited]
void TestBase::afterTestCase ( std::string testCaseName ) [inherited]

| void TestBase::testCaseSetUp | ( | | ) | [virtual, inherited] | | ---------------------------- | - | | - | ---------------------- |

Equivalent to JUnit TestCase.setUp; this is called before each test case method is invoked.

Default is no-op.

Reimplemented in LbmEntryTest, LbmExecStreamTestBase, LbmLoadBitmapTest, LbmSearchTest, LbmSplicerExecStreamTest, LcsClusterAppendExecStreamTest, LcsClusterReplaceExecStreamTest, LcsMultiClusterAppendTest, LcsRowScanExecStreamTest, BTreeReadersTest, BTreeTest, BTreeTxnTest, ExecStreamGovernorTest, ExecStreamTestBase, ExecStreamUnitTestBase, ExternalSortExecStreamTest, LhxHashTableTest, LogicalTxnTest, and SnapshotSegmentTestBase.

Definition at line 235 of file TestBase.cpp.

Referenced by ExecStreamTestBase::testCaseSetUp().

| void TestBase::testCaseTearDown | ( | | ) | [virtual, inherited] | | ------------------------------- | - | | - | ---------------------- |

Equivalent to JUnit TestCase.tearDown; this is called after each test case method is invoked.

Default is no-op.

Reimplemented in LbmEntryTest, LbmLoadBitmapTest, LbmSearchTest, LcsClusterAppendExecStreamTest, LcsClusterReplaceExecStreamTest, LcsMultiClusterAppendTest, LcsRowScanExecStreamTest, BTreeReadersTest, BTreeTest, BTreeTxnTest, CacheTestBase, DatabaseTest, ExecStreamTestBase, LhxHashTableTest, RandomAccessFileDeviceTest, and SparseBitmapTest.

Definition at line 239 of file TestBase.cpp.

Referenced by SparseBitmapTest::testCaseTearDown().

void TestBase::notifyTrace ( std::string source,
TraceLevel level,
std::string message
) [virtual, inherited]
TraceLevel TestBase::getSourceTraceLevel ( std::string source ) [virtual, inherited]
void TraceSource::initTraceSource ( SharedTraceTarget pTraceTarget,
std::string name
) [virtual, inherited]
void TraceSource::trace ( TraceLevel level,
std::string message
) const [inherited]

| bool TraceSource::isTracing | ( | | ) | const [inline, inherited] | | --------------------------- | - | | - | --------------------------- |

bool TraceSource::isTracingLevel ( TraceLevel level ) const [inline, inherited]

| TraceTarget& TraceSource::getTraceTarget | ( | | ) | const [inline, inherited] | | ----------------------------------------------------------------- | - | | - | --------------------------- |

| std::string TraceSource::getTraceSourceName | ( | | ) | const [inline, inherited] | | ------------------------------------------- | - | | - | --------------------------- |

void TraceSource::setTraceSourceName ( std::string const & n ) [inline, inherited]

Sets the name of this source.

Useful to construct dynamic names for fine-grained filtering.

Definition at line 136 of file TraceSource.h.

00137 { 00138 name = n; 00139 }

| TraceLevel TraceSource::getMinimumTraceLevel | ( | | ) | const [inline, inherited] | | ------------------------------------------------------------------------------------------------------ | - | | - | --------------------------- |

| void TraceSource::disableTracing | ( | | ) | [inherited] | | -------------------------------- | - | | - | ------------- |


Member Data Documentation

Configuration parameters.

The reason this is static is so that no constructor parameters (which burden virtual bases) are needed.

Definition at line 155 of file TestBase.h.

Referenced by TestBase::afterTestCase(), TestBase::beforeTestCase(), BTreeTxnTest::BTreeTxnTest(), CacheTestBase::CacheTestBase(), BackupRestoreTest::createSnapshotData(), DatabaseTest::DatabaseTest(), TestOptionsTest::extra(), DatabaseTest::loadDatabase(), SparseBitmapTest::openStorage(), PagingTestBase::PagingTestBase(), ParallelExecStreamSchedulerTest::ParallelExecStreamSchedulerTest(), RandomAccessFileDeviceTest::RandomAccessFileDeviceTest(), TestBase::readParams(), SegStorageTestBase::SegStorageTestBase(), TestOptionsTest::test1(), TestOptionsTest::test2(), BackupRestoreTest::testBackupCleanup(), TestBase::TestBase(), BTreeTxnTest::testCaseSetUp(), BTreeTxnTest::testCheckpoint(), DatabaseTest::testCreateEmpty(), DatabaseTest::testForceTxns(), BackupRestoreTest::testHeaderBackupRestore(), SegPageEntryIterTest::testIter(), SegStreamTest::testRead(), BTreeTxnTest::testTxns(), SegStreamTest::testWrite(), ThreadedTestBase::ThreadedTestBase(), and TestBase::~TestBase().


The documentation for this class was generated from the following file:


Generated on Mon Jun 22 04:00:28 2009 for Fennel by doxygen 1.5.1