testCalcExtended.cpp File Reference

Go to the source code of this file.

Classes

class  TestCalculator
 Subclass of Calculator specialized for testing extended instructions. More...

Functions

void fail (const char *str, int line)
void convertDoubleToFloat (RegisterRef< float > *regOut, RegisterRef< double > *regIn)
void convertFloatToDouble (RegisterRef< double > *regOut, RegisterRef< float > *regIn)
void convertFloatToInt (RegisterRef< int > *regOut, RegisterRef< float > *regIn)
void convertIntToFloat (RegisterRef< float > *regOut, RegisterRef< int > *regIn)
void convertDecimal (RegisterRef< int32_t > *resultReg, RegisterRef< int32_t > *inputReg, RegisterRef< int32_t > *exponentReg)
 Assigns "input" * 10 ^ "exponent" to "result".
void convertStringToExactNumber (RegisterRef< int > *regOut, RegisterRef< char * > *regIn)
void convertExactNumberToString (RegisterRef< char * > *regOut, RegisterRef< int > *regIn)
void convertStringToFloat (RegisterRef< float > *regOut, RegisterRef< char * > *regIn)
void convertFloatToString (RegisterRef< char * > *regOut, RegisterRef< float > *regIn)
void convertStringToDouble (RegisterRef< double > *regOut, RegisterRef< char * > *regIn)
void convertDoubleToString (RegisterRef< char * > *regOut, RegisterRef< double > *regIn)
void printTestHeader (const char *msg)
void testConvertDoubleToFloat (double val, float expected)
void testConvertFloatToDouble (float val, double expected)
void testConvertFloatToIntTypes (const char *const str, float val, int expected)
void testConvertIntTypesToFloat (const char *const str, int val, float expected)
void testConvertDecimal (const char *const str, int val, int exp, int expected)
void testConvertStringToExactNumber (const char *str, int expected)
void testConvertExactNumberToString (int num, char *expected)
void testStringToApproximateNumber (char *str, float expected)
void testApproximateNumberToString (float expected, char *str)
void testStringToDate (char *str, long long expected)
void testDateToString (long long d, char *expected)
int main (int argc, char *argv[])
boost::unit_test_framework::test_suite * init_unit_test_suite (int, char **)

Variables

char * ProgramName


Function Documentation

void convertDecimal ( RegisterRef< int32_t > *  resultReg,
RegisterRef< int32_t > *  inputReg,
RegisterRef< int32_t > *  exponentReg 
)

Assigns "input" * 10 ^ "exponent" to "result".

Definition at line 91 of file testCalcExtended.cpp.

References RegisterRef< TMPLT >::value().

Referenced by testConvertDecimal().

00095 {
00096     int32_t in = inputReg->value();
00097     int32_t exp = exponentReg->value();
00098     int32_t result = in;
00099     if (exp < 0) {
00100         while (exp++ < 0) {
00101             result /= 10;
00102         }
00103     } else {
00104         while (exp-- > 0) {
00105             result *= 10;
00106         }
00107     }
00108     resultReg->value(result);
00109 }

void convertDoubleToFloat ( RegisterRef< float > *  regOut,
RegisterRef< double > *  regIn 
)

Definition at line 64 of file testCalcExtended.cpp.

References RegisterRef< TMPLT >::value().

Referenced by testConvertDoubleToFloat().

00067 {
00068     regOut->value((float)regIn->value());
00069 }

void convertDoubleToString ( RegisterRef< char * > *  regOut,
RegisterRef< double > *  regIn 
)

Definition at line 210 of file testCalcExtended.cpp.

00213 {}

void convertExactNumberToString ( RegisterRef< char * > *  regOut,
RegisterRef< int > *  regIn 
)

Definition at line 147 of file testCalcExtended.cpp.

References RegisterRef< TMPLT >::pointer(), RegisterRef< TMPLT >::storage(), RegisterRef< TMPLT >::value(), and RegisterRef< TMPLT >::valueToString().

Referenced by testConvertExactNumberToString().

