/* GenericRecordRepresentation(Test) - introspective representation of object-like data 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/diff/record.hpp" #include "lib/itertools.hpp" #include "lib/util.hpp" //////TODO necessary? #include //#include #include #include using std::string; using util::isSameObject; using util::isnil; using std::vector; //using std::swap; using std::cout; using std::endl; namespace lib { namespace diff{ namespace test{ // using lumiera::error::LUMIERA_ERROR_LOGIC; using lumiera::error::LUMIERA_ERROR_INVALID; using lumiera::error::LUMIERA_ERROR_BOTTOM_VALUE; namespace {//Test fixture.... using Seq = vector; using RecS = Record; template inline Seq contents (IT const& it) { Seq collected; append_all (it, collected); return collected; } inline Seq contents (RecS const& rec_of_strings) { return contents (rec_of_strings.begin()); } template inline Seq strings (std::initializer_list const& con) { Seq collected; for (auto elm : con) collected.push_back(elm); return collected; } }//(End)Test fixture /*************************************************************************************//** * @test Verify properties of a special collection type meant for external representation * of object-like data. * * @see IndexTable * @see DiffListApplication_test */ class GenericRecordRepresentation_test : public Test { virtual void run (Arg) { simpleUsage(); verifyCreation(); verifyMutations(); copy_and_move(); equality(); wrapRef(); } void simpleUsage() { RecS enterprise("starship" , strings ({"Name = USS Enterprise" ,"Registry = NCC-1701-D" ,"Class = Galaxy" ,"Owner = United Federation of Planets" ,"built=2363" }) , strings ({"Picard", "Riker", "Data", "Troi", "Worf", "Crusher", "La Forge"}) ); CHECK (enterprise.getType() == "starship"); CHECK (enterprise.get("Registry") == "NCC-1701-D"); CHECK (enterprise.hasAttribute("Owner")); CHECK (!enterprise.hasAttribute("owner")); CHECK (!enterprise.hasAttribute("Owner ")); CHECK (enterprise.contains("Data")); CHECK (!enterprise.contains("Woof")); CHECK (util::contains (enterprise, "Worf")); VERIFY_ERROR (INVALID, enterprise.get("warp10")); cout << "enterprise = " << string(enterprise)< empty; CHECK (bool(empty) == false); CHECK (nullptr == empty.get()); VERIFY_ERROR (BOTTOM_VALUE, empty.operator RecS&() ); RecordRef ref(oo); CHECK (ref); CHECK (ref.get() == &oo); RecS& oor = ref; CHECK ("🌰" == oor.getType()); CHECK (oor.get("♄") == "saturn"); // are copyable and assignable RecordRef r2 = ref; CHECK (r2); CHECK (r2.get() == ref.get()); CHECK (!isSameObject (r2, ref)); empty = std::move(r2); CHECK (empty); CHECK (!r2); CHECK (nullptr == r2.get()); } }; /** Register this test class... */ LAUNCHER (GenericRecordRepresentation_test, "unit common"); }}} // namespace lib::diff::test