|
Packit |
1244b8 |
/*
|
|
Packit |
1244b8 |
* Copyright 2016 Intel Corporation
|
|
Packit |
1244b8 |
*
|
|
Packit |
1244b8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit |
1244b8 |
* you may not use this file except in compliance with the License.
|
|
Packit |
1244b8 |
* You may obtain a copy of the License at
|
|
Packit |
1244b8 |
*
|
|
Packit |
1244b8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
1244b8 |
*
|
|
Packit |
1244b8 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
1244b8 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
1244b8 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
1244b8 |
* See the License for the specific language governing permissions and
|
|
Packit |
1244b8 |
* limitations under the License.
|
|
Packit |
1244b8 |
*/
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
// primary header
|
|
Packit |
1244b8 |
#include "common/factory.h"
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
// library headers
|
|
Packit |
1244b8 |
#include "common/unittest.h"
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
// system headers
|
|
Packit |
1244b8 |
#include <vector>
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
template <class Base, class Derived>
|
|
Packit |
1244b8 |
class FactoryTest
|
|
Packit |
1244b8 |
: public ::testing::Test {
|
|
Packit |
1244b8 |
protected:
|
|
Packit |
1244b8 |
typedef std::vector<typename Factory<Base>::KeyType> FactoryKeys;
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
void doFactoryTest(const FactoryKeys& keys) {
|
|
Packit |
1244b8 |
::testing::StaticAssertTypeEq<Base*, typename Factory<Base>::Type>();
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
EXPECT_TRUE(Derived::s_registered);
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
const typename FactoryKeys::const_iterator end(keys.end());
|
|
Packit |
1244b8 |
for ( typename FactoryKeys::const_iterator key(keys.begin());
|
|
Packit |
1244b8 |
key != end; ++key) {
|
|
Packit |
1244b8 |
SCOPED_TRACE("key: " + *key);
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
ASSERT_FALSE(Factory<Base>::template register_<Derived>(*key));
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
Base* object(NULL);
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
ASSERT_TRUE(object == NULL);
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
object = Factory<Base>::create(*key);
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
EXPECT_TRUE(object != NULL);
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
EXPECT_TRUE(dynamic_cast<Derived*>(object));
|
|
Packit |
1244b8 |
|
|
Packit |
1244b8 |
delete object;
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
}
|
|
Packit |
1244b8 |
};
|