00150 {
00151 #if 1
00152     // TODO: Change the following proof-of-concept code into
00153     // TODO: something real.
00154     char *nullTermStr = new char[256];
00155     sprintf(nullTermStr, "%d", regIn->value());
00156 
00157     uint dstL = regOut->storage();
00158     uint newL = strlen(nullTermStr);
00159 
00160     printf("dstL = %d  newL = %d\n", dstL, newL);
00161 
00162     if (newL > dstL) {
00163         // TODO: Must check right space padding to see what, if
00164         // anything valid is truncated before going all wild and
00165         // throwing exception
00166         assert(0);        // TODO: Must have a valid pc here!
00167         // SQL99 Part 2 Section 22.1 22-001 "string data, right truncation"
00168         memcpy(regOut->pointer(), nullTermStr, dstL);
00169         regOut->putS(dstL);
00170         throw CalcMessage("22001", 0); // TODO: PC is bogus
00171         printf("ConvertExactNumberToString\n");
00172         assert(newL <= dstL);
00173     }
00174 
00175     regOut->putS(newL);
00176     memcpy(regOut->pointer(), nullTermStr, newL);
00177     delete [] nullTermStr;
00178 #endif
00179 #if 0
00180 // TODO: JR 6/07 ... valueToStringis not implemented yet ...
00181 // re-enabled the above ...
00182     const char *pString = regIn->valueToString().c_str();
00183     assert(pString);
00184     regOut->value(const_cast<char*>(pString));
00185 #endif
00186 }

void convertFloatToDouble ( RegisterRef< double > *  regOut,
RegisterRef< float > *  regIn 
)

Definition at line 70 of file testCalcExtended.cpp.

References RegisterRef< TMPLT >::value().

Referenced by testConvertFloatToDouble().

00073 {
00074     regOut->value((double)regIn->value());
00075 }

void convertFloatToInt ( RegisterRef< int > *  regOut,
RegisterRef< float > *  regIn 
)

Definition at line 76 of file testCalcExtended.cpp.

References RegisterRef< TMPLT >::value().

00079 {
00080     regOut->value((int)regIn->value());
00081 }

void convertFloatToString ( RegisterRef< char * > *  regOut,
RegisterRef< float > *  regIn 
)

Definition at line 196 of file testCalcExtended.cpp.

00199 {
00200     //*str = itoa ((int) *approx);
00201 }

void convertIntToFloat ( RegisterRef< float > *  regOut,
RegisterRef< int > *  regIn 
)

Definition at line 82 of file testCalcExtended.cpp.

References RegisterRef< TMPLT >::value().

Referenced by testConvertIntTypesToFloat().

00085 {
00086     regOut->value((float)regIn->value());
00087 }

void convertStringToDouble ( RegisterRef< double > *  regOut,
RegisterRef< char * > *  regIn 
)

Definition at line 203 of file testCalcExtended.cpp.

00206 {
00207     //*regOut = strtod(*regIn, (char **)NULL);
00208 }

void convertStringToExactNumber ( RegisterRef< int > *  regOut,
RegisterRef< char * > *  regIn 
)

Definition at line 111 of file testCalcExtended.cpp.

References RegisterRef< TMPLT >::pointer(), RegisterRef< TMPLT >::stringLength(), RegisterRef< TMPLT >::value(), and RegisterRef< TMPLT >::valueToString().

Referenced by testConvertStringToExactNumber().

00114 {
00115 #if 0
00116     // TODO: Wrap this code in
00117     uint srcL = regIn->getS();
00118     // TODO: Change the following proof-of-concept code into
00119     // TODO: something real.
00120     char *nullTermStr = new char[srcL + 1];
00121     nullTermStr[srcL + 1] = 0;
00122     memcpy(nullTermStr, regIn->pointer(), srcL);
00123     regOut->value(strtol(nullTermStr, 0, 10));
00124     delete [] nullTermStr;
00125 #endif
00126 #if 0
00127 
00128     // TODO: Nope this is a disaster JR 6/07 (valueToString() returns "Unimpl");
00129     const char *pString = regIn->valueToString().c_str();
00130     assert(pString);
00131     int iValue = atoi(pString);
00132     regOut->value(iValue);
00133 #endif
00134 
00135     // Try original pointer casting code updated to new class interface
00136     // This code is the same as above
00137     uint srcL = regIn->stringLength();
00138     char *nullTermStr = new char[srcL + 1];
00139     nullTermStr[srcL] = 0;
00140     memcpy(nullTermStr, regIn->pointer(), srcL);
00141     regOut->value(strtol(nullTermStr, 0, 10));
00142     delete [] nullTermStr;
00143 }

