2007-11-27 06:40:51 +01:00
|
|
|
/*
|
|
|
|
|
VisitingTool(Test) - check the acyclic visitor lib implementation
|
|
|
|
|
|
|
|
|
|
Copyright (C) CinelerraCV
|
|
|
|
|
2007, 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 "common/test/run.hpp"
|
|
|
|
|
#include "common/visitor.hpp"
|
|
|
|
|
//#include "common/factory.hpp"
|
|
|
|
|
//#include "common/util.hpp"
|
|
|
|
|
|
2007-11-28 04:19:21 +01:00
|
|
|
#include <boost/format.hpp>
|
2007-11-27 06:40:51 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2007-11-28 04:19:21 +01:00
|
|
|
using boost::format;
|
2007-11-27 06:40:51 +01:00
|
|
|
using std::string;
|
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
|
|
|
2007-11-28 04:19:21 +01:00
|
|
|
namespace cinelerra
|
2007-11-27 06:40:51 +01:00
|
|
|
{
|
2007-11-28 04:19:21 +01:00
|
|
|
namespace visitor
|
2007-11-27 06:40:51 +01:00
|
|
|
{
|
|
|
|
|
namespace test
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2007-11-28 04:19:21 +01:00
|
|
|
class HomoSapiens : public Visitable<>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DEFINE_PROCESSABLE_BY (Tool);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Boss : public HomoSapiens
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DEFINE_PROCESSABLE_BY (Tool);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BigBoss : public Boss
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DEFINE_PROCESSABLE_BY (Tool);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Leader : public Boss
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VerboseVisitor
|
|
|
|
|
: public Tool,
|
|
|
|
|
public Applicable<Boss>,
|
|
|
|
|
public Applicable<BigBoss>
|
|
|
|
|
{
|
|
|
|
|
void talk_to (string guy)
|
|
|
|
|
{
|
|
|
|
|
cout << format ("Hello %s, nice to meet you...\n") % guy;
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
void treat (Boss&) { talk_to("Boss"); }
|
|
|
|
|
void treat (BigBoss&) { talk_to("big Boss"); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-11-27 06:40:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
|
* @test our lib implementation of the acyclic visitor pattern.
|
|
|
|
|
* Defines a hierarchy of test classes to check the following cases
|
|
|
|
|
* <ul><li>calling the correct visiting tool specialized function
|
|
|
|
|
* for given concrete hierarchy classes</li>
|
|
|
|
|
* <li>visiting tool not declaring to visit some class</li>
|
|
|
|
|
* <li>newly added class causes the catch-all to be invoked
|
|
|
|
|
* when visited by known visitor</li>
|
|
|
|
|
* </ul>
|
|
|
|
|
*/
|
|
|
|
|
class VisitingTool_test : public Test
|
|
|
|
|
{
|
|
|
|
|
virtual void run(Arg arg)
|
|
|
|
|
{
|
|
|
|
|
known_visitor_known_class();
|
2007-11-28 04:19:21 +01:00
|
|
|
TODO ("implement the more complicated visitor test cases");
|
|
|
|
|
//visitor_not_visiting_some_class();
|
|
|
|
|
//visitor_treating_new_subclass();
|
2007-11-27 06:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void known_visitor_known_class()
|
|
|
|
|
{
|
2007-11-28 04:19:21 +01:00
|
|
|
HomoSapiens x1;
|
|
|
|
|
Boss x2;
|
|
|
|
|
BigBoss x3;
|
|
|
|
|
|
|
|
|
|
HomoSapiens& xx2 (x2);
|
|
|
|
|
HomoSapiens& xx3 (x3);
|
|
|
|
|
|
|
|
|
|
VerboseVisitor wizzy;
|
|
|
|
|
x1.apply (wizzy);
|
|
|
|
|
xx2.apply (wizzy);
|
|
|
|
|
xx3.apply (wizzy);
|
2007-11-27 06:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void visitor_not_visiting_some_class()
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED ("testing the generic visitor pattern");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void visitor_treating_new_subclass()
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED ("testing the generic visitor pattern");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
LAUNCHER (VisitingTool_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
|
2007-11-28 04:19:21 +01:00
|
|
|
} // namespace visitor
|
2007-11-27 06:40:51 +01:00
|
|
|
|
2007-11-28 04:19:21 +01:00
|
|
|
} // namespace cinelerra
|