|
| 1 | +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <gtest/gtest.h> |
| 16 | + |
| 17 | +#include <fastdds/dds/xtypes/dynamic_types/DynamicDataFactory.hpp> |
| 18 | +#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilder.hpp> |
| 19 | +#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp> |
| 20 | +#include <ScopedLogs.hpp> |
| 21 | + |
| 22 | +using namespace eprosima::fastdds::rtps; |
| 23 | +using namespace eprosima::fastdds::dds; |
| 24 | + |
| 25 | + |
| 26 | +class IdlParserTests : public ::testing::Test |
| 27 | +{ |
| 28 | +public: |
| 29 | + |
| 30 | + IdlParserTests() = default; |
| 31 | + |
| 32 | + ~IdlParserTests() |
| 33 | + { |
| 34 | + Log::Flush(); |
| 35 | + } |
| 36 | + |
| 37 | + virtual void TearDown() |
| 38 | + { |
| 39 | + DynamicDataFactory::delete_instance(); |
| 40 | + DynamicTypeBuilderFactory::delete_instance(); |
| 41 | + } |
| 42 | + |
| 43 | +}; |
| 44 | + |
| 45 | +TEST_F(IdlParserTests, primitives) |
| 46 | +{ |
| 47 | + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; |
| 48 | + std::vector<std::string> empty_include_paths; |
| 49 | + |
| 50 | + DynamicTypeBuilder::_ref_type builder1 = factory->create_type_w_document("IDL/primitives.idl", "ShortStruct", empty_include_paths); |
| 51 | + EXPECT_TRUE(builder1); |
| 52 | + DynamicType::_ref_type type1 = builder1->build(); |
| 53 | + ASSERT_TRUE(type1); |
| 54 | + DynamicData::_ref_type data1 {DynamicDataFactory::get_instance()->create_data(type1)}; |
| 55 | + ASSERT_TRUE(data1); |
| 56 | + int16_t test1 {0}; |
| 57 | + EXPECT_EQ(data1->set_int16_value(0, 100), RETCODE_OK); |
| 58 | + EXPECT_EQ(data1->get_int16_value(test1, 0), RETCODE_OK); |
| 59 | + EXPECT_EQ(test1, 100); |
| 60 | + |
| 61 | + DynamicTypeBuilder::_ref_type builder2 = factory->create_type_w_document("IDL/primitives.idl", "UShortStruct", empty_include_paths); |
| 62 | + EXPECT_TRUE(builder2); |
| 63 | + DynamicType::_ref_type type2 = builder2->build(); |
| 64 | + ASSERT_TRUE(type2); |
| 65 | + DynamicData::_ref_type data2 {DynamicDataFactory::get_instance()->create_data(type2)}; |
| 66 | + ASSERT_TRUE(data2); |
| 67 | + |
| 68 | + DynamicTypeBuilder::_ref_type builder3 = factory->create_type_w_document("IDL/primitives.idl", "LongStruct", empty_include_paths); |
| 69 | + EXPECT_TRUE(builder3); |
| 70 | + DynamicType::_ref_type type3 = builder3->build(); |
| 71 | + ASSERT_TRUE(type3); |
| 72 | + |
| 73 | + DynamicTypeBuilder::_ref_type builder4 = factory->create_type_w_document("IDL/primitives.idl", "ULongStruct", empty_include_paths); |
| 74 | + EXPECT_TRUE(builder4); |
| 75 | + DynamicType::_ref_type type4 = builder4->build(); |
| 76 | + ASSERT_TRUE(type4); |
| 77 | + |
| 78 | + DynamicTypeBuilder::_ref_type builder5 = factory->create_type_w_document("IDL/primitives.idl", "LongLongStruct", empty_include_paths); |
| 79 | + EXPECT_TRUE(builder5); |
| 80 | + DynamicType::_ref_type type5 = builder5->build(); |
| 81 | + ASSERT_TRUE(type5); |
| 82 | + |
| 83 | + DynamicTypeBuilder::_ref_type builder6 = factory->create_type_w_document("IDL/primitives.idl", "ULongLongStruct", empty_include_paths); |
| 84 | + EXPECT_TRUE(builder6); |
| 85 | + DynamicType::_ref_type type6 = builder6->build(); |
| 86 | + ASSERT_TRUE(type6); |
| 87 | + |
| 88 | + DynamicTypeBuilder::_ref_type builder7 = factory->create_type_w_document("IDL/primitives.idl", "FloatStruct", empty_include_paths); |
| 89 | + EXPECT_TRUE(builder7); |
| 90 | + DynamicType::_ref_type type7 = builder7->build(); |
| 91 | + ASSERT_TRUE(type7); |
| 92 | + |
| 93 | + DynamicTypeBuilder::_ref_type builder8 = factory->create_type_w_document("IDL/primitives.idl", "DoubleStruct", empty_include_paths); |
| 94 | + EXPECT_TRUE(builder8); |
| 95 | + DynamicType::_ref_type type8 = builder8->build(); |
| 96 | + ASSERT_TRUE(type8); |
| 97 | + |
| 98 | + DynamicTypeBuilder::_ref_type builder9 = factory->create_type_w_document("IDL/primitives.idl", "LongDoubleStruct", empty_include_paths); |
| 99 | + EXPECT_TRUE(builder9); |
| 100 | + DynamicType::_ref_type type9 = builder9->build(); |
| 101 | + ASSERT_TRUE(type9); |
| 102 | + |
| 103 | + DynamicTypeBuilder::_ref_type builder10 = factory->create_type_w_document("IDL/primitives.idl", "BooleanStruct", empty_include_paths); |
| 104 | + EXPECT_TRUE(builder10); |
| 105 | + DynamicType::_ref_type type10 = builder10->build(); |
| 106 | + ASSERT_TRUE(type10); |
| 107 | + |
| 108 | + DynamicTypeBuilder::_ref_type builder11 = factory->create_type_w_document("IDL/primitives.idl", "OctetStruct", empty_include_paths); |
| 109 | + EXPECT_TRUE(builder11); |
| 110 | + DynamicType::_ref_type type11 = builder11->build(); |
| 111 | + ASSERT_TRUE(type11); |
| 112 | + |
| 113 | + DynamicTypeBuilder::_ref_type builder12 = factory->create_type_w_document("IDL/primitives.idl", "CharStruct", empty_include_paths); |
| 114 | + EXPECT_TRUE(builder12); |
| 115 | + DynamicType::_ref_type type12 = builder12->build(); |
| 116 | + ASSERT_TRUE(type12); |
| 117 | + |
| 118 | + DynamicTypeBuilder::_ref_type builder13 = factory->create_type_w_document("IDL/primitives.idl", "WCharStruct", empty_include_paths); |
| 119 | + EXPECT_TRUE(builder13); |
| 120 | + DynamicType::_ref_type type13 = builder13->build(); |
| 121 | + ASSERT_TRUE(type13); |
| 122 | + |
| 123 | + DynamicTypeBuilder::_ref_type builder14 = factory->create_type_w_document("IDL/primitives.idl", "Int8Struct", empty_include_paths); |
| 124 | + EXPECT_TRUE(builder14); |
| 125 | + DynamicType::_ref_type type14 = builder14->build(); |
| 126 | + ASSERT_TRUE(type14); |
| 127 | + |
| 128 | + DynamicTypeBuilder::_ref_type builder15 = factory->create_type_w_document("IDL/primitives.idl", "Uint8Struct", empty_include_paths); |
| 129 | + EXPECT_TRUE(builder15); |
| 130 | + DynamicType::_ref_type type15 = builder15->build(); |
| 131 | + ASSERT_TRUE(type15); |
| 132 | + |
| 133 | + DynamicTypeBuilder::_ref_type builder16 = factory->create_type_w_document("IDL/primitives.idl", "Int16Struct", empty_include_paths); |
| 134 | + EXPECT_TRUE(builder16); |
| 135 | + DynamicType::_ref_type type16 = builder16->build(); |
| 136 | + ASSERT_TRUE(type16); |
| 137 | + |
| 138 | + DynamicTypeBuilder::_ref_type builder17 = factory->create_type_w_document("IDL/primitives.idl", "Uint16Struct", empty_include_paths); |
| 139 | + EXPECT_TRUE(builder17); |
| 140 | + DynamicType::_ref_type type17 = builder17->build(); |
| 141 | + ASSERT_TRUE(type17); |
| 142 | + |
| 143 | + DynamicTypeBuilder::_ref_type builder18 = factory->create_type_w_document("IDL/primitives.idl", "Int32Struct", empty_include_paths); |
| 144 | + EXPECT_TRUE(builder18); |
| 145 | + DynamicType::_ref_type type18 = builder18->build(); |
| 146 | + ASSERT_TRUE(type18); |
| 147 | + |
| 148 | + DynamicTypeBuilder::_ref_type builder19 = factory->create_type_w_document("IDL/primitives.idl", "Uint32Struct", empty_include_paths); |
| 149 | + EXPECT_TRUE(builder19); |
| 150 | + DynamicType::_ref_type type19 = builder19->build(); |
| 151 | + ASSERT_TRUE(type19); |
| 152 | + |
| 153 | + DynamicTypeBuilder::_ref_type builder20 = factory->create_type_w_document("IDL/primitives.idl", "Int64Struct", empty_include_paths); |
| 154 | + EXPECT_TRUE(builder20); |
| 155 | + DynamicType::_ref_type type20 = builder20->build(); |
| 156 | + ASSERT_TRUE(type20); |
| 157 | + |
| 158 | + DynamicTypeBuilder::_ref_type builder21 = factory->create_type_w_document("IDL/primitives.idl", "Uint64Struct", empty_include_paths); |
| 159 | + EXPECT_TRUE(builder21); |
| 160 | + DynamicType::_ref_type type21 = builder21->build(); |
| 161 | + ASSERT_TRUE(type21); |
| 162 | +} |
| 163 | + |
| 164 | +TEST_F(IdlParserTests, strings) |
| 165 | +{ |
| 166 | + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; |
| 167 | + std::vector<std::string> empty_include_paths; |
| 168 | + |
| 169 | + DynamicTypeBuilder::_ref_type builder1 = factory->create_type_w_document("IDL/strings.idl", "StringStruct", empty_include_paths); |
| 170 | + EXPECT_TRUE(builder1); |
| 171 | + DynamicType::_ref_type type1 = builder1->build(); |
| 172 | + ASSERT_TRUE(type1); |
| 173 | + DynamicData::_ref_type data1 {DynamicDataFactory::get_instance()->create_data(type1)}; |
| 174 | + ASSERT_TRUE(data1); |
| 175 | + std::string test1; |
| 176 | + EXPECT_EQ(data1->set_string_value(0, "hello"), RETCODE_OK); |
| 177 | + EXPECT_EQ(data1->get_string_value(test1, 0), RETCODE_OK); |
| 178 | + EXPECT_EQ(test1, "hello"); |
| 179 | + |
| 180 | + DynamicTypeBuilder::_ref_type builder2 = factory->create_type_w_document("IDL/strings.idl", "WStringStruct", empty_include_paths); |
| 181 | + EXPECT_TRUE(builder2); |
| 182 | + DynamicType::_ref_type type2 = builder2->build(); |
| 183 | + ASSERT_TRUE(type2); |
| 184 | + |
| 185 | + DynamicTypeBuilder::_ref_type builder3 = factory->create_type_w_document("IDL/strings.idl", "SmallStringStruct", empty_include_paths); |
| 186 | + EXPECT_TRUE(builder3); |
| 187 | + DynamicType::_ref_type type3 = builder3->build(); |
| 188 | + ASSERT_TRUE(type3); |
| 189 | + |
| 190 | + DynamicTypeBuilder::_ref_type builder4 = factory->create_type_w_document("IDL/strings.idl", "SmallWStringStruct", empty_include_paths); |
| 191 | + EXPECT_TRUE(builder4); |
| 192 | + DynamicType::_ref_type type4 = builder4->build(); |
| 193 | + ASSERT_TRUE(type4); |
| 194 | + |
| 195 | + DynamicTypeBuilder::_ref_type builder5 = factory->create_type_w_document("IDL/strings.idl", "LargeStringStruct", empty_include_paths); |
| 196 | + EXPECT_TRUE(builder5); |
| 197 | + DynamicType::_ref_type type5 = builder5->build(); |
| 198 | + ASSERT_TRUE(type5); |
| 199 | + |
| 200 | + DynamicTypeBuilder::_ref_type builder6 = factory->create_type_w_document("IDL/strings.idl", "LargeWStringStruct", empty_include_paths); |
| 201 | + EXPECT_TRUE(builder6); |
| 202 | + DynamicType::_ref_type type6 = builder6->build(); |
| 203 | + ASSERT_TRUE(type6); |
| 204 | +} |
| 205 | + |
| 206 | +int main( |
| 207 | + int argc, |
| 208 | + char** argv) |
| 209 | +{ |
| 210 | + Log::SetVerbosity(Log::Info); |
| 211 | + |
| 212 | + testing::InitGoogleTest(&argc, argv); |
| 213 | + return RUN_ALL_TESTS(); |
| 214 | +} |
0 commit comments