void convertStringToFloat ( RegisterRef< float > *  regOut,
RegisterRef< char * > *  regIn 
)

Definition at line 189 of file testCalcExtended.cpp.

00192 {
00193     //*regOut = strtof(*regIn, (char **)NULL);
00194 }

void fail ( const char *  str,
int  line 
)

Definition at line 55 of file testCalcExtended.cpp.

References ProgramName.

00055                                 {
00056     assert(ProgramName);
00057     assert(str);
00058     printf("%s: unit test failed: |%s| line %d\n", ProgramName, str, line);
00059     exit(-1);
00060 }

boost::unit_test_framework::test_suite* init_unit_test_suite ( int  ,
char **   
)

Definition at line 900 of file testCalcExtended.cpp.

00901 {
00902     return NULL;
00903 }

int main ( int  argc,
char *  argv[] 
)

Definition at line 871 of file testCalcExtended.cpp.

References ProgramName, testConvertDecimal(), testConvertDoubleToFloat(), testConvertFloatToDouble(), testConvertFloatToIntTypes(), testConvertIntTypesToFloat(), and testConvertStringToExactNumber().

00872 {
00873     ProgramName = argv[0];
00874     testConvertDoubleToFloat((double) 100.33, (float) 100.33);
00875     testConvertFloatToDouble((float) 33.3378, (double) 33.3378);
00876     testConvertFloatToIntTypes("s1",(float) 45.65, 45);
00877     testConvertFloatToIntTypes("u1",(float) 45.65, 45);
00878     testConvertFloatToIntTypes("s2",(float) 45.65, 45);
00879     testConvertFloatToIntTypes("u2",(float) 45.65, 45);
00880     testConvertFloatToIntTypes("s4",(float) 45.65, 45);
00881     testConvertFloatToIntTypes("u4",(float) 45.65, 45);
00882     testConvertFloatToIntTypes("s8",(float) 45.65, 45);
00883     testConvertFloatToIntTypes("u8",(float) 45.65, 45);
00884     testConvertIntTypesToFloat("s1", 4565, (float) 4565);
00885     testConvertIntTypesToFloat("u1", 4565, (float) 4565);
00886     testConvertIntTypesToFloat("s2", 4565, (float) 4565);
00887     testConvertIntTypesToFloat("u2", 4565, (float) 4565);
00888     testConvertIntTypesToFloat("s4", 4565, (float) 4565);
00889     testConvertIntTypesToFloat("u4", 4565, (float) 4565);
00890     testConvertIntTypesToFloat("s8", 4565, (float) 4565);
00891     testConvertIntTypesToFloat("u8", 4565, (float) 4565);
00892     testConvertDecimal("s2", 123, 3, 123000);
00893 
00894     testConvertStringToExactNumber("123", 123);
00895 //    testConvertExactNumberToString(123, "123"); -- JR 6/07 removing this
00896     printf("all tests passed\n");
00897     exit(0);
00898 }

void printTestHeader ( const char *  msg  ) 

Definition at line 459 of file testCalcExtended.cpp.

Referenced by testConvertDecimal(), testConvertDoubleToFloat(), testConvertExactNumberToString(), testConvertFloatToDouble(), testConvertFloatToIntTypes(), testConvertIntTypesToFloat(), and testConvertStringToExactNumber().

00460 {
00461     printf("=========================================================\n");
00462     printf("=========================================================\n");
00463     printf("=====\n");
00464     printf("=====     ");
00465     printf("%s", msg);
00466     printf("\n");
00467     printf("=====\n");
00468     printf("=========================================================\n");
00469     printf("=========================================================\n");
00470 }

void testApproximateNumberToString ( float  expected,
char *  str 
)

Definition at line 858 of file testCalcExtended.cpp.

00859 {
00860 }

void testConvertDecimal ( const char *const  str,
int  val,
int  exp,
int  expected 
)

Definition at line 679 of file testCalcExtended.cpp.

