From 0d7fe492a3d8e1a2fc544a98e398b5f1ed854a10 Mon Sep 17 00:00:00 2001 From: Vasily Fedorov Date: Wed, 12 Jan 2022 21:44:07 +0300 Subject: [PATCH 1/7] rewrited example test to type-parametrized --- examples/vectorTest/Vector/VectorTest.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/vectorTest/Vector/VectorTest.cpp b/examples/vectorTest/Vector/VectorTest.cpp index 74dedca..485e482 100644 --- a/examples/vectorTest/Vector/VectorTest.cpp +++ b/examples/vectorTest/Vector/VectorTest.cpp @@ -22,8 +22,22 @@ #include #include -TEST(VectorTest, Clearing) { - std::vector vect{1, 2, 3}; +template +class VectorTest : public ::testing::test { + protected: + using Vector = std::vector; +} + +TYPED_TEST_SUITE_P(VectorTest); + +TYPED_TEST_P(VectorTest, Clearing) { + std::vector vect{0}; vect.clear(); EXPECT_EQ(vect.empty(), true); -} \ No newline at end of file +} + +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 From 8bca678ce88dabcbe5cf47b59a08f1f3d9402651 Mon Sep 17 00:00:00 2001 From: Vasily Fedorov Date: Wed, 12 Jan 2022 21:52:13 +0300 Subject: [PATCH 2/7] added pushing to vector_tests to events that trigger workflow --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7e7fc8..63338a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,8 @@ on: - main push: branches: - - main + - main, + - vector_tests jobs: build: From ec0a12854436246828cbccf003973c87864a54f0 Mon Sep 17 00:00:00 2001 From: Vasily Fedorov Date: Fri, 14 Jan 2022 19:11:01 +0300 Subject: [PATCH 3/7] fixed crashing on compiling --- examples/vectorTest/Vector/VectorTest.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/vectorTest/Vector/VectorTest.cpp b/examples/vectorTest/Vector/VectorTest.cpp index 485e482..04b417d 100644 --- a/examples/vectorTest/Vector/VectorTest.cpp +++ b/examples/vectorTest/Vector/VectorTest.cpp @@ -22,11 +22,15 @@ #include #include +namespace { + template -class VectorTest : public ::testing::test { +class VectorTest : public ::testing::Test { protected: using Vector = std::vector; -} +}; + +using testing::Types; TYPED_TEST_SUITE_P(VectorTest); @@ -40,4 +44,5 @@ 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 +INSTANTIATE_TYPED_TEST_SUITE_P(VectorTesting, VectorTest, TestedTypes); +} \ No newline at end of file From 05f5097aa322c8f49e9799cb18277fa25654f3a4 Mon Sep 17 00:00:00 2001 From: Vasily Fedorov Date: Sun, 16 Jan 2022 17:59:31 +0300 Subject: [PATCH 4/7] added reading config --- examples/vectorTest/Vector/VectorTest.h | 92 +++++++++++++++++++++++ examples/vectorTest/vectorTypesConfig.txt | 3 + 2 files changed, 95 insertions(+) create mode 100644 examples/vectorTest/Vector/VectorTest.h create mode 100644 examples/vectorTest/vectorTypesConfig.txt diff --git a/examples/vectorTest/Vector/VectorTest.h b/examples/vectorTest/Vector/VectorTest.h new file mode 100644 index 0000000..bdd01a5 --- /dev/null +++ b/examples/vectorTest/Vector/VectorTest.h @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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 { + + public: + ConfigReader() { + + } + + list typeNames(){ + ifstream inputStream(configFile); + string configLine; + list typeNameList; + while (getline(inputStream, configLine)) { + int typenameStart = configLine.find("<") + 1; + int typenameEnd = configLine.find(">") - 1; + typeNameList.push_back(configLine.substr(typenameStart, typenameEnd - typenameStart + 1)); + } + return typeNameList; + } + + list exampleStringValues(string typeName){ + ifstream inputStream(configFile); + string configLine; + list valueList; + while (getline(inputStream, configLine)) + { + if(configLine.find("<" + typeName + ">") != -1) { + int valueListStart = configLine.find("{") + 1; + int valueListEnd = configLine.find("}") - 1; + istringstream valuesWithoutBraces(configLine.substr(valueListStart, valueListEnd - valueListStart + 1)); + do { + string currentValue; + valuesWithoutBraces >> currentValue; + valueList.push_back(currentValue); + } while (valuesWithoutBraces); + break; + } + } + return valueList; + } +}; + +template +class TestedVector : public std::vector { + public: + TestedVector() { CreateTestedVector(); } + std::vector testedVect; + private: + void CreateTestedVector(){ + ConfigReader configReader; + std::list stringVectorValues = configReader.exampleStringValues(typeid(T).name()); + while (!stringVectorValues.empty()) + { + string nextStringValue = stringVectorValues.front(); + stringVectorValues.pop_front(); + T nextValue; + stringstream convertTypenameToType(nextStringValue); + convertTypenameToType >> nextValue; + testedVect.push_back(nextValue); + } + } +}; \ 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 From 4071b9d5b987402586cc9cc36316e8f3a416a722 Mon Sep 17 00:00:00 2001 From: Vasily Fedorov Date: Sun, 16 Jan 2022 18:00:51 +0300 Subject: [PATCH 5/7] moved creating vector to test fixture --- examples/vectorTest/Vector/VectorTest.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/vectorTest/Vector/VectorTest.cpp b/examples/vectorTest/Vector/VectorTest.cpp index 04b417d..a681ba4 100644 --- a/examples/vectorTest/Vector/VectorTest.cpp +++ b/examples/vectorTest/Vector/VectorTest.cpp @@ -21,23 +21,35 @@ #include #include +#include "VectorTest.h" namespace { + +template +::std::vector CreateVector() { + TestedVector vectCreator; + ::std::vector vect = vectCreator.testedVect; + return vect; +} + template class VectorTest : public ::testing::Test { protected: - using Vector = std::vector; + VectorTest() { + ::std::vector vect = CreateVector(); + } + ~VectorTest() override {} + ::std::vector vect; }; -using testing::Types; +using ::testing::Types; TYPED_TEST_SUITE_P(VectorTest); TYPED_TEST_P(VectorTest, Clearing) { - std::vector vect{0}; - vect.clear(); - EXPECT_EQ(vect.empty(), true); + this->vect.clear(); + EXPECT_EQ(this->vect.empty(), true); } REGISTER_TYPED_TEST_SUITE_P( From 4edc96295ca519015286625d99fe0edcf401fe13 Mon Sep 17 00:00:00 2001 From: Vasily Fedorov Date: Mon, 17 Jan 2022 21:44:35 +0300 Subject: [PATCH 6/7] refactored VectorTest.h --- examples/vectorTest/Vector/VectorTest.h | 72 ++++++++++++++----------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/examples/vectorTest/Vector/VectorTest.h b/examples/vectorTest/Vector/VectorTest.h index bdd01a5..bdf3776 100644 --- a/examples/vectorTest/Vector/VectorTest.h +++ b/examples/vectorTest/Vector/VectorTest.h @@ -31,38 +31,59 @@ 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(){ - ifstream inputStream(configFile); - string configLine; + list typeNames() { list typeNameList; - while (getline(inputStream, configLine)) { - int typenameStart = configLine.find("<") + 1; - int typenameEnd = configLine.find(">") - 1; - typeNameList.push_back(configLine.substr(typenameStart, typenameEnd - typenameStart + 1)); + for(string configLine : readConfigFile()) { + typeNameList.push_back(findTypeNameInLine(configLine)); } return typeNameList; } - list exampleStringValues(string typeName){ - ifstream inputStream(configFile); - string configLine; + list exampleStringValues(string typeName) { list valueList; - while (getline(inputStream, configLine)) + for(string configLine : readConfigFile()) { if(configLine.find("<" + typeName + ">") != -1) { - int valueListStart = configLine.find("{") + 1; - int valueListEnd = configLine.find("}") - 1; - istringstream valuesWithoutBraces(configLine.substr(valueListStart, valueListEnd - valueListStart + 1)); - do { - string currentValue; - valuesWithoutBraces >> currentValue; - valueList.push_back(currentValue); - } while (valuesWithoutBraces); + valueList = findValueListInLine(configLine); break; } } @@ -77,16 +98,7 @@ class TestedVector : public std::vector { std::vector testedVect; private: void CreateTestedVector(){ - ConfigReader configReader; - std::list stringVectorValues = configReader.exampleStringValues(typeid(T).name()); - while (!stringVectorValues.empty()) - { - string nextStringValue = stringVectorValues.front(); - stringVectorValues.pop_front(); - T nextValue; - stringstream convertTypenameToType(nextStringValue); - convertTypenameToType >> nextValue; - testedVect.push_back(nextValue); - } + // there is a place where typenames should + // be provided on the compile time } }; \ No newline at end of file From bdd7d1ce0fade06ac57acdfcaf5fd51b4d0a2156 Mon Sep 17 00:00:00 2001 From: Vasily Fedorov Date: Mon, 17 Jan 2022 21:52:03 +0300 Subject: [PATCH 7/7] deleted running workflow on pushing not to master --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63338a0..901dd4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,7 @@ on: - main push: branches: - - main, - - vector_tests + - main jobs: build: @@ -127,4 +126,4 @@ jobs: shell: bash run: | cd build - ctest \ No newline at end of file + ctest