diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2019-12-05 16:10:23 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2019-12-17 09:43:58 (GMT) |
commit | a38d04c0764b3550bd7d17b659945a38c1368f1e (patch) | |
tree | 67c5c928c47121a6646b5a666fe2a496c446b21f /Tests/CMakeLib | |
parent | d082d0e109257ea2f1adce278658fa825a3f08a2 (diff) | |
download | CMake-a38d04c0764b3550bd7d17b659945a38c1368f1e.zip CMake-a38d04c0764b3550bd7d17b659945a38c1368f1e.tar.gz CMake-a38d04c0764b3550bd7d17b659945a38c1368f1e.tar.bz2 |
Refactoring: introduce header cmext/algorithm with append functions
Diffstat (limited to 'Tests/CMakeLib')
-rw-r--r-- | Tests/CMakeLib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/CMakeLib/testCMExtAlgorithm.cxx | 117 |
2 files changed, 118 insertions, 0 deletions
diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt index 976c924..25d2de6 100644 --- a/Tests/CMakeLib/CMakeLists.txt +++ b/Tests/CMakeLib/CMakeLists.txt @@ -26,6 +26,7 @@ set(CMakeLib_TESTS testUVRAII.cxx testUVStreambuf.cxx testCMExtMemory.cxx + testCMExtAlgorithm.cxx ) add_executable(testUVProcessChainHelper testUVProcessChainHelper.cxx) diff --git a/Tests/CMakeLib/testCMExtAlgorithm.cxx b/Tests/CMakeLib/testCMExtAlgorithm.cxx new file mode 100644 index 0000000..c731b72 --- /dev/null +++ b/Tests/CMakeLib/testCMExtAlgorithm.cxx @@ -0,0 +1,117 @@ +#include <iostream> +#include <memory> +#include <utility> +#include <vector> + +#include <cmext/algorithm> + +namespace { + +int failed = 0; + +void testAppend() +{ + std::cout << "testAppend()" << std::endl; + + // ---------------------------------------------------- + // cm::append(Vector, Iterator, Iterator) + { + std::vector<int> v1{ 1, 2, 3 }; + std::vector<int> v1_ref{ 1, 2, 3, 4, 5, 6 }; + std::vector<int> v2{ 4, 5, 6 }; + std::vector<int> v2_ref{ 4, 5, 6 }; + + cm::append(v1, v2.begin(), v2.end()); + + if (v1 != v1_ref || v2 != v2_ref) { + ++failed; + } + } + + // ---------------------------------------------------- + // cm::append(Vector, Range) + { + std::vector<int> v1{ 1, 2, 3 }; + std::vector<int> v1_ref{ 1, 2, 3, 4, 5, 6 }; + std::vector<int> v2{ 4, 5, 6 }; + std::vector<int> v2_ref{ 4, 5, 6 }; + + cm::append(v1, v2); + + if (v1 != v1_ref || v2 != v2_ref) { + ++failed; + } + } + + // ---------------------------------------------------- + // cm::append(Vector<*>, Vector<unique_ptr>) + { + std::vector<int*> v1{ new int(1), new int(2), new int(3) }; + std::vector<int*> v1_ref = v1; + std::vector<std::unique_ptr<int>> v2; + + v2.emplace_back(new int(4)); + v2.emplace_back(new int(5)); + v2.emplace_back(new int(6)); + + cm::append(v1, v2); + + if (v1.size() == 6 && v2.size() == 3) { + for (int i = 0; i < 3; i++) { + if (v1[i] != v1_ref[i]) { + ++failed; + break; + } + } + for (int i = 0; i < 3; i++) { + if (v1[i + 3] != v2[i].get()) { + ++failed; + break; + } + } + } else { + ++failed; + } + + // free memory to please memory sanitizer + delete v1[0]; + delete v1[1]; + delete v1[2]; + } + + // ---------------------------------------------------- + // cm::append(Vector<unique_ptr>, Vector<unique_ptr>) + { + std::vector<std::unique_ptr<int>> v1; + std::vector<std::unique_ptr<int>> v2; + + v1.emplace_back(new int(1)); + v1.emplace_back(new int(2)); + v1.emplace_back(new int(3)); + + v2.emplace_back(new int(4)); + v2.emplace_back(new int(5)); + v2.emplace_back(new int(6)); + + cm::append(v1, std::move(v2)); + + if (v1.size() == 6 && v2.empty()) { + for (int i = 0; i < 6; i++) { + if (*v1[i] != i + 1) { + ++failed; + break; + } + } + } else { + ++failed; + } + } +} +} + +int testCMExtAlgorithm(int /*unused*/, char* /*unused*/ []) +{ + testAppend(); + + return failed; +} |