From d75656dad7aaf95c1c7835ad3709f75b1fac7fbb Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 1 May 2013 12:41:19 -0400 Subject: [PATCH] testTypeCast use epicsUnitTest --- testApp/misc/Makefile | 18 +++---- testApp/misc/testTypeCast.cpp | 96 ++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 59 deletions(-) diff --git a/testApp/misc/Makefile b/testApp/misc/Makefile index 4e2cf83..2ed381d 100644 --- a/testApp/misc/Makefile +++ b/testApp/misc/Makefile @@ -2,51 +2,45 @@ TOP=../.. include $(TOP)/configure/CONFIG +PROD_LIBS += pvData Com + PROD_HOST += testThread testThread_SRCS += testThread.cpp -testThread_LIBS += pvData Com PROD_HOST += testTimer testTimer_SRCS += testTimer.cpp -testTimer_LIBS += pvData Com PROD_HOST += testBitSet testBitSet_SRCS += testBitSet.cpp -testBitSet_LIBS += pvData Com PROD_HOST += testByteOrder testByteOrder_SRCS += testByteOrder.cpp -testByteOrder_LIBS += Com PROD_HOST += testByteBuffer testByteBuffer_SRCS += testByteBuffer.cpp -testByteBuffer_LIBS += pvData Com PROD_HOST += testBaseException testBaseException_SRCS += testBaseException.cpp -testBaseException_LIBS += pvData Com PROD_HOST += testSerialization testSerialization_SRCS += testSerialization.cpp -testSerialization_LIBS += pvData Com PROD_HOST += testTimeStamp testTimeStamp_SRCS += testTimeStamp.cpp -testTimeStamp_LIBS += pvData Com PROD_HOST += testQueue testQueue_SRCS += testQueue.cpp -testQueue_LIBS += pvData Com PROD_HOST += testMessageQueue testMessageQueue_SRCS += testMessageQueue.cpp -testMessageQueue_LIBS += pvData Com -PROD_HOST += testTypeCast +TESTPROD += testTypeCast testTypeCast_SRCS += testTypeCast.cpp -testTypeCast_LIBS += pvData Com +TESTS += testTypeCast +TESTSCRIPTS_HOST += $(TESTS:%=%.t) + include $(TOP)/configure/RULES #---------------------------------------- # ADD RULES AFTER THIS LINE diff --git a/testApp/misc/testTypeCast.cpp b/testApp/misc/testTypeCast.cpp index d258edc..dc74d60 100644 --- a/testApp/misc/testTypeCast.cpp +++ b/testApp/misc/testTypeCast.cpp @@ -19,12 +19,11 @@ #include #include -#include +#include +#include #include "pv/typeCast.h" -#include - using epics::pvData::String; namespace { @@ -44,8 +43,9 @@ namespace { template struct testcase { - static bool op(std::ostream& msg, TO expect, FROM inp) + static void op(TO expect, FROM inp) { + std::ostringstream msg; TO actual; try { actual = ::epics::pvData::castUnsafe(inp); @@ -54,71 +54,69 @@ namespace { msg<<"Failed to cast " < " <::op(actual, expect)) { msg<<"Failed cast gives unexpected value " < " < " < struct testfail { - static bool op(std::ostream& msg, FROM inp) + static void op(FROM inp) { + std::ostringstream msg; TO actual; try { actual = ::epics::pvData::castUnsafe(inp); msg<<"Failed to generate expected error " < (" < (" <::op(*out, VTO, VFRO) +#define TEST(TTO, VTO, TFRO, VFRO) testcase::op(VTO, VFRO) // Test cast and reverse #define TEST2(TTO, VTO, TFRO, VFRO) TEST(TTO, VTO, TFRO, VFRO); TEST(TFRO, VFRO, TTO, VTO) -#define FAIL(TTO, TFRO, VFRO) fail |= !testfail::op(*out, VFRO) +#define FAIL(TTO, TFRO, VFRO) testfail::op(VFRO) } // end namespace -int main(int argc,char *argv[]) +MAIN(testTypeCast) { - std::ostream *out = &std::cerr; - std::ofstream outf; - if(argc>1){ - outf.open(argv[1]); - if(!outf.good()) { - std::cerr<<"Failed to open "< unsigned\n"; + testDiag("Integer signed <=> unsigned"); TEST2(uint8_t, std::numeric_limits::max(), int8_t, -1); TEST2(uint16_t, std::numeric_limits::max(), int8_t, -1); TEST2(uint32_t, std::numeric_limits::max(), int8_t, -1); TEST2(uint64_t, std::numeric_limits::max(), int8_t, -1); - *out << "Integer unsigned promote (and demote when in range)\n"; + testDiag("Integer unsigned promote (and demote when in range)"); TEST2(uint16_t, 0xff, uint8_t, 0xff); TEST2(uint32_t, 0xffff, uint16_t, 0xffff); @@ -290,7 +288,7 @@ int main(int argc,char *argv[]) TEST2(int32_t, 0x7fff, int16_t, 0x7fff); TEST2(int64_t, 0x7fffffff, int32_t, 0x7fffffff); - *out << "Double to int w/ round towards zero (aka truncation)\n"; + testDiag("Double to int w/ round towards zero (aka truncation)"); TEST(int32_t, 2, double, 2.1); TEST(int32_t, 2, double, 2.5); @@ -299,7 +297,7 @@ int main(int argc,char *argv[]) TEST(int32_t, -2, double, -2.5); TEST(int32_t, -2, double, -2.7); - *out << "Float to int w/ round towards zero (aka truncation)\n"; + testDiag("Float to int w/ round towards zero (aka truncation)"); TEST(int32_t, 2, float, 2.1); TEST(int32_t, 2, float, 2.5); @@ -308,7 +306,7 @@ int main(int argc,char *argv[]) TEST(int32_t, -2, float, -2.5); TEST(int32_t, -2, float, -2.7); - *out << "String Printing/parsing\n"; + testDiag("String Printing/parsing"); TEST2(String, "1", int32_t, 1); TEST2(String, "-1", int32_t, -1); @@ -339,7 +337,7 @@ int main(int argc,char *argv[]) TEST(double, 1.1e100, String, "1.1E+100"); - *out << "String Parsing\n"; + testDiag("String Parsing"); TEST(int32_t, 15, String, "0xf"); TEST(int32_t, 15, String, "0xF"); @@ -363,7 +361,7 @@ int main(int argc,char *argv[]) TEST(int64_t, -7, String, "-07"); TEST(int64_t, -8, String, "-010"); - *out << "String parsing errors\n"; + testDiag("String parsing errors"); FAIL(int32_t, String, "hello!"); FAIL(int32_t, String, "42 is the answer"); @@ -374,32 +372,36 @@ int main(int argc,char *argv[]) FAIL(int8_t, String, "1000"); FAIL(int8_t, String, "-1000"); - +; FAIL(double, String, "1e+10000000"); - *out << "Floating point overflows\n"; + testDiag("Floating point overflows"); TEST(float, FLT_MAX, double, 1e300); TEST(float, -FLT_MAX, double, -1e300); TEST(float, FLT_MIN, double, 1e-300); TEST(float, -FLT_MIN, double, -1e-300); + xfloat = ::epics::pvData::castUnsafe(epicsNAN); - *out << "Test cast double NAN to float NAN yields: "< String\n"; + testDiag("Test vcast int32 -> String"); epics::pvData::castUnsafeV(3, epics::pvData::pvString, (void*)result, epics::pvData::pvInt, (void*)in); - *out << "Yields "<