diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-16 21:31:30 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-16 21:31:30 +0100 | 
| commit | b2f0c0b59dd7603a4ac29a1690237be51e1afb80 (patch) | |
| tree | 0545328ba5175f34bbefc643e301ec69853865f0 | |
| parent | Add test over lazy pointer operator bool (diff) | |
| download | libadhocutil-b2f0c0b59dd7603a4ac29a1690237be51e1afb80.tar.bz2 libadhocutil-b2f0c0b59dd7603a4ac29a1690237be51e1afb80.tar.xz libadhocutil-b2f0c0b59dd7603a4ac29a1690237be51e1afb80.zip | |
Improve coverage and factory correctness testing
| -rw-r--r-- | libadhocutil/unittests/testFactory.cpp | 43 | 
1 files changed, 32 insertions, 11 deletions
| diff --git a/libadhocutil/unittests/testFactory.cpp b/libadhocutil/unittests/testFactory.cpp index da8ab6f..dbca28b 100644 --- a/libadhocutil/unittests/testFactory.cpp +++ b/libadhocutil/unittests/testFactory.cpp @@ -10,29 +10,42 @@ using namespace AdHoc;  class BaseThing {  	public: -		BaseThing(int, const std::string &){} +		BaseThing(int, std::string * n) : +			name(n) +		{ +		} +  		virtual ~BaseThing() = default;  		virtual void execute() const = 0; + +	protected: +		std::string * name;  };  class ImplOfThing : public BaseThing {  	public: -		ImplOfThing(int i, const std::string & s) : BaseThing(i, s) {} -		void execute() const { } +		ImplOfThing(int i, std::string * s) : BaseThing(i, s) {} +		void execute() const +		{ +			*name = typeid(this).name(); +		}  };  class OtherImplOfThing : public BaseThing {  	public: -		OtherImplOfThing(int i, const std::string & s) : BaseThing(i, s) {} -		void execute() const { } +		OtherImplOfThing(int i, std::string * s) : BaseThing(i, s) {} +		void execute() const +		{ +			*name = typeid(this).name(); +		}  }; -typedef AdHoc::Factory<BaseThing, int, std::string> BaseThingFactory; +typedef AdHoc::Factory<BaseThing, int, std::string *> BaseThingFactory;  NAMEDFACTORY("a", ImplOfThing, BaseThingFactory);  FACTORY(OtherImplOfThing, BaseThingFactory); -INSTANTIATEFACTORY(BaseThing, int, std::string); +INSTANTIATEFACTORY(BaseThing, int, std::string *);  // Multiple factories in one compilation unit  INSTANTIATEFACTORY(BaseThing, std::string, std::string);  // Factories of things with commas @@ -59,12 +72,19 @@ BOOST_AUTO_TEST_CASE( create )  {  	auto factory1 = BaseThingFactory::get("a");  	auto factory2 = BaseThingFactory::get("OtherImplOfThing"); -	auto i1 = factory1->create(1, "std"); -	auto i2 = factory1->create(1, "std"); -	auto i3 = factory2->create(1, "std"); +	std::string n; +	auto i1 = factory1->create(1, &n); +	auto i2 = factory1->create(1, &n); +	auto i3 = factory2->create(1, &n);  	BOOST_REQUIRE(i1); +	i1->execute(); +	BOOST_REQUIRE_EQUAL(n, "PK11ImplOfThing");  	BOOST_REQUIRE(i2); +	i2->execute(); +	BOOST_REQUIRE_EQUAL(n, "PK11ImplOfThing");  	BOOST_REQUIRE(i3); +	i3->execute(); +	BOOST_REQUIRE_EQUAL(n, "PK16OtherImplOfThing");  	BOOST_REQUIRE(i1 != i2);  	BOOST_REQUIRE(i1 != i3);  	BOOST_REQUIRE(i2 != i3); @@ -72,7 +92,8 @@ BOOST_AUTO_TEST_CASE( create )  BOOST_AUTO_TEST_CASE( createNew )  { -	auto i = BaseThingFactory::createNew("a", 1, "std"); +	std::string n; +	auto i = BaseThingFactory::createNew("a", 1, &n);  	BOOST_REQUIRE(i);  	delete i;  } | 
