/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvxs is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include namespace { using namespace pvxs; template void testEmpty() { testDiag("%s", __func__); shared_array v; testOk1(v.unique()); testOk1(v.empty()); testEq(v.size(), 0u); } template void testInt() { testDiag("%s w/ %s", __func__, typeid(I).name()); shared_array X(2, 5); testOk1(X.unique()); testOk1(!X.empty()); if(testEq(X.size(), 2u)) { testEq(X[0], 5); testEq(X[1], 5); } shared_array Y(X); testOk1(!X.unique()); testOk1(!Y.unique()); testEq(X.size(), Y.size()); X.clear(); testOk1(X.unique()); testOk1(Y.unique()); testEq(X.size(), 0u); testEq(Y.size(), 2u); X = std::move(Y); testOk1(X.unique()); testOk1(Y.unique()); testEq(X.size(), 2u); testEq(Y.size(), 0u); shared_array Z(std::move(X)); testOk1(X.unique()); testOk1(Y.unique()); testOk1(Z.unique()); testEq(X.size(), 0u); testEq(Y.size(), 0u); testEq(Z.size(), 2u); // copy empty shared_array Q(Y); testOk1(Y.unique()); testOk1(Q.unique()); testEq(Y.size(), 0u); testEq(Q.size(), 0u); } template void testVoid() { testDiag("%s", __func__); shared_array X(2); shared_array Y(X.template castTo()); testOk1(!X.unique()); testOk1(!Y.unique()); testEq(X.size(), 2u); testEq(Y.size(), 8u); testEq(Y.original_type(), ArrayType::UInt32); // never const uint32_t testThrows([&Y]() { auto Z = Y.freeze(); }); X.clear(); testOk1(Y.unique()); auto Z = Y.freeze(); testOk1(Y.unique()); testOk1(Z.unique()); testEq(Y.size(), 0u); testEq(Z.size(), 8u); } void testFreeze() { testDiag("%s", __func__); shared_array X(2, 5); shared_array Y(X.freeze()); testOk1(X.unique()); testOk1(Y.unique()); testEq(X.size(), 0u); testEq(Y.size(), 2u); } void testFreezeError() { testDiag("%s", __func__); shared_array X(2, 5), Z(X); testOk1(!X.unique()); testThrows([&X]() { shared_array Y(X.freeze()); })<<"Attempt to freeze() non-unique"; } void testComplex() { testDiag("%s", __func__); shared_array> X(2, nullptr); X[0] = decltype (X)::value_type{new uint32_t(4u)}; testEq(*X[0], 4u); } } // namespace MAIN(testshared) { testPlan(93); testEmpty(); testEmpty(); testEmpty(); testEmpty(); testInt(); testInt(); testVoid(); testVoid(); testFreeze(); testFreezeError(); testComplex(); return testDone(); }