blob: 8b2546e2cd7b0ff3f1e74cdacc162b0fb6ebe259 [file] [log] [blame]
Constantin Ziesche02817f12020-08-04 21:40:43 +02001#include <gtest/gtest.h>
2#include <tuple>
3
4#include <BaSyx/submodel/map_v2/parts/ConceptDescription.h>
5#include <BaSyx/submodel/simple/parts/ConceptDescription.h>
6
7#include <BaSyx/util/util.h>
8
9using namespace basyx::submodel;
10
11using ImplTypes = ::testing::Types
12<
13 std::tuple<map::ConceptDescription, map::Reference, map::DataSpecification>,
14 std::tuple<simple::ConceptDescription, simple::Reference, simple::DataSpecification>
15>;
16
17template<class Impl>
18class ConceptDescriptionTest :public ::testing::Test {
19protected:
20 using impl_t = typename std::tuple_element<0, Impl>::type;
21 using impl_ref_t = typename std::tuple_element<1, Impl>::type;
22 using impl_dataSpec_t = typename std::tuple_element<2, Impl>::type;
23
24 std::unique_ptr<impl_t> conceptDescription;
25 std::unique_ptr<impl_ref_t> testingReference;
26 std::unique_ptr<impl_dataSpec_t> testingDataSpecification;
27protected:
28 void SetUp() override
29 {
30 simple::Identifier id;
31 conceptDescription = util::make_unique<impl_t>("test id", id);
32 simple::Key key(KeyElements::Property, true, KeyType::IdShort, "test");
33 testingReference = util::make_unique<impl_ref_t>(key);
34 testingDataSpecification = util::make_unique<impl_dataSpec_t>("test data spec", id);
35 }
36
37 void TearDown() override
38 { }
39};
40
41TYPED_TEST_CASE(ConceptDescriptionTest, ImplTypes);
42
43TYPED_TEST(ConceptDescriptionTest, TestConstructor)
44{
45 auto & cases = this->conceptDescription->getIsCaseOf();
46 auto & references = this->conceptDescription->getDataSpecificationReference();
47
48 ASSERT_EQ(references.size(), 0);
49 ASSERT_EQ(cases.size(), 0);
50}
51
52TYPED_TEST(ConceptDescriptionTest, TestAddIsCaseOf)
53{
54 this->conceptDescription->addIsCaseOf(std::move(this->testingReference));
55
56 auto & references = this->conceptDescription->getIsCaseOf();
57 auto keys = references.at(0)->getKeys();
58 ASSERT_EQ(1, keys.size());
59 ASSERT_EQ("test", keys.at(0).getValue());
60}
61
62TYPED_TEST(ConceptDescriptionTest, TestAddEmbeddedDataSpecification)
63{
64 this->conceptDescription->addEmbeddedDataSpecification(std::move(this->testingDataSpecification));
65
66 auto & references = this->conceptDescription->getEmbeddedDataSpecification();
67 ASSERT_NE(references.getElement("test data spec"), nullptr);
68}