Fennel: /home/pub/open/dev/fennel/calctest/CalcExtDateTimeTest.cpp Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 #include "fennel/common/CommonPreamble.h" 00024 #include "fennel/test/TestBase.h" 00025 #include "fennel/common/TraceSource.h" 00026 00027 #include "fennel/tuple/TupleDataWithBuffer.h" 00028 #include "fennel/tuple/TuplePrinter.h" 00029 #include "fennel/calculator/CalcCommon.h" 00030 #include "fennel/common/FennelExcn.h" 00031 00032 #include <boost/test/test_tools.hpp> 00033 #include <boost/scoped_array.hpp> 00034 #include 00035 #include 00036 00037 using namespace fennel; 00038 using namespace std; 00039 00040 00041 class CalcExtDateTimeTest : virtual public TestBase, public TraceSource 00042 { 00043 void testCalcExtConvertDateToString(); 00044 void testCalcExtLocalTime(); 00045 void testCalcExtLocalTimestamp(); 00046 00047 void checkWarnings(Calculator& calc, string expected); 00048 void printOutput( 00049 TupleData const & tup, 00050 Calculator const & calc); 00051 00052 public: 00053 explicit CalcExtDateTimeTest() 00054 : TraceSource(shared_from_this(),"CalcExtDateTimeTest") 00055 { 00056 srand(time(NULL)); 00057 CalcInit::instance(); 00058 FENNEL_UNIT_TEST_CASE( 00059 CalcExtDateTimeTest, testCalcExtConvertDateToString); 00060 FENNEL_UNIT_TEST_CASE(CalcExtDateTimeTest, testCalcExtLocalTime); 00061 FENNEL_UNIT_TEST_CASE(CalcExtDateTimeTest, testCalcExtLocalTimestamp); 00062 } 00063 00064 virtual ~CalcExtDateTimeTest() 00065 { 00066 } 00067 00068
00069 00070 bool equals(TupleDatum buf, const char *expected) { 00071 char s = reinterpret_cast<char *>(const_cast(buf.pData)); 00072 return !strncmp(expected, s, buf.cbData); 00073 } 00074 }; 00075 00076 00077 void 00078 CalcExtDateTimeTest::printOutput( 00079 TupleData const & tup, 00080 Calculator const & calc) 00081 { 00082 #if 1 00083 TuplePrinter tuplePrinter; 00084 tuplePrinter.print(cout, calc.getOutputRegisterDescriptor(), tup); 00085 cout << endl; 00086 #endif 00087 } 00088 00089 00090 void 00091 CalcExtDateTimeTest::testCalcExtConvertDateToString() 00092 { 00093 ostringstream pg(""); 00094 00095 pg << "O vc,10;" << endl; 00096 pg << "L vc,10;" << endl; 00097 pg << "C s8;" << endl; 00098 pg << "V 115200000;" << endl; 00099 pg << "T;" << endl; 00100 pg << "CALL 'CastDateToStrA(L0, C0);" << endl; 00101 pg << "REF O0, L0;" << endl; 00102 00103 Calculator calc(0); 00104 00105 try { 00106 calc.assemble(pg.str().c_str()); 00107 } catch (FennelExcn& ex) { 00108 BOOST_FAIL("Assemble exception " << ex.getMessage()<< pg.str()); 00109 } 00110 00111 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00112 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00113 00114 calc.bind(&inTuple, &outTuple); 00115 calc.exec(); 00116
00117 00118 BOOST_CHECK(equals(outTuple[0], "1970-01-02")); 00119 } 00120 00121 void 00122 CalcExtDateTimeTest::testCalcExtLocalTime() 00123 { 00124 ostringstream pg(""); 00125 00126 pg << "O s8;" << endl; 00127 pg << "I s4;" << endl; 00128 pg << "L s8;" << endl; 00129 pg << "C bo, bo, c,23;" << endl; 00130 pg << "V 1, 0, 0x5053542D385044542C4D332E322E302C4D31312E312E30" 00131 " /
PST-8PDT,M3.2.0,M11.1.0 /;" << endl; 00132 pg << "T;" << endl; 00133 pg << "CALL 'LocalTime2(L0, C2) / 0: LOCALTIME($t1) /;" << endl; 00134 pg << "REF O0, L0 / 1: /;" << endl; 00135
00136 00137 Calculator calc(0); 00138 00139 try { 00140 calc.assemble(pg.str().c_str()); 00141 } catch (FennelExcn& ex) { 00142 BOOST_FAIL("Assemble exception " << ex.getMessage()<< pg.str()); 00143 } 00144 00145 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00146 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00147 00148 calc.bind(&inTuple, &outTuple); 00149 calc.exec(); 00150 printOutput(outTuple, calc); 00151 00152 } 00153 00154 void 00155 CalcExtDateTimeTest::testCalcExtLocalTimestamp() 00156 { 00157 ostringstream pg(""); 00158 00159 pg << "O s8;" << endl; 00160 pg << "I s4;" << endl; 00161 pg << "L s8;" << endl; 00162 pg << "C bo, bo, c,23;" << endl; 00163 pg << "V 1, 0, 0x5053542D385044542C4D332E322E302C4D31312E312E30" 00164 " /
PST-8PDT,M3.2.0,M11.1.0 /;" << endl; 00165 pg << "T;" << endl; 00166 pg << "CALL 'LocalTimestamp2(L0, C2) / 0: LOCALTIMESTAMP($t1) /;" << endl; 00167 pg << "REF O0, L0 / 1: */;" << endl; 00168
00169 00170 Calculator calc(0); 00171 00172 try { 00173 calc.assemble(pg.str().c_str()); 00174 } catch (FennelExcn& ex) { 00175 BOOST_FAIL("Assemble exception " << ex.getMessage()<< pg.str()); 00176 } 00177 00178 TupleDataWithBuffer outTuple(calc.getOutputRegisterDescriptor()); 00179 TupleDataWithBuffer inTuple(calc.getInputRegisterDescriptor()); 00180 00181 calc.bind(&inTuple, &outTuple); 00182 calc.exec(); 00183 printOutput(outTuple, calc); 00184 00185 } 00186 00187 FENNEL_UNIT_TEST_SUITE(CalcExtDateTimeTest); 00188 00189