#include #include #include #include #include "anyscalar.h" namespace pvd = epics::pvData; namespace { void test_empty() { testDiag("test_empty()"); AnyScalar O; testOk1(O.empty()); testOk1(!O); testThrows(AnyScalar::bad_cast, O.ref()); testThrows(AnyScalar::bad_cast, O.as()); } void test_basic() { testDiag("test_basic()"); AnyScalar I(42); testOk1(!I.empty()); testOk1(!!I); testEqual(I.type(), pvd::pvInt); testEqual(I.ref(), 42); testEqual(I.as(), 42); testEqual(I.as(), 42.0); testEqual(I.as(), "42"); testThrows(AnyScalar::bad_cast, I.ref()); { std::ostringstream strm; strm<() = 43; testEqual(I.ref(), 43); testEqual(I.as(), 43); testEqual(I.as(), 43.0); I = AnyScalar("hello"); testEqual(I.type(), pvd::pvString); testEqual(I.ref(), "hello"); testEqual(I.as(), "hello"); testThrows(AnyScalar::bad_cast, I.ref()); { AnyScalar O(I); testOk1(!I.empty()); testOk1(!O.empty()); testEqual(I.ref(), "hello"); testEqual(O.ref(), "hello"); } { AnyScalar O; I.swap(O); testOk1(I.empty()); testOk1(!O.empty()); testThrows(AnyScalar::bad_cast, I.ref()); testEqual(O.ref(), "hello"); I.swap(O); } } } MAIN(testanyscalar) { testPlan(28); try { test_empty(); test_basic(); }catch(std::exception& e){ testAbort("Unexpected exception: %s", e.what()); } return testDone(); }