References ExtendedInstructionTable::add(), Calculator::appendInstruction(), Calculator::appendRegRef(), TestCalculator::bind(), convertDecimal(), ExtendedInstructionDef::createInstruction(), RegisterReference::EInput, RegisterReference::EOutput, Calculator::exec(), StandardTypeDescriptor::fromString(), ExtendedInstructionDef::getName(), TestCalculator::getOutput(), ExtendedInstructionDef::getParameterTypes(), TestCalculator::printOutput(), printTestHeader(), TestCalculator::setInput(), STANDARD_TYPE_INT_32, and STANDARD_TYPE_INT_8.

Referenced by main().

00680 {
00681     printTestHeader("testConvertDecimal()");
00682     ExtendedInstructionTable table;
00683     vector<StandardTypeDescriptorOrdinal> parameterTypes;
00684     // define a function
00685     parameterTypes.resize(3);
00686     parameterTypes[0] = StandardTypeDescriptor::fromString(str);
00687     parameterTypes[1] = StandardTypeDescriptor::fromString(str);
00688     parameterTypes[2] = STANDARD_TYPE_INT_8;
00689     table.add(
00690         "convert",
00691         parameterTypes,
00692         (ExtendedInstruction3<int, int, int>*) NULL,
00693         &convertDecimal);
00694     // lookup a function
00695     string s("convert(");
00696     s += str;
00697     s += ",";
00698     s += str;
00699     s += ",";
00700     s += "s1";
00701     s += ")";
00702     cout << s << endl;
00703     ExtendedInstructionDef *pDef = table[s];
00704     assert(pDef != NULL);
00705     assert(pDef->getName() == string("convert"));
00706     assert(pDef->getParameterTypes().size() == 3);
00707     // Set up the Calculator
00708     DynamicParamManager dpm;
00709     TestCalculator c(&dpm, true, pDef);
00710     c.setInput(0, &val);
00711     c.setInput(1, &exp);
00712     // setup registers
00713     vector<RegisterReference *> regRefs(3);
00714     regRefs[0] = new RegisterRef<int>(
00715         RegisterReference::EOutput, 0,
00716         STANDARD_TYPE_INT_32);
00717     regRefs[1] = new RegisterRef<int>(
00718         RegisterReference::EInput, 0,
00719         STANDARD_TYPE_INT_32);
00720     regRefs[2] = new RegisterRef<int>(
00721         RegisterReference::EInput, 1,
00722         STANDARD_TYPE_INT_32);
00723     c.appendRegRef(regRefs[0]);
00724     c.appendRegRef(regRefs[1]);
00725     c.appendRegRef(regRefs[2]);
00726     c.bind();
00727     // create an instruction
00728     //ExtendedInstruction *pInstr = pDef->createInstruction(&c, regRefs);
00729     ExtendedInstruction *pInstr = pDef->createInstruction(regRefs);
00730     assert(pInstr != NULL);
00731     // execute it
00732     c.appendInstruction(pInstr);
00733     c.exec();
00734     c.printOutput();
00735     int i;
00736     c.getOutput(0, i);
00737     //cout << i << endl;
00738     assert(abs(expected - i)<0.00001);
00739 };

void testConvertDoubleToFloat ( double  val,
float  expected 
)

Definition at line 472 of file testCalcExtended.cpp.

References ExtendedInstructionTable::add(), Calculator::appendInstruction(), Calculator::appendRegRef(), TestCalculator::bind(), convertDoubleToFloat(), ExtendedInstructionDef::createInstruction(), RegisterReference::EInput, RegisterReference::EOutput, Calculator::exec(), ExtendedInstructionDef::getName(), TestCalculator::getOutput(), ExtendedInstructionDef::getParameterTypes(), TestCalculator::printOutput(), printTestHeader(), TestCalculator::setInput(), STANDARD_TYPE_DOUBLE, and STANDARD_TYPE_REAL.

Referenced by main().

