├── cevelop-workspace ├── .gitignore ├── scope17 │ ├── .gitignore │ ├── .project │ ├── src │ │ ├── license.txt │ │ └── Test.cpp │ └── cute │ │ ├── cute_version.h │ │ ├── cute.h │ │ ├── cute_listener.h │ │ ├── cute_determine_version.h │ │ ├── cute_suite.h │ │ ├── cute_determine_traits.h │ │ ├── cute_suite_test.h │ │ ├── cute_determine_library.h │ │ ├── cute_repeated_test.h │ │ ├── cute_xml_file.h │ │ ├── cute_deprecated.h │ │ ├── cute_diff_values.h │ │ ├── cute_test.h │ │ ├── cute_throws.h │ │ ├── cute_counting_listener.h │ │ ├── cute_test_incarnate.h │ │ ├── ostream_listener.h │ │ ├── cute_range.h │ │ ├── cute_base.h │ │ ├── tap_listener.h │ │ ├── cute_integer_sequence.h │ │ ├── cute_relops.h │ │ ├── ide_listener.h │ │ ├── cute_testmember.h │ │ ├── xml_listener.h │ │ ├── cute_data_driven.h │ │ ├── cute_demangle.h │ │ ├── cute_runner.h │ │ ├── cute_equals.h │ │ └── cute_to_string.h └── CMakeLists.txt ├── .clang-format ├── scopeConfig.cmake.in ├── examples ├── CMakeLists.txt └── Demo.cpp ├── appveyor.yml ├── .gitignore ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── .travis.yml ├── README.md ├── LICENSE_1_0.txt ├── CMakeLists.txt └── scope.hpp /cevelop-workspace/.gitignore: -------------------------------------------------------------------------------- 1 | /.metadata/ 2 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | demo_hello.txt 3 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | IndentWidth: 4 4 | # BraceWrapping: 5 | -------------------------------------------------------------------------------- /scopeConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/scopeTargets.cmake") 4 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.12...3.19 FATAL_ERROR) 2 | 3 | project(demo LANGUAGES CXX) 4 | 5 | if(NOT TARGET scope) 6 | find_package(scope CONFIG REQUIRED) 7 | endif() 8 | 9 | add_executable(Demo Demo.cpp) 10 | target_link_libraries(Demo PRIVATE std::scope) 11 | 12 | if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux") 13 | target_link_libraries(Demo PRIVATE "stdc++fs") 14 | endif() 15 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | 2 | image: 3 | - Visual Studio 2017 4 | - Visual Studio 2019 5 | 6 | platform: 7 | - x64 8 | - Win32 9 | 10 | configuration: 11 | - Debug 12 | - Release 13 | 14 | matrix: 15 | fast_finish: true 16 | 17 | build_script: 18 | - cmd: >- 19 | mkdir build && cd build && cmake -A %platform% .. && cmake --build . --config %configuration% 20 | 21 | test_script: 22 | - cmd: >- 23 | ctest -C %configuration% 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.bbl 3 | *.blg 4 | *.dvi 5 | *.fdb_latexmk 6 | *.fls 7 | *.glg 8 | *.glo 9 | *.gls 10 | *.idx 11 | *.ilg 12 | *.ind 13 | *.ist 14 | *.lof 15 | *.log 16 | *.lot 17 | *.nav 18 | *.nlo 19 | *.out 20 | *.pdfsync 21 | *.ps 22 | *.snm 23 | *.synctex.gz 24 | *.toc 25 | *.vrb 26 | *.maf 27 | *.mtc 28 | *.mtc0 29 | 30 | .DS_Store 31 | 32 | Release 33 | Debug 34 | .metadata/ 35 | .settings/ 36 | .cproject 37 | *Test.xml 38 | .*.html 39 | scope17.xml 40 | 41 | build/ 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: cpp 3 | 4 | matrix: 5 | include: 6 | - os: linux 7 | dist: bionic 8 | addons: 9 | apt: 10 | sources: 11 | - ubuntu-toolchain-r-test 12 | packages: 13 | - g++-8 14 | env: 15 | - CC=gcc-8 16 | - CXX=g++-8 17 | - configuration=Debug 18 | 19 | - os: linux 20 | dist: bionic 21 | addons: 22 | apt: 23 | sources: 24 | - ubuntu-toolchain-r-test 25 | packages: 26 | - g++-8 27 | env: 28 | - CC=gcc-8 29 | - CXX=g++-8 30 | - configuration=Release 31 | 32 | script: 33 | mkdir build && cd build && cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE .. && cmake --build . --config $configuration && ctest -C $configuration 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # scope17 2 | C++17 version of `unique_resource` and `scope_guards` from LFTS3 3 | 4 | List of tested compilers: 5 | - OSX and AppleClang 12.0 6 | - Linux and gcc 8.3 7 | - Windows and msvc 2017 8 | - Windows and msvc 2019 9 | 10 | Status of tests in CI servers: 11 | 12 | | Branch | Travis | Appveyor | 13 | | ---- | -------- | -------- | 14 | | **Master** | [![Travis Build](https://travis-ci.org/menuet/scope17.svg?branch=master)](https://travis-ci.org/menuet/scope17) | [![Appveyor Build](https://ci.appveyor.com/api/projects/status/g4oox7x8f7ytfmv6/branch/master?svg=true)](https://ci.appveyor.com/project/menuet/scope17/branch/master) | 15 | 16 | How to build and run the tests locally: 17 | ``` 18 | mkdir build && cd build && cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE .. && cmake --build . --config Debug && ctest -C Debug 19 | ``` 20 | -------------------------------------------------------------------------------- /cevelop-workspace/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(scope_test scope17/src/Test.cpp ../scope.hpp) 2 | target_include_directories(scope_test PRIVATE scope17/cute) 3 | target_link_libraries(scope_test PRIVATE scope) 4 | 5 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR 6 | ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")) 7 | target_compile_definitions(scope_test PRIVATE _CRT_SECURE_NO_WARNINGS) 8 | endif() 9 | 10 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 11 | add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wold-style-cast) 12 | endif() 13 | 14 | if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux") 15 | target_link_libraries(scope_test PRIVATE "stdc++fs") 16 | endif() 17 | 18 | add_test(NAME scope_test COMMAND scope_test) 19 | 20 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | scope17 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | ch.hsr.ifs.cute.ui.cutenature 23 | org.eclipse.cdt.core.cnature 24 | org.eclipse.cdt.core.ccnature 25 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 26 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 27 | 28 | 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/src/license.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Copyright (c) 2016-2022 Eric Niebler and Peter Sommerlad 4 | 5 | Permission is hereby granted, free of charge, to any person or organization 6 | obtaining a copy of the software and accompanying documentation covered by 7 | this license (the "Software") to use, reproduce, display, distribute, 8 | execute, and transmit the Software, and to prepare derivative works of the 9 | Software, and to permit third-parties to whom the Software is furnished to 10 | do so, all subject to the following: 11 | 12 | The copyright notices in the Software and this entire statement, including 13 | the above license grant, this restriction and the following disclaimer, 14 | must be included in all copies of the Software, in whole or in part, and 15 | all derivative works of the Software, unless such copies or derivative 16 | works are solely in the form of machine-executable object code generated by 17 | a source language processor. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | 27 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_version.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2008-2018 Peter Sommerlad, Emanuel Graf, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_VERSION_H_ 27 | #define CUTE_VERSION_H_ 28 | 29 | #define CUTE_LIB_VERSION "2.2.6" 30 | 31 | #endif /*CUTE_VERSION_H_*/ 32 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2006-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_H_ 27 | #define CUTE_H_ 28 | // all CUTE includes for writing tests and suites 29 | #include "cute_base.h" 30 | #include "cute_equals.h" 31 | #include "cute_relops.h" 32 | #include "cute_data_driven.h" 33 | #include "cute_throws.h" 34 | #include "cute_suite.h" 35 | #include "cute_repeated_test.h" 36 | #include "cute_suite_test.h" 37 | #include "cute_test_incarnate.h" 38 | #include "cute_test.h" 39 | #include "cute_testmember.h" 40 | #include "cute_version.h" 41 | #endif /*CUTE_H_*/ 42 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_listener.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_LISTENER_H_ 27 | #define CUTE_LISTENER_H_ 28 | #include "cute_base.h" 29 | #include "cute_suite.h" 30 | namespace cute { 31 | struct null_listener{ // defines Contract of runner parameter 32 | void begin(suite const &, char const * /*info*/, size_t /*n_of_tests*/){} 33 | void end(suite const &, char const * /*info*/){} 34 | void start(test const &){} 35 | void success(test const &,char const * /*msg*/){} 36 | void failure(test const &,test_failure const &){} 37 | void error(test const &,char const * /*what*/){} 38 | }; 39 | } 40 | #endif /* CUTE_LISTENER_H_ */ 41 | 42 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_determine_version.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_DETERMINE_VERSION_H_ 27 | #define CUTE_DETERMINE_VERSION_H_ 28 | 29 | #if __cplusplus >= 201103L && ! defined (USE_STD11) 30 | #define USE_STD11 1 31 | #endif 32 | 33 | #if defined(__GNUG__) && defined(__GXX_EXPERIMENTAL_CXX0X__) && ! defined(USE_TR1) && ! defined(USE_STD11) 34 | #define USE_STD11 1 35 | #endif 36 | 37 | #ifdef _MSC_VER 38 | #if (_MSC_VER >= 1400) 39 | #define USE_STD11 1 40 | #endif 41 | #endif 42 | 43 | #if __cplusplus >= 201402L 44 | #define USE_STD14 45 | #endif 46 | 47 | #if __cplusplus >= 201703L 48 | #define USE_STD17 49 | #endif 50 | #endif /*CUTE_DETERMINE_VERSION_H_*/ 51 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_suite.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2006-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_SUITE_H_ 27 | #define CUTE_SUITE_H_ 28 | 29 | #include "cute_test.h" 30 | 31 | #include 32 | 33 | namespace cute { 34 | typedef std::vector suite; 35 | // convenience operator for appending to suites, might not be right 36 | // deprecated, not supported by plug-in, not needed with Eclipse plug-in 37 | inline 38 | suite &operator+=(suite &left, suite const &right){ 39 | left.insert(left.end(),right.begin(),right.end()); 40 | return left; 41 | } 42 | inline 43 | suite &operator+=(suite &left, test const &right){ 44 | left.push_back(right); 45 | return left; 46 | } 47 | } 48 | 49 | #endif /*CUTE_SUITE_H_*/ 50 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_determine_traits.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2013-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_DETERMINE_TRAITS_H_ 27 | #define CUTE_DETERMINE_TRAITS_H_ 28 | #include "cute_determine_version.h" 29 | #if defined(USE_STD11) 30 | #include 31 | #elif defined(USE_TR1) 32 | #include 33 | #else 34 | #include 35 | #include 36 | #include 37 | #endif 38 | #if defined(USE_STD11) 39 | namespace impl_place_for_traits = std; 40 | #elif defined(USE_TR1) 41 | namespace impl_place_for_traits = std::tr1; 42 | #else 43 | namespace impl_place_for_traits = boost; 44 | #endif 45 | 46 | #endif /* CUTE_DETERMINE_TRAITS_H_ */ 47 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_suite_test.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2006-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_SUITE_TEST_H_ 27 | #define CUTE_SUITE_TEST_H_ 28 | #include "cute_suite.h" 29 | #include "cute_determine_library.h" 30 | 31 | #include 32 | namespace cute{ 33 | // make a whole suite a test, failure stops the suite's execution 34 | struct suite_test { 35 | suite theSuite; 36 | suite_test(suite const &s):theSuite(s){} 37 | void operator()(){ 38 | std::for_each(theSuite.begin(),theSuite.end(),boost_or_tr1::bind(&test::operator(),_1)); 39 | } 40 | }; 41 | } 42 | #define CUTE_SUITE_TEST(s) cute::test(cute::suite_test((s)),#s) 43 | #define CUTE_SUITE_TEST_NAME(s, name) cute::test(cute::suite_test((s)),name) 44 | #endif /*CUTE_SUITE_TEST_H_*/ 45 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_determine_library.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_DETERMINE_LIBRARY_H_ 27 | #define CUTE_DETERMINE_LIBRARY_H_ 28 | #include "cute_determine_version.h" 29 | #if defined(USE_TR1) 30 | #include 31 | // bind already given by in cute_test.h from cute_suite.h 32 | namespace boost_or_tr1 = std::tr1; 33 | namespace cute { 34 | using namespace boost_or_tr1::placeholders; 35 | } 36 | #elif defined(USE_STD11) 37 | #include 38 | namespace boost_or_tr1 = std; 39 | namespace cute { 40 | using namespace boost_or_tr1::placeholders; 41 | } 42 | #else 43 | #include 44 | #include 45 | namespace boost_or_tr1 = boost; 46 | #endif 47 | 48 | #endif /*CUTE_DETERMINE_LIBRARY_H_*/ 49 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_repeated_test.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2006-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_REPEATED_TEST_H_ 27 | #define CUTE_REPEATED_TEST_H_ 28 | 29 | #include "cute_test.h" 30 | 31 | namespace cute{ 32 | struct repeated_test { 33 | repeated_test(test const &t,unsigned int n):theTest(t),repetitions(n){} 34 | void operator()(){ 35 | for (unsigned int i=0;i 30 | #include 31 | 32 | namespace cute { 33 | struct xml_file_opener { 34 | std::string filename; 35 | std::ofstream out; 36 | xml_file_opener(int argc, char const *const* argv) 37 | :filename(argc>0&&argv[0]?basename(argv[0]):"testresult.xml") 38 | ,out(filename.c_str()){} 39 | std::string basename(std::string path){ 40 | #if defined( _MSC_VER ) || defined(__MINGW32__) 41 | char const sep='\\'; 42 | #else 43 | char const sep='/'; 44 | #endif 45 | std::string::size_type pos=path.find_last_of(sep,path.size()-1); 46 | if (pos != std::string::npos) path.erase(0,pos+1); 47 | path+=".xml"; 48 | return path; 49 | } 50 | }; 51 | } 52 | 53 | #endif /* CUTE_XML_FILE_H_ */ 54 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_deprecated.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2016-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_DEPRECATED_H_ 27 | #define CUTE_DEPRECATED_H_ 28 | 29 | #if __cplusplus >= 201402L 30 | #define DEPRECATE(orig, repl) [[deprecated ("Use "#repl" instead.")]] inline void orig() {} 31 | #elif defined(__GNUG__) 32 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 33 | #if GCC_VERSION >= 40500 || defined(__clang__) 34 | #define DEPRECATE(orig, repl) __attribute__((deprecated("Use "#repl" instead."))) inline void orig() {} 35 | #else 36 | #define DEPRECATE(orig, repl) __attribute__((deprecated)) inline void orig() {} 37 | #endif 38 | #elif defined(_MSC_VER) 39 | #define DEPRECATE(orig, repl) __declspec(deprecated(#orig" is deprecated, use "#repl" instead.")) inline void orig() {} 40 | #endif 41 | 42 | #ifdef DEPRECATE 43 | #define DEPRECATED(name) name() 44 | #endif 45 | 46 | #endif /*CUTE_DEPRECATED_H_*/ 47 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.12...3.19 FATAL_ERROR) 2 | 3 | project(scope17 VERSION 0.9.0 LANGUAGES CXX) 4 | 5 | set(MASTER_PROJECT OFF) 6 | if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) 7 | set(MASTER_PROJECT ON) 8 | message(STATUS "CMake version: ${CMAKE_VERSION}") 9 | endif() 10 | 11 | #---------------------------------------------------------- 12 | # Compiler config 13 | #---------------------------------------------------------- 14 | if(NOT DEFINED CMAKE_CXX_STANDARD) 15 | set(CMAKE_CXX_STANDARD 17) 16 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 17 | set(CMAKE_CXX_EXTENSIONS OFF) 18 | endif() 19 | 20 | add_library(scope INTERFACE) 21 | add_library(std::scope ALIAS scope) 22 | 23 | ### target_sources(scope INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/scope.hpp) 24 | target_include_directories(scope INTERFACE 25 | $ 26 | ) 27 | target_include_directories(scope SYSTEM INTERFACE 28 | $/include/experimental> 29 | ) 30 | target_compile_features(scope INTERFACE cxx_std_17) 31 | 32 | option(SCOPE_TEST "Generate the scope_test target" ${MASTER_PROJECT}) 33 | if(SCOPE_TEST) 34 | enable_testing() 35 | add_subdirectory(cevelop-workspace) 36 | add_subdirectory(examples) 37 | endif() 38 | 39 | option(SCOPE_INSTALL "Generate the scope_test target" ${MASTER_PROJECT}) 40 | if(SCOPE_INSTALL) 41 | install(TARGETS scope EXPORT scopeTargets 42 | INCLUDES DESTINATION include 43 | ) 44 | 45 | install(EXPORT scopeTargets 46 | FILE scopeTargets.cmake 47 | NAMESPACE std:: 48 | DESTINATION lib/cmake/scope 49 | ) 50 | 51 | export(TARGETS scope 52 | NAMESPACE std:: 53 | FILE scopeTargets.cmake 54 | ) 55 | 56 | install(FILES scope.hpp DESTINATION include/experimental) 57 | 58 | include(CMakePackageConfigHelpers) 59 | configure_package_config_file(scopeConfig.cmake.in 60 | ${CMAKE_CURRENT_BINARY_DIR}/scopeConfig.cmake 61 | INSTALL_DESTINATION lib/cmake/scope 62 | ) 63 | write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/scopeConfigVersion.cmake 64 | COMPATIBILITY SameMajorVersion 65 | ) 66 | 67 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/scopeConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/scopeConfigVersion.cmake 68 | DESTINATION lib/cmake/scope 69 | ) 70 | endif() 71 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_diff_values.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2013-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_DIFF_VALUES_H_ 27 | #define CUTE_DIFF_VALUES_H_ 28 | #include "cute_to_string.h" 29 | namespace cute { 30 | // you could provide your own overload for diff_values for your app-specific types 31 | // be sure to use tabs as given below, then the CUTE eclipse plug-in will parse correctly 32 | template 33 | std::string diff_values(ExpectedValue const &expected 34 | , ActualValue const & actual 35 | , char const *left="expected" 36 | , char const *right="but was"){ 37 | // construct a simple message...to be parsed by IDE support 38 | std::string res; 39 | res += ' '; 40 | res += left; 41 | res+=":\t" + cute_to_string::backslashQuoteTabNewline(cute_to_string::to_string(expected))+'\t'; 42 | res += right; 43 | res +=":\t"+cute_to_string::backslashQuoteTabNewline(cute_to_string::to_string(actual))+'\t'; 44 | return res; 45 | } 46 | } 47 | 48 | #endif /* CUTE_DIFF_VALUES_H_ */ 49 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_test.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, Emanuel Graf, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_TEST_H_ 27 | #define CUTE_TEST_H_ 28 | 29 | #include "cute_determine_library.h" 30 | #include "cute_demangle.h" 31 | 32 | // make plain functions as tests more 'cute': 33 | namespace cute { 34 | 35 | struct test{ 36 | void operator()()const{ theTest(); } 37 | std::string name()const{ return name_;} 38 | 39 | 40 | // (real) functor types can (almost) spell their name 41 | // but a name can also be given explicitely, e.g. for CUTE() macro 42 | // for simple test functions 43 | template 44 | test(VoidFunctor const &t, std::string sname = demangle(typeid(VoidFunctor).name())) 45 | :name_(sname),theTest(t){} 46 | // separate overload to allow nicer C++11 initializers with {"name",lambda} 47 | template 48 | test(std::string sname,VoidFunctor const &t) 49 | :name_(sname),theTest(t){} 50 | 51 | private: 52 | std::string name_; 53 | boost_or_tr1::function theTest; 54 | }; 55 | 56 | } 57 | 58 | #define CUTE(name) cute::test((&name),(#name)) 59 | 60 | #endif /*CUTE_TEST_H_*/ 61 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_throws.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_THROWS_H_ 27 | #define CUTE_THROWS_H_ 28 | 29 | #include "cute_base.h" 30 | 31 | // should we allow arbitrary code and remove the parentheses around the macro expansion? 32 | // not now, strange compilation side-effects might result. 33 | namespace cute { 34 | namespace do_not_use_this_namespace { 35 | struct assert_throws_failure_exception { 36 | struct cute::test_failure original; 37 | assert_throws_failure_exception(std::string const &r,char const *f, int line): 38 | original(r,f, line){} 39 | }; 40 | } 41 | } 42 | 43 | #define ASSERT_THROWSM(anuncommonmessagetextparametername,code,exc) \ 44 | do { \ 45 | try { \ 46 | { code ; } \ 47 | throw cute::do_not_use_this_namespace::assert_throws_failure_exception((anuncommonmessagetextparametername),__FILE__,__LINE__); \ 48 | } catch(exc const &){ \ 49 | } catch(cute::do_not_use_this_namespace::assert_throws_failure_exception const &atf){throw atf.original;} \ 50 | } while(0) 51 | #define ASSERT_THROWS(code,exc) ASSERT_THROWSM(" expecting " #code " to throw " #exc,code,exc) 52 | 53 | #endif /*CUTE_THROWS_H_*/ 54 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_counting_listener.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_COUNTING_LISTENER_H_ 27 | #define CUTE_COUNTING_LISTENER_H_ 28 | #include "cute_listener.h" 29 | namespace cute{ 30 | template 31 | struct counting_listener:Listener{ 32 | counting_listener() 33 | :Listener() 34 | ,numberOfTests(0),successfulTests(0),failedTests(0),errors(0),numberOfSuites(0),numberOfTestsInSuites(0){} 35 | 36 | counting_listener(Listener const &s) 37 | :Listener(s) 38 | ,numberOfTests(0),successfulTests(0),failedTests(0),errors(0),numberOfSuites(0),numberOfTestsInSuites(0){} 39 | 40 | void begin(suite const &s,char const *info, size_t n_of_tests){ 41 | ++numberOfSuites; 42 | numberOfTestsInSuites+=n_of_tests; 43 | Listener::begin(s,info, n_of_tests); 44 | } 45 | void start(test const &t){ 46 | ++numberOfTests; 47 | Listener::start(t); 48 | } 49 | void success(test const &t,char const *msg){ 50 | ++successfulTests; 51 | Listener::success(t,msg); 52 | } 53 | void failure(test const &t,test_failure const &e){ 54 | ++failedTests; 55 | Listener::failure(t,e); 56 | } 57 | void error(test const &t,char const *what){ 58 | ++errors; 59 | Listener::error(t,what); 60 | } 61 | size_t numberOfTests; 62 | size_t successfulTests; 63 | size_t failedTests; 64 | size_t errors; 65 | size_t numberOfSuites; 66 | size_t numberOfTestsInSuites; 67 | 68 | }; 69 | } 70 | #endif /*CUTE_COUNTING_LISTENER_H_*/ 71 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_test_incarnate.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2006-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_TEST_INCARNATE_H_ 27 | #define CUTE_TEST_INCARNATE_H_ 28 | 29 | #include "cute_test.h" 30 | 31 | // idea blatantly stolen from Aeryn 32 | namespace cute { 33 | template 34 | struct test_incarnate { 35 | void operator()(){ 36 | TestFunctor()(); 37 | } 38 | }; 39 | // TODO: check if there are problems with references. 40 | template 41 | struct test_incarnate_with_context { 42 | test_incarnate_with_context(ContextObject context):theContext(context) 43 | {} 44 | test_incarnate_with_context(test_incarnate_with_context const &other):theContext(other.theContext){} // provide copy-ctor in case compiler will define it deleted 45 | void operator()(){ 46 | TestFunctor t(theContext);// wouldn't create temporary to call with ()() 47 | t(); 48 | } 49 | ContextObject theContext; 50 | }; 51 | template 52 | test make_incarnate_with_context(ContextObject obj){ 53 | return test(test_incarnate_with_context(obj),demangle(typeid(TestFunctor).name())); 54 | } 55 | } 56 | 57 | #define CUTE_INCARNATE(TestFunctor) cute::test(cute::test_incarnate(),cute::demangle(typeid(TestFunctor).name())) 58 | #define CUTE_INCARNATE_WITH_CONTEXT(TestFunctor,contextObject) cute::make_incarnate_with_context(contextObject) 59 | 60 | #endif /*CUTE_TEST_INCARNATE_H_*/ 61 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/ostream_listener.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef OSTREAM_LISTENER_H_ 27 | #define OSTREAM_LISTENER_H_ 28 | 29 | #include "cute_listener.h" 30 | 31 | #include 32 | 33 | namespace cute { 34 | // a "root" listener displaying output, use it as an example on how to build your own, e.g., for XML output 35 | template 36 | struct ostream_listener:Listener 37 | { 38 | std::ostream &out; 39 | public: 40 | ostream_listener(std::ostream &os=std::cerr):out(os) {} 41 | void begin(suite const &t,char const *info, size_t n_of_tests){ 42 | out << "beginning: " << info << std::endl; 43 | Listener::begin(t,info, n_of_tests); 44 | } 45 | void end(suite const &t, char const *info){ 46 | out << "ending: " << info << std::endl; 47 | Listener::end(t,info); 48 | } 49 | void start(test const &t){ 50 | out << "starting: " << t.name() << std::endl; 51 | Listener::start(t); 52 | } 53 | void success(test const &t, char const *msg){ 54 | out << t.name() << " " << msg << std::endl; 55 | Listener::success(t,msg); 56 | } 57 | void failure(test const &t,test_failure const &e){ 58 | out << std::dec << e.filename << ":" << e.lineno << ": testcase failed: " << e.reason << " in " << t.name() << std::endl; 59 | Listener::failure(t,e); 60 | } 61 | void error(test const &t, char const *what){ 62 | out << what << " in " << t.name() << std::endl; 63 | Listener::error(t,what); 64 | } 65 | }; 66 | } 67 | 68 | #endif /*OSTREAM_LISTENER_H_*/ 69 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_range.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2015-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_RANGE_H_ 27 | #define CUTE_RANGE_H_ 28 | 29 | #include "cute_determine_version.h" 30 | 31 | #include 32 | #include 33 | #ifdef USE_STD11 34 | #include 35 | #endif 36 | 37 | namespace cute{ 38 | template 39 | struct range { 40 | typedef ForwardIterator const_iterator; // for to_stream dispatch 41 | typedef typename std::iterator_traits::value_type value_type; 42 | const_iterator const b; 43 | const_iterator const e; 44 | range(ForwardIterator bb,ForwardIterator ee):b(bb),e(ee){} 45 | const_iterator begin() const { return b; } 46 | const_iterator end() const { return e; } 47 | template 48 | bool operator==(RangeOrContainer const &other) const{ 49 | #ifdef USE_STD14 50 | return std::equal(begin(),end(),other.begin(),other.end()); 51 | #else 52 | if (std::distance(begin(),end())==std::distance(other.begin(),other.end())){ 53 | return std::equal(begin(),end(),other.begin()); 54 | } 55 | return false; 56 | #endif 57 | } 58 | }; 59 | template 60 | range make_range(ForwardIterator b, ForwardIterator e){ 61 | return range(b,e); 62 | } 63 | 64 | #ifdef USE_STD11 65 | template 66 | range::iterator> 67 | make_range(std::initializer_list const &il){ 68 | return range::iterator>(il.begin(),il.end()); 69 | } 70 | #endif 71 | } 72 | 73 | #endif /* CUTE_RANGE_H_ */ 74 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_base.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_BASE_H_ 27 | #define CUTE_BASE_H_ 28 | 29 | #include "cute_to_string.h" 30 | #include "cute_determine_version.h" 31 | 32 | #include 33 | 34 | namespace cute { 35 | struct test_failure { 36 | std::string reason; 37 | std::string filename; 38 | int lineno; 39 | 40 | test_failure(std::string const &r,char const *f, int line) 41 | :reason(r),filename(f),lineno(line) 42 | { } 43 | char const * what() const { return reason.c_str(); } 44 | }; 45 | } 46 | 47 | #if defined(USE_STD11) && !defined(_MSC_VER) 48 | #define CUTE_FUNCNAME_PREFIX std::string(__func__)+": " 49 | #else 50 | #if defined( _MSC_VER ) || defined(__GNUG__) 51 | //#if defined(USE_STD11) 52 | //#define CUTE_FUNCNAME_PREFIX 53 | // workaround doesn't work namespace { char const __FUNCTION__ []="lambda";} 54 | // MSC can not use lambdas outside of function bodies for tests. 55 | //#endif 56 | // use -D CUTE_FUNCNAME_PREFIX if you want to use non-local lambdas with test macros 57 | #if !defined(CUTE_FUNCNAME_PREFIX) 58 | #define CUTE_FUNCNAME_PREFIX std::string(__FUNCTION__)+": " 59 | #endif 60 | #else // could provide #defines for other compiler-specific extensions... need to experiment, i.e., MS uses __FUNCTION__ 61 | #define CUTE_FUNCNAME_PREFIX std::string("") 62 | #endif 63 | #endif 64 | #define ASSERTM(msg,cond) do { if (!(cond)) throw cute::test_failure(CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__);} while(false) 65 | #define ASSERT(cond) ASSERTM(#cond,cond) 66 | #define FAIL() ASSERTM("FAIL()",false) 67 | #define FAILM(msg) ASSERTM(msg,false) 68 | #endif /*CUTE_BASE_H_*/ 69 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/tap_listener.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2017-2018 Felix Morgner 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef TAP_LISTENER_H_ 27 | #define TAP_LISTENER_H_ 28 | 29 | #include 30 | #include 31 | 32 | #include "cute_listener.h" 33 | 34 | namespace cute { 35 | 36 | template 37 | struct tap_listener : Listener { 38 | tap_listener(std::ostream & out = std::cout) : out(out),nofTests(0) { } 39 | 40 | ~tap_listener() { 41 | if (nofTests) { 42 | out << "1.." << nofTests << '\n'; 43 | } 44 | } 45 | 46 | void begin(suite const & suite, char const * info, size_t n_of_tests) { 47 | out << "# Starting suite '" << info << "' containing " << n_of_tests << " tests\n"; 48 | Listener::begin(suite, info, n_of_tests); 49 | } 50 | 51 | void end(suite const & suite, char const * info) { 52 | out << "# Ending suite '" << info << "'\n"; 53 | Listener::end(suite, info); 54 | } 55 | 56 | void start(test const & test) { 57 | ++nofTests; 58 | Listener::start(test); 59 | } 60 | 61 | void success(test const & test, char const * msg) { 62 | out << "ok " << nofTests << ' ' << test.name() << '\n'; 63 | Listener::success(test, msg); 64 | } 65 | 66 | void failure(test const & test, test_failure const & reason) { 67 | out << "not ok " << nofTests << ' ' << test.name() << '\n'; 68 | out << "# Assertion failed: " << reason.what() << '\n'; 69 | Listener::failure(test, reason); 70 | } 71 | 72 | void error(test const & test, char const * what) { 73 | out << "not ok " << nofTests << ' ' << test.name() << '\n'; 74 | out << "# Unexpected exception: " << what << '\n'; 75 | Listener::error(test, what); 76 | } 77 | 78 | private: 79 | std::ostream & out; 80 | std::size_t nofTests; 81 | }; 82 | 83 | } 84 | 85 | #endif /* TAP_LISTENER_H_ */ 86 | 87 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_integer_sequence.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2016-2018 Felix Morgner 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_INTEGER_SEQUENCE_H_ 27 | #define CUTE_INTEGER_SEQUENCE_H_ 28 | 29 | #include "cute_determine_version.h" 30 | 31 | #ifdef USE_STD14 32 | #include 33 | namespace cute { 34 | using std::index_sequence; 35 | using std::index_sequence_for; 36 | } 37 | #else 38 | #include 39 | namespace cute { 40 | namespace do_not_use_this_namespace { 41 | template 42 | struct integer_sequence { 43 | using type = integer_sequence; 44 | using value_type = IntType; 45 | static constexpr std::size_t size() { return sizeof...(Ints); } 46 | }; 47 | 48 | template 49 | struct flatten; 50 | 51 | template 52 | struct flatten, integer_sequence> 53 | : integer_sequence {}; 54 | 55 | template 56 | struct make_integer_sequence; 57 | 58 | template 59 | struct make_integer_sequence 60 | : integer_sequence{}; 61 | 62 | template 63 | struct make_integer_sequence 64 | : integer_sequence{}; 65 | 66 | template 67 | struct make_integer_sequence 68 | : flatten::type, 69 | typename make_integer_sequence::type>::type {}; 70 | 71 | template 72 | using make_index_sequence = make_integer_sequence; 73 | } 74 | 75 | template 76 | using index_sequence = do_not_use_this_namespace::integer_sequence; 77 | 78 | template 79 | using index_sequence_for = do_not_use_this_namespace::make_index_sequence; 80 | } 81 | #endif 82 | 83 | #endif //CUTE_INTEGER_SEQUENCE_H_ 84 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_relops.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2013-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_RELOPS_H_ 27 | #define CUTE_RELOPS_H_ 28 | 29 | #include "cute_base.h" 30 | #include "cute_diff_values.h" 31 | #include 32 | 33 | namespace cute { 34 | 35 | namespace cute_relops_detail{ 36 | template 37 | std::string compare_values(LeftValue const &left 38 | , RightValue const & right){ 39 | return cute::diff_values(left,right,"left","right"); 40 | } 41 | } 42 | template class RELOP,typename TL, typename TR> 43 | void assert_relop(TL const &left 44 | , TR const &right 45 | ,std::string const &msg 46 | ,char const *file 47 | ,int line) { 48 | if (RELOP()(left,right)) return; 49 | throw test_failure(msg + cute_relops_detail::compare_values(left,right),file,line); 50 | } 51 | 52 | } 53 | #define ASSERT_LESSM(msg,left,right) cute::assert_relop((left),(right),\ 54 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__) 55 | #define ASSERT_LESS(left,right) ASSERT_LESSM(#left " < " #right, (left),(right)) 56 | #define ASSERT_LESS_EQUALM(msg,left,right) cute::assert_relop((left),(right),\ 57 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__) 58 | #define ASSERT_LESS_EQUAL(left,right) ASSERT_LESS_EQUALM(#left " <= " #right, (left),(right)) 59 | #define ASSERT_GREATERM(msg,left,right) cute::assert_relop((left),(right),\ 60 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__) 61 | #define ASSERT_GREATER(left,right) ASSERT_GREATERM(#left " > " #right, (left),(right)) 62 | #define ASSERT_GREATER_EQUALM(msg,left,right) cute::assert_relop((left),(right),\ 63 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__) 64 | #define ASSERT_GREATER_EQUAL(left,right) ASSERT_GREATER_EQUALM(#left " >= " #right, (left),(right)) 65 | #define ASSERT_NOT_EQUAL_TOM(msg,left,right) cute::assert_relop((left),(right),\ 66 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__) 67 | #define ASSERT_NOT_EQUAL_TO(left,right) ASSERT_NOT_EQUAL_TOM(#left " != " #right, (left),(right)) 68 | 69 | #endif /* CUTE_RELOPS_H_ */ 70 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/ide_listener.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef IDE_LISTENER_H_ 27 | #define IDE_LISTENER_H_ 28 | 29 | #include "cute_listener.h" 30 | 31 | #include 32 | #include 33 | #ifdef _MSC_VER 34 | #define WIN32_LEAN_AND_MEAN 35 | #include 36 | #include 37 | #endif 38 | 39 | namespace cute { 40 | template 41 | struct ide_listener: Listener 42 | { 43 | ide_listener(std::ostream &os=std::cout):out(os) {} 44 | void begin(suite const &t,char const *info, size_t n_of_tests){ 45 | out << std::dec << "\n#beginning " << info << " " << n_of_tests << '\n' << std::flush; 46 | Listener::begin(t,info,n_of_tests); 47 | } 48 | void end(suite const &t, char const *info){ 49 | out << "\n#ending " << info << '\n' << std::flush; 50 | Listener::end(t,info); 51 | } 52 | void start(test const &t){ 53 | out << "\n#starting " << t.name() << '\n' << std::flush; 54 | Listener::start(t); 55 | } 56 | void success(test const &t, char const *msg){ 57 | out << "\n#success " << maskBlanks(t.name()) << " " << msg << '\n' << std::flush; 58 | Listener::success(t,msg); 59 | } 60 | void failure(test const &t,test_failure const &e){ 61 | out << std::dec << "\n#failure " << maskBlanks(t.name()) << " " << e.filename << ":" << e.lineno << " " << (e.reason) << '\n' << std::flush; 62 | Listener::failure(t,e); 63 | #ifdef _MSC_VER 64 | std::ostringstream os; 65 | os << std::dec << e.filename << "(" << e.lineno << ") : failure: " < 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "scope.hpp" 10 | 11 | #ifndef _MSC_VER 12 | #include 13 | #include 14 | #else 15 | #include 16 | #define open _open 17 | #define close _close 18 | #define unlink _unlink 19 | #define write _write 20 | #endif 21 | 22 | namespace { 23 | using namespace std::experimental; 24 | 25 | using std::filesystem::path; 26 | 27 | void copy_file_transact(path const &from, path const &to) { 28 | path t{to}; 29 | t += path{".deleteme"}; 30 | auto guard = scope_fail{[t] { remove(t); }}; 31 | copy_file(from, t); 32 | rename(t, to); 33 | } 34 | 35 | void DemonstrateTransactionFilecopy() { 36 | std::string name("hello.txt"); 37 | path to("/tmp/scope_hello.txt"); 38 | { 39 | std::ofstream ofs{name}; 40 | ofs << "Hello world\n"; 41 | } 42 | 43 | copy_file_transact(name, to); 44 | auto guard = scope_success{[to] { remove(to); }}; 45 | assert(exists(to) == true); 46 | } 47 | 48 | void demonstrate_unique_resource_with_stdio() { 49 | const std::string filename = "hello.txt"; 50 | auto fclose = [](auto file) { 51 | ::fclose(file); 52 | }; // not allowed to take address const std::string filename = "hello.txt"; 53 | { 54 | auto file = make_unique_resource_checked(::fopen(filename.c_str(), "w"), 55 | nullptr, fclose); 56 | ::fputs("Hello World!\n", file.get()); 57 | assert(file.get() != nullptr); 58 | } 59 | { 60 | std::ifstream input{filename}; 61 | std::string line{}; 62 | getline(input, line); 63 | assert("Hello World!" == line); 64 | getline(input, line); 65 | assert(input.eof()); 66 | } 67 | ::unlink(filename.c_str()); 68 | { 69 | auto file = make_unique_resource_checked( 70 | ::fopen("nonexistingfile.txt", "r"), nullptr, fclose); 71 | assert(nullptr == file.get()); 72 | } 73 | } 74 | 75 | void demontrate_unique_resource_with_POSIX_IO() { 76 | const std::string filename = "hello1.txt"; 77 | auto close = [](auto fd) { ::close(fd); }; 78 | { 79 | auto file = make_unique_resource_checked( 80 | ::open(filename.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0666), -1, 81 | close); 82 | ::write(file.get(), "Hello World!\n", 12u); 83 | assert(file.get() != -1); 84 | } 85 | { 86 | std::ifstream input{filename}; 87 | std::string line{}; 88 | getline(input, line); 89 | assert("Hello World!" == line); 90 | getline(input, line); 91 | assert(input.eof()); 92 | } 93 | ::unlink(filename.c_str()); 94 | { 95 | auto file = make_unique_resource_checked( 96 | ::open("nonexistingfile.txt", O_RDONLY), -1, close); 97 | assert(-1 == file.get()); 98 | } 99 | } 100 | 101 | void demo_scope_exit_fail_success() { 102 | std::ostringstream out{}; 103 | auto lam = [&] { out << "called "; }; 104 | try { 105 | auto v = scope_exit([&] { out << "always "; }); 106 | auto w = scope_success([&] { out << "not "; }); 107 | auto x = scope_fail(lam); // called too 108 | throw 42; 109 | } catch (...) { 110 | auto y = scope_fail([&] { out << "not "; }); 111 | auto z = scope_success([&] { out << "handled"; }); // called too 112 | } 113 | assert("called always handled" == out.str()); 114 | } 115 | } // namespace 116 | 117 | int main() { 118 | DemonstrateTransactionFilecopy(); 119 | demonstrate_unique_resource_with_stdio(); 120 | demontrate_unique_resource_with_POSIX_IO(); 121 | demo_scope_exit_fail_success(); 122 | } 123 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_testmember.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2006-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_TESTMEMBER_H_ 27 | #define CUTE_TESTMEMBER_H_ 28 | 29 | #include "cute_test.h" 30 | 31 | namespace cute { 32 | template 33 | test makeMemberFunctionTest(TestClass &t,void (TestClass::*fun)(),char const *name){ 34 | return test(boost_or_tr1::bind(fun,boost_or_tr1::ref(t)),demangle(typeid(TestClass).name())+"::"+name); 35 | } 36 | template 37 | test makeMemberFunctionTest(TestClass const &t,void (TestClass::*fun)()const,char const *name){ 38 | return test(boost_or_tr1::bind(fun,boost_or_tr1::cref(t)),demangle(typeid(TestClass).name())+"::"+name); 39 | } 40 | template 41 | struct incarnate_for_member_function { 42 | MemFun memfun; 43 | incarnate_for_member_function(MemFun f):memfun(f){} 44 | void operator()(){ 45 | TestClass t; 46 | (t.*memfun)(); 47 | } 48 | }; 49 | template 50 | test makeSimpleMemberFunctionTest(MemFun fun,char const *name){ 51 | return test(incarnate_for_member_function(fun),demangle(typeid(TestClass).name())+"::"+name); 52 | } 53 | template 54 | struct incarnate_for_member_function_with_context_object { 55 | MemFun memfun; 56 | Context context; 57 | incarnate_for_member_function_with_context_object(MemFun f,Context c) 58 | :memfun(f),context(c){} 59 | incarnate_for_member_function_with_context_object(incarnate_for_member_function_with_context_object const &other) 60 | :memfun(other.memfun),context(other.context){} // provide copy-ctor for std::function ctor requirement should be =default on C++11 61 | 62 | void operator()(){ 63 | TestClass t(context); 64 | (t.*memfun)(); 65 | } 66 | }; 67 | template 68 | test makeMemberFunctionTestWithContext(Context c,MemFun fun,char const *name){ 69 | return test(incarnate_for_member_function_with_context_object(fun,c),demangle(typeid(TestClass).name())+"::"+name); 70 | } 71 | } 72 | 73 | #define CUTE_MEMFUN(testobject,TestClass,MemberFunctionName) \ 74 | cute::makeMemberFunctionTest(testobject,\ 75 | &TestClass::MemberFunctionName,\ 76 | #MemberFunctionName) 77 | #define CUTE_SMEMFUN(TestClass,MemberFunctionName) \ 78 | cute::makeSimpleMemberFunctionTest(\ 79 | &TestClass::MemberFunctionName,\ 80 | #MemberFunctionName) 81 | #define CUTE_CONTEXT_MEMFUN(context_object,TestClass,MemberFunctionName) \ 82 | cute::makeMemberFunctionTestWithContext(\ 83 | context_object,\ 84 | &TestClass::MemberFunctionName,\ 85 | #MemberFunctionName) 86 | 87 | #endif /*CUTE_TESTMEMBER_H_*/ 88 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/xml_listener.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef XML_LISTENER_H_ 27 | #define XML_LISTENER_H_ 28 | 29 | #include "cute_listener.h" 30 | #include "cute_xml_file.h" // for convenience 31 | 32 | #include 33 | 34 | namespace cute { 35 | template 36 | class xml_listener:public Listener 37 | { 38 | protected: 39 | std::string mask_xml_chars(std::string in){ 40 | std::string::size_type pos=0; 41 | while((pos=in.find_first_of("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\"&'<>", pos, 34))!=std::string::npos){ 42 | switch(in[pos]){ 43 | case '&': in.replace(pos,1,"&"); pos +=5; break; 44 | case '<': in.replace(pos,1,"<"); pos += 4; break; 45 | case '>': in.replace(pos,1,">"); pos += 4; break; 46 | case '"': in.replace(pos,1,"""); pos+=6; break; 47 | case '\'':in.replace(pos,1,"'"); pos+=6; break; 48 | default: 49 | char c = in[pos]; 50 | std::string replacement = "0x" + cute_to_string::hexit(c); 51 | in.replace(pos, 1, replacement); pos += replacement.size(); break; 52 | break; 53 | } 54 | } 55 | return in; 56 | } 57 | std::ostream &out; 58 | std::string current_suite; 59 | public: 60 | xml_listener(std::ostream &os):out(os) { 61 | out << "\n"; 62 | } 63 | ~xml_listener(){ 64 | out << "\n"<< std::flush; 65 | } 66 | 67 | void begin(suite const &t,char const *info, size_t n_of_tests){ 68 | current_suite=mask_xml_chars(info); 69 | out << std::dec << "\t\n"; 70 | Listener::begin(t,info, n_of_tests); 71 | } 72 | void end(suite const &t, char const *info){ 73 | out << "\t\n"; 74 | current_suite.clear(); 75 | Listener::end(t,info); 76 | } 77 | void start(test const &t){ 78 | out << "\t\t\n"; 83 | Listener::success(t,msg); 84 | } 85 | void failure(test const &t,test_failure const &e){ 86 | out << std::dec << ">\n\t\t\t\n"<\n\t\t\n"; 88 | Listener::failure(t,e); 89 | } 90 | void error(test const &t, char const *what){ 91 | out << ">\n\t\t\t\n"<\n\t\t\n"; 94 | Listener::error(t,what); 95 | } 96 | }; 97 | } 98 | 99 | #endif /*IDE_LISTENER_H_*/ 100 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_data_driven.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2013-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_DATA_DRIVEN_H_ 27 | #define CUTE_DATA_DRIVEN_H_ 28 | 29 | #include "cute_base.h" 30 | #include "cute_equals.h" 31 | #include "cute_relops.h" 32 | 33 | #define DDTM(msg) (cute::test_failure(cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__)) 34 | #define DDT() DDTM("") 35 | 36 | #define ASSERT_DDTM(cond,msg,failure) do{ \ 37 | if (!(cond)) \ 38 | throw cute::test_failure(CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)+(failure).reason,\ 39 | (failure).filename.c_str(),(failure).lineno);\ 40 | } while (false) 41 | #define ASSERT_DDT(cond,failure) ASSERT_DDTM(cond,#cond,(failure)) 42 | 43 | #define ASSERT_EQUAL_DDTM(msg,expected,actual,failure) cute::assert_equal((expected),(actual),\ 44 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)\ 45 | +(failure).reason,(failure).filename.c_str(),(failure).lineno) 46 | #define ASSERT_EQUAL_DDT(expected,actual,failure) ASSERT_EQUAL_DDTM(#expected " == " #actual, (expected),(actual),(failure)) 47 | #define ASSERT_EQUAL_DELTA_DDTM(msg,expected,actual,delta,failure) cute::assert_equal_delta((expected),(actual),(delta),\ 48 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)\ 49 | +(failure).reason,(failure).filename.c_str(),(failure).lineno) 50 | #define ASSERT_EQUAL_DELTA_DDT(expected,actual,delta,failure) ASSERT_EQUAL_DELTA_DDTM(#expected " == " #actual " with error " #delta ,(expected),(actual),(delta),(failure)) 51 | 52 | #define ASSERT_LESS_DDTM(msg,left,right,failure) cute::assert_relop((left),(right),\ 53 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)\ 54 | +(failure).reason,(failure).filename.c_str(),(failure).lineno) 55 | #define ASSERT_LESS_DDT(left,right,failure) ASSERT_LESS_DDTM(#left " < " #right, (left),(right),(failure)) 56 | 57 | #define ASSERT_LESS_EQUAL_DDTM(msg,left,right,failure) cute::assert_relop((left),(right),\ 58 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)\ 59 | +(failure).reason,(failure).filename.c_str(),(failure).lineno) 60 | #define ASSERT_LESS_EQUAL_DDT(left,right,failure) ASSERT_LESS_EQUAL_DDTM(#left " <= " #right, (left),(right),(failure)) 61 | 62 | #define ASSERT_GREATER_DDTM(msg,left,right,failure) cute::assert_relop((left),(right),\ 63 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)\ 64 | +(failure).reason,(failure).filename.c_str(),(failure).lineno) 65 | #define ASSERT_GREATER_DDT(left,right,failure) ASSERT_GREATER_DDTM(#left " > " #right, (left),(right),(failure)) 66 | 67 | #define ASSERT_GREATER_EQUAL_DDTM(msg,left,right,failure) cute::assert_relop((left),(right),\ 68 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)\ 69 | +(failure).reason,(failure).filename.c_str(),(failure).lineno) 70 | #define ASSERT_GREATER_EQUAL_DDT(left,right,failure) ASSERT_GREATER_EQUAL_DDTM(#left " >= " #right, (left),(right),(failure)) 71 | 72 | #define ASSERT_NOT_EQUAL_TO_DDTM(msg,left,right,failure) cute::assert_relop((left),(right),\ 73 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg)\ 74 | +(failure).reason,(failure).filename.c_str(),(failure).lineno) 75 | #define ASSERT_NOT_EQUAL_TO_DDT(left,right,failure) ASSERT_NOT_EQUAL_TO_DDTM(#left " != " #right, (left),(right),(failure)) 76 | 77 | 78 | 79 | #endif /* CUTE_DATA_DRIVEN_H_ */ 80 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_demangle.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2009-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_DEMANGLE_H_ 27 | #define CUTE_DEMANGLE_H_ 28 | #include 29 | // needs adaptation for different compilers 30 | // dependency to demangle is a given, 31 | // otherwise we have to use macros everywhere 32 | #ifdef __GNUG__ // also for clang... 33 | #include // __cxa_demangle 34 | #include // ::free() 35 | namespace cute { 36 | extern inline std::string demangle(char const *name); 37 | 38 | namespace cute_impl_demangle { 39 | inline std::string plain_demangle(char const *name){ 40 | if (!name) return "unknown"; 41 | char const *toBeFreed = abi::__cxa_demangle(name,0,0,0); 42 | std::string result(toBeFreed?toBeFreed:name); 43 | ::free(const_cast(toBeFreed)); 44 | return result; 45 | } 46 | #if defined(_LIBCPP_ABI_NAMESPACE) || defined(_LIBCPP_NAMESPACE) || defined(_GLIBCXX_USE_CXX11_ABI) 47 | inline void patch_library_namespace(std::string &mightcontaininlinenamespace) { 48 | // libc++ uses inline namespace std::_LIBCPP_NAMESPACE:: for its classes. This breaks the tests relying on meta information. re-normalize the names back to std:: 49 | // libstdc++ (at least in version 6.3.1) puts some STL classes into the inline namespace std::_GLIBCXX_NAMESPACE_CXX11 if in C++11 mode 50 | std::string::size_type pos=std::string::npos; 51 | #define XNS(X) #X 52 | #define NS(X) XNS(X) 53 | #if defined( _LIBCPP_NAMESPACE) 54 | #define TOREPLACE "::" NS(_LIBCPP_NAMESPACE) 55 | #elif defined(_LIBCPP_ABI_NAMESPACE) 56 | #define TOREPLACE "::" NS(_LIBCPP_ABI_NAMESPACE) 57 | #else 58 | #define TOREPLACE "::" NS(_GLIBCXX_NAMESPACE_CXX11) 59 | #endif 60 | std::string const nothing; 61 | while (std::string::npos != (pos= mightcontaininlinenamespace.find(TOREPLACE))) 62 | mightcontaininlinenamespace.erase(pos,sizeof(TOREPLACE)-1); 63 | #undef NS 64 | #undef XNS 65 | #undef TOREPLACE 66 | } 67 | inline void patchresultforstring(std::string& result) { 68 | static const std::string stringid=plain_demangle(typeid(std::string).name()); 69 | std::string::size_type pos=std::string::npos; 70 | while(std::string::npos != (pos=result.find(stringid))){ 71 | if (!result.compare(pos+stringid.size(),2," >",2)) result.erase(pos+stringid.size(),1); // makes templates look nice 72 | result.replace(pos,stringid.size(),"std::string"); 73 | } 74 | patch_library_namespace(result); 75 | } 76 | #endif 77 | 78 | } 79 | inline std::string demangle(char const *name){ 80 | if (!name) return "unknown"; 81 | std::string result(cute_impl_demangle::plain_demangle(name)); 82 | #if defined(_LIBCPP_ABI_NAMESPACE) || defined(_LIBCPP_NAMESPACE) || defined(_GLIBCXX_USE_CXX11_ABI) 83 | cute_impl_demangle::patchresultforstring(result); 84 | #endif 85 | return result; 86 | } 87 | } 88 | #else 89 | namespace cute { 90 | #ifdef _MSC_VER 91 | namespace cute_demangle_impl { 92 | 93 | inline void removeMSKeyword(std::string &name,std::string const &kw){ 94 | std::string::size_type pos=std::string::npos; 95 | while (std::string::npos != (pos= name.find(kw))) 96 | name.erase(pos,kw.size()); 97 | 98 | } 99 | inline void patchresultforstring(std::string& result) { 100 | static const std::string stringid=(typeid(std::string).name()); 101 | std::string::size_type pos=std::string::npos; 102 | while(std::string::npos != (pos=result.find(stringid))){ 103 | if (!result.compare(pos+stringid.size(),2," >",2)) result.erase(pos+stringid.size(),1); // makes templates look nice 104 | result.replace(pos,stringid.size(),"std::string"); 105 | } 106 | } 107 | 108 | inline void patchMSMangling(std::string &name){ 109 | patchresultforstring(name); 110 | removeMSKeyword(name,"class "); 111 | removeMSKeyword(name,"struct "); 112 | for (std::string::iterator i=name.begin(); i != name.end(); ++i){ 113 | if (*i==','){ i = name.insert(i+1,' ');} 114 | } 115 | std::string::size_type pos=0; 116 | while(std::string::npos !=(pos=name.find(" ,",pos))){ 117 | name.erase(pos,1); 118 | ++pos; 119 | } 120 | } 121 | } 122 | inline std::string demangle(char const *name){ 123 | std::string result(name?name:"unknown"); 124 | cute_demangle_impl::patchMSMangling(result); 125 | return result; 126 | } 127 | 128 | #else 129 | // this default works reasonably with MSVC71 and 8, hopefully for others as well 130 | inline std::string demangle(char const *name){ 131 | return std::string(name?name:"unknown"); 132 | } 133 | #endif 134 | } 135 | #endif 136 | 137 | #endif /* CUTE_DEMANGLE_H_ */ 138 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_runner.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2006-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_RUNNER_H_ 27 | #define CUTE_RUNNER_H_ 28 | 29 | #include "cute_test.h" 30 | #include "cute_suite.h" 31 | #include "cute_listener.h" 32 | #include "cute_determine_traits.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace cute { 40 | namespace runner_aux { 41 | struct prefixMatcher 42 | { 43 | prefixMatcher(std::string const &prefix):prefix(prefix){} 44 | bool operator()(std::string const &s) const { 45 | size_t found=s.find(prefix); 46 | return found==0 && (s.size()==prefix.size() || s[prefix.size()]=='#'); 47 | } 48 | private: 49 | std::string const prefix; 50 | }; 51 | struct prefixCutter 52 | { 53 | prefixCutter(std::string const &prefix):prefix(prefix){} 54 | std::string operator()(std::string s) const { 55 | size_t found=s.find(prefix); 56 | if ( found==0 && s.size()>prefix.size() && s[prefix.size()]=='#'){ 57 | s = s.substr(prefix.size()+1); 58 | } else { 59 | s.clear(); // either no match, or no individual test 60 | } 61 | return s; 62 | } 63 | private: 64 | std::string const prefix; 65 | }; 66 | class ArgvTestFilter 67 | { 68 | std::set match; 69 | bool shouldRunSuite(std::string const &info, std::vector const &args) 70 | { 71 | if(!args.size() || !info.size()) 72 | return true; 73 | if(args.end() != find_if(args.begin(), args.end(), prefixMatcher(info))){ 74 | std::transform(args.begin(), args.end(), std::inserter(match,match.begin()),prefixCutter(info)); 75 | match.erase(std::string()); // get rid of empty string 76 | return true; 77 | } 78 | return false; 79 | } 80 | public: 81 | bool const shouldrunsuite; 82 | ArgvTestFilter(std::string const &info, std::vector const &args) 83 | :shouldrunsuite(shouldRunSuite(info,args)){} 84 | bool shouldRun(const std::string & name) const 85 | { 86 | return match.empty() || match.count(name); 87 | } 88 | }; 89 | } // namespace runner_aux 90 | template 91 | struct runner{ 92 | Listener &listener; 93 | std::vector args; 94 | runner(Listener &l, int argc = 0, const char *const *argv = 0):listener(l){ 95 | if(needsFiltering(argc,argv)){ 96 | std::remove_copy_if(argv + 1, argv + argc,back_inserter(args),std::logical_not()); 97 | } 98 | } 99 | bool operator()(const test & t) const 100 | { 101 | return runit(t); 102 | } 103 | 104 | bool operator ()(suite const &s, const char *info = "") const 105 | { 106 | runner_aux::ArgvTestFilter filter(info,args); 107 | 108 | bool result = true; 109 | if(filter.shouldrunsuite){ 110 | listener.begin(s, info, (size_t) 111 | count_if(s.begin(),s.end(),boost_or_tr1::bind(&runner_aux::ArgvTestFilter::shouldRun,filter,boost_or_tr1::bind(&test::name,_1)))); 112 | for(suite::const_iterator it = s.begin();it != s.end();++it){ 113 | if (filter.shouldRun(it->name())) result = this->runit(*it) && result; 114 | } 115 | listener.end(s, info); 116 | } 117 | 118 | return result; 119 | } 120 | private: 121 | bool needsFiltering(int argc, const char *const *argv) const 122 | { 123 | return argc > 1 && argv ; 124 | } 125 | 126 | 127 | bool runit(const test & t) const 128 | { 129 | try { 130 | listener.start(t); 131 | t(); 132 | listener.success(t, "OK"); 133 | return true; 134 | } catch(const cute::test_failure & e){ 135 | listener.failure(t, e); 136 | } catch(const std::exception & exc){ 137 | listener.error(t, demangle(exc.what()).c_str()); 138 | } catch(std::string & s){ 139 | listener.error(t, s.c_str()); 140 | } catch(const char *&cs) { 141 | listener.error(t,cs); 142 | } catch(...) { 143 | listener.error(t,"unknown exception thrown"); 144 | } 145 | return false; 146 | } 147 | }; 148 | template 149 | runner makeRunner(Listener &s, int argc = 0, const char *const *argv = 0){ 150 | return runner(s,argc,argv); 151 | } 152 | } 153 | 154 | #endif /*CUTE_RUNNER_H_*/ 155 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_equals.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, Emanuel Graf, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_EQUALS_H_ 27 | #define CUTE_EQUALS_H_ 28 | #include "cute_base.h" 29 | #include "cute_diff_values.h" 30 | #include "cute_determine_traits.h" 31 | #include "cute_determine_version.h" 32 | #include "cute_deprecated.h" 33 | #include "cute_range.h" 34 | #include 35 | #include 36 | #include 37 | #ifdef USE_STD11 38 | #include 39 | #endif 40 | 41 | 42 | namespace cute { 43 | 44 | 45 | namespace cute_do_equals { 46 | // provide some template meta programming tricks to select "correct" comparison for floating point and integer types 47 | template 48 | bool do_equals_floating_with_delta(ExpectedValue const &expected 49 | ,ActualValue const &actual 50 | ,DeltaValue const &delta) { 51 | using std::abs; // allow for user-defined types with abs overload 52 | #pragma GCC diagnostic push 53 | #pragma GCC diagnostic ignored "-Wconversion" 54 | return bool(abs(delta) >= abs(expected-actual)); // Accommodate non-standard boolean type with explicit conversion 55 | #pragma GCC diagnostic pop 56 | } 57 | template 58 | bool do_equals_floating(ExpectedValue const &expected 59 | ,ActualValue const &actual,const impl_place_for_traits::integral_constant&){ 60 | return bool(expected==actual); // normal case for most types uses operator==!, accommodate non bool operator == 61 | } 62 | template 63 | bool do_equals_floating(ExpectedValue const &expected 64 | ,ActualValue const &actual,const impl_place_for_traits::true_type&){ 65 | const ExpectedValue automatic_delta_masking_last_significant_digit=(10*std::numeric_limits::epsilon())*expected; 66 | return do_equals_floating_with_delta(expected,actual,automatic_delta_masking_last_significant_digit); 67 | } 68 | // TMP-overload dispatch for floating points 2 bool params --> 4 overloads 69 | template 70 | bool do_equals(ExpectedValue const &expected 71 | ,ActualValue const &actual 72 | ,const impl_place_for_traits::integral_constant&/*exp_is_integral*/ 73 | ,const impl_place_for_traits::integral_constant&/*act_is_integral*/){ 74 | return do_equals_floating(expected,actual,impl_place_for_traits::is_floating_point()); 75 | } 76 | template 77 | bool do_equals(ExpectedValue const &expected 78 | ,ActualValue const &actual 79 | ,const impl_place_for_traits::false_type&,const impl_place_for_traits::false_type&){ 80 | return do_equals_floating(expected,actual,impl_place_for_traits::is_floating_point()); 81 | } 82 | template 83 | bool do_equals(ExpectedValue const &expected 84 | ,ActualValue const &actual 85 | ,const impl_place_for_traits::integral_constant&/*exp_is_integral*/ 86 | ,const impl_place_for_traits::true_type&){ 87 | return do_equals_floating(expected,actual,impl_place_for_traits::is_floating_point()); 88 | } 89 | template 90 | bool do_equals(ExpectedValue const &expected 91 | ,ActualValue const &actual 92 | ,const impl_place_for_traits::true_type&,const impl_place_for_traits::integral_constant&/*act_is_integral*/){ 93 | return do_equals_floating(expected,actual,impl_place_for_traits::is_floating_point()); 94 | } 95 | #ifdef USE_STD11 96 | template 97 | bool do_equals(std::tuple const &expected 98 | ,std::tuple const &actual,const std::integral_constant&){ 99 | return expected==actual; 100 | } 101 | #endif 102 | // can I get rid of the following complexity by doing a do_equals_integral 103 | // parameterized by is_signed==is_signed or nofBits < nofBits 104 | 105 | 106 | // this is an optimization for avoiding if and sign-extend overhead if both int types are the same as below 107 | template 108 | bool do_equals(IntType const &expected 109 | ,IntType const &actual 110 | ,const impl_place_for_traits::true_type&,const impl_place_for_traits::true_type&){ 111 | return expected==actual; 112 | } 113 | // bool cannot be made signed, therefore we need the following three overloads, also to avoid ambiguity 114 | template 115 | bool do_equals(bool const &expected 116 | ,IntType const &actual 117 | ,const impl_place_for_traits::true_type&,const impl_place_for_traits::true_type&){ 118 | return expected== !(!actual); // warning from VS 119 | } 120 | template 121 | bool do_equals(IntType const &expected 122 | ,bool const &actual 123 | ,const impl_place_for_traits::true_type&,const impl_place_for_traits::true_type&){ 124 | return !(!expected)==actual; // warning from VS 125 | } 126 | // do not forget the inline on a non-template overload! 127 | // this overload is needed to actually avoid ambiguity for comparing bool==bool as a best match 128 | inline bool do_equals(bool const &expected 129 | ,bool const &actual 130 | , const impl_place_for_traits::true_type&,const impl_place_for_traits::true_type&){ 131 | return expected==actual; 132 | } 133 | // overload for char const *, my test case failed because VC++ doesn't use string constant folding like g++/clang 134 | // a feature where we should do string comparison 135 | inline bool do_equals(char const *const &expected 136 | ,char const *const &actual 137 | , const impl_place_for_traits::false_type&,const impl_place_for_traits::false_type&){ 138 | return std::string(expected) == actual; 139 | } 140 | template 141 | size_t nof_bits(IntegralType const &){ 142 | return std::numeric_limits::digits; 143 | } 144 | #if defined(USE_STD11)||defined(USE_TR1) 145 | template 146 | bool do_equals_integral(ExpectedValue const &expected 147 | ,ActualValue const &actual 148 | ,const impl_place_for_traits::true_type&,const impl_place_for_traits::true_type&){ 149 | if (nof_bits(expected) < nof_bits(actual)) 150 | return static_cast(expected) == actual; 151 | else 152 | return expected == static_cast(actual); 153 | return false; 154 | } 155 | template 156 | bool do_equals_integral(ExpectedValue const &expected 157 | ,ActualValue const &actual 158 | ,const impl_place_for_traits::false_type&,const impl_place_for_traits::true_type&){ 159 | //TODO complicated case, one signed one unsigned type. since it is about equality casting to the longer should work? 160 | if (sizeof(ExpectedValue) > sizeof(ActualValue)) 161 | return expected==static_cast(actual); 162 | else 163 | return static_cast(expected) == actual; 164 | } 165 | template 166 | bool do_equals_integral(ExpectedValue const &expected 167 | ,ActualValue const &actual 168 | ,const impl_place_for_traits::true_type&,const impl_place_for_traits::false_type&){ 169 | //TODO 170 | if (sizeof(ExpectedValue) < sizeof(ActualValue)) 171 | return static_cast(expected)== actual; 172 | else 173 | return expected == static_cast(actual); 174 | } 175 | template 176 | bool do_equals_integral(ExpectedValue const &expected 177 | ,ActualValue const &actual 178 | ,const impl_place_for_traits::false_type&,const impl_place_for_traits::false_type&){ 179 | if (nof_bits(expected) < nof_bits(actual)) 180 | return static_cast(expected) == actual; 181 | else 182 | return expected == static_cast(actual); 183 | return false; 184 | } 185 | #endif 186 | // will not work if either type is bool, therefore the overloads above. 187 | template 188 | bool do_equals(ExpectedValue const &expected 189 | ,ActualValue const &actual 190 | ,const impl_place_for_traits::true_type&,const impl_place_for_traits::true_type&){ 191 | #if defined(USE_STD11) || defined(USE_TR1) 192 | return do_equals_integral(expected,actual, 193 | impl_place_for_traits::is_signed() 194 | ,impl_place_for_traits::is_signed()); 195 | #else 196 | //TODO: replace the following code with a dispatcher on signed/unsigned 197 | typedef typename impl_place_for_traits::make_signed::type ex_s; 198 | typedef typename impl_place_for_traits::make_signed::type ac_s; 199 | // need to sign extend with the longer type, should work... 200 | // might be done through more template meta prog tricks....but... 201 | if (nof_bits(expected) < nof_bits(actual)) 202 | return static_cast(expected) == static_cast(actual); 203 | else 204 | return static_cast(expected) == static_cast(actual); 205 | #endif 206 | } 207 | } // namespace equals_impl 208 | template 209 | void assert_equal(ExpectedValue const &expected 210 | ,ActualValue const &actual 211 | ,std::string const &msg 212 | ,char const *file 213 | ,int line) { 214 | // unfortunately there is no is_integral_but_not_bool_or_enum 215 | typedef typename impl_place_for_traits::is_integral exp_integral; 216 | typedef typename impl_place_for_traits::is_integral act_integral; 217 | if (cute_do_equals::do_equals(expected,actual,exp_integral(),act_integral())) 218 | return; 219 | throw test_failure(msg + diff_values(expected,actual),file,line); 220 | } 221 | 222 | template 223 | void assert_equal_delta(ExpectedValue const &expected 224 | ,ActualValue const &actual 225 | ,DeltaValue const &delta 226 | ,std::string const &msg 227 | ,char const *file 228 | ,int line) { 229 | if (cute_do_equals::do_equals_floating_with_delta(expected,actual,delta)) return; 230 | throw test_failure(msg + diff_values(expected,actual),file,line); 231 | } 232 | 233 | } 234 | 235 | #define ASSERT_EQUALM(msg,expected,actual) cute::assert_equal((expected),(actual),\ 236 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__) 237 | #define ASSERT_EQUAL(expected,actual) ASSERT_EQUALM(#expected " == " #actual, (expected),(actual)) 238 | #define ASSERT_EQUAL_DELTAM(msg,expected,actual,delta) cute::assert_equal_delta((expected),(actual),(delta),\ 239 | CUTE_FUNCNAME_PREFIX+cute::cute_to_string::backslashQuoteTabNewline(msg),__FILE__,__LINE__) 240 | #define ASSERT_EQUAL_DELTA(expected,actual,delta) ASSERT_EQUAL_DELTAM(#expected " == " #actual " with error " #delta ,(expected),(actual),(delta)) 241 | 242 | DEPRECATE(ASSERT_EQUAL_RANGES_M, ASSERT_EQUAL_RANGESM) 243 | #define ASSERT_EQUAL_RANGES_M(msg,expbeg,expend,actbeg,actend) DEPRECATED(ASSERT_EQUAL_RANGES_M), ASSERT_EQUALM(msg,cute::make_range(expbeg,expend),cute::make_range(actbeg,actend)) 244 | #define ASSERT_EQUAL_RANGESM(msg,expbeg,expend,actbeg,actend) ASSERT_EQUALM(msg,cute::make_range(expbeg,expend),cute::make_range(actbeg,actend)) 245 | #define ASSERT_EQUAL_RANGES(expbeg,expend,actbeg,actend) ASSERT_EQUAL_RANGESM("range{" #expbeg "," #expend "} == range{" #actbeg "," #actend "}",expbeg,expend,actbeg,actend) 246 | #endif /*CUTE_EQUALS_H_*/ 247 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/cute/cute_to_string.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * This file is part of CUTE. 3 | * 4 | * Copyright (c) 2007-2018 Peter Sommerlad, IFS 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | *********************************************************************************/ 25 | 26 | #ifndef CUTE_TO_STRING_H_ 27 | #define CUTE_TO_STRING_H_ 28 | 29 | #include 30 | #include 31 | #ifdef USE_STD17 32 | #include 33 | #endif 34 | 35 | namespace cute { 36 | namespace cute_to_string { 37 | static inline std::string backslashQuoteTabNewline(std::string const &input){ 38 | std::string result; 39 | result.reserve(input.size()); 40 | for (std::string::size_type i=0; i < input.length() ; ++i){ 41 | switch(input[i]) { 42 | case '\n': result += "\\n"; break; 43 | case '\t': result += "\\t"; break; 44 | case '\\': result += "\\\\"; break; 45 | case '\r': result += "\\r"; break; 46 | default: result += input[i]; 47 | } 48 | } 49 | return result; 50 | } 51 | // common overloads of interface that work without an ostream 52 | static inline std::string to_string(char const *const &s){ 53 | return s; 54 | } 55 | static inline std::string to_string(std::string const &s){ 56 | return s; 57 | } 58 | template 59 | std::string hexit(T const &t){ // must be an unsigned type 60 | std::string hexed; 61 | if (t == 0) hexed+='0'; 62 | for (T x=t;x>0;x /= 16){ 63 | hexed += "0123456789ABCDEF"[x%16]; 64 | } 65 | reverse(hexed.begin(),hexed.end()); 66 | return hexed; 67 | } 68 | } 69 | } 70 | #ifndef DONT_USE_IOSTREAM 71 | #include 72 | #include 73 | #include 74 | #ifdef _MSC_VER 75 | #include 76 | #include 77 | #endif 78 | #include "cute_demangle.h" 79 | #include "cute_determine_version.h" 80 | #ifdef USE_STD11 81 | #include "cute_integer_sequence.h" 82 | #include 83 | #endif 84 | namespace cute { 85 | namespace cute_to_string { 86 | template 87 | std::ostream &to_stream(std::ostream &os,T const &t); // recursion needs forward 88 | #ifdef USE_STD17 89 | inline std::ostream &to_stream(std::ostream &os,std::byte t); // recursion needs forward 90 | #endif 91 | 92 | // the following code was stolen and adapted from Boost Exception library. 93 | // it avoids compile errors, if a type used with ASSERT_EQUALS doesn't provide an output shift operator 94 | namespace to_string_detail { 95 | template 96 | char operator<<( std::basic_ostream &, T const & ); 97 | template 98 | struct is_output_streamable_impl { 99 | static std::basic_ostream & f(); 100 | static T const & g(); 101 | enum e { value = (sizeof(char) != sizeof(f()< 105 | struct is_output_streamable_impl { 106 | static std::basic_ostream & f(); 107 | static T const * g(); 108 | enum e { value = (sizeof(char) != sizeof(f()< 111 | struct has_begin_end_const_member { 112 | template struct type_check; 113 | #ifdef USE_STD17 114 | template static typename C::const_iterator test( 115 | type_check*); 116 | #else 117 | template static typename C::const_iterator test( 118 | type_check*); 119 | #endif 120 | template static char test(...); 121 | enum e { value = (sizeof(char) != sizeof(test(0))) 122 | }; 123 | }; // this doesn't work with VS library for set/map due to implementation in parent 124 | // no useful workaround possible 125 | //-> internal compiler errors for VS2010/12/12CTP Nov 12 126 | } 127 | template > 128 | struct is_output_streamable { 129 | enum e { value=to_string_detail::is_output_streamable_impl::value }; 130 | }; 131 | // detect standard container conforming begin() end() iterator accessors. 132 | // might employ begin/end traits from c++0x for loop in the future. --> select_container 133 | template 134 | struct printItWithDelimiter 135 | { 136 | std::ostream &os; 137 | bool first; // allow use of for_each algorithm 138 | printItWithDelimiter(std::ostream &os):os(os),first(true){} 139 | void operator()(T const &t){ 140 | if (!first) os<<','; 141 | else first=false; 142 | os << '\n'; // use newlines so that CUTE's plug-in result viewer gives nice diffs 143 | cute_to_string::to_stream(os,t); 144 | } 145 | }; 146 | //try print_pair with specialization of template function instead: 147 | // the generic version prints about missing operator<< that is the last resort 148 | template 149 | std::ostream &print_pair(std::ostream &os,T const &){ 150 | return os << "no operator<<(ostream&, " < 154 | std::ostream &print_pair(std::ostream &os,std::pair const &p){ 155 | os << '[' ; 156 | cute_to_string::to_stream(os,p.first); 157 | os << " -> "; 158 | cute_to_string::to_stream(os,p.second); 159 | os << ']'; 160 | return os; 161 | } 162 | // overload for Arrays 163 | template 164 | std::ostream &print_pair(std::ostream &os,T const (&t)[N]){ 165 | printItWithDelimiter printer(os); 166 | os << cute::demangle(typeid(T).name()) <<'['< 173 | using size = std::integral_constant; 174 | struct empty { templateempty(Types const &...){} }; 175 | template 176 | std::ostream &print_tuple(std::ostream &os, std::tuple const &t, size<_> const, index_sequence){ 177 | empty{os << '\n' 178 | ,cute_to_string::to_stream(os, std::get(t)) 179 | ,(os << ",\n", cute_to_string::to_stream(os, std::get(t)))...}; 180 | return os; 181 | } 182 | template 183 | std::ostream &print_tuple(std::ostream &os, std::tuple const &t, size<_> const s) { 184 | return print_tuple(os, t, s, index_sequence_for{}); 185 | } 186 | template 187 | std::ostream &print_tuple(std::ostream &os, std::tuple<_...> const &t, size<1> const){ 188 | return os << '\n', cute_to_string::to_stream(os, std::get<0>(t)); 189 | } 190 | template 191 | std::ostream &print_tuple(std::ostream &os, std::tuple<_...> const &, size<0>){ 192 | return os; 193 | } 194 | // overload for std::tuple<...> 195 | template 196 | std::ostream &print_pair(std::ostream &os, std::tuple const &t){ 197 | os << cute::demangle(typeid(decltype(t)).name()) << '{'; 198 | auto olflags = os.flags(); 199 | os << std::boolalpha; 200 | print_tuple(os, t, size{}); 201 | os.flags(olflags); 202 | os << '}'; 203 | return os; 204 | } 205 | #endif 206 | template 207 | struct select_container { 208 | std::ostream &os; 209 | select_container(std::ostream &os):os(os){} 210 | std::ostream& operator()(T const &t){ 211 | printItWithDelimiter printer(os); 212 | os << cute::demangle(typeid(T).name()) << '{'; 213 | std::for_each(t.begin(),t.end(),printer); 214 | return os << '}'; 215 | } 216 | }; 217 | 218 | template 219 | struct select_container { 220 | std::ostream &os; 221 | select_container(std::ostream &os):os(os){} 222 | std::ostream & operator()(T const &t){ 223 | // look for std::pair. a future with tuple might be useful as well, but not now. 224 | return print_pair(os,t); // here a simple template function overload works. 225 | } 226 | }; 227 | 228 | template 229 | struct select_built_in_shift_if { 230 | std::ostream &os; 231 | select_built_in_shift_if(std::ostream &ros):os(ros){} 232 | std::ostream& operator()(T const &t){ 233 | return os << t ; // default uses operator<<(std::ostream&,T const&) if available 234 | } 235 | }; 236 | 237 | template 238 | struct select_built_in_shift_if { 239 | std::ostream &os; 240 | select_built_in_shift_if(std::ostream &ros):os(ros){} 241 | std::ostream & operator()(T const &t){ 242 | // if no operator<< is found, try if it is a container or std::pair 243 | return select_container::value) >(os)(t); 244 | } 245 | }; 246 | template 247 | std::ostream &to_stream(std::ostream &os,T const &t){ 248 | select_built_in_shift_if::value > out(os); 249 | return out(t); 250 | } 251 | #ifdef USE_STD17 252 | inline std::ostream &to_stream(std::ostream &os,std::byte b){ 253 | return os << "0x" << hexit(static_cast>(b)); 254 | } 255 | #endif 256 | #ifdef _MSC_VER 257 | // special overloads because VC can not detect begin/end 258 | inline std::ostream& to_stream(std::ostream &os,std::string const &s){ 259 | return os< class S, 262 | typename K, typename CMP, typename ALLOC> 263 | std::ostream &to_stream(std::ostream &os,S const &t){ 264 | printItWithDelimiter::value_type> printer(os); 265 | os << cute::demangle(typeid(S).name()) << '{'; 266 | std::for_each(t.begin(),t.end(),printer); 267 | return os << '}'; 268 | } 269 | template class M,typename K, typename V, typename CMP, typename ALLOC> 270 | std::ostream &to_stream(std::ostream &os,M const &t){ 271 | printItWithDelimiter::value_type> printer(os); 272 | os << cute::demangle(typeid(M).name()) << '{'; 273 | std::for_each(t.begin(),t.end(),printer); 274 | return os << '}'; 275 | } 276 | #endif 277 | 278 | // this is the interface: 279 | template 280 | std::string to_string(T const &t) { 281 | std::ostringstream os; 282 | to_stream(os,t); 283 | return os.str(); 284 | } 285 | } 286 | } 287 | #else 288 | #include "cute_determine_traits.h" 289 | #include 290 | // traits 291 | namespace cute{ 292 | namespace cute_to_string { 293 | template 294 | void adjust_long(T const &,std::string &to_adjust){ // assumes T is an integral type 295 | if (sizeof(T) <= sizeof(int)) return; // don't mark int sized integrals with L 296 | if (sizeof(T)>=sizeof(long)) to_adjust+='L'; 297 | if (sizeof(T)> sizeof(long)) to_adjust+='L'; // if there is support for (unsigned) long long 298 | } 299 | template 300 | std::string to_string_embedded_int_signed(T const &t, impl_place_for_traits::true_type ){ 301 | std::string convert; // t is an integral value 302 | T x=t; 303 | bool negative=t<0; 304 | bool minint=false; 305 | if (x == std::numeric_limits::min()){ // can not easily convert it, assuming 2s complement 306 | minint=true; 307 | x++; // add 1, but 1 might be incompatible type, so use ++ 308 | } 309 | if (x < 0) x = static_cast(-x); 310 | if (x == 0) convert += '0'; 311 | while (x > 0) { 312 | convert += "0123456789"[x%10]; 313 | x /= 10; 314 | } 315 | if (minint) ++ convert[0]; // adjust last digit 316 | if (negative) convert += '-'; 317 | reverse(convert.begin(),convert.end()); 318 | cute::cute_to_string::adjust_long(t,convert); 319 | return convert; 320 | } 321 | template 322 | std::string to_string_embedded_int_signed(T const &t, impl_place_for_traits::false_type ){ 323 | // manual hex conversion to avoid ostream dependency for unsigned values 324 | std::string hexed="0x"+cute::cute_to_string::hexit(t); 325 | cute::cute_to_string::adjust_long(t,hexed); 326 | return hexed; 327 | } 328 | template 329 | std::string to_string_embedded_int(T const &t, impl_place_for_traits::true_type ){ 330 | return to_string_embedded_int_signed(t,impl_place_for_traits::is_signed()); 331 | } 332 | template 333 | std::string to_string_embedded_int(T const &, impl_place_for_traits::false_type ){ 334 | return "no to_string"; 335 | } 336 | // convenience for pointers.... useful? 337 | template 338 | std::string to_string(T * const&t) { 339 | std::string result; 340 | if (sizeof(T *) <= sizeof(unsigned long)) 341 | result = cute::cute_to_string::hexit(reinterpret_cast(t)); 342 | else 343 | #if defined(USE_STD11) /* should allow for all compilers supporting ULL*/ 344 | result = cute::cute_to_string::hexit(reinterpret_cast(t)); 345 | #else 346 | return "no to_string"; 347 | #endif 348 | result.insert(0u,sizeof(T*)*2-result.size(),'0'); 349 | result.insert(0,1,'p'); 350 | return result; 351 | } 352 | 353 | // this is the interface: 354 | template 355 | std::string to_string(T const &t) { 356 | return to_string_embedded_int(t, impl_place_for_traits::is_integral()); 357 | } 358 | } 359 | } 360 | #endif 361 | #endif /* CUTE_TO_STRING_H_ */ 362 | -------------------------------------------------------------------------------- /scope.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SRC_SCOPE_HPP_ 2 | #define SRC_SCOPE_HPP_ 3 | 4 | // Copyright Eric Niebler and Peter Sommerlad 2016 - 2022. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // https://www.boost.org/LICENSE_1_0.txt) 8 | 9 | 10 | #include 11 | #include 12 | #include // for maxint 13 | #include 14 | #include // for std::uncaught_exceptions 15 | 16 | #ifdef FOR_BOOST 17 | #define SCOPE_NS boost 18 | #define SCOPE_NS_END 19 | #define SCOPE_NS_PREFIX boost 20 | #else 21 | #define SCOPE_NS std { namespace experimental 22 | #define SCOPE_NS_END } 23 | #define SCOPE_NS_PREFIX std::experimental 24 | #endif 25 | namespace SCOPE_NS { 26 | namespace detail { 27 | namespace hidden{ 28 | 29 | struct factory_holder; 30 | 31 | // should this helper be standardized? // write testcase where recognizable. 32 | template 33 | constexpr std::conditional_t< 34 | std::is_nothrow_move_assignable_v, 35 | T &&, 36 | T const &> 37 | _move_assign_if_noexcept(T &x) noexcept 38 | { 39 | return std::move(x); 40 | } 41 | template< class T > 42 | constexpr typename std::conditional< 43 | !std::is_nothrow_move_constructible_v && std::is_copy_constructible_v, 44 | const T&, 45 | T&& 46 | >::type move_if_noexcept(T& x) noexcept; 47 | 48 | } 49 | template 50 | class _box 51 | { 52 | T value; 53 | explicit _box(T const &t) noexcept(noexcept(T(t))) 54 | : value(t) 55 | {} 56 | explicit _box(T &&t) noexcept(noexcept(T(std::move_if_noexcept(t)))) 57 | : value(std::move_if_noexcept(t)) 58 | {} 59 | 60 | public: 61 | template>> 63 | // explicit _box(TT &&t, GG &&guard) noexcept(noexcept(_box((T &&) t))) 64 | explicit _box(TT &&t, GG &&guard) noexcept(noexcept(_box(std::declval()))) 65 | : _box(std::forward(t)) 66 | { 67 | guard.release(); 68 | } 69 | T &get() noexcept 70 | { 71 | return value; 72 | } 73 | T const &get() const noexcept 74 | { 75 | return value; 76 | } 77 | T &&move() noexcept 78 | { 79 | return std::move(value); 80 | } 81 | void reset(T const &t) noexcept(noexcept(value = t)) 82 | { 83 | value = t; 84 | } 85 | void reset(T &&t) noexcept(noexcept(value = hidden::_move_assign_if_noexcept(t))) 86 | { 87 | value = hidden::_move_assign_if_noexcept(t); 88 | } 89 | 90 | }; 91 | 92 | template 93 | class _box 94 | { 95 | std::reference_wrapper value; 96 | public: 97 | template>> 99 | _box(TT &&t, GG &&guard) noexcept(noexcept(static_cast(static_cast( t)))) 100 | : value(static_cast(t)) 101 | { 102 | guard.release(); 103 | } 104 | T &get() const noexcept 105 | { 106 | return value.get(); 107 | } 108 | T &move() const noexcept 109 | { 110 | return get(); 111 | } 112 | void reset(T &t) noexcept 113 | { 114 | value = std::ref(t); 115 | } 116 | }; 117 | 118 | 119 | 120 | 121 | 122 | // new policy-based exception proof design by Eric Niebler 123 | 124 | struct on_exit_policy 125 | { 126 | bool execute_{ true }; 127 | 128 | void release() noexcept 129 | { 130 | execute_ = false; 131 | } 132 | 133 | bool should_execute() const noexcept 134 | { 135 | return execute_; 136 | } 137 | }; 138 | 139 | 140 | struct on_fail_policy 141 | { 142 | int ec_ { std::uncaught_exceptions() }; 143 | 144 | void release() noexcept 145 | { 146 | ec_ = std::numeric_limits::max(); 147 | } 148 | 149 | bool should_execute() const noexcept 150 | { 151 | return ec_ < std::uncaught_exceptions(); 152 | } 153 | }; 154 | 155 | struct on_success_policy 156 | { 157 | int ec_ { std::uncaught_exceptions() }; 158 | 159 | void release() noexcept 160 | { 161 | ec_ = -1; 162 | } 163 | 164 | bool should_execute() const noexcept 165 | { 166 | return ec_ >= std::uncaught_exceptions() ; 167 | } 168 | }; 169 | } 170 | template 171 | class basic_scope_exit; // silence brain dead clang warning -Wmismatched-tags 172 | 173 | //PS: It would be nice if just the following would work in C++17 174 | //PS: however, we need a real class for template argument deduction 175 | //PS: and a deduction guide, because the ctors are partially instantiated 176 | //template 177 | //using scope_exit = basic_scope_exit; 178 | 179 | template 180 | struct [[nodiscard]] scope_exit : basic_scope_exit{ 181 | using basic_scope_exit::basic_scope_exit; 182 | }; 183 | 184 | template 185 | scope_exit(EF) -> scope_exit; 186 | 187 | //template 188 | //using scope_fail = basic_scope_exit; 189 | 190 | template 191 | struct scope_fail : basic_scope_exit{ 192 | using basic_scope_exit::basic_scope_exit; 193 | }; 194 | 195 | template 196 | scope_fail(EF) -> scope_fail; 197 | 198 | //template 199 | //using scope_success = basic_scope_exit; 200 | 201 | template 202 | struct scope_success : basic_scope_exit{ 203 | using basic_scope_exit::basic_scope_exit; 204 | }; 205 | 206 | template 207 | scope_success(EF) -> scope_success; 208 | 209 | 210 | 211 | namespace detail{ 212 | // DETAIL: 213 | template 214 | auto _make_guard(EF &&ef) 215 | { 216 | return basic_scope_exit, Policy>(std::forward(ef)); 217 | } 218 | struct _empty_scope_exit 219 | { 220 | void release() const noexcept 221 | {} 222 | }; 223 | 224 | } 225 | 226 | // Requires: EF is Callable 227 | // Requires: EF is nothrow MoveConstructible OR CopyConstructible 228 | template 229 | class [[nodiscard]] basic_scope_exit : Policy 230 | { 231 | static_assert(std::is_invocable_v,"scope guard must be callable"); 232 | static_assert(std::is_nothrow_move_constructible_v||std::is_copy_constructible_v, 233 | "scope guard function must be nothrow move constructible or copy constructible"); 234 | detail::_box exit_function; 235 | // lambdas can degenerate to object pointers 236 | static auto _make_failsafe(std::true_type, const void *) 237 | { 238 | return detail::_empty_scope_exit{}; 239 | } 240 | // function pointers (from reference) can not degenerate to an object pointer 241 | static auto _make_failsafe(std::true_type, void( * ) ()) 242 | { 243 | return detail::_empty_scope_exit{}; 244 | } 245 | template 246 | static auto _make_failsafe(std::false_type, Fn *fn) 247 | { 248 | return basic_scope_exit(*fn); 249 | } 250 | template 251 | using _ctor_from = std::is_constructible, EFP, detail::_empty_scope_exit>; 252 | template 253 | #ifndef _MSC_VER 254 | using _noexcept_ctor_from = std::bool_constant(std::declval(), detail::_empty_scope_exit{}))>; 255 | #else 256 | // MSVC thinks that it is a function style cast 257 | using _noexcept_ctor_from = std::bool_constant::_box(std::declval(), detail::_empty_scope_exit{}))>; 258 | #endif 259 | public: 260 | template::value>> 261 | explicit basic_scope_exit(EFP &&ef) noexcept(_noexcept_ctor_from::value) 262 | : exit_function(std::forward( ef), _make_failsafe(_noexcept_ctor_from{}, &ef)) 263 | {} 264 | basic_scope_exit(basic_scope_exit &&that) noexcept(noexcept(detail::_box(that.exit_function.move(), that))) 265 | : Policy(that), exit_function(that.exit_function.move(), that) 266 | {} 267 | ~basic_scope_exit() noexcept(noexcept(exit_function.get()())) 268 | { 269 | if(this->should_execute()) 270 | exit_function.get()(); 271 | } 272 | // implicitly deleted or not defined 273 | // basic_scope_exit(const basic_scope_exit &) = delete; 274 | // basic_scope_exit &operator=(const basic_scope_exit &) = delete; 275 | // basic_scope_exit &operator=(basic_scope_exit &&) = delete; 276 | 277 | using Policy::release; 278 | 279 | }; 280 | 281 | template 282 | void swap(basic_scope_exit &, basic_scope_exit &) = delete; 283 | 284 | 285 | 286 | template 287 | class unique_resource 288 | { 289 | static_assert((std::is_move_constructible_v && std::is_nothrow_move_constructible_v) || 290 | std::is_copy_constructible_v, 291 | "resource must be nothrow_move_constructible or copy_constructible"); 292 | static_assert((std::is_move_constructible_v && std::is_nothrow_move_constructible_v) || 293 | std::is_copy_constructible_v, 294 | "deleter must be nothrow_move_constructible or copy_constructible"); 295 | 296 | static const unique_resource &this_; // never ODR used! Just for getting no_except() expr 297 | 298 | detail::_box resource; 299 | detail::_box deleter; 300 | bool execute_on_destruction { true }; 301 | 302 | static constexpr auto is_nothrow_delete_v=std::bool_constant()(std::declval()))>::value; 303 | 304 | template, RR, detail::_empty_scope_exit> && 306 | std::is_constructible_v, DD, detail::_empty_scope_exit>>> 307 | unique_resource(RR &&r, DD &&d, bool should_run) 308 | noexcept(noexcept(detail::_box(std::forward(r), detail::_empty_scope_exit {})) && 309 | noexcept(detail::_box(std::forward
(d), detail::_empty_scope_exit {}))) 310 | : resource{std::forward(r), scope_exit([&] {if (should_run) d(r);})} 311 | , deleter{std::forward
(d), scope_exit([&, this] {if (should_run) d(get());})} 312 | , execute_on_destruction { should_run } 313 | {} 314 | friend struct detail::hidden::factory_holder; // a level of indirection is the trick... 315 | public: 316 | template, RR, detail::_empty_scope_exit>::value && 318 | std::is_constructible, DD, detail::_empty_scope_exit>::value > 319 | > 320 | unique_resource(RR &&r, DD &&d) 321 | noexcept(noexcept(detail::_box(std::forward(r), detail::_empty_scope_exit {})) && 322 | noexcept(detail::_box(std::forward
(d), detail::_empty_scope_exit {}))) 323 | : resource(std::forward(r), scope_exit([&] {d(r);})) 324 | , deleter(std::forward
(d), scope_exit([&, this] {d(get());})) 325 | {} 326 | unique_resource( unique_resource&& that) 327 | noexcept(noexcept(detail::_box(that.resource.move(), detail::_empty_scope_exit {})) && 328 | noexcept(detail::_box(that.deleter.move(), detail::_empty_scope_exit {}))) 329 | : resource(that.resource.move(), detail::_empty_scope_exit { }) 330 | , deleter(that.deleter.move(), scope_exit([&, this] { if (that.execute_on_destruction) that.get_deleter()(get());that.release(); })) 331 | , execute_on_destruction(std::exchange(that.execute_on_destruction, false)) 332 | { } 333 | 334 | unique_resource &operator=(unique_resource &&that) noexcept(is_nothrow_delete_v && 335 | std::is_nothrow_move_assignable_v && 336 | std::is_nothrow_move_assignable_v) 337 | { 338 | static_assert(std::is_nothrow_move_assignable::value || 339 | std::is_copy_assignable::value, 340 | "The resource must be nothrow-move assignable, or copy assignable"); 341 | static_assert(std::is_nothrow_move_assignable::value || 342 | std::is_copy_assignable::value, 343 | "The deleter must be nothrow-move assignable, or copy assignable"); 344 | if (&that != this) { 345 | reset(); 346 | if constexpr (std::is_nothrow_move_assignable_v>) 347 | if constexpr (is_nothrow_move_assignable_v>) { 348 | resource = std::move(that.resource); 349 | deleter = std::move(that.deleter); 350 | } else { 351 | deleter = _as_const(that.deleter); 352 | resource = std::move(that.resource); 353 | } 354 | else if constexpr (is_nothrow_move_assignable_v>) { 355 | resource = _as_const(that.resource); 356 | deleter = std::move(that.deleter); 357 | } else { 358 | resource = _as_const(that.resource); 359 | deleter = _as_const(that.deleter); 360 | } 361 | execute_on_destruction = std::exchange(that.execute_on_destruction, false); 362 | } 363 | return *this; 364 | } 365 | ~unique_resource() 366 | { 367 | reset(); 368 | } 369 | 370 | void reset() noexcept 371 | { 372 | if(execute_on_destruction) 373 | { 374 | execute_on_destruction = false; 375 | get_deleter()(get()); 376 | } 377 | } 378 | template 379 | auto reset(RR &&r) 380 | noexcept(noexcept(resource.reset(std::forward(r)))) 381 | -> decltype(resource.reset(std::forward(r)), void()) 382 | { 383 | auto &&guard = scope_fail([&, this]{ get_deleter()(r); }); // -Wunused-variable on clang 384 | reset(); 385 | resource.reset(std::forward(r)); 386 | execute_on_destruction = true; 387 | } 388 | void release() noexcept 389 | { 390 | execute_on_destruction = false; 391 | } 392 | decltype(auto) get() const noexcept 393 | { 394 | return resource.get(); 395 | } 396 | decltype(auto) get_deleter() const noexcept 397 | { 398 | return deleter.get(); 399 | } 400 | // THIS IS NOT A POINTER TYPE, the following operations are only available if R is a native pointer 401 | template 402 | auto operator->() const noexcept 403 | -> std::enable_if_t,decltype(get())> 404 | { 405 | return get(); 406 | } 407 | template 408 | auto operator*() const noexcept 409 | -> std::enable_if_t && ! std::is_void_v>, 410 | std::add_lvalue_reference_t>> 411 | { 412 | return *get(); 413 | } 414 | 415 | // implicitly deleted: 416 | // unique_resource& operator=(const unique_resource &) = delete; 417 | // unique_resource(const unique_resource &) = delete; 418 | 419 | }; 420 | namespace detail{ 421 | namespace hidden { 422 | struct factory_holder{ 423 | template 424 | static 425 | auto special_maker(MR&& r, MD&& d, bool shouldrun){ 426 | unique_resource,std::decay_t> 427 | resource{std::forward(r), std::forward(d),shouldrun}; 428 | return resource; 429 | } 430 | }; 431 | } 432 | } 433 | 434 | 435 | template 436 | unique_resource(R, D) 437 | -> unique_resource; 438 | template 439 | unique_resource(R, D, bool) 440 | -> unique_resource; 441 | 442 | template 443 | [[nodiscard]] 444 | auto make_unique_resource_checked(MR &&r, const S &invalid, MD &&d) 445 | noexcept(std::is_nothrow_constructible_v,MR> && 446 | std::is_nothrow_constructible_v,MD>) 447 | ->unique_resource,std::decay_t> 448 | { 449 | bool const mustrelease(r == invalid); 450 | auto resource = detail::hidden::factory_holder::special_maker(std::forward(r), std::forward(d),!mustrelease); 451 | // unique_resource resource{std::forward(r), std::forward(d),!mustrelease}; 452 | return resource; 453 | 454 | } 455 | 456 | SCOPE_NS_END 457 | } 458 | 459 | 460 | #endif /* SRC_SCOPE_HPP_ */ 461 | -------------------------------------------------------------------------------- /cevelop-workspace/scope17/src/Test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | 4 | Copyright (c) 2016/2017 Peter Sommerlad 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | #include "scope.hpp" 25 | #include "cute.h" 26 | #include "ide_listener.h" 27 | #include "xml_listener.h" 28 | #include "cute_runner.h" 29 | #include 30 | #include 31 | #include 32 | #ifndef _MSC_VER 33 | #include 34 | #else 35 | #include 36 | #define open _open 37 | #define close _close 38 | #define unlink _unlink 39 | #define write _write 40 | #endif 41 | 42 | #include 43 | 44 | #include 45 | 46 | #include 47 | 48 | #include 49 | #include 50 | #include 51 | 52 | //#define CHECK_COMPILE_ERRORS 53 | 54 | using std::experimental::unique_resource; 55 | using std::experimental::make_unique_resource_checked; 56 | using std::experimental::scope_exit; 57 | using std::experimental::scope_fail; 58 | using std::experimental::scope_success; 59 | 60 | void DemoFstream(){ 61 | { 62 | std::ofstream ofs{"demo_hello.txt"}; 63 | ofs << "Hello world\n"; 64 | } 65 | { 66 | std::ifstream ifs{"demo_hello.txt"}; 67 | std::string s { }; 68 | ASSERT(getline(ifs,s)); 69 | ASSERT_EQUAL("Hello world",s); 70 | } 71 | } 72 | 73 | using std::filesystem::path; 74 | void copy_file_transact(path const & from, path const & to) { 75 | path t{to}; 76 | t += path{".deleteme"}; 77 | auto guard= scope_fail{ [t]{remove(t);} }; 78 | copy_file(from, t); 79 | rename(t, to); 80 | } 81 | void DemonstrateTransactionFilecopy(){ 82 | 83 | } 84 | 85 | 86 | 87 | std::string access_returned_from_string(size_t& len){ 88 | std::string s{"a long string to prevent SSO, so let us see if the move and RVO inhibit really is destructive"}; 89 | scope_exit guard{[&]{ len = s.size();}}; 90 | return std::move(s); // pessimize copy elision to demonstrate effect 91 | } 92 | void DemonstrateSurprisingReturnedFromBehavior(){ 93 | size_t len{0xffffffff}; 94 | auto const s = access_returned_from_string(len); 95 | // exected: ASSERT_EQUAL(s.size(),len); 96 | // what really happens 97 | ASSERT_EQUAL(0,len); 98 | } 99 | 100 | 101 | void InsaneBool() { 102 | std::ostringstream out { }; 103 | { 104 | auto guard = scope_exit([&] {out << "done\n";}); 105 | } 106 | ASSERT_EQUAL("done\n", out.str()); 107 | } 108 | 109 | void testScopeExitWithCPP17DeducingCtors() { 110 | std::ostringstream out { }; 111 | { 112 | scope_exit guard([&] {out << "done\n";}); 113 | } 114 | ASSERT_EQUAL("done\n", out.str()); 115 | } 116 | void testScopeFailWithCPP17DeducingCtors(){ 117 | std::ostringstream out { }; 118 | { 119 | scope_fail guard([&] {out << "not done\n";}); 120 | } 121 | ASSERT_EQUAL("",out.str()); 122 | try { 123 | scope_fail guard([&] {out << "done\n";}); 124 | throw 0; 125 | } catch (const int) { 126 | } 127 | ASSERT_EQUAL("done\n", out.str()); 128 | } 129 | void testScopeSuccessWithCPP17DeducingCtors(){ 130 | std::ostringstream out { }; 131 | { 132 | scope_success guard([&] {out << "done\n";}); 133 | } 134 | ASSERT_EQUAL("done\n", out.str()); 135 | try { 136 | scope_success guard([&] {out << "not done\n";}); 137 | throw 0; 138 | } catch(int){} 139 | ASSERT_EQUAL("done\n", out.str()); 140 | } 141 | 142 | 143 | void testDismissedGuard() { 144 | std::ostringstream out { }; 145 | { 146 | auto guard = scope_exit([&] {out << "done1\n";}); 147 | auto guard2dismiss = scope_exit([&] {out << "done2\n";}); 148 | guard2dismiss.release(); 149 | } 150 | ASSERT_EQUAL("done1\n", out.str()); 151 | } 152 | void testThrowDoesntCrashIt() { // LEWG wants it to crash! 153 | std::ostringstream out { }; 154 | { 155 | auto guard = scope_exit([&] {out << "done\n";}); 156 | auto guard1 = scope_exit([] {throw 42;}); 157 | guard1.release(); // we no longer want throwing scope guards 158 | } 159 | ASSERT_EQUAL("done\n", out.str()); 160 | 161 | } 162 | void testScopeExitWithReferenceWrapper(){ 163 | std::ostringstream out { }; 164 | const auto &lambda = [&] {out << "lambda done.\n";}; 165 | { 166 | auto guard=scope_exit(std::cref(lambda)); 167 | } 168 | ASSERT_EQUAL("lambda done.\n",out.str()); 169 | } 170 | struct non_assignable_resource{ 171 | non_assignable_resource()=default; 172 | non_assignable_resource(int){} 173 | void operator=(const non_assignable_resource &) = delete; 174 | non_assignable_resource& operator=(non_assignable_resource &&) noexcept(false){ throw "buh";}; 175 | non_assignable_resource(non_assignable_resource &&) =default; 176 | }; 177 | void testscopeExitWithNonAssignableResourceAndReset(){ 178 | std::ostringstream out { }; 179 | const auto &lambda = [&](auto &&) {out << "lambda done.\n";}; 180 | { 181 | auto guard=unique_resource(non_assignable_resource{},std::cref(lambda)); 182 | //guard.reset(2);//throws... need to figure out, what I wanted to trigger here. AH, compile error? 183 | } 184 | ASSERT_EQUAL("lambda done.\n",out.str()); 185 | } 186 | 187 | 188 | 189 | // by Eric Niebler, adapted for unit testing 190 | struct throwing_copy 191 | { 192 | throwing_copy(const char* sz, std::ostream &os) : 193 | sz_ { sz }, out { os } { 194 | } 195 | throwing_copy(const throwing_copy &other) : 196 | out { other.out } 197 | { 198 | using namespace std::literals; 199 | throw "throwing_copy copy attempt:"s+sz_; 200 | } 201 | void operator()() const 202 | { 203 | out << sz_ << std::endl; 204 | } 205 | template 206 | void operator()(RES const &res) const 207 | { 208 | out << sz_ << res<< std::endl; 209 | } 210 | 211 | bool operator==(int i)const &{ 212 | return i==0; 213 | } 214 | friend std::ostream& operator<<(std::ostream &os,throwing_copy const &t){ 215 | return os << t.sz_ ; 216 | } 217 | private: 218 | const char *sz_ { "" }; 219 | std::ostream &out; 220 | }; 221 | 222 | 223 | 224 | void testsFromEricNiebler_scope_exit_with_throwing_function_object(){ 225 | std::ostringstream out { }; 226 | try 227 | { 228 | throwing_copy c{"called anyway",out}; 229 | auto &&x = scope_exit(c); // -Wunused-variable on clang 230 | out << "whoops" << std::endl; 231 | } 232 | catch(...) 233 | { 234 | out << "expected"; 235 | } 236 | ASSERT_EQUAL("called anyway\nexpected", out.str()); 237 | } 238 | 239 | void testsFromEricNiebler_scope_success_with_throwing_function_object(){ 240 | std::ostringstream out { }; 241 | try 242 | { 243 | throwing_copy c{"Oh noes!!!",out}; 244 | auto &&x = scope_success(c);// -Wunused-variable on clang 245 | out << "whoops" << std::endl; 246 | } 247 | catch(...) 248 | { 249 | out << "just exception\n"; 250 | } 251 | ASSERT_EQUAL("just exception\n", out.str()); 252 | } 253 | 254 | void testsFromEricNiebler_scope_fail_with_throwing_function_object(){ 255 | std::ostringstream out { }; 256 | try 257 | { 258 | throwing_copy c{"called because of exception!!!",out}; 259 | auto &&x = scope_fail(c);// -Wunused-variable on clang 260 | out << "whoops" << std::endl; 261 | } 262 | catch(...) 263 | { 264 | out << "expected"; 265 | } 266 | ASSERT_EQUAL("called because of exception!!!\nexpected", out.str()); 267 | } 268 | 269 | 270 | void testThrowOnUniqueResourceDoesntCrashIt() { 271 | std::ostringstream out { }; 272 | { 273 | auto guard = unique_resource(1, [&] (auto) {out << "done\n";}); 274 | // we do no longer allow that for unique_resource 275 | // try { 276 | // { 277 | // auto guard1 = unique_resource(2, [] (auto) noexcept(false) {throw 42;}); 278 | // guard1.reset(); 279 | // } 280 | // FAILM("didn't throw"); 281 | // } catch (int) { 282 | // } catch (...) { 283 | // FAILM("threw unknown error"); 284 | // } 285 | } 286 | ASSERT_EQUAL("done\n", out.str()); 287 | 288 | } 289 | 290 | void testUniqueResourceSimple() { 291 | using namespace std; 292 | std::ostringstream out { }; 293 | 294 | const std::string msg { " deleted resource\n" }; 295 | { 296 | auto res = unique_resource(std::ref(msg), [&out](string msg) {out << msg<>(msg, [&out](string msg) {out << msg<< flush;}); 308 | } 309 | ASSERT_EQUAL(msg, out.str()); 310 | } 311 | 312 | void test_unique_resource_semantics_reset() { 313 | std::ostringstream out { }; 314 | { 315 | auto cleanup = unique_resource(1, [&out](int i) {out << "cleaned " << i;}); 316 | cleanup.reset(2); 317 | } 318 | ASSERT_EQUAL("cleaned 1cleaned 2", out.str()); 319 | } 320 | 321 | void demonstrate_unique_resource_with_stdio() { 322 | const std::string filename = "hello.txt"; 323 | auto fclose=[](auto fptr){::fclose(fptr);}; 324 | { 325 | auto file = unique_resource(::fopen(filename.c_str(), "w"), fclose); 326 | ::fputs("Hello World!\n", file.get()); 327 | ASSERT(file.get()!= NULL); 328 | } 329 | { 330 | std::ifstream input { filename }; 331 | std::string line { }; 332 | getline(input, line); 333 | ASSERT_EQUAL("Hello World!", line); 334 | getline(input, line); 335 | ASSERT(input.eof()); 336 | } 337 | ::unlink(filename.c_str()); 338 | { 339 | auto file = make_unique_resource_checked(::fopen("nonexistentfile.txt", "r"), nullptr, fclose); 340 | ASSERT_EQUAL((FILE*)NULL, file.get()); 341 | } 342 | 343 | } 344 | void demonstrate_unique_resource_with_stdio_Cpp17() { 345 | const std::string filename = "hello.txt"; 346 | auto fclose=[](auto fptr){::fclose(fptr);}; 347 | 348 | { 349 | unique_resource file(::fopen(filename.c_str(), "w"), fclose); 350 | ::fputs("Hello World!\n", file.get()); 351 | ASSERT(file.get()!= NULL); 352 | } 353 | { 354 | std::ifstream input { filename }; 355 | std::string line { }; 356 | getline(input, line); 357 | ASSERT_EQUAL("Hello World!", line); 358 | getline(input, line); 359 | ASSERT(input.eof()); 360 | } 361 | ::unlink(filename.c_str()); 362 | { 363 | auto file = make_unique_resource_checked(::fopen("nonexistentfile.txt", "r"), nullptr, fclose); 364 | ASSERT_EQUAL((FILE*)NULL, file.get()); 365 | } 366 | 367 | } 368 | 369 | void demontrate_unique_resource_with_POSIX_IO() { 370 | const std::string filename = "./hello1.txt"; 371 | auto close=[](auto fd){::close(fd);}; 372 | { 373 | auto file = unique_resource(::open(filename.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0666), close); 374 | 375 | ::write(file.get(), "Hello World!\n", 12u); 376 | ASSERT(file.get() != -1); 377 | } 378 | { 379 | std::ifstream input { filename }; 380 | std::string line { }; 381 | getline(input, line); 382 | ASSERT_EQUAL("Hello World!", line); 383 | getline(input, line); 384 | ASSERT(input.eof()); 385 | } 386 | ::unlink(filename.c_str()); 387 | { 388 | auto file = make_unique_resource_checked(::open("nonexistingfile.txt", O_RDONLY), -1, close); 389 | ASSERT_EQUAL(-1, file.get()); 390 | } 391 | 392 | } 393 | 394 | void demontrate_unique_resource_with_POSIX_IO_lvalue() { 395 | const std::string filename = "./hello1.txt"; 396 | auto close=[](auto fd){::close(fd);}; 397 | { 398 | auto fd = ::open(filename.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0666); 399 | 400 | auto file = make_unique_resource_checked(fd,-1, close); 401 | ASSERT(fd!=-1); 402 | ::write(file.get(), "Hello World!\n", 12u); 403 | ASSERT(file.get() != -1); 404 | } 405 | { 406 | std::ifstream input { filename }; 407 | std::string line { }; 408 | getline(input, line); 409 | ASSERT_EQUAL("Hello World!", line); 410 | getline(input, line); 411 | ASSERT(input.eof()); 412 | } 413 | ::unlink(filename.c_str()); 414 | { 415 | auto fd=::open("nonexistingfile.txt", O_RDONLY); 416 | auto file = make_unique_resource_checked(fd, -1, close); 417 | ASSERT_EQUAL(-1, file.get()); 418 | } 419 | 420 | } 421 | 422 | 423 | void test_make_unique_resource_checked(){ 424 | std::ostringstream out{}; 425 | 426 | { 427 | auto bar=make_unique_resource_checked(0.0,0,[&out](auto i){out << i << "not called";}); 428 | auto foo=make_unique_resource_checked(0.0,-1,[&out](auto ){out << "called";}); 429 | } 430 | ASSERT_EQUAL("called",out.str()); 431 | 432 | } 433 | 434 | struct throwing_copy_movable_resource 435 | { 436 | throwing_copy_movable_resource(const char* sz, std::ostream &os) : 437 | sz_ { sz }, out { os } { 438 | } 439 | throwing_copy_movable_resource(const throwing_copy_movable_resource &other) : 440 | out { other.out } 441 | { 442 | using namespace std::literals; 443 | throw "throwing_copy copy attempt:"s+sz_; 444 | } 445 | throwing_copy_movable_resource(throwing_copy_movable_resource && other) noexcept = default; 446 | bool operator==(int i)const &{ 447 | return i==0; 448 | } 449 | friend std::ostream& operator<<(std::ostream &os,throwing_copy_movable_resource const &t){ 450 | return os << t.sz_ ; 451 | } 452 | private: 453 | const char *sz_ { "" }; 454 | std::ostream &out; 455 | }; 456 | 457 | bool operator==(std::reference_wrapperconst&,int i){ 458 | return i==0; 459 | } 460 | 461 | void test_make_unique_resource_checked_lvalue(){ 462 | std::ostringstream out{}; 463 | 464 | { 465 | //throwing_copy r{"",out}; // this does not work, make_unique_resource_checked only works for copies 466 | auto r{0LL}; 467 | auto bar=make_unique_resource_checked(r,0,[&out](auto & ){out << "not called";}); 468 | auto foo=make_unique_resource_checked(r,1,[&out](auto & ){out << "called\n";}); 469 | } 470 | ASSERT_EQUAL("called\n",out.str()); 471 | } 472 | void test_make_unique_resource_checked_failing_copy(){ 473 | std::ostringstream out{}; 474 | { 475 | throwing_copy_movable_resource x{"x by ref ",out}; 476 | auto bar=make_unique_resource_checked(std::ref(x),0, 477 | [&out](auto const & i){out << i.get()<<"not called";}); 478 | auto foo=make_unique_resource_checked(std::ref(x),1, 479 | [&out](auto const & i){out <foo();// compile error! 563 | *x; // compile error! 564 | y->foo(); 565 | *y; 566 | #endif 567 | 568 | } 569 | void testCompilabilityGuardForPointerTypes() { 570 | auto x = unique_resource(new int { 42 }, [](int * ptr) {delete ptr;}); 571 | ASSERT_EQUAL(42, *x); 572 | auto y = unique_resource(new X { }, [](X * ptr) {delete ptr;}); 573 | y->foo(); // compiles, SFINAE works 574 | (void)*y; // compiles, through SFINAE (again) 575 | ASSERT_EQUAL(42,*(int*)(void*)x.get()); 576 | } 577 | 578 | struct functor_copy_throws{ 579 | functor_copy_throws()=default; 580 | functor_copy_throws(const functor_copy_throws &) noexcept(false) { 581 | throw 42; 582 | } 583 | functor_copy_throws(functor_copy_throws &&)=default; 584 | void operator()(){} 585 | }; 586 | struct functor_move_throws{ // bad idea anyway. 587 | functor_move_throws()=default; 588 | functor_move_throws(functor_move_throws &&)noexcept(false){ throw 42;} 589 | functor_move_throws(const functor_move_throws &) = default; 590 | void operator()()const{} 591 | }; 592 | 593 | struct functor_move_copy_throws{ 594 | functor_move_copy_throws()=default; 595 | functor_move_copy_throws(functor_move_copy_throws &&)noexcept(false){ throw 42;} 596 | functor_move_copy_throws(const functor_move_copy_throws &) noexcept(false) { 597 | throw 42; 598 | } 599 | void operator()()const{} 600 | }; 601 | 602 | 603 | void test_scope_exit_with_throwing_fun_copy(){ 604 | functor_copy_throws fun { }; 605 | #if defined(CHECK_COMPILE_ERRORS) 606 | auto x = scope_exit(std::move(fun)); // doesn't compile due to static_assert 607 | auto x1 = scope_exit(42); // not callable 608 | auto const &ff=functor_copy_throws{}; 609 | auto z = scope_exit(std::ref(ff)); // hold by const reference 610 | #endif 611 | auto y = scope_exit(std::ref(fun)); // hold by reference 612 | ASSERTM("should just work",true); 613 | } 614 | 615 | void test_scope_exit_with_throwing_fun_move(){ 616 | functor_move_throws fun { }; 617 | const functor_move_throws &funref { fun }; 618 | //#if defined(CHECK_COMPILE_ERRORS) 619 | auto x = scope_exit(std::move(fun)); // no longer a compile error, because it is copied. 620 | //#endif 621 | auto y = scope_exit(fun); // hold by copy 622 | auto z = scope_exit(funref); // hold by copy?, no const ref 623 | ASSERTM("should just work",true); 624 | } 625 | void test_scope_exit_with_throwing_fun_move_and_copy(){ 626 | functor_move_copy_throws fun { }; 627 | #if defined(CHECK_COMPILE_ERRORS) 628 | auto x = scope_exit(std::move(fun)); // compile error, because non-copyable 629 | #endif 630 | auto y = scope_exit(std::ref(fun)); // hold by reference works 631 | ASSERTM("should not work",true); 632 | } 633 | 634 | void test_scope_success_with_side_effect(){ 635 | std::ostringstream out{}; 636 | auto lam=[&]{out << "not called";}; 637 | try{ 638 | auto x=scope_success(lam); // lam not called 639 | throw 42; 640 | }catch(...){ 641 | auto y=scope_success([&]{out << "handled";}); 642 | } 643 | ASSERT_EQUAL("handled",out.str()); 644 | } 645 | void test_scope_success_might_throw(){ 646 | std::ostringstream out{}; 647 | auto lam=[&]{out << "called"; /* throw 42;*/}; // doesn't work. 648 | try{{ 649 | auto x=scope_success(lam); 650 | } 651 | //out << " never "; 652 | } catch (int) { 653 | // OK 654 | } catch (...) { 655 | out << "bla"; 656 | } 657 | ASSERT_EQUAL("called",out.str()); 658 | } 659 | 660 | 661 | 662 | void demo_scope_exit_fail_success(){ 663 | std::ostringstream out{}; 664 | auto lam=[&]{out << "called ";}; 665 | try{ 666 | auto v=scope_exit([&]{out << "always ";}); 667 | auto w=scope_success([&]{out << "not ";}); // not called 668 | auto x=scope_fail(lam); // called 669 | throw 42; 670 | }catch(...){ 671 | auto y=scope_fail([&]{out << "not ";}); // not called 672 | auto z=scope_success([&]{out << "handled";}); // called 673 | } 674 | ASSERT_EQUAL("called always handled",out.str()); 675 | } 676 | 677 | void demo_scope_exit_fail_success_Cpp17(){ 678 | std::ostringstream out{}; 679 | auto lam=[&]{out << "called ";}; 680 | try{ 681 | scope_exit v([&]{out << "always ";}); 682 | scope_success w([&]{out << "not ";}); // not called 683 | scope_fail x(lam); // called 684 | throw 42; 685 | }catch(...){ 686 | scope_fail y([&]{out << "not ";}); // not called 687 | scope_success z([&]{out << "handled";}); // called 688 | } 689 | ASSERT_EQUAL("called always handled",out.str()); 690 | } 691 | 692 | 693 | void test_scope_exit_lvalue_ref_passing_rvalue_fails_to_compile(){ 694 | using fun = void(*)(); 695 | auto y = scope_exit(fun(nullptr)); // no static assert needed. fails to match. 696 | y.release(); // avoid crash from calling nullptr 697 | scope_exit z(fun(nullptr)); 698 | z.release();// avoid crash from calling nullptr 699 | scope_exit zz(fun(nullptr)); 700 | zz.release(); 701 | #if defined(CHECK_COMPILE_ERRORS) 702 | auto x=scope_exit(fun(nullptr)); // no static assert needed. fails to match 703 | std::experimental::scope_exit se { fun(nullptr) }; // static assert needed 704 | scope_exit se17 { fun(nullptr) }; // static assert needed 705 | #endif 706 | 707 | 708 | } 709 | 710 | 711 | 712 | 713 | struct nasty{}; 714 | 715 | struct deleter_2nd_throwing_copy { 716 | deleter_2nd_throwing_copy()=default; 717 | deleter_2nd_throwing_copy(deleter_2nd_throwing_copy const &){ 718 | if (copied %2) { 719 | throw nasty{}; 720 | } 721 | ++copied; 722 | } 723 | void operator()(int const & ) const { 724 | ++deleted; 725 | } 726 | static inline int deleted{}; 727 | static inline int copied{}; 728 | }; 729 | 730 | void test_sometimes_throwing_deleter_copy_ctor(){ 731 | using uid=unique_resource; 732 | uid strange{1,deleter_2nd_throwing_copy{}}; 733 | ASSERT_EQUAL(0,deleter_2nd_throwing_copy::deleted); 734 | 735 | strange.release(); 736 | ASSERT_EQUAL(0,deleter_2nd_throwing_copy::deleted); 737 | 738 | try { 739 | uid x{ std::move(strange)}; 740 | FAILM("should have thrown"); 741 | } catch(nasty const &){ 742 | } 743 | ASSERT_EQUAL(0,deleter_2nd_throwing_copy::deleted); 744 | ASSERT_EQUAL(1,deleter_2nd_throwing_copy::copied); 745 | } 746 | 747 | namespace{ 748 | std::string just_for_testing_side_effect{}; 749 | } 750 | 751 | void functocall(){ 752 | just_for_testing_side_effect.append("functocall_called\n"); 753 | } 754 | 755 | void testThatExplicitReferenceParameterCompiles(){ 756 | { 757 | scope_exit guard{functocall}; 758 | scope_exit guardfromptr{functocall}; 759 | } 760 | ASSERT_EQUAL("functocall_called\nfunctocall_called\n",just_for_testing_side_effect); 761 | } 762 | 763 | 764 | 765 | 766 | bool runAllTests(int argc, const char *argv[]) { 767 | cute::suite s; 768 | //TODO add your test here 769 | s.push_back(CUTE(InsaneBool)); 770 | s.push_back(CUTE(testscopeExitWithNonAssignableResourceAndReset)); 771 | s.push_back(CUTE(testCompilabilityGuardForPointerTypes)); 772 | s.push_back(CUTE(testTalkToTheWorld)); 773 | s.push_back(CUTE(demontrate_unique_resource_with_POSIX_IO)); 774 | s.push_back(CUTE(demontrate_unique_resource_with_POSIX_IO_lvalue)); 775 | s.push_back(CUTE(demonstrate_unique_resource_with_stdio)); 776 | s.push_back(CUTE(demonstrate_unique_resource_with_stdio_Cpp17)); 777 | s.push_back(CUTE(test_unique_resource_semantics_reset)); 778 | s.push_back(CUTE(testUniqueResourceSimple)); 779 | s.push_back(CUTE(testThrowOnUniqueResourceDoesntCrashIt)); 780 | s.push_back(CUTE(testThrowDoesntCrashIt)); 781 | s.push_back(CUTE(testDismissedGuard)); 782 | s.push_back(CUTE(testUniqueResourceByReference)); 783 | s.push_back(CUTE(test_scope_exit_with_throwing_fun_copy)); 784 | s.push_back(CUTE(test_scope_success_with_side_effect)); 785 | s.push_back(CUTE(demo_scope_exit_fail_success)); 786 | s.push_back(CUTE(demo_scope_exit_fail_success_Cpp17)); 787 | s.push_back(CUTE(test_scope_exit_lvalue_ref_passing_rvalue_fails_to_compile)); 788 | s.push_back(CUTE(test_scope_success_might_throw)); 789 | s.push_back(CUTE(test_make_unique_resource_checked)); 790 | s.push_back(CUTE(test_make_unique_resource_checked_lvalue)); 791 | s.push_back(CUTE(test_make_unique_resource_checked_failing_copy)); 792 | s.push_back(CUTE(test_make_unique_resource_checked_with_deleter_throwing_on_copy)); 793 | s.push_back(CUTE(testReferenceWrapper)); 794 | s.push_back(CUTE(testScopeExitWithReferenceWrapper)); 795 | s.push_back(CUTE(testsFromEricNiebler_scope_exit_with_throwing_function_object)); 796 | s.push_back(CUTE(testsFromEricNiebler_scope_success_with_throwing_function_object)); 797 | s.push_back(CUTE(testsFromEricNiebler_scope_fail_with_throwing_function_object)); 798 | s.push_back(CUTE(testScopeExitWithCPP17DeducingCtors)); 799 | s.push_back(CUTE(testScopeFailWithCPP17DeducingCtors)); 800 | s.push_back(CUTE(testScopeSuccessWithCPP17DeducingCtors)); 801 | s.push_back(CUTE(test_sometimes_throwing_deleter_copy_ctor)); 802 | s.push_back(CUTE(DemoFstream)); 803 | s.push_back(CUTE(DemonstrateTransactionFilecopy)); 804 | s.push_back(CUTE(DemonstrateSurprisingReturnedFromBehavior)); 805 | s.push_back(CUTE(testThatExplicitReferenceParameterCompiles)); 806 | cute::xml_file_opener xmlfile(argc, argv); 807 | cute::xml_listener> lis(xmlfile.out); 808 | auto runner = cute::makeRunner(lis, argc, argv); 809 | bool success = runner(s, "AllTests"); 810 | return success; 811 | } 812 | 813 | int main(int argc, char const *argv[]) { 814 | return runAllTests(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE; 815 | } 816 | 817 | 818 | 819 | --------------------------------------------------------------------------------