2009-05-22 02:40:20 +02:00
|
|
|
/*
|
2009-05-23 05:13:51 +02:00
|
|
|
HashIndexed(Test) - proof-of-concept test for a hash based and typed ID
|
2009-05-22 02:40:20 +02:00
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
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"
|
2009-05-22 03:41:58 +02:00
|
|
|
|
2009-05-23 05:13:51 +02:00
|
|
|
#include "lib/hash-indexed.hpp"
|
2009-05-22 02:40:20 +02:00
|
|
|
|
2009-05-23 05:13:51 +02:00
|
|
|
//#include <boost/format.hpp>
|
2009-05-22 03:41:58 +02:00
|
|
|
#include <iostream>
|
2009-05-22 02:40:20 +02:00
|
|
|
|
2009-05-23 05:13:51 +02:00
|
|
|
//using boost::format;
|
2009-05-22 03:41:58 +02:00
|
|
|
//using std::string;
|
|
|
|
|
using std::cout;
|
2009-05-22 02:40:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
namespace test{
|
|
|
|
|
|
2009-05-24 01:46:00 +02:00
|
|
|
/* == a hierarchy of test-dummy objects to use the HashIndexed::ID == */
|
2009-05-22 03:41:58 +02:00
|
|
|
|
|
|
|
|
struct Base
|
|
|
|
|
{
|
2009-05-23 05:13:51 +02:00
|
|
|
long ii_;
|
2009-05-22 03:41:58 +02:00
|
|
|
};
|
|
|
|
|
|
2009-05-24 01:46:00 +02:00
|
|
|
struct TestB : Base, HashIndexed<TestB,LuidH> ///< Base class to mix in the hash ID facility
|
2009-05-22 03:41:58 +02:00
|
|
|
{
|
2009-05-23 05:13:51 +02:00
|
|
|
TestB () {}
|
|
|
|
|
TestB (ID const& refID) : HashIndexed<TestB,LuidH>(refID) {}
|
2009-05-22 03:41:58 +02:00
|
|
|
};
|
2009-05-23 05:13:51 +02:00
|
|
|
struct TestDA : TestB {};
|
|
|
|
|
struct TestDB : TestB {};
|
2009-05-22 03:41:58 +02:00
|
|
|
|
|
|
|
|
|
2009-05-22 02:40:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
* @test proof-of-concept test for a generic hash based and typed ID struct.
|
2009-05-23 05:13:51 +02:00
|
|
|
* @see lib::HashIndexed::Id
|
2009-05-22 02:40:20 +02:00
|
|
|
*/
|
2009-05-23 05:13:51 +02:00
|
|
|
class HashIndexed_test : public Test
|
2009-05-22 02:40:20 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
run (Arg)
|
|
|
|
|
{
|
2009-05-23 05:13:51 +02:00
|
|
|
TestB::Id<TestDA> idDA;
|
2009-05-22 03:41:58 +02:00
|
|
|
|
2009-05-23 05:13:51 +02:00
|
|
|
TestB bb (idDA);
|
2009-05-22 03:41:58 +02:00
|
|
|
|
2009-05-23 05:13:51 +02:00
|
|
|
TestB::Id<TestDB> idDB1 ;
|
|
|
|
|
TestB::Id<TestDB> idDB2 (idDB1);
|
2009-05-22 03:41:58 +02:00
|
|
|
|
2009-05-23 05:13:51 +02:00
|
|
|
ASSERT (sizeof (idDB1) == sizeof (idDA) );
|
|
|
|
|
ASSERT (sizeof (TestB::ID) == sizeof (LuidH));
|
|
|
|
|
ASSERT (sizeof (TestDA) == sizeof (LuidH) + sizeof (Base));
|
2009-05-22 03:41:58 +02:00
|
|
|
|
2009-05-24 01:46:00 +02:00
|
|
|
ASSERT (idDA == bb.getID() );
|
|
|
|
|
ASSERT (idDB1 == idDB2 ); // equality handled by the hash impl (here LuidH)
|
2009-05-22 03:41:58 +02:00
|
|
|
|
2009-05-23 05:13:51 +02:00
|
|
|
TestDA d1;
|
|
|
|
|
TestDA d2;
|
2009-05-24 01:46:00 +02:00
|
|
|
ASSERT (d1.getID() != d2.getID()); // should be different because LUIDs are random
|
2009-05-23 05:13:51 +02:00
|
|
|
|
2009-05-24 01:46:00 +02:00
|
|
|
d2 = d1;
|
|
|
|
|
ASSERT (d1.getID() == d2.getID()); // default assignment operator works as expected
|
2009-05-22 02:40:20 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2009-05-23 05:13:51 +02:00
|
|
|
LAUNCHER (HashIndexed_test, "unit common");
|
2009-05-22 02:40:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace lib::test
|