00473 {
00474     printTestHeader("testConvertDoubleToFloat()");
00475     ExtendedInstructionTable table;
00476     vector<StandardTypeDescriptorOrdinal> parameterTypes;
00477     // define a function
00478     parameterTypes.resize(2);
00479     parameterTypes[0] = STANDARD_TYPE_REAL;
00480     parameterTypes[1] = STANDARD_TYPE_DOUBLE;
00481     table.add(
00482         "convert",
00483         parameterTypes,
00484         (ExtendedInstruction2<float,double>*) NULL,
00485         &convertDoubleToFloat);
00486     // lookup a function
00487     ExtendedInstructionDef *pDef = table["convert(r,d)"];
00488     assert(pDef != NULL);
00489     assert(pDef->getName() == string("convert"));
00490     assert(pDef->getParameterTypes().size() == 2);
00491     // lookup non-existent, should return NULL
00492     ExtendedInstructionDef *pNonExistentDef = table["convert(d,r)"];
00493     assert(pNonExistentDef == NULL);
00494     // Set up the Calculator
00495     DynamicParamManager dpm;
00496     TestCalculator c(&dpm, true, pDef);
00497     c.setInput(0, &val);
00498     // setup registers
00499     vector<RegisterReference *> regRefs(2);
00500     regRefs[0] = new RegisterRef<float>(
00501         RegisterReference::EOutput, 0,
00502         STANDARD_TYPE_REAL);
00503     regRefs[1] = new RegisterRef<double>(
00504         RegisterReference::EInput, 0,
00505         STANDARD_TYPE_DOUBLE);
00506     c.appendRegRef(regRefs[0]);
00507     c.appendRegRef(regRefs[1]);
00508     c.bind();
00509     // create an instruction
00510     //ExtendedInstruction *pInstr = pDef->createInstruction(&c, regRefs);
00511     ExtendedInstruction *pInstr = pDef->createInstruction(regRefs);
00512     assert(pInstr != NULL);
00513     // execute it
00514     c.appendInstruction(pInstr);
00515     c.exec();
00516     c.printOutput();
00517     float f;
00518     c.getOutput(0, f);
00519     cout << f << endl;
00520     assert(fabs(expected - f) < 0.0001);
00521 };

void testConvertExactNumberToString ( int  num,
char *  expected 
)

Definition at line 796 of file testCalcExtended.cpp.

References ExtendedInstructionTable::add(), Calculator::appendInstruction(), Calculator::appendRegRef(), TestCalculator::bind(), convertExactNumberToString(), ExtendedInstructionDef::createInstruction(), RegisterReference::EInput, RegisterReference::EOutput, Calculator::exec(), ExtendedInstructionDef::getName(), TestCalculator::getOutputP(), ExtendedInstructionDef::getParameterTypes(), TestCalculator::printOutput(), printTestHeader(), TestCalculator::setInput(), TestCalculator::setOutput(), STANDARD_TYPE_INT_32, and STANDARD_TYPE_VARCHAR.

00797 {
00798     printTestHeader("testConvertExactNumberToString()");
00799     ExtendedInstructionTable table;
00800     vector<StandardTypeDescriptorOrdinal> parameterTypes;
00801     // define a function
00802     parameterTypes.resize(2);
00803     parameterTypes[0] = STANDARD_TYPE_VARCHAR;
00804     parameterTypes[1] = STANDARD_TYPE_INT_32;
00805 
00806     table.add(
00807         "convert",
00808         parameterTypes,
00809         (ExtendedInstruction2<char *, int32_t>*) NULL,
00810         &convertExactNumberToString);
00811 
00812     // lookup a function
00813     ExtendedInstructionDef *pDef = table["convert(vc,s4)"];
00814     assert(pDef != NULL);
00815     assert(pDef->getName() == string("convert"));
00816     assert(pDef->getParameterTypes().size() == 2);
00817 
00818     // Set up the Calculator
00819     DynamicParamManager dpm;
00820     TestCalculator c(&dpm, true, pDef);
00821     c.setInput(0, &num);
00822     int destLen = strlen(expected);
00823     char *buf = new char[destLen*2];
00824     memset(buf, 'X', destLen*2); // no null terminator
00825     c.setOutput(0, buf, destLen*2, destLen*2);
00826 
00827     // setup registers
00828     vector<RegisterReference *> regRefs(2);
00829     regRefs[0] = new RegisterRef<int32_t>(
00830         RegisterReference::EOutput, 0,
00831         STANDARD_TYPE_VARCHAR);
00832     regRefs[1] = new RegisterRef<char *>(
00833         RegisterReference::EInput, 0,
00834         STANDARD_TYPE_INT_32);
00835     c.appendRegRef(regRefs[0]);
00836     c.appendRegRef(regRefs[1]);
00837     c.bind();
00838 
00839     // create an instruction
00840     //ExtendedInstruction *pInstr = pDef->createInstruction(&c, regRefs);
00841     ExtendedInstruction *pInstr = pDef->createInstruction(regRefs);
00842     assert(pInstr != NULL);
00843     // execute it
00844     c.appendInstruction(pInstr);
00845     c.exec();
00846     c.printOutput();
00847     char *outP;
00848     c.getOutputP(0, outP);
00849     assert(outP == buf);
00850     assert(!strncmp(outP, expected, destLen));
00851     outP[destLen] = 0;
00852     cout << outP << endl;
00853 }

