diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7e7fc8..901dd4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,4 +126,4 @@ jobs: shell: bash run: | cd build - ctest \ No newline at end of file + ctest diff --git a/examples/vectorTest/Vector/VectorTest.cpp b/examples/vectorTest/Vector/VectorTest.cpp index 74dedca..a681ba4 100644 --- a/examples/vectorTest/Vector/VectorTest.cpp +++ b/examples/vectorTest/Vector/VectorTest.cpp @@ -21,9 +21,40 @@ #include #include +#include "VectorTest.h" -TEST(VectorTest, Clearing) { - std::vector vect{1, 2, 3}; - vect.clear(); - EXPECT_EQ(vect.empty(), true); +namespace { + + +template +::std::vector CreateVector() { + TestedVector vectCreator; + ::std::vector vect = vectCreator.testedVect; + return vect; +} + +template +class VectorTest : public ::testing::Test { + protected: + VectorTest() { + ::std::vector vect = CreateVector(); + } + ~VectorTest() override {} + ::std::vector vect; +}; + +using ::testing::Types; + +TYPED_TEST_SUITE_P(VectorTest); + +TYPED_TEST_P(VectorTest, Clearing) { + this->vect.clear(); + EXPECT_EQ(this->vect.empty(), true); +} + +REGISTER_TYPED_TEST_SUITE_P( + VectorTest, + Clearing); +using TestedTypes = ::testing::Types; +INSTANTIATE_TYPED_TEST_SUITE_P(VectorTesting, VectorTest, TestedTypes); } \ No newline at end of file diff --git a/examples/vectorTest/Vector/VectorTest.h b/examples/vectorTest/Vector/VectorTest.h new file mode 100644 index 0000000..bdf3776 --- /dev/null +++ b/examples/vectorTest/Vector/VectorTest.h @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2022 ArSysOp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * (ArSysOp) - initial API and implementation + *******************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#define configFile "../vectorTypesConfig.txt" +using namespace std; + +class ConfigReader { + + private: + + list readConfigFile() { + list lines; + ifstream inputStream(configFile); + string configLine; + while (getline(inputStream, configLine)) + { + lines.push_back(configLine); + } + return lines; + } + + string findTypeNameInLine(string line) { + int typenameStart = line.find("<") + 1; + int typenameEnd = line.find(">") - 1; + string _typename = line.substr(typenameStart, typenameEnd - typenameStart + 1); + return _typename; + } + + list findValueListInLine(string line) { + list valueList; + int typenameStart = line.find("{") + 1; + int typenameEnd = line.find("}") - 1; + istringstream valuesWithoutBraces(line.substr(typenameStart, typenameEnd - typenameStart + 1)); + do { + string currentValue; + valuesWithoutBraces >> currentValue; + valueList.push_back(currentValue); + } while (valuesWithoutBraces); + + return valueList; + } + + public: + ConfigReader() { + + } + + list typeNames() { + list typeNameList; + for(string configLine : readConfigFile()) { + typeNameList.push_back(findTypeNameInLine(configLine)); + } + return typeNameList; + } + + list exampleStringValues(string typeName) { + list valueList; + for(string configLine : readConfigFile()) + { + if(configLine.find("<" + typeName + ">") != -1) { + valueList = findValueListInLine(configLine); + break; + } + } + return valueList; + } +}; + +template +class TestedVector : public std::vector { + public: + TestedVector() { CreateTestedVector(); } + std::vector testedVect; + private: + void CreateTestedVector(){ + // there is a place where typenames should + // be provided on the compile time + } +}; \ No newline at end of file diff --git a/examples/vectorTest/vectorTypesConfig.txt b/examples/vectorTest/vectorTypesConfig.txt new file mode 100644 index 0000000..ce3f8be --- /dev/null +++ b/examples/vectorTest/vectorTypesConfig.txt @@ -0,0 +1,3 @@ +TYPE {0 1 2} +TYPE {1.2 2.3 3.14} +TYPE {$ & @} \ No newline at end of file