diff --git a/src/lib/p.hpp b/src/lib/p.hpp index 8bb46aacb..4ac393a18 100644 --- a/src/lib/p.hpp +++ b/src/lib/p.hpp @@ -41,7 +41,7 @@ ** as template parameter. ** ** @see asset.hpp - ** @see customsharedptrtest.cpp + ** @see custom-shared-ptr-test.cpp ** @see orderingofassetstest.cpp */ diff --git a/tests/components/proc/asset/asset-category-test.cpp b/tests/components/proc/asset/asset-category-test.cpp new file mode 100644 index 000000000..a211cd963 --- /dev/null +++ b/tests/components/proc/asset/asset-category-test.cpp @@ -0,0 +1,140 @@ +/* + AssetCategory(Test) - verifying Asset category tuple functions + + Copyright (C) Lumiera.org + 2008, 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/util.hpp" + +#include "proc/asset/category.hpp" + +#include +#include + +using boost::format; +using util::isnil; +using std::string; +using std::cout; + + +namespace asset{ +namespace test { + + + + + /*********************************************************************** + * @test checking the properties of Asset Category structs. + * They are included in the Asset::Ident identification tuple + * of Assets and can be used to organize Assets into a tree + * like structure + */ + class AssetCategory_test : public Test + { + virtual void run(Arg) + { + createCategory(); + containmentQuery(); + ordering(); + } + + + + + void createCategory() + { + Category c1 (AUDIO); + Category c2 (VIDEO,"bin1"); + Category c3 (VIDEO,"bin1/subbin"); + Category c4 (EFFECT,"some_kind"); + + format fmt ("Category: %s"); + + cout << fmt % c1 << "\n"; + cout << fmt % c2 << "\n"; + cout << fmt % c3 << "\n"; + cout << fmt % c4 << "\n"; + } + + + void containmentQuery() + { + Category c1 (VIDEO); + Category c2 (VIDEO,"bin1"); + Category c3 (VIDEO,"bin1/subbin"); + Category c4 (EFFECT,"some_kind"); + + ASSERT ( c1.hasKind(VIDEO) ); + ASSERT (!c1.hasKind(AUDIO) ); + ASSERT ( c2.isWithin(c1) ); + ASSERT ( c3.isWithin(c2) ); + ASSERT ( c3.isWithin(c1) ); + ASSERT (!c1.isWithin(c2) ); + ASSERT (!c2.isWithin(c3) ); + ASSERT (!c1.isWithin(c3) ); + ASSERT (!c3.isWithin(c4) ); + ASSERT (!c4.isWithin(c3) ); + } + + + void ordering() + { + Category c1 (AUDIO); + Category c2 (VIDEO); + Category c3 (EFFECT); + Category c4 (CODEC); + Category c5 (STRUCT); + Category c6 (META); + + ASSERT (0 > c1.compare(c2)); + ASSERT (0 > c2.compare(c3)); + ASSERT (0 > c3.compare(c4)); + ASSERT (0 > c4.compare(c5)); + ASSERT (0 > c5.compare(c6)); + + ASSERT (0 ==c1.compare(c1)); + ASSERT (0 > c1.compare(c6)); + + Category c21 (VIDEO,"bin1"); + Category c22 (VIDEO,"bin2"); + Category c23 (VIDEO,"bin2/sub"); + + ASSERT (0 > c1.compare(c21)); + ASSERT (0 > c2.compare(c21)); + ASSERT (0 < c22.compare(c21)); + ASSERT (0 < c23.compare(c22)); + ASSERT (0 < c23.compare(c21)); + ASSERT ( 0==c22.compare(c22)); + + + ASSERT ( c2 == c2 ); + ASSERT ( c2 != c22 ); + ASSERT ( c2 != c3 ); + } + }; + + + /** Register this test class... */ + LAUNCHER (AssetCategory_test, "unit asset"); + + + +}} // namespace asset::test diff --git a/tests/components/proc/asset/assetcategorytest.cpp b/tests/components/proc/asset/assetcategorytest.cpp deleted file mode 100644 index 245443eed..000000000 --- a/tests/components/proc/asset/assetcategorytest.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - AssetCategory(Test) - verifying Asset category tuple functions - - Copyright (C) Lumiera.org - 2008, 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/util.hpp" - -#include "proc/asset/category.hpp" - -#include -#include - -using boost::format; -using util::isnil; -using std::string; -using std::cout; - - -namespace asset - { - namespace test - { - - - - - /*********************************************************************** - * @test checking the properties of Asset Category structs. - * They are included in the Asset::Ident identification tuple - * of Assets and can be used to organize Assets into a tree - * like structure - */ - class AssetCategory_test : public Test - { - virtual void run(Arg) - { - createCategory(); - containmentQuery(); - ordering(); - } - - - - - void createCategory() - { - Category c1 (AUDIO); - Category c2 (VIDEO,"bin1"); - Category c3 (VIDEO,"bin1/subbin"); - Category c4 (EFFECT,"some_kind"); - - format fmt ("Category: %s"); - - cout << fmt % c1 << "\n"; - cout << fmt % c2 << "\n"; - cout << fmt % c3 << "\n"; - cout << fmt % c4 << "\n"; - } - - - void containmentQuery() - { - Category c1 (VIDEO); - Category c2 (VIDEO,"bin1"); - Category c3 (VIDEO,"bin1/subbin"); - Category c4 (EFFECT,"some_kind"); - - ASSERT ( c1.hasKind(VIDEO) ); - ASSERT (!c1.hasKind(AUDIO) ); - ASSERT ( c2.isWithin(c1) ); - ASSERT ( c3.isWithin(c2) ); - ASSERT ( c3.isWithin(c1) ); - ASSERT (!c1.isWithin(c2) ); - ASSERT (!c2.isWithin(c3) ); - ASSERT (!c1.isWithin(c3) ); - ASSERT (!c3.isWithin(c4) ); - ASSERT (!c4.isWithin(c3) ); - } - - - void ordering() - { - Category c1 (AUDIO); - Category c2 (VIDEO); - Category c3 (EFFECT); - Category c4 (CODEC); - Category c5 (STRUCT); - Category c6 (META); - - ASSERT (0 > c1.compare(c2)); - ASSERT (0 > c2.compare(c3)); - ASSERT (0 > c3.compare(c4)); - ASSERT (0 > c4.compare(c5)); - ASSERT (0 > c5.compare(c6)); - - ASSERT (0 ==c1.compare(c1)); - ASSERT (0 > c1.compare(c6)); - - Category c21 (VIDEO,"bin1"); - Category c22 (VIDEO,"bin2"); - Category c23 (VIDEO,"bin2/sub"); - - ASSERT (0 > c1.compare(c21)); - ASSERT (0 > c2.compare(c21)); - ASSERT (0 < c22.compare(c21)); - ASSERT (0 < c23.compare(c22)); - ASSERT (0 < c23.compare(c21)); - ASSERT ( 0==c22.compare(c22)); - - - ASSERT ( c2 == c2 ); - ASSERT ( c2 != c22 ); - ASSERT ( c2 != c3 ); - } - }; - - - /** Register this test class... */ - LAUNCHER (AssetCategory_test, "unit asset"); - - - - } // namespace test - -} // namespace asset diff --git a/tests/components/proc/asset/create-asset-test.cpp b/tests/components/proc/asset/create-asset-test.cpp new file mode 100644 index 000000000..cec6d97ef --- /dev/null +++ b/tests/components/proc/asset/create-asset-test.cpp @@ -0,0 +1,204 @@ +/* + CreateAsset(Test) - constructing and registering Assets + + Copyright (C) Lumiera.org + 2008, 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 "include/logging.h" +#include "lib/test/run.hpp" +#include "lib/util.hpp" + +#include "proc/assetmanager.hpp" +#include "proc/asset/media.hpp" +#include "proc/asset/proc.hpp" + +#include "proc/asset/asset-diagnostics.hpp" + +using util::isnil; +using std::string; + + +namespace asset { +namespace test { + + + + + /*********************************************************************** + * @test creating new Assets and registering them with the AssetManager. + * @see proc_interface::AssetManager#reg + */ + class CreateAsset_test : public Test + { + virtual void run(Arg arg) + { + createMedia(); + factoryVariants(); + + if (!isnil (arg)) + dumpAssetManager(); + TRACE (asset_mem, "leaving CreateAsset_test::run()"); + } + + + ////////////////////////////////////TICKET #589 + typedef P PM; /////TODO: transition to P<> + + /** @test Creating and automatically registering Asset instances. + * Re-Retrieving the newly created objects from AssetManager. + * Checking AssetManager access functions, esp. getting + * different kinds of Assets by ID, querying with the + * wrong Category and querying unknown IDs. + */ + void createMedia() + { + Category cat(VIDEO,"bin1"); + Asset::Ident key("Name-1", cat, "ichthyo", 5); + PM mm1 = asset::Media::create(key,"testfile.mov"); + PM mm2 = asset::Media::create("testfile1.mov", cat); + PM mm3 = asset::Media::create("testfile2.mov", VIDEO); + + // Assets have been registered and can be retrieved by ID + AssetManager& aMang = AssetManager::instance(); + PM registered; /////TODO: transition to P<> + registered = aMang.getAsset (mm1->getID()); + ASSERT (registered == mm1); + registered = aMang.getAsset (mm2->getID()); + ASSERT (registered == mm2); + registered = aMang.getAsset (mm3->getID()); + ASSERT (registered == mm3); + + registered = aMang.getAsset (mm1->getID()); + ASSERT (registered != mm2); +/* +* TODO: switch back to original version +* once the transition to P is done... +* + ASSERT (aMang.getAsset (mm1->getID()) == mm1); + ASSERT (aMang.getAsset (mm2->getID()) == mm2); + ASSERT (aMang.getAsset (mm3->getID()) == mm3); + + ASSERT (aMang.getAsset (mm1->getID()) != mm2); +*/ + PAsset aa1 = aMang.getAsset (ID(mm1->getID())); // note we get an Asset ref + ASSERT (aa1 == mm1); + PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref + ASSERT (mX1 == mm1); + ASSERT (mX1 == aa1); + + ASSERT (aMang.known (mm1->getID())); + ASSERT (aMang.known (mm2->getID())); + ASSERT (aMang.known (mm3->getID())); + + ASSERT ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category + try + { // can't be found if specifying wrong Asset kind.... + aMang.getAsset (ID(mm1->getID())); + NOTREACHED(); + } + catch (lumiera::error::Invalid& xxx) {ASSERT (xxx.getID()==LUMIERA_ERROR_WRONG_ASSET_KIND);} + try + { // try accessing nonexistent ID + aMang.getAsset (ID (1234567890)); + NOTREACHED(); + } + catch (lumiera::error::Invalid& xxx) {ASSERT (xxx.getID()==LUMIERA_ERROR_UNKNOWN_ASSET_ID);} + lumiera_error (); // reset errorflag + + + // checking the Ident-Fields + ASSERT (mm1->ident.name == "Name-1"); + ASSERT (mm2->ident.name == "testfile1"); + ASSERT (mm3->ident.name == "testfile2"); + + ASSERT (cat == Category (VIDEO,"bin1")); + ASSERT (mm1->ident.category == Category (VIDEO,"bin1")); + ASSERT (mm2->ident.category == Category (VIDEO,"bin1")); + ASSERT (mm3->ident.category == Category (VIDEO )); + + ASSERT (mm1->ident.org == "ichthyo"); + ASSERT (mm2->ident.org == "lumi"); + ASSERT (mm3->ident.org == "lumi"); + + ASSERT (mm1->ident.version == 5); + ASSERT (mm2->ident.version == 1); + ASSERT (mm3->ident.version == 1); + + ASSERT (mm1->getFilename() == "testfile.mov"); + ASSERT (mm2->getFilename() == "testfile1.mov"); + ASSERT (mm3->getFilename() == "testfile2.mov"); + + + TRACE (asset_mem, "leaving test method scope"); + } + + + /** @test different variants of calling the MediaFactory, + * with focus on the behaviour of the basic Asset + * creation machinery. Covers filling out Asset's + * datafields, amending missing pieces of information. + */ + void factoryVariants() + { + PM candi; + + Asset::Ident key1("Au-1", Category(AUDIO), "ichthyo", 5); + candi = asset::Media::create(key1); + ASSERT ( checkProperties (candi, key1, "")); + + candi = asset::Media::create(key1, string("testfile.wav")); + ASSERT ( checkProperties (candi, key1, "testfile.wav")); + + Asset::Ident key2("", Category(AUDIO), "ichthyo", 5); + candi = asset::Media::create(key2, string("testfile2.wav")); + ASSERT ( checkProperties (candi, key2, "testfile2.wav")); + ASSERT (key2.name == "testfile2"); // name filled in automatically + + candi = asset::Media::create(string("testfile3.wav"), Category(AUDIO)); + ASSERT ( checkProperties (candi, Asset::Ident("testfile3", Category(AUDIO), "lumi", 1) + , "testfile3.wav")); + + candi = asset::Media::create("some/path/testfile4.wav", Category(AUDIO)); + ASSERT ( checkProperties (candi, Asset::Ident("testfile4", Category(AUDIO), "lumi", 1) + , "some/path/testfile4.wav")); + + candi = asset::Media::create("", Category(AUDIO,"sub/bin")); + ASSERT ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "lumi", 1) + , "")); + + candi = asset::Media::create("", AUDIO); + ASSERT ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "lumi", 1) + , "")); + } + + bool checkProperties (PM object, Asset::Ident identity, string filename) + { + return identity == object->ident + && filename == object->getFilename(); + } + }; + + + /** Register this test class... */ + LAUNCHER (CreateAsset_test, "unit asset"); + + + +}} // namespace asset::test diff --git a/tests/components/proc/asset/createassettest.cpp b/tests/components/proc/asset/createassettest.cpp deleted file mode 100644 index 719b7756f..000000000 --- a/tests/components/proc/asset/createassettest.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - CreateAsset(Test) - constructing and registering Assets - - Copyright (C) Lumiera.org - 2008, 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 "include/logging.h" -#include "lib/test/run.hpp" -#include "lib/util.hpp" - -#include "proc/assetmanager.hpp" -#include "proc/asset/media.hpp" -#include "proc/asset/proc.hpp" - -#include "proc/asset/asset-diagnostics.hpp" - -using util::isnil; -using std::string; - - -namespace asset - { - namespace test - { - - - - - /*********************************************************************** - * @test creating new Assets and registering them with the AssetManager. - * @see proc_interface::AssetManager#reg - */ - class CreateAsset_test : public Test - { - virtual void run(Arg arg) - { - createMedia(); - factoryVariants(); - - if (!isnil (arg)) - dumpAssetManager(); - TRACE (asset_mem, "leaving CreateAsset_test::run()"); - } - - - - typedef P PM; /////TODO: transition to P<> - - /** @test Creating and automatically registering Asset instances. - * Re-Retrieving the newly created objects from AssetManager. - * Checking AssetManager access functions, esp. getting - * different kinds of Assets by ID, querying with the - * wrong Category and querying unknown IDs. - */ - void createMedia() - { - Category cat(VIDEO,"bin1"); - Asset::Ident key("Name-1", cat, "ichthyo", 5); - PM mm1 = asset::Media::create(key,"testfile.mov"); - PM mm2 = asset::Media::create("testfile1.mov", cat); - PM mm3 = asset::Media::create("testfile2.mov", VIDEO); - - // Assets have been registered and can be retrieved by ID - AssetManager& aMang = AssetManager::instance(); - PM registered; /////TODO: transition to P<> - registered = aMang.getAsset (mm1->getID()); - ASSERT (registered == mm1); - registered = aMang.getAsset (mm2->getID()); - ASSERT (registered == mm2); - registered = aMang.getAsset (mm3->getID()); - ASSERT (registered == mm3); - - registered = aMang.getAsset (mm1->getID()); - ASSERT (registered != mm2); -/* - * TODO: switch back to original version - * once the transition to P ist done... - * - ASSERT (aMang.getAsset (mm1->getID()) == mm1); - ASSERT (aMang.getAsset (mm2->getID()) == mm2); - ASSERT (aMang.getAsset (mm3->getID()) == mm3); - - ASSERT (aMang.getAsset (mm1->getID()) != mm2); -*/ - PAsset aa1 = aMang.getAsset (ID(mm1->getID())); // note we get an Asset ref - ASSERT (aa1 == mm1); - PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref - ASSERT (mX1 == mm1); - ASSERT (mX1 == aa1); - - ASSERT (aMang.known (mm1->getID())); - ASSERT (aMang.known (mm2->getID())); - ASSERT (aMang.known (mm3->getID())); - - ASSERT ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category - try - { // can't be found if specifying wrong Asset kind.... - aMang.getAsset (ID(mm1->getID())); - NOTREACHED(); - } - catch (lumiera::error::Invalid& xxx) {ASSERT (xxx.getID()==LUMIERA_ERROR_WRONG_ASSET_KIND);} - try - { // try accessing nonexistant ID - aMang.getAsset (ID (1234567890)); - NOTREACHED(); - } - catch (lumiera::error::Invalid& xxx) {ASSERT (xxx.getID()==LUMIERA_ERROR_UNKNOWN_ASSET_ID);} - lumiera_error (); // reset errorflag - - - // checking the Ident-Fields - ASSERT (mm1->ident.name == "Name-1"); - ASSERT (mm2->ident.name == "testfile1"); - ASSERT (mm3->ident.name == "testfile2"); - - ASSERT (cat == Category (VIDEO,"bin1")); - ASSERT (mm1->ident.category == Category (VIDEO,"bin1")); - ASSERT (mm2->ident.category == Category (VIDEO,"bin1")); - ASSERT (mm3->ident.category == Category (VIDEO )); - - ASSERT (mm1->ident.org == "ichthyo"); - ASSERT (mm2->ident.org == "lumi"); - ASSERT (mm3->ident.org == "lumi"); - - ASSERT (mm1->ident.version == 5); - ASSERT (mm2->ident.version == 1); - ASSERT (mm3->ident.version == 1); - - ASSERT (mm1->getFilename() == "testfile.mov"); - ASSERT (mm2->getFilename() == "testfile1.mov"); - ASSERT (mm3->getFilename() == "testfile2.mov"); - - - TRACE (asset_mem, "leaving test method scope"); - } - - - /** @test different variants of calling the MediaFactory, - * with focus on the behaviour of the basic Asset - * creation machinery. Covers filling out Asset's - * datafields, amending missing pieces of information. - */ - void factoryVariants() - { - PM candi; - - Asset::Ident key1("Au-1", Category(AUDIO), "ichthyo", 5); - candi = asset::Media::create(key1); - ASSERT ( checkProperties (candi, key1, "")); - - candi = asset::Media::create(key1, string("testfile.wav")); - ASSERT ( checkProperties (candi, key1, "testfile.wav")); - - Asset::Ident key2("", Category(AUDIO), "ichthyo", 5); - candi = asset::Media::create(key2, string("testfile2.wav")); - ASSERT ( checkProperties (candi, key2, "testfile2.wav")); - ASSERT (key2.name == "testfile2"); // name filled in automatically - - candi = asset::Media::create(string("testfile3.wav"), Category(AUDIO)); - ASSERT ( checkProperties (candi, Asset::Ident("testfile3", Category(AUDIO), "lumi", 1) - , "testfile3.wav")); - - candi = asset::Media::create("some/path/testfile4.wav", Category(AUDIO)); - ASSERT ( checkProperties (candi, Asset::Ident("testfile4", Category(AUDIO), "lumi", 1) - , "some/path/testfile4.wav")); - - candi = asset::Media::create("", Category(AUDIO,"sub/bin")); - ASSERT ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "lumi", 1) - , "")); - - candi = asset::Media::create("", AUDIO); - ASSERT ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "lumi", 1) - , "")); - } - - bool checkProperties (PM object, Asset::Ident identity, string filename) - { - return identity == object->ident - && filename == object->getFilename(); - } - }; - - - /** Register this test class... */ - LAUNCHER (CreateAsset_test, "unit asset"); - - - - } // namespace test - -} // namespace asset diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index d70cd432e..4909b6265 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -40,7 +40,7 @@ test_lib_SOURCES = \ $(testlib_srcdir)/mainsuite.cpp \ $(testlib_srcdir)/allocationclustertest.cpp \ $(testlib_srcdir)/appconfigtest.cpp \ - $(testlib_srcdir)/customsharedptrtest.cpp \ + $(testlib_srcdir)/custom-shared-ptr-test.cpp \ $(testlib_srcdir)/bool-checkable-test.cpp \ $(testlib_srcdir)/exceptionerrortest.cpp \ $(testlib_srcdir)/factory-special-test.cpp \ diff --git a/tests/lib/custom-shared-ptr-test.cpp b/tests/lib/custom-shared-ptr-test.cpp new file mode 100644 index 000000000..fe85e5149 --- /dev/null +++ b/tests/lib/custom-shared-ptr-test.cpp @@ -0,0 +1,325 @@ +/* + CustomSharedPtr(Test) - ref counting, equality and comparisons + + Copyright (C) Lumiera.org + 2008-2010, 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 "lib/p.hpp" + +#include + + + +namespace lib { +namespace test{ + + using lumiera::P; + using std::string; + using std::tr1::shared_ptr; + using std::tr1::weak_ptr; + + using lumiera::error::LUMIERA_ERROR_ASSERTION; + + + struct X + : boost::totally_ordered + { + long x_; + + X(long x=0) : x_(x) {} + operator long () { return x_; } + + bool operator< (const X& ox) const { return x_ < ox.x_; } + bool operator== (const X& ox) const { return x_ == ox.x_; } + + virtual ~X() {} // using RTTI + }; + + struct XX : public X + { + long xx_; + + XX(long x=0) : X(x), xx_(x+1) {} + }; + + + /**************************************************************** + * @test assure correct behaviour of lumiera's custom shared-ptr, + * including ADL of operators, shared ownership, typing + * and ordering + * @see lumiera::P + */ + class CustomSharedPtr_test : public Test + { + virtual void + run (Arg) + { + check_refcounting (); + check_shared_ownership (); + check_type_relations (); + check_ordering (); + } + + + /** @test smart-ptr basic behaviour */ + void + check_refcounting () + { + P p1 (new X(7)); + ASSERT (p1); + ASSERT (1 == p1.use_count()); + ASSERT (7 == p1->x_); + + { + P p2 (new X(9)); + ASSERT (1 == p2.use_count()); + + p2.swap (p1); + ASSERT (1 == p1.use_count()); + ASSERT (1 == p2.use_count()); + + p2 = p1; + ASSERT (2 == p1.use_count()); + ASSERT (2 == p2.use_count()); + } + + ASSERT (1 == p1.use_count()); + ASSERT (9 == p1->x_); + + p1.reset(); + ASSERT (0 == p1.use_count()); + ASSERT (!p1); + } + + + /** @test cooperation with other shared-ptr types */ + void + check_shared_ownership () + { + std::auto_ptr au (new X(22)); + ASSERT (au.get()); + + P pX (au); + ASSERT (!au.get()); + ASSERT (pX); + ASSERT (1 == pX.use_count()); + ASSERT (22 == pX->x_); + + weak_ptr wX (pX); + ASSERT (wX.lock()); + ASSERT (1 == pX.use_count()); + + shared_ptr sp1 (wX); + shared_ptr sp2 (pX); + shared_ptr sp3; sp3 = pX; + + ASSERT (22 == sp3->x_); + ASSERT (4 == pX.use_count()); + ASSERT (*pX == *sp1); + ASSERT (*sp1 == *sp2); + ASSERT (*sp2 == *sp3); + + P pX2; + pX2.swap(pX); + ASSERT (!pX); + ASSERT (0 == pX.use_count()); + ASSERT (4 == pX2.use_count()); + + P > pXX (pX2); // a different type, but compatible pointers + pX2 = pX; + ASSERT (!pX2); + ASSERT (0 == pX2.use_count()); + ASSERT (4 == pXX.use_count()); + + sp3 = sp2 = sp1 = pX; + ASSERT (22 == pXX->x_); + ASSERT (1 == pXX.use_count()); + ASSERT (!sp1); + ASSERT (!sp2); + ASSERT (!sp3); + + ASSERT (22 == wX.lock()->x_); + ASSERT (1 == pXX.use_count()); + + pXX.reset(); + ASSERT (!pXX); + ASSERT (!wX.lock()); + } + + + /** @test building type relationships on smart-ptrs */ + void + check_type_relations () + { + P pX; // Base: shared_ptr + P pX1; // Base: shared_ptr + P > pX2; // Base: P + P > pX3; // Base: shared_ptr + P > pLo;// Base: shared_ptr (rather nonsense, but well...) + P pLoL; // Base: std::string + P pLoLoL; // Base: shared_ptr + + ASSERT (INSTANCEOF (shared_ptr, &pX)); + + ASSERT ( INSTANCEOF (shared_ptr, &pX1)); +// ASSERT (!INSTANCEOF (shared_ptr, &pX1)); // doesn't compile (no RTTI) -- that's correct +// ASSERT (!INSTANCEOF (P, &pX1)); // similar, type mismatch detected by compiler + + ASSERT ( INSTANCEOF (shared_ptr, &pX2)); +// ASSERT (!INSTANCEOF (shared_ptr, &pX2)); + ASSERT ( INSTANCEOF (P, &pX2)); + + ASSERT ( INSTANCEOF (shared_ptr, &pX3)); +// ASSERT (!INSTANCEOF (shared_ptr, &pX3)); +// ASSERT (!INSTANCEOF (P, &pX3)); + + ASSERT ( INSTANCEOF (shared_ptr, &pLo)); +// ASSERT (!INSTANCEOF (shared_ptr, &pLo)); +// ASSERT (!INSTANCEOF (P, &pLo)); + +// ASSERT (!INSTANCEOF (shared_ptr, &pLoL)); +// ASSERT (!INSTANCEOF (shared_ptr, &pLoL)); +// ASSERT (!INSTANCEOF (P, &pLoL)); + ASSERT ( INSTANCEOF (string, &pLoL)); + + ASSERT ( INSTANCEOF (shared_ptr, &pLoLoL)); +// ASSERT (!INSTANCEOF (string, &pLoLoL)); +// ASSERT (!INSTANCEOF (shared_ptr, &pLoLoL)); + + pX = pX1; // OK: pointee subtype... + pX = pX2; // invokes shared_ptr::operator= (shared_ptr const&) + pX = pX3; +// pX = pLo; // similar, but long* not assignable to X* +// pX = pLoL; // similar, but string* not assignable to X* +// pX = pLoLoL; // same... + // you won't be able to do much with the "LoLo"-Types, + // as their types and pointee types's relations don't match + + pX.reset (new XX(5)); + ASSERT (5 == *pX); // implicit conversion from X to long + + pX2 = pX; // works, because both are implemented in terms of shared_ptr + ASSERT (5 == pX2->x_); + ASSERT (6 == pX2->xx_); // using the XX interface (performing dynamic downcast) + + pX3.reset (new X(7)); // again works because implemented in terms of shared_ptr + pX2 = pX3; // same + ASSERT (pX2); // both contain indeed a valid pointer.... + ASSERT (pX3); + ASSERT (! pX2.get()); // but dynamic cast to XX at access fails + ASSERT (! pX3.get()); + } + + + /** @test equality and ordering operators forwarded to pointee */ + void + check_ordering () + { + typedef P PX; + typedef P PXX; + + PX pX1 (new X(3)); + PX pX2 (new XX(5)); + PX pX3, pX4, pX5, pX6; + PXX pXX (new XX(7)); + + pX3 = pXX; + pX4.reset(new X(*pXX)); + + ASSERT ( (pX1 == pX1)); // reflexivity + ASSERT (!(pX1 != pX1)); + ASSERT (!(pX1 < pX1)); + ASSERT (!(pX1 > pX1)); + ASSERT ( (pX1 <= pX1)); + ASSERT ( (pX1 >= pX1)); + + ASSERT (!(pX1 == pX2)); // compare to same ptr type with larger pointee of subtype + ASSERT ( (pX1 != pX2)); + ASSERT ( (pX1 < pX2)); + ASSERT (!(pX1 > pX2)); + ASSERT ( (pX1 <= pX2)); + ASSERT (!(pX1 >= pX2)); + + ASSERT (!(pX2 == pXX)); // compare to ptr subtype with larger pointee of same subtype + ASSERT ( (pX2 != pXX)); + ASSERT ( (pX2 < pXX)); + ASSERT (!(pX2 > pXX)); + ASSERT ( (pX2 <= pXX)); + ASSERT (!(pX2 >= pXX)); + + ASSERT (!(pX1 == pXX)); // transitively compare to ptr subtype with larger pointee of subtype + ASSERT ( (pX1 != pXX)); + ASSERT ( (pX1 < pXX)); + ASSERT (!(pX1 > pXX)); + ASSERT ( (pX1 <= pXX)); + ASSERT (!(pX1 >= pXX)); + + ASSERT ( (pX3 == pXX)); // compare ptr to subtype ptr both referring to same pointee + ASSERT (!(pX3 != pXX)); + ASSERT (!(pX3 < pXX)); + ASSERT (!(pX3 > pXX)); + ASSERT ( (pX3 <= pXX)); + ASSERT ( (pX3 >= pXX)); + + ASSERT ( (pX4 == pXX)); // compare ptr to subtype ptr both referring to different but equal pointees + ASSERT (!(pX4 != pXX)); + ASSERT (!(pX4 < pXX)); + ASSERT (!(pX4 > pXX)); + ASSERT ( (pX4 <= pXX)); + ASSERT ( (pX4 >= pXX)); + + ASSERT (!(pXX == pX5)); // compare subtype ptr to empty ptr: "unequal but not orderable" + ASSERT ( (pXX != pX5)); + + ASSERT ( (pX5 == pX6)); // compare two empty ptrs: "equal, equivalent but not orderable" + ASSERT (!(pX5 != pX6)); + + // order relations on NIL pointers disallowed + +#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT + VERIFY_ERROR (ASSERTION, pXX < pX5 ); + VERIFY_ERROR (ASSERTION, pXX > pX5 ); + VERIFY_ERROR (ASSERTION, pXX <= pX5 ); + VERIFY_ERROR (ASSERTION, pXX >= pX5 ); + + VERIFY_ERROR (ASSERTION, pX5 < pXX ); + VERIFY_ERROR (ASSERTION, pX5 > pXX ); + VERIFY_ERROR (ASSERTION, pX5 <= pXX ); + VERIFY_ERROR (ASSERTION, pX5 >= pXX ); + + VERIFY_ERROR (ASSERTION, pX5 < pX6 ); + VERIFY_ERROR (ASSERTION, pX5 > pX6 ); + VERIFY_ERROR (ASSERTION, pX5 <= pX6 ); + VERIFY_ERROR (ASSERTION, pX5 >= pX6 ); +#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT + } + }; + + + /** Register this test class... */ + LAUNCHER (CustomSharedPtr_test, "unit common"); + + + +}} // namespace lib::test diff --git a/tests/lib/customsharedptrtest.cpp b/tests/lib/customsharedptrtest.cpp deleted file mode 100644 index 5c8817dce..000000000 --- a/tests/lib/customsharedptrtest.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/* - CustomSharedPtr(Test) - ref counting, equality and comparisons - - Copyright (C) Lumiera.org - 2008, 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 "lib/p.hpp" - -#include - -using std::string; - - -namespace asset { - namespace test{ - - using lumiera::P; - using std::tr1::shared_ptr; - using std::tr1::weak_ptr; - - using lumiera::error::LUMIERA_ERROR_ASSERTION; - - - struct X - : boost::totally_ordered - { - long x_; - - X(long x=0) : x_(x) {} - operator long () { return x_; } - - bool operator< (const X& ox) const { return x_ < ox.x_; } - bool operator== (const X& ox) const { return x_ == ox.x_; } - - virtual ~X() {} // using RTTI - }; - - struct XX : public X - { - long xx_; - - XX(long x=0) : X(x), xx_(x+1) {} - }; - - - /**************************************************************** - * @test assure correct behaviour of lumiera's custom shared-ptr, - * including ADL of operators, shared ownership, typing - * and ordering - * @see lumiera::P - */ - class CustomSharedPtr_test : public Test - { - virtual void - run (Arg) - { - check_refcounting (); - check_shared_ownership (); - check_type_relations (); - check_ordering (); - } - - - /** @test smart-ptr basic behaviour */ - void - check_refcounting () - { - P p1 (new X(7)); - ASSERT (p1); - ASSERT (1 == p1.use_count()); - ASSERT (7 == p1->x_); - - { - P p2 (new X(9)); - ASSERT (1 == p2.use_count()); - - p2.swap (p1); - ASSERT (1 == p1.use_count()); - ASSERT (1 == p2.use_count()); - - p2 = p1; - ASSERT (2 == p1.use_count()); - ASSERT (2 == p2.use_count()); - } - - ASSERT (1 == p1.use_count()); - ASSERT (9 == p1->x_); - - p1.reset(); - ASSERT (0 == p1.use_count()); - ASSERT (!p1); - } - - - /** @test cooperation with other shared-ptr types */ - void - check_shared_ownership () - { - std::auto_ptr au (new X(22)); - ASSERT (au.get()); - - P pX (au); - ASSERT (!au.get()); - ASSERT (pX); - ASSERT (1 == pX.use_count()); - ASSERT (22 == pX->x_); - - weak_ptr wX (pX); - ASSERT (wX.lock()); - ASSERT (1 == pX.use_count()); - - shared_ptr sp1 (wX); - shared_ptr sp2 (pX); - shared_ptr sp3; sp3 = pX; - - ASSERT (22 == sp3->x_); - ASSERT (4 == pX.use_count()); - ASSERT (*pX == *sp1); - ASSERT (*sp1 == *sp2); - ASSERT (*sp2 == *sp3); - - P pX2; - pX2.swap(pX); - ASSERT (!pX); - ASSERT (0 == pX.use_count()); - ASSERT (4 == pX2.use_count()); - - P > pXX (pX2); // a different type, but compatible pointers - pX2 = pX; - ASSERT (!pX2); - ASSERT (0 == pX2.use_count()); - ASSERT (4 == pXX.use_count()); - - sp3 = sp2 = sp1 = pX; - ASSERT (22 == pXX->x_); - ASSERT (1 == pXX.use_count()); - ASSERT (!sp1); - ASSERT (!sp2); - ASSERT (!sp3); - - ASSERT (22 == wX.lock()->x_); - ASSERT (1 == pXX.use_count()); - - pXX.reset(); - ASSERT (!pXX); - ASSERT (!wX.lock()); - } - - - /** @test building type relationships on smart-ptrs */ - void - check_type_relations () - { - P pX; // Base: shared_ptr - P pX1; // Base: shared_ptr - P > pX2; // Base: P - P > pX3; // Base: shared_ptr - P > pLo;// Base: shared_ptr (quite a nonsense, but well...) - P pLoL; // Base: std::string - P pLoLoL; // Base: shared_ptr - - ASSERT (INSTANCEOF (shared_ptr, &pX)); - - ASSERT ( INSTANCEOF (shared_ptr, &pX1)); -// ASSERT (!INSTANCEOF (shared_ptr, &pX1)); // doesn't compile (no RTTI) -- that's correct -// ASSERT (!INSTANCEOF (P, &pX1)); // similar, type mismatch detected by compiler - - ASSERT ( INSTANCEOF (shared_ptr, &pX2)); -// ASSERT (!INSTANCEOF (shared_ptr, &pX2)); - ASSERT ( INSTANCEOF (P, &pX2)); - - ASSERT ( INSTANCEOF (shared_ptr, &pX3)); -// ASSERT (!INSTANCEOF (shared_ptr, &pX3)); -// ASSERT (!INSTANCEOF (P, &pX3)); - - ASSERT ( INSTANCEOF (shared_ptr, &pLo)); -// ASSERT (!INSTANCEOF (shared_ptr, &pLo)); -// ASSERT (!INSTANCEOF (P, &pLo)); - -// ASSERT (!INSTANCEOF (shared_ptr, &pLoL)); -// ASSERT (!INSTANCEOF (shared_ptr, &pLoL)); -// ASSERT (!INSTANCEOF (P, &pLoL)); - ASSERT ( INSTANCEOF (string, &pLoL)); - - ASSERT ( INSTANCEOF (shared_ptr, &pLoLoL)); -// ASSERT (!INSTANCEOF (string, &pLoLoL)); -// ASSERT (!INSTANCEOF (shared_ptr, &pLoLoL)); - - pX = pX1; // OK: pointee subtype... - pX = pX2; // invokes shared_ptr::operator= (shared_ptr const&) - pX = pX3; -// pX = pLo; // similar, but long* not assignable to X* -// pX = pLoL; // similar, but string* not assignable to X* -// pX = pLoLoL; // same... - // you won't be able to do much with the "LoLo"-Types, - // as their types and pointee types's relations don't match - - pX.reset (new XX(5)); - ASSERT (5 == *pX); // implicit conversion from X to long - - pX2 = pX; // works, because both are implemented in terms of shared_ptr - ASSERT (5 == pX2->x_); - ASSERT (6 == pX2->xx_); // using the XX interface (performing dynamic downcast) - - pX3.reset (new X(7)); // again works because implemented in terms of shared_ptr - pX2 = pX3; // same - ASSERT (pX2); // both contain indeed a valid pointer.... - ASSERT (pX3); - ASSERT (! pX2.get()); // but dynamic cast to XX at access fails - ASSERT (! pX3.get()); - } - - - /** @test equality and ordering operators forwarded to pointee */ - void - check_ordering () - { - typedef P PX; - typedef P PXX; - - PX pX1 (new X(3)); - PX pX2 (new XX(5)); - PX pX3, pX4, pX5, pX6; - PXX pXX (new XX(7)); - - pX3 = pXX; - pX4.reset(new X(*pXX)); - - ASSERT ( (pX1 == pX1)); // reflexivity - ASSERT (!(pX1 != pX1)); - ASSERT (!(pX1 < pX1)); - ASSERT (!(pX1 > pX1)); - ASSERT ( (pX1 <= pX1)); - ASSERT ( (pX1 >= pX1)); - - ASSERT (!(pX1 == pX2)); // compare to same ptr type with larger pointee of subtype - ASSERT ( (pX1 != pX2)); - ASSERT ( (pX1 < pX2)); - ASSERT (!(pX1 > pX2)); - ASSERT ( (pX1 <= pX2)); - ASSERT (!(pX1 >= pX2)); - - ASSERT (!(pX2 == pXX)); // compare to ptr subtype with larger pointee of same subtype - ASSERT ( (pX2 != pXX)); - ASSERT ( (pX2 < pXX)); - ASSERT (!(pX2 > pXX)); - ASSERT ( (pX2 <= pXX)); - ASSERT (!(pX2 >= pXX)); - - ASSERT (!(pX1 == pXX)); // transitively compare to ptr subtype with larger pointee of subtype - ASSERT ( (pX1 != pXX)); - ASSERT ( (pX1 < pXX)); - ASSERT (!(pX1 > pXX)); - ASSERT ( (pX1 <= pXX)); - ASSERT (!(pX1 >= pXX)); - - ASSERT ( (pX3 == pXX)); // compare ptr to subtype ptr both referring to same pointee - ASSERT (!(pX3 != pXX)); - ASSERT (!(pX3 < pXX)); - ASSERT (!(pX3 > pXX)); - ASSERT ( (pX3 <= pXX)); - ASSERT ( (pX3 >= pXX)); - - ASSERT ( (pX4 == pXX)); // compare ptr to subtype ptr both referring to different but equal pointees - ASSERT (!(pX4 != pXX)); - ASSERT (!(pX4 < pXX)); - ASSERT (!(pX4 > pXX)); - ASSERT ( (pX4 <= pXX)); - ASSERT ( (pX4 >= pXX)); - - ASSERT (!(pXX == pX5)); // compare subtype ptr to empty ptr: "unequal but not orderable" - ASSERT ( (pXX != pX5)); - - ASSERT ( (pX5 == pX6)); // compare two empty ptrs: "equal, equivalent but not orderable" - ASSERT (!(pX5 != pX6)); - - // order relations on NIL pointers disallowed - -#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT - VERIFY_ERROR (ASSERTION, pXX < pX5 ); - VERIFY_ERROR (ASSERTION, pXX > pX5 ); - VERIFY_ERROR (ASSERTION, pXX <= pX5 ); - VERIFY_ERROR (ASSERTION, pXX >= pX5 ); - - VERIFY_ERROR (ASSERTION, pX5 < pXX ); - VERIFY_ERROR (ASSERTION, pX5 > pXX ); - VERIFY_ERROR (ASSERTION, pX5 <= pXX ); - VERIFY_ERROR (ASSERTION, pX5 >= pXX ); - - VERIFY_ERROR (ASSERTION, pX5 < pX6 ); - VERIFY_ERROR (ASSERTION, pX5 > pX6 ); - VERIFY_ERROR (ASSERTION, pX5 <= pX6 ); - VERIFY_ERROR (ASSERTION, pX5 >= pX6 ); -#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT - } - }; - - - /** Register this test class... */ - LAUNCHER (CustomSharedPtr_test, "unit common"); - - - - } // namespace test - -} // namespace asset diff --git a/tests/lib/meta/function-erasure-test.cpp b/tests/lib/meta/function-erasure-test.cpp index 090fb8825..1b4fb733e 100644 --- a/tests/lib/meta/function-erasure-test.cpp +++ b/tests/lib/meta/function-erasure-test.cpp @@ -145,7 +145,7 @@ namespace test { ASSERT (INSTANCEOF (function, &f5.getFun())); -#if false ////////////////////////////////////////////////////////TODO: restore throwing ASSERT +#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT VERIFY_ERROR (ASSERTION, f1.getFun() ); VERIFY_ERROR (ASSERTION, f1.getFun() ); VERIFY_ERROR (ASSERTION, f1.getFun() ); @@ -165,7 +165,7 @@ namespace test { VERIFY_ERROR (ASSERTION, f5.getFun() ); VERIFY_ERROR (ASSERTION, f5.getFun() ); VERIFY_ERROR (ASSERTION, f5.getFun() ); -#endif //////////////////////////////////////////////////////// +#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT } diff --git a/tests/lib/opaque-holder-test.cpp b/tests/lib/opaque-holder-test.cpp index 09c595d07..5eae7ebb8 100644 --- a/tests/lib/opaque-holder-test.cpp +++ b/tests/lib/opaque-holder-test.cpp @@ -217,9 +217,9 @@ namespace test{ ASSERT (!oo); ASSERT (isnil(oo)); VERIFY_ERROR (INVALID, oo.get() ); -#if false ////////////////////////////////////////////////////////TODO: restore throwing ASSERT +#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT VERIFY_ERROR (ASSERTION, oo->getIt() ); -#endif//////////////////////////////////////////////////////////// +#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT // can't access empty holder... Opaque o1 (oo); diff --git a/tests/lib/test/test-helper-test.cpp b/tests/lib/test/test-helper-test.cpp index 84d3cfe92..6b782a76d 100644 --- a/tests/lib/test/test-helper-test.cpp +++ b/tests/lib/test/test-helper-test.cpp @@ -137,10 +137,10 @@ namespace test{ // verify the exception is indeed raised VERIFY_ERROR (EXCEPTION, doThrow() ); -#if false ////////////////////////////////////////////////////////TODO: restore throwing ASSERT +#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT // and when actually no exception is raised, this is an ASSERTION failure VERIFY_ERROR (ASSERTION, VERIFY_ERROR (EXCEPTION, dontThrow() )); -#endif //////////////////////////////////////////////////////// +#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT } };