/* Variant(Test) - verify the lightweight typesafe union record Copyright (C) 2015, Hermann Vosseler   **Lumiera** 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. See the file COPYING for further details. * *****************************************************************/ /** @file variant-test.cpp ** unit test \ref Variant_test */ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/time/timevalue.hpp" #include "lib/format-cout.hpp" #include "lib/variant.hpp" #include "lib/util.hpp" #include namespace lib { namespace test{ using ::Test; using meta::Types; using lib::time::Time; using lib::time::TimeVar; using util::contains; using std::string; using error::LUMIERA_ERROR_WRONG_TYPE; using error::LUMIERA_ERROR_LOGIC; // Test fixture... using TestVariant = Variant>; /****************************************************************************//** * @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 TreeMutator_test */ class Variant_test : public Test { virtual void run (Arg) { seedRand(); createVariant(); accessVariant(); acceptPredicate(); verifyAssignment(); } void createVariant() { Time someTime; TestVariant v0; TestVariant v1(11); TestVariant v2(string("lololo")); TestVariant v3(someTime); //// does not compile.... // TestVariant evil(3.1415); cout << v0 <() ); CHECK (someVal == v1.get()); CHECK (someStr == v2.get() ); CHECK (someTime == v3.get