void testConvertFloatToDouble ( float  val,
double  expected 
)

Definition at line 523 of file testCalcExtended.cpp.

References ExtendedInstructionTable::add(), Calculator::appendInstruction(), Calculator::appendRegRef(), TestCalculator::bind(), convertFloatToDouble(), ExtendedInstructionDef::createInstruction(), RegisterReference::EInput, RegisterReference::EOutput, Calculator::exec(), ExtendedInstructionDef::getName(), TestCalculator::getOutput(), ExtendedInstructionDef::getParameterTypes(), TestCalculator::printOutput(), printTestHeader(), TestCalculator::setInput(), STANDARD_TYPE_DOUBLE, and STANDARD_TYPE_REAL.

Referenced by main().

00524 {
00525     printTestHeader("testConvertFloatToDouble()");
00526     ExtendedInstructionTable table;
00527     vector<StandardTypeDescriptorOrdinal> parameterTypes;
00528     // define a function
00529     parameterTypes.resize(2);
00530     parameterTypes[0] = STANDARD_TYPE_DOUBLE;
00531     parameterTypes[1] = STANDARD_TYPE_REAL;
00532     table.add(
00533         "convert",
00534         parameterTypes,
00535         (ExtendedInstruction2<double, float>*) NULL,
00536         &convertFloatToDouble);
00537     // lookup a function
00538     ExtendedInstructionDef *pDef = table["convert(d,r)"];
00539     assert(pDef != NULL);
00540     assert(pDef->getName() == string("convert"));
00541     assert(pDef->getParameterTypes().size() == 2);
00542     // Set up the Calculator
00543     DynamicParamManager dpm;
00544     TestCalculator c(&dpm, true, pDef);
00545     c.setInput(0, &val);
00546     // setup registers
00547     vector<RegisterReference *> regRefs(2);
00548     regRefs[0] = new RegisterRef<double>(
00549         RegisterReference::EOutput, 0,
00550         STANDARD_TYPE_DOUBLE);
00551     regRefs[1] = new RegisterRef<float>(
00552         RegisterReference::EInput, 0,
00553         STANDARD_TYPE_REAL);
00554     c.appendRegRef(regRefs[0]);
00555     c.appendRegRef(regRefs[1]);
00556     c.bind();
00557     // create an instruction
00558     //ExtendedInstruction *pInstr = pDef->createInstruction(&c, regRefs);
00559     ExtendedInstruction *pInstr = pDef->createInstruction(regRefs);
00560     assert(pInstr != NULL);
00561     // execute it
00562     c.appendInstruction(pInstr);
00563     c.exec();
00564     c.printOutput();
00565     double d;
00566     c.getOutput(0, d);
00567     cout << d << endl;
00568     assert(fabs(expected - d) < 0.0001);
00569 };

void testConvertFloatToIntTypes ( const char *const  str,
float  val,
int  expected 
)

Definition at line 572 of file testCalcExtended.cpp.

References ExtendedInstructionTable::add(), Calculator::appendInstruction(), Calculator::appendRegRef(), TestCalculator::bind(), convertFloatToInt(), ExtendedInstructionDef::createInstruction(), RegisterReference::EInput, RegisterReference::EOutput, Calculator::exec(), StandardTypeDescriptor::fromString(), ExtendedInstructionDef::getName(), TestCalculator::getOutput(), ExtendedInstructionDef::getParameterTypes(), TestCalculator::printOutput(), printTestHeader(), TestCalculator::setInput(), STANDARD_TYPE_INT_32, and STANDARD_TYPE_REAL.

Referenced by main().

