From eb263d44d75c8c300567942432f705fb7b2a7e7f Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 16 Apr 2015 20:29:03 +0200 Subject: [PATCH] TICKET #738: design API of a new variant implementation - we do not want type mutations - we do not want "empty" records ever - we do not support "probing" for contents - visitor style access for generic value handling --- tests/library/variant-test.cpp | 232 +++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 tests/library/variant-test.cpp diff --git a/tests/library/variant-test.cpp b/tests/library/variant-test.cpp new file mode 100644 index 000000000..2d6421c21 --- /dev/null +++ b/tests/library/variant-test.cpp @@ -0,0 +1,232 @@ +/* + Variant(Test) - verify the lightweight typesafe union record + + Copyright (C) Lumiera.org + 2015, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + + + +#include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +#include "lib/util.hpp" + + +//#include +#include +#include +//#include +//using boost::lexical_cast; +#include + +using util::contains; +using std::string; +using std::cout; +using std::endl; + + +namespace lib { +namespace test{ + + using ::Test; + + namespace { // test fixture... + + }//(End) test fixture + + typedef Variant> TestVariant; + + + + /****************************************************************************//** + * @test cover the essential properties of Lumiera's lightweight variant record. + * - this typesafe union can never be constructed empty + * - it defaults to the default constructed first type in list + * - it is copyable and assignable, but only with compatible type + * - value access requires knowledge of the contained type + * - generic visitor style access + * + * @see lib::Variant + * @see util::AccessCasted + * @see lib::OpaqueHolder + * @see GenericTreeMutator_test + */ + class Variant_test : public Test + { + + virtual void + run (Arg) + { + createVariant(); + accessVariant(); + verifyAssignment(); + } + + + void + createVariant() + { + TestVariant v0; + TestVariant v1(11); + TestVariant v2("lololo"); + + auto v3 = TestVariant::empty