00573 {
00574     printTestHeader("testConvertFloatToIntTypes()");
00575     ExtendedInstructionTable table;
00576     vector<StandardTypeDescriptorOrdinal> parameterTypes;
00577     // define a function
00578     parameterTypes.resize(2);
00579     parameterTypes[0] = StandardTypeDescriptor::fromString(str);
00580     parameterTypes[1] = STANDARD_TYPE_REAL;
00581     table.add(
00582         "convert",
00583         parameterTypes,
00584         (ExtendedInstruction2<int, float>*) NULL,
00585         &convertFloatToInt);
00586     // lookup a function
00587     string s("convert(");
00588     s += str;
00589     s += ",r)";
00590     cout << s << endl;
00591     ExtendedInstructionDef *pDef = table[s];
00592     assert(pDef != NULL);
00593     assert(pDef->getName() == string("convert"));
00594     assert(pDef->getParameterTypes().size() == 2);
00595     // lookup non-existent, should return NULL
00596     ExtendedInstructionDef *pNonExistentDef = table["convert(d,r)"];
00597     assert(pNonExistentDef == NULL);
00598     // Set up the Calculator
00599     DynamicParamManager dpm;
00600     TestCalculator c(&dpm, true, pDef);
00601     c.setInput(0, &val);
00602     // setup registers
00603     vector<RegisterReference *> regRefs(2);
00604     regRefs[0] = new RegisterRef<int>(
00605         RegisterReference::EOutput, 0,
00606         STANDARD_TYPE_INT_32);
00607     regRefs[1] = new RegisterRef<float>(
00608         RegisterReference::EInput, 0,
00609         STANDARD_TYPE_REAL);
00610     c.appendRegRef(regRefs[0]);
00611     c.appendRegRef(regRefs[1]);
00612     c.bind();
00613     // create an instruction
00614     //ExtendedInstruction *pInstr = pDef->createInstruction(&c, regRefs);
00615     ExtendedInstruction *pInstr = pDef->createInstruction(regRefs);
00616     assert(pInstr != NULL);
00617     // execute it
00618     c.appendInstruction(pInstr);
00619     c.exec();
00620     c.printOutput();
00621     int d;
00622     c.getOutput(0, d);
00623     cout << d << endl;
00624     assert(expected == d);
00625 };

void testConvertIntTypesToFloat ( const char *const  str,
int  val,
float  expected 
)

Definition at line 627 of file testCalcExtended.cpp.

References ExtendedInstructionTable::add(), Calculator::appendInstruction(), Calculator::appendRegRef(), TestCalculator::bind(), convertIntToFloat(), ExtendedInstructionDef::createInstruction(), RegisterReference::EInput, RegisterReference::EOutput, Calculator::exec(), StandardTypeDescriptor::fromString(), ExtendedInstructionDef::getName(), TestCalculator::getOutput(), ExtendedInstructionDef::getParameterTypes(), TestCalculator::printOutput(), printTestHeader(), TestCalculator::setInput(), STANDARD_TYPE_INT_32, and STANDARD_TYPE_REAL.

Referenced by main().

00628 {
00629     printTestHeader("testConvertIntTypesToFloat()");
00630     ExtendedInstructionTable table;
00631     vector<StandardTypeDescriptorOrdinal> parameterTypes;
00632     // define a function
00633     parameterTypes.resize(2);
00634     parameterTypes[0] = STANDARD_TYPE_REAL;
00635     parameterTypes[1] = StandardTypeDescriptor::fromString(str);
00636     table.add(
00637         "convert",
00638         parameterTypes,
00639         (ExtendedInstruction2<float, int>*) NULL,
00640         &convertIntToFloat);
00641     // lookup a function
00642     string s("convert(r,");
00643     s += str;
00644     s += ")";
00645     cout << s << endl;
00646     ExtendedInstructionDef *pDef = table[s];
00647     assert(pDef != NULL);
00648     assert(pDef->getName() == string("convert"));
00649     assert(pDef->getParameterTypes().size() == 2);
00650     // Set up the Calculator
00651     DynamicParamManager dpm;
00652     TestCalculator c(&dpm, true, pDef);
00653     c.setInput(0, &val);
00654     // setup registers
00655     vector<RegisterReference *> regRefs(2);
00656     regRefs[0] = new RegisterRef<float>(
00657         RegisterReference::EOutput, 0,
00658         STANDARD_TYPE_REAL);
00659     regRefs[1] = new RegisterRef<int>(
00660         RegisterReference::EInput, 0,
00661         STANDARD_TYPE_INT_32);
00662     c.appendRegRef(regRefs[0]);
00663     c.appendRegRef(regRefs[1]);
00664     c.bind();
00665     // create an instruction
00666     //ExtendedInstruction *pInstr = pDef->createInstruction(&c, regRefs);
00667     ExtendedInstruction *pInstr = pDef->createInstruction(regRefs);
00668     assert(pInstr != NULL);
00669     // execute it
00670     c.appendInstruction(pInstr);
00671     c.exec();
00672     c.printOutput();
00673     float f;
00674     c.getOutput(0, f);
00675     cout << f << endl;
00676     assert(expected == f);
00677 };

void testConvertStringToExactNumber ( const char *  str,
int  expected 
)

Definition at line 741 of file testCalcExtended.cpp.

References ExtendedInstructionTable::add(), Calculator::appendInstruction(), Calculator::appendRegRef(), TestCalculator::bind(), convertStringToExactNumber(), ExtendedInstructionDef::createInstruction(), RegisterReference::EInput, RegisterReference::EOutput, Calculator::exec(), ExtendedInstructionDef::getName(), TestCalculator::getOutput(), ExtendedInstructionDef::getParameterTypes(), TestCalculator::printOutput(), printTestHeader(), TestCalculator::setInput(), STANDARD_TYPE_INT_32, and STANDARD_TYPE_VARCHAR.

Referenced by main().

00742 {
00743     printTestHeader("testConvertStringToExactNumber()");
00744     ExtendedInstructionTable table;
00745     vector<StandardTypeDescriptorOrdinal> parameterTypes;
00746     // define a function
00747     parameterTypes.resize(2);
00748     parameterTypes[0] = STANDARD_TYPE_INT_32;
00749     parameterTypes[1] = STANDARD_TYPE_VARCHAR;
00750 
00751     table.add(
00752         "convert",
00753         parameterTypes,
00754         (ExtendedInstruction2<int32_t, char *>*) NULL,
00755         &convertStringToExactNumber);
00756 
00757     // lookup a function
00758     ExtendedInstructionDef *pDef = table["convert(s4,vc)"];
00759     assert(pDef != NULL);
00760     assert(pDef->getName() == string("convert"));
00761     assert(pDef->getParameterTypes().size() == 2);
00762 
00763     // Set up the Calculator
00764     DynamicParamManager dpm;
00765     TestCalculator c(&dpm, true, pDef);
00766     c.setInput(0, str, strlen(str));
00767 
00768     // setup registers
00769     vector<RegisterReference *> regRefs(2);
00770     regRefs[0] = new RegisterRef<int32_t>(
00771         RegisterReference::EOutput, 0,
00772         STANDARD_TYPE_INT_32);
00773     regRefs[1] = new RegisterRef<char *>(
00774         RegisterReference::EInput, 0,
00775         STANDARD_TYPE_VARCHAR);
00776     c.appendRegRef(regRefs[0]);
00777     c.appendRegRef(regRefs[1]);
00778     c.bind();
00779 
00780     // create an instruction
00781     //ExtendedInstruction *pInstr = pDef->createInstruction(&c, regRefs);
00782     ExtendedInstruction *pInstr = pDef->createInstruction(regRefs);
00783     assert(pInstr != NULL);
00784     // execute it
00785     c.appendInstruction(pInstr);
00786     c.exec();
00787     c.printOutput();
00788     int i;
00789     c.getOutput(0, i);
00790     assert(i == expected);
00791     cout << i << endl;
00792 }

void testDateToString ( long long  d,
char *  expected 
)

Definition at line 864 of file testCalcExtended.cpp.

00865 {
00866 }

void testStringToApproximateNumber ( char *  str,
float  expected 
)

Definition at line 855 of file testCalcExtended.cpp.

00856 {
00857 }

void testStringToDate ( char *  str,
long long  expected 
)

Definition at line 861 of file testCalcExtended.cpp.

00862 {
00863 }


Variable Documentation

char* ProgramName

Definition at line 53 of file testCalcExtended.cpp.


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