├── .dir-locals.el ├── doc ├── Gen.md ├── Seq.md ├── user_guide.md ├── boost.md ├── displaying.md ├── gmock.md ├── distribution.md └── Shrinkable.md ├── .gitignore ├── examples ├── classify │ ├── CMakeLists.txt │ └── main.cpp ├── database │ ├── CMakeLists.txt │ ├── DatabaseConnection.h │ ├── Database.h │ ├── Generators.h │ ├── User.h │ └── User.cpp ├── gtest │ ├── CMakeLists.txt │ └── main.cpp ├── mapparser │ ├── CMakeLists.txt │ ├── MapParser.h │ └── main.cpp ├── CMakeLists.txt ├── counter │ ├── CMakeLists.txt │ └── main.cpp └── boost_test │ ├── CMakeLists.txt │ └── main.cpp ├── extras ├── boost │ ├── include │ │ └── rapidcheck │ │ │ ├── boost.h │ │ │ └── gen │ │ │ └── boost │ │ │ ├── Optional.h │ │ │ └── Optional.hpp │ ├── CMakeLists.txt │ └── test │ │ ├── main.cpp │ │ ├── CMakeLists.txt │ │ └── OptionalTests.cpp ├── catch │ ├── CMakeLists.txt │ └── include │ │ └── rapidcheck │ │ └── catch.h ├── gtest │ └── CMakeLists.txt ├── boost_test │ └── CMakeLists.txt ├── gmock │ ├── CMakeLists.txt │ └── test │ │ └── CMakeLists.txt └── CMakeLists.txt ├── src ├── BeforeMinimalTestCase.cpp ├── GenerationFailure.cpp ├── gen │ ├── Text.cpp │ ├── detail │ │ ├── GenerationHandler.cpp │ │ ├── ExecHandler.cpp │ │ ├── Recipe.cpp │ │ └── ScaleInteger.cpp │ └── Numeric.cpp ├── detail │ ├── FuzzData.cpp │ ├── ImplicitParam.cpp │ ├── Serialization.cpp │ ├── Base64.h │ ├── TestMetadata.cpp │ ├── ParseException.cpp │ ├── StringSerialization.h │ ├── DefaultTestListener.h │ ├── FrequencyMap.cpp │ ├── Any.cpp │ ├── PropertyContext.cpp │ ├── MapParser.h │ ├── MulticastTestListener.h │ ├── ReproduceListener.h │ ├── ParseException.h │ ├── LogTestListener.h │ ├── StringSerialization.cpp │ ├── TestParams.cpp │ ├── ReproduceListener.cpp │ ├── MulticastTestListener.cpp │ ├── DefaultTestListener.cpp │ ├── LogTestListener.cpp │ └── Assertions.cpp ├── Log.cpp ├── Classify.cpp ├── Show.cpp └── Random.cpp ├── include ├── rapidcheck │ ├── gen │ │ ├── Chrono.h │ │ ├── Maybe.h │ │ ├── detail │ │ │ ├── ScaleInteger.h │ │ │ ├── ShrinkValueIterator.h │ │ │ ├── ExecRaw.h │ │ │ ├── ExecHandler.h │ │ │ ├── GenerationHandler.h │ │ │ ├── Recipe.h │ │ │ └── ShrinkValueIterator.hpp │ │ ├── Numeric.h │ │ ├── Exec.hpp │ │ ├── Create.hpp │ │ ├── Tuple.h │ │ ├── Arbitrary.h │ │ ├── Text.h │ │ ├── Arbitrary.hpp │ │ ├── Create.h │ │ ├── Exec.h │ │ ├── Chrono.hpp │ │ ├── Container.h │ │ ├── Maybe.hpp │ │ └── Predicate.h │ ├── Log.hpp │ ├── state.h │ ├── GenerationFailure.h │ ├── Log.h │ ├── Nothing.h │ ├── BeforeMinimalTestCase.h │ ├── detail │ │ ├── ShowType.h │ │ ├── TestListenerAdapter.h │ │ ├── TestMetadata.h │ │ ├── FrequencyMap.h │ │ ├── FuzzData.h │ │ ├── ExecFixture.h │ │ ├── Platform.h │ │ ├── AlignedUnion.h │ │ ├── Property.h │ │ ├── TestParams.h │ │ ├── Results.hpp │ │ ├── Traits.h │ │ ├── TypeList.h │ │ ├── PropertyContext.h │ │ ├── TestListener.h │ │ ├── ImplicitParam.hpp │ │ ├── IntSequence.h │ │ ├── BitStream.h │ │ ├── Any.h │ │ ├── Any.hpp │ │ ├── FunctionTraits.h │ │ ├── Configuration.h │ │ └── ApplyTuple.h │ ├── Classify.hpp │ ├── fn │ │ ├── Common.h │ │ └── Common.hpp │ ├── Check.h │ ├── Traits.h │ ├── Classify.h │ ├── Random.hpp │ ├── seq │ │ ├── SeqIterator.h │ │ ├── SeqIterator.hpp │ │ ├── Operations.h │ │ ├── Operations.hpp │ │ └── Create.h │ ├── state │ │ ├── gen │ │ │ └── Commands.h │ │ ├── State.hpp │ │ ├── Command.hpp │ │ ├── State.h │ │ └── Command.h │ ├── Show.h │ ├── Assertions.hpp │ ├── shrinkable │ │ ├── Operations.h │ │ ├── Operations.hpp │ │ ├── Create.h │ │ └── Transform.h │ ├── shrink │ │ └── Shrink.h │ └── Shrinkable.h └── rapidcheck.h ├── .gitmodules ├── test ├── main.cpp ├── detail │ ├── SerializationTests │ │ └── Integers.cpp │ ├── StringSerializationTests.cpp │ ├── TestMetadataTests.cpp │ ├── TestParamsTests.cpp │ ├── FrequencyMapTests.cpp │ ├── ApplyTupleTests.cpp │ ├── Base64Tests.cpp │ └── ReproduceListenerTests.cpp ├── util │ ├── ArbitraryRandom.cpp │ ├── SeqUtils.h │ ├── Box.h │ ├── ShowTypeTestUtils.h │ ├── ThrowOnCopy.h │ ├── Meta.h │ ├── ShrinkableUtils.cpp │ ├── DestructNotifier.h │ ├── ArbitraryRandom.h │ ├── MockTestListener.h │ ├── Util.h │ ├── AppleOrange.h │ ├── IntVec.h │ ├── NonCopyableModel.h │ ├── TypeListMacros.h │ ├── TemplateProps.h │ ├── GenUtils.cpp │ └── Serialization.h ├── fn │ └── CommonTests.cpp ├── gen │ ├── CreateTests.cpp │ ├── detail │ │ └── ScaleIntegerTests.cpp │ ├── ChronoTests.cpp │ └── ExecTests.cpp ├── LogTests.cpp ├── seq │ └── SeqIteratorTests.cpp ├── state │ └── StateTests.cpp └── ClassifyTests.cpp ├── ext ├── get_boost.sh └── CMakeLists.txt ├── appveyor.yml ├── LICENSE.md ├── fuzz_encoding.cc ├── danluu_example.cc ├── encode.h ├── .clang-format └── main.cc /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((nil . ((c-basic-offset . 2)))) 2 | -------------------------------------------------------------------------------- /doc/Gen.md: -------------------------------------------------------------------------------- 1 | `Gen` 2 | ======= 3 | _This section is incomplete._ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build* 2 | GPATH 3 | GRTAGS 4 | GTAGS 5 | TAGS 6 | ext/gmock 7 | ext/boost -------------------------------------------------------------------------------- /examples/classify/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(classify main.cpp) 2 | target_link_libraries(classify rapidcheck) -------------------------------------------------------------------------------- /extras/boost/include/rapidcheck/boost.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "rapidcheck/gen/boost/Optional.h" 6 | -------------------------------------------------------------------------------- /src/BeforeMinimalTestCase.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/BeforeMinimalTestCase.h" 2 | 3 | namespace rc { 4 | 5 | void beforeMinimalTestCase() {} 6 | 7 | } // namespace rc 8 | -------------------------------------------------------------------------------- /examples/database/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(database main.cpp 2 | Database.cpp 3 | DatabaseConnection.cpp 4 | User.cpp) 5 | 6 | target_link_libraries(database rapidcheck) -------------------------------------------------------------------------------- /extras/catch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rapidcheck_catch INTERFACE) 2 | target_link_libraries(rapidcheck_catch INTERFACE rapidcheck) 3 | target_include_directories(rapidcheck_catch INTERFACE include) -------------------------------------------------------------------------------- /extras/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rapidcheck_gtest INTERFACE) 2 | target_link_libraries(rapidcheck_gtest INTERFACE rapidcheck) 3 | target_include_directories(rapidcheck_gtest INTERFACE include) 4 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Chrono.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace rc { 6 | namespace gen { 7 | 8 | } // namespace gen 9 | } // namespace rc 10 | 11 | #include "Chrono.hpp" 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ext/catch"] 2 | path = ext/catch 3 | url = https://github.com/philsquared/Catch.git 4 | [submodule "ext/googletest"] 5 | path = ext/googletest 6 | url = https://github.com/google/googletest 7 | -------------------------------------------------------------------------------- /extras/boost_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rapidcheck_boost_test INTERFACE) 2 | target_link_libraries(rapidcheck_boost_test INTERFACE rapidcheck) 3 | target_include_directories(rapidcheck_boost_test INTERFACE include) 4 | -------------------------------------------------------------------------------- /examples/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(gtest_integration main.cpp) 2 | target_link_libraries(gtest_integration rapidcheck_gtest gtest) 3 | target_include_directories(gtest_integration PRIVATE 4 | ${CMAKE_SOURCE_DIR}/ext/gmock/gtest/include) 5 | -------------------------------------------------------------------------------- /extras/boost/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rapidcheck_boost INTERFACE) 2 | target_link_libraries(rapidcheck_boost INTERFACE rapidcheck) 3 | target_include_directories(rapidcheck_boost INTERFACE include) 4 | 5 | if (RC_ENABLE_TESTS) 6 | add_subdirectory(test) 7 | endif() -------------------------------------------------------------------------------- /extras/gmock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(rapidcheck_gmock INTERFACE) 2 | target_link_libraries(rapidcheck_gmock INTERFACE rapidcheck) 3 | target_include_directories(rapidcheck_gmock INTERFACE include) 4 | 5 | if (RC_ENABLE_TESTS) 6 | add_subdirectory(test) 7 | endif() -------------------------------------------------------------------------------- /src/GenerationFailure.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/GenerationFailure.h" 2 | 3 | #include 4 | 5 | namespace rc { 6 | 7 | GenerationFailure::GenerationFailure(std::string msg) 8 | : std::runtime_error(std::move(msg)) {} 9 | 10 | } // namespace rc 11 | -------------------------------------------------------------------------------- /examples/mapparser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(mapparser main.cpp MapParser.cpp) 2 | 3 | target_compile_options(mapparser PRIVATE -fsanitize=fuzzer,address) 4 | target_link_libraries(mapparser -fsanitize=fuzzer,address) 5 | 6 | target_link_libraries(mapparser rapidcheck) 7 | -------------------------------------------------------------------------------- /src/gen/Text.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/gen/Text.h" 2 | 3 | template rc::Gen rc::gen::string(); 4 | template rc::Gen rc::gen::string(); 5 | template struct rc::Arbitrary; 6 | template struct rc::Arbitrary; 7 | -------------------------------------------------------------------------------- /include/rapidcheck/Log.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | namespace detail { 5 | 6 | /// Returns the current logging stream. 7 | std::ostream &log(); 8 | 9 | /// Logs the given message. 10 | void log(const std::string &msg); 11 | 12 | } // namespace detail 13 | } // namespace rc 14 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(counter) 2 | add_subdirectory(mapparser) 3 | add_subdirectory(database) 4 | add_subdirectory(classify) 5 | 6 | if (RC_ENABLE_GTEST) 7 | add_subdirectory(gtest) 8 | endif() 9 | 10 | if (RC_ENABLE_BOOST_TEST) 11 | add_subdirectory(boost_test) 12 | endif() 13 | -------------------------------------------------------------------------------- /include/rapidcheck/state.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "rapidcheck/state/Command.h" 6 | #include "rapidcheck/state/Commands.h" 7 | #include "rapidcheck/state/State.h" 8 | #include "rapidcheck/state/gen/Commands.h" 9 | #include "rapidcheck/state/gen/ExecCommands.h" 10 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #if (__GLIBCXX__ / 10000) >= 2014 3 | 4 | namespace std { 5 | 6 | inline bool uncaught_exception() noexcept(true) { 7 | return current_exception() != nullptr; 8 | } 9 | 10 | } // namespace std 11 | 12 | #endif 13 | 14 | #define CATCH_CONFIG_MAIN 15 | #include 16 | -------------------------------------------------------------------------------- /extras/boost/test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #if (__GLIBCXX__ / 10000) == 2014 3 | 4 | namespace std { 5 | 6 | inline bool uncaught_exception() noexcept(true) { 7 | return current_exception() != nullptr; 8 | } 9 | 10 | } // namespace std 11 | 12 | #endif 13 | 14 | #define CATCH_CONFIG_MAIN 15 | #include 16 | -------------------------------------------------------------------------------- /examples/counter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(counter main.cpp) 2 | 3 | target_compile_options(counter PRIVATE -fsanitize=fuzzer) 4 | target_link_libraries(counter 5 | PRIVATE -fsanitize=fuzzer 6 | ) 7 | 8 | target_link_libraries(counter PUBLIC rapidcheck) 9 | #target_include_directories(counter PRIVATE ../../ext/catch/include) 10 | -------------------------------------------------------------------------------- /include/rapidcheck/GenerationFailure.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace rc { 6 | 7 | /// Thrown to indicate that an appropriate value couldn't be generated. 8 | class GenerationFailure : public std::runtime_error { 9 | public: 10 | explicit GenerationFailure(std::string msg); 11 | }; 12 | 13 | } // namespace rc 14 | -------------------------------------------------------------------------------- /extras/boost/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(rapidcheck_boost_tests 2 | main.cpp 3 | OptionalTests.cpp 4 | ) 5 | 6 | target_link_libraries(rapidcheck_boost_tests 7 | boost 8 | rapidcheck_boost 9 | rapidcheck_catch 10 | rapidcheck_test_utils 11 | catch) 12 | 13 | add_test( 14 | NAME rapidcheck_boost_tests 15 | COMMAND rapidcheck_boost_tests) -------------------------------------------------------------------------------- /ext/get_boost.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | curl -s -L -o boost_1_59_0.tar.bz2 "http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.59.0%2Fboost_1_59_0.tar.bz2%2Fdownload&ts=1441133751&use_mirror=skylink" 3 | tar xjfp boost_1_59_0.tar.bz2 4 | mv boost_1_59_0 boost 5 | rm boost_1_59_0.tar.bz2 6 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Maybe.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | namespace gen { 5 | 6 | /// Generates a `Maybe` of the type of the given generator. At small sizes, the 7 | /// frequency of `Nothing` is greater than at larger sizes. 8 | template 9 | Gen> maybe(Gen gen); 10 | 11 | } // namespace gen 12 | } // namespace rc 13 | 14 | #include "Maybe.hpp" 15 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/detail/ScaleInteger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace rc { 6 | namespace gen { 7 | namespace detail { 8 | 9 | /// Scales a 64-bit integer according to `size` without overflows. `size` maxes 10 | /// out at `100`. 11 | uint64_t scaleInteger(uint64_t rangeSize, int size); 12 | 13 | } // namespace detail 14 | } // namespace gen 15 | } // namespace rc 16 | -------------------------------------------------------------------------------- /examples/boost_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(boost_test_integration main.cpp) 2 | target_link_libraries(boost_test_integration rapidcheck_boost_test boost) 3 | if (MSVC) 4 | target_compile_options(boost_test_integration PRIVATE "/EHa") 5 | else() 6 | # Boost uses auto_ptr which causes warnings on (at least) GCC 7 | target_compile_options(boost_test_integration PRIVATE "-Wno-deprecated-declarations") 8 | endif() 9 | -------------------------------------------------------------------------------- /include/rapidcheck/Log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /// Logs additional information about the run of a test case. Can be used either 6 | /// like a stream (`RC_LOG() << "foobar"`) or taking a string 7 | /// (`RC_LOG("foobar")`). When using the latter form, a newline will be appended 8 | /// automatically. 9 | #define RC_LOG(...) ::rc::detail::log(__VA_ARGS__) 10 | 11 | #include "Log.hpp" 12 | -------------------------------------------------------------------------------- /include/rapidcheck/Nothing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | 5 | /// Tag struct that can be used to construct different types to an uninitialized 6 | /// or empty state. 7 | struct NothingType { 8 | /// Explicit conversion to false. 9 | explicit operator bool() const { return false; } 10 | }; 11 | 12 | /// Singleton NothingType value. 13 | constexpr NothingType Nothing = NothingType(); 14 | 15 | } // namespace rc 16 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Numeric.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/Gen.h" 4 | 5 | namespace rc { 6 | namespace gen { 7 | 8 | /// Generates an integer in a given range. 9 | /// 10 | /// @param min The minimum value, inclusive. 11 | /// @param max The maximum value, exclusive. 12 | template 13 | Gen inRange(T min, T max); 14 | 15 | } // namespace gen 16 | } // namespace rc 17 | 18 | #include "Numeric.hpp" 19 | -------------------------------------------------------------------------------- /include/rapidcheck/BeforeMinimalTestCase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | 5 | /// This is called before the final minimal test case is run when a property 6 | /// fails. Set a breakpoint here if you want to debug that test case. When the 7 | /// debugger breaks here, you can set up any further breakpoints or other tools 8 | /// before the test case is actually run. 9 | void beforeMinimalTestCase(); 10 | 11 | } // namespace rc 12 | -------------------------------------------------------------------------------- /src/detail/FuzzData.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "rapidcheck/detail/FuzzData.h" 4 | 5 | namespace rc { 6 | FuzzData::FuzzData(const uint8_t *Data, size_t Size) { 7 | // TODO: really stupid way to fill the container 8 | const size_t size64 = Size / 8; 9 | auto Data64 = reinterpret_cast(Data); 10 | for (size_t i = 0; i < size64; i++) { 11 | m_data.push(Data64[i]); 12 | } 13 | } 14 | } // namespace rc 15 | -------------------------------------------------------------------------------- /extras/boost/include/rapidcheck/gen/boost/Optional.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace rc { 6 | namespace gen { 7 | namespace boost { 8 | 9 | /// Generates a `boost::optional` of values generated by the given generator. 10 | template 11 | Gen<::boost::optional> optional(Gen gen); 12 | 13 | } // namespace boost 14 | } // namespace gen 15 | } // namespace rc 16 | 17 | #include "Optional.hpp" 18 | -------------------------------------------------------------------------------- /src/Log.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/Log.h" 2 | 3 | #include "rapidcheck/detail/ImplicitParam.h" 4 | #include "rapidcheck/detail/PropertyContext.h" 5 | 6 | namespace rc { 7 | namespace detail { 8 | 9 | std::ostream &log() { 10 | return ImplicitParam::value()->logStream(); 11 | } 12 | 13 | void log(const std::string &msg) { 14 | log() << msg << std::endl; 15 | } 16 | 17 | } // namespace detail 18 | } // namespace rc 19 | -------------------------------------------------------------------------------- /src/detail/ImplicitParam.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/detail/ImplicitParam.h" 2 | 3 | namespace rc { 4 | namespace detail { 5 | 6 | ImplicitScope::ImplicitScope() { m_scopes.emplace(); } 7 | 8 | ImplicitScope::~ImplicitScope() { 9 | for (auto destructor : m_scopes.top()) { 10 | destructor(); 11 | } 12 | m_scopes.pop(); 13 | } 14 | 15 | ImplicitScope::ScopeStack ImplicitScope::m_scopes; 16 | 17 | } // namespace detail 18 | } // namespace rc 19 | -------------------------------------------------------------------------------- /include/rapidcheck/detail/ShowType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | namespace detail { 5 | 6 | /** 7 | * Outputs a string representation of `T` to `os`. 8 | */ 9 | template 10 | void showType(std::ostream &os); 11 | 12 | /** 13 | * Returns a string representation of type `T`. 14 | */ 15 | template 16 | std::string typeToString(); 17 | 18 | } // namespace detail 19 | } // namespace rc 20 | 21 | #include "ShowType.hpp" 22 | -------------------------------------------------------------------------------- /src/detail/Serialization.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/detail/Serialization.h" 2 | 3 | namespace rc { 4 | namespace detail { 5 | 6 | SerializationException::SerializationException(const std::string &msg) 7 | : m_msg(msg) {} 8 | 9 | std::string SerializationException::message() const { return m_msg; } 10 | 11 | const char *SerializationException::what() const noexcept { 12 | return m_msg.c_str(); 13 | } 14 | 15 | } // namespace detail 16 | } // namespace rc 17 | -------------------------------------------------------------------------------- /test/detail/SerializationTests/Integers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "rapidcheck/detail/Serialization.h" 5 | 6 | #include "util/Meta.h" 7 | #include "util/TypeListMacros.h" 8 | #include "util/Serialization.h" 9 | 10 | using namespace rc; 11 | using namespace rc::detail; 12 | using namespace rc::test; 13 | 14 | TEST_CASE("serialization(integers)") { 15 | forEachType(); 16 | } 17 | -------------------------------------------------------------------------------- /include/rapidcheck/Classify.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace rc { 6 | namespace detail { 7 | 8 | struct Stringified { 9 | template 10 | Stringified(const T &value) 11 | : str(toString(value)) {} 12 | std::string str; 13 | }; 14 | 15 | void tag(std::initializer_list tags); 16 | void classify(std::string condition, std::initializer_list tags); 17 | 18 | } // namespace detail 19 | } // namespace rc 20 | -------------------------------------------------------------------------------- /include/rapidcheck/fn/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | namespace fn { 5 | 6 | template 7 | class Constant; 8 | 9 | /// Returns a functor which always returns the given value, regardless of the 10 | /// arguments passed to it. The returned functor is polymorphic in both arity 11 | /// and types. 12 | template 13 | Constant> constant(T &&value); 14 | 15 | } // namespace fn 16 | } // namespace rc 17 | 18 | #include "Common.hpp" 19 | -------------------------------------------------------------------------------- /src/detail/Base64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace rc { 7 | namespace detail { 8 | 9 | /// The alphabet that is used for Base64. 10 | extern const char *kBase64Alphabet; 11 | 12 | /// Encodes the given data as (some variant of) Base64. 13 | std::string base64Encode(const std::vector &data); 14 | 15 | /// Decodes the given data as (some variant of) Base64. 16 | std::vector base64Decode(const std::string &data); 17 | 18 | } // namespace detail 19 | } // namespace rc 20 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/detail/ShrinkValueIterator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | namespace gen { 5 | namespace detail { 6 | 7 | template 8 | class ShrinkValueIterator; 9 | 10 | /// Wraps an iterator that iterates over `Shrinkable`s and makes it returns the 11 | /// value of the shrinkables instead. 12 | template 13 | ShrinkValueIterator makeShrinkValueIterator(Iterator it); 14 | 15 | } // namespace detail 16 | } // namespace gen 17 | } // namespace rc 18 | 19 | #include "ShrinkValueIterator.hpp" 20 | -------------------------------------------------------------------------------- /test/detail/StringSerializationTests.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "detail/StringSerialization.h" 5 | 6 | #include "util/Generators.h" 7 | 8 | using namespace rc; 9 | using namespace rc::detail; 10 | 11 | TEST_CASE("stringToReproduceMap") { 12 | prop("deserializes what reproduceToString serialized", 13 | [](const std::unordered_map &reproMap) { 14 | RC_ASSERT(stringToReproduceMap(reproduceMapToString(reproMap)) == 15 | reproMap); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Exec.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/gen/detail/Recipe.h" 4 | #include "rapidcheck/gen/detail/ExecRaw.h" 5 | 6 | namespace rc { 7 | namespace gen { 8 | 9 | template 10 | Gen>> exec(Callable &&callable) { 11 | using namespace detail; 12 | using T = rc::detail::ReturnType; 13 | 14 | return gen::map(execRaw(std::forward(callable)), 15 | [](std::pair &&p) { return std::move(p.first); }); 16 | } 17 | 18 | } // namespace gen 19 | } // namespace rc 20 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/detail/ExecRaw.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/detail/FunctionTraits.h" 4 | #include "rapidcheck/gen/detail/Recipe.h" 5 | 6 | namespace rc { 7 | namespace gen { 8 | namespace detail { 9 | 10 | /// "Raw" version of `gen::exec` (which uses this generator) that both return 11 | /// the generated value and the `Recipe` used to do so. 12 | template 13 | Gen, Recipe>> 14 | execRaw(Callable callable); 15 | 16 | } // namespace detail 17 | } // namespace gen 18 | } // namespace rc 19 | 20 | #include "ExecRaw.hpp" 21 | -------------------------------------------------------------------------------- /examples/database/DatabaseConnection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | struct Message { 8 | Message() = default; 9 | Message(std::string t, 10 | std::vector p = std::vector()); 11 | 12 | std::string type; 13 | std::vector params; 14 | }; 15 | 16 | class IDatabaseConnection { 17 | public: 18 | virtual Message sendMessage(const Message &msg) = 0; 19 | virtual ~IDatabaseConnection() = default; 20 | }; 21 | 22 | std::unique_ptr connectToDatabase(const std::string &id); 23 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Create.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/fn/Common.h" 4 | #include "rapidcheck/shrinkable/Create.h" 5 | 6 | namespace rc { 7 | namespace gen { 8 | 9 | template 10 | Gen> just(T &&value) { 11 | return fn::constant(shrinkable::just(std::forward(value))); 12 | } 13 | 14 | template 15 | Gen::type::ValueType> 16 | lazy(Callable &&callable) { 17 | return 18 | [=](const Random &random, int size) { return callable()(random, size); }; 19 | } 20 | 21 | } // namespace gen 22 | } // namespace rc 23 | -------------------------------------------------------------------------------- /include/rapidcheck/detail/TestListenerAdapter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/detail/TestListener.h" 4 | 5 | namespace rc { 6 | namespace detail { 7 | 8 | /// `TestListener` that has no-op default implementations of all methods. 9 | class TestListenerAdapter : public TestListener { 10 | public: 11 | void onTestCaseFinished(const CaseDescription &/*description*/) {} 12 | void onShrinkTried(const CaseDescription &/*shrink*/, bool /*accepted*/) {} 13 | void onTestFinished(const TestMetadata &/*metadata*/, const TestResult &/*result*/) {} 14 | }; 15 | 16 | } // namespace detail 17 | } // namespace rc 18 | -------------------------------------------------------------------------------- /test/detail/TestMetadataTests.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "rapidcheck/detail/TestMetadata.h" 5 | 6 | #include "util/TemplateProps.h" 7 | #include "util/Generators.h" 8 | 9 | using namespace rc; 10 | using namespace rc::detail; 11 | 12 | TEST_CASE("TestMetadata") { 13 | SECTION("operator==/operator!=") { 14 | propConformsToEquals(); 15 | PROP_REPLACE_MEMBER_INEQUAL(TestMetadata, id); 16 | PROP_REPLACE_MEMBER_INEQUAL(TestMetadata, description); 17 | } 18 | 19 | SECTION("operator<<") { propConformsToOutputOperator(); } 20 | } 21 | -------------------------------------------------------------------------------- /extras/gmock/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(rapidcheck_gmock_tests main.cpp) 2 | target_link_libraries(rapidcheck_gmock_tests 3 | rapidcheck_gmock 4 | rapidcheck_catch 5 | catch 6 | gmock) 7 | target_include_directories(rapidcheck_gmock_tests PRIVATE 8 | ${CMAKE_SOURCE_DIR}/ext/googletest/googletest/include 9 | ${CMAKE_SOURCE_DIR}/ext/googletest/googlemock/include) 10 | 11 | # Prevent collision between Gmock and Catch 12 | target_compile_definitions(rapidcheck_gmock_tests PRIVATE 13 | CATCH_CONFIG_PREFIX_ALL) 14 | 15 | add_test( 16 | NAME rapidcheck_gmock_tests 17 | COMMAND rapidcheck_gmock_tests) 18 | -------------------------------------------------------------------------------- /src/detail/TestMetadata.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/detail/TestMetadata.h" 2 | 3 | namespace rc { 4 | namespace detail { 5 | 6 | std::ostream &operator<<(std::ostream &os, const TestMetadata &info) { 7 | os << "id='" << info.id << "', description='" << info.description << "'"; 8 | return os; 9 | } 10 | 11 | bool operator==(const TestMetadata &lhs, const TestMetadata &rhs) { 12 | return (lhs.id == rhs.id) && (lhs.description == rhs.description); 13 | } 14 | 15 | bool operator!=(const TestMetadata &lhs, const TestMetadata &rhs) { 16 | return !(lhs == rhs); 17 | } 18 | 19 | } // namespace detail 20 | } // namespace rc 21 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Tuple.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/Gen.h" 4 | 5 | namespace rc { 6 | namespace gen { 7 | 8 | /// Given a number of generators, returns a generator for a tuple with the value 9 | /// types of those generators. 10 | template 11 | Gen> tuple(Gen... gens); 12 | 13 | /// Given two generators, returns a generator for a pair with the value types of 14 | /// those generators. 15 | template 16 | Gen> pair(Gen gen1, Gen gen2); 17 | 18 | } // namespace gen 19 | } // namespace rc 20 | 21 | #include "Tuple.hpp" 22 | -------------------------------------------------------------------------------- /src/detail/ParseException.cpp: -------------------------------------------------------------------------------- 1 | #include "ParseException.h" 2 | 3 | namespace rc { 4 | namespace detail { 5 | 6 | ParseException::ParseException(std::string::size_type pos, 7 | const std::string &msg) 8 | : m_pos(pos) 9 | , m_msg(msg) 10 | , m_what("@" + std::to_string(m_pos) + ": " + msg) {} 11 | 12 | std::string::size_type ParseException::position() const { return m_pos; } 13 | 14 | std::string ParseException::message() const { return m_msg; } 15 | 16 | const char *ParseException::what() const noexcept { return m_what.c_str(); } 17 | 18 | } // namespace detail 19 | } // namespace rc 20 | -------------------------------------------------------------------------------- /include/rapidcheck/detail/TestMetadata.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace rc { 7 | namespace detail { 8 | 9 | /// Describes a property. 10 | struct TestMetadata { 11 | /// A unique identifier for the test. 12 | std::string id; 13 | /// A description of the test. 14 | std::string description; 15 | }; 16 | 17 | std::ostream &operator<<(std::ostream &os, const TestMetadata &info); 18 | bool operator==(const TestMetadata &lhs, const TestMetadata &rhs); 19 | bool operator!=(const TestMetadata &lhs, const TestMetadata &rhs); 20 | 21 | } // namespace detail 22 | } // namespace rc 23 | -------------------------------------------------------------------------------- /test/detail/TestParamsTests.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "rapidcheck/detail/Configuration.h" 5 | 6 | #include "util/TemplateProps.h" 7 | #include "util/Generators.h" 8 | 9 | using namespace rc; 10 | using namespace rc::detail; 11 | 12 | TEST_CASE("TestParams") { 13 | propConformsToEquals(); 14 | propConformsToOutputOperator(); 15 | PROP_REPLACE_MEMBER_INEQUAL(TestParams, seed); 16 | PROP_REPLACE_MEMBER_INEQUAL(TestParams, maxSuccess); 17 | PROP_REPLACE_MEMBER_INEQUAL(TestParams, maxSize); 18 | PROP_REPLACE_MEMBER_INEQUAL(TestParams, maxDiscardRatio); 19 | } 20 | -------------------------------------------------------------------------------- /test/util/ArbitraryRandom.cpp: -------------------------------------------------------------------------------- 1 | #include "ArbitraryRandom.h" 2 | 3 | #include "rapidcheck/gen/Numeric.h" 4 | 5 | // TODO clean up, formalize 6 | 7 | namespace rc { 8 | 9 | template struct Arbitrary; 10 | 11 | namespace test { 12 | 13 | Gen trulyArbitraryRandom() { 14 | return gen::map( 15 | gen::pair(gen::arbitrary(), gen::inRange(0, 10000)), 16 | [](std::pair &&p) { 17 | auto nexts = p.second; 18 | while (nexts-- > 0) { 19 | p.first.next(); 20 | } 21 | return p.first; 22 | }); 23 | } 24 | 25 | } // namespace test 26 | } // namespace rc 27 | -------------------------------------------------------------------------------- /test/util/SeqUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/seq/Operations.h" 4 | 5 | namespace rc { 6 | namespace test { 7 | 8 | /// Forwards Seq a random amount and copies it to see if it is equal to the 9 | /// original. Must not be infinite, of course. 10 | template 11 | void assertEqualCopies(Seq seq) { 12 | std::size_t len = seq::length(seq); 13 | if (len != 0) { 14 | std::size_t n = *gen::inRange(0, len * 2); 15 | while (n--) { 16 | seq.next(); 17 | } 18 | } 19 | const auto copy = seq; 20 | RC_ASSERT(copy == seq); 21 | } 22 | 23 | } // namespace test 24 | } // namespace rc 25 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Arbitrary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/Gen.h" 4 | 5 | namespace rc { 6 | 7 | /// Specialize this template to provide default arbitrary generators for custom 8 | /// types. Specializations should have a static method `Gen arbitrary()` that 9 | /// returns a suitable generator for generating arbitrary values of `T`. 10 | template 11 | struct Arbitrary; 12 | 13 | namespace gen { 14 | 15 | /// Returns a generator for arbitrary values of `T`. 16 | template 17 | decltype(Arbitrary::arbitrary()) arbitrary(); 18 | 19 | } // namespace gen 20 | } // namespace rc 21 | 22 | #include "Arbitrary.hpp" 23 | -------------------------------------------------------------------------------- /src/detail/StringSerialization.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "rapidcheck/detail/Results.h" 6 | 7 | namespace rc { 8 | namespace detail { 9 | 10 | /// Converts a Reproduce map to a string. 11 | /// 12 | /// @throws ParseException on failure to parse. 13 | std::string reproduceMapToString( 14 | const std::unordered_map &reproduceMap); 15 | 16 | /// Converts a string Reproduce map to a string. 17 | /// 18 | /// @throws ParseException on failure to parse. 19 | std::unordered_map 20 | stringToReproduceMap(const std::string &str); 21 | 22 | } // namespace detail 23 | } // namespace rc 24 | -------------------------------------------------------------------------------- /src/detail/DefaultTestListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "rapidcheck/detail/TestListener.h" 6 | #include "rapidcheck/detail/Configuration.h" 7 | 8 | namespace rc { 9 | namespace detail { 10 | 11 | /// Creates a default `TestListener`. 12 | /// 13 | /// @param config The configuration describing the listener. 14 | /// @param os The output stream to print information to. 15 | std::unique_ptr 16 | makeDefaultTestListener(const Configuration &config, std::ostream &os); 17 | 18 | /// Returns the global default `TestListener`. 19 | TestListener &globalTestListener(); 20 | 21 | } // namespace detail 22 | } // namespace rc 23 | -------------------------------------------------------------------------------- /src/detail/FrequencyMap.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/detail/FrequencyMap.h" 2 | 3 | #include 4 | 5 | namespace rc { 6 | namespace detail { 7 | 8 | FrequencyMap::FrequencyMap(const std::vector &frequencies) 9 | : m_sum(0) { 10 | m_table.reserve(frequencies.size()); 11 | for (auto x : frequencies) { 12 | m_sum += x; 13 | m_table.push_back(m_sum); 14 | } 15 | } 16 | 17 | std::size_t FrequencyMap::lookup(std::size_t x) const { 18 | return std::upper_bound(begin(m_table), end(m_table), x) - begin(m_table); 19 | } 20 | 21 | std::size_t FrequencyMap::sum() const { return m_sum; } 22 | 23 | } // namespace detail 24 | } // namespace rc 25 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Text.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/Gen.h" 4 | 5 | namespace rc { 6 | namespace gen { 7 | 8 | /// Generator of text characters. Common occuring characters have a higher 9 | /// probability of being generated. 10 | template 11 | Gen character(); 12 | 13 | /// Generator of strings. Essentially equivalent to 14 | /// `gen::container(gen::character())` but 15 | /// a lot faster. If you need to use a custom character generator, use 16 | /// `gen::container`. 17 | template 18 | Gen string(); 19 | 20 | } // namespace gen 21 | } // namespace rc 22 | 23 | #include "Text.hpp" 24 | -------------------------------------------------------------------------------- /src/detail/Any.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/detail/Any.h" 2 | 3 | namespace rc { 4 | namespace detail { 5 | 6 | Any::Any() noexcept {} 7 | 8 | void Any::reset() { m_impl.reset(); } 9 | 10 | 11 | void Any::showType(std::ostream &os) const { 12 | if (m_impl) { 13 | m_impl->showType(os); 14 | } 15 | } 16 | 17 | void Any::showValue(std::ostream &os) const { 18 | if (m_impl) { 19 | m_impl->showValue(os); 20 | } 21 | } 22 | 23 | Any::operator bool() const { return static_cast(m_impl); } 24 | 25 | std::ostream &operator<<(std::ostream &os, const Any &value) { 26 | value.showValue(os); 27 | return os; 28 | } 29 | 30 | } // namespace detail 31 | } // namespace rc 32 | -------------------------------------------------------------------------------- /include/rapidcheck/detail/FrequencyMap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace rc { 6 | namespace detail { 7 | 8 | /// Helper class for implementing weighted random generators. Using a table of 9 | /// weights, provides a fast lookup of a value in the range `[0, sum(weights))` 10 | /// to an index into the weights table. 11 | class FrequencyMap { 12 | public: 13 | explicit FrequencyMap(const std::vector &frequencies); 14 | 15 | std::size_t lookup(std::size_t x) const; 16 | std::size_t sum() const; 17 | 18 | private: 19 | std::size_t m_sum; 20 | std::vector m_table; 21 | }; 22 | 23 | } // namespace detail 24 | } // namespace rc 25 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/detail/ExecHandler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/gen/detail/GenerationHandler.h" 4 | #include "rapidcheck/gen/detail/Recipe.h" 5 | 6 | namespace rc { 7 | namespace gen { 8 | namespace detail { 9 | 10 | /// `GenerationHandler` used to implement `execRaw`. 11 | class ExecHandler : public GenerationHandler { 12 | public: 13 | ExecHandler(Recipe &recipe); 14 | rc::detail::Any onGenerate(const Gen &gen); 15 | 16 | private: 17 | Recipe &m_recipe; 18 | Random m_random; 19 | using Iterator = Recipe::Ingredients::iterator; 20 | Iterator m_it; 21 | }; 22 | 23 | } // namespace detail 24 | } // namespace gen 25 | } // namespace rc 26 | -------------------------------------------------------------------------------- /src/detail/PropertyContext.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidcheck/detail/PropertyContext.h" 2 | 3 | namespace rc { 4 | namespace detail { 5 | namespace param { 6 | namespace { 7 | 8 | class DummyPropertyContext : public PropertyContext { 9 | public: 10 | bool reportResult(const CaseResult &/*result*/) override { return false; } 11 | std::ostream &logStream() override { return std::cerr; } 12 | void addTag(std::string /*str*/) override {} 13 | }; 14 | 15 | } // namespace 16 | 17 | PropertyContext *CurrentPropertyContext::defaultValue() { 18 | static DummyPropertyContext dummyContext; 19 | return &dummyContext; 20 | } 21 | 22 | } // namespace param 23 | } // namespace detail 24 | } // namespace rc 25 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Arbitrary.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | namespace gen { 5 | namespace detail { 6 | 7 | template 8 | struct DefaultArbitrary; 9 | 10 | } // namespace detail 11 | 12 | template 13 | decltype(Arbitrary::arbitrary()) arbitrary() { 14 | static const auto instance = rc::Arbitrary::arbitrary(); 15 | return instance; 16 | } 17 | 18 | } // namespace gen 19 | 20 | template 21 | struct Arbitrary { 22 | static decltype(gen::detail::DefaultArbitrary::arbitrary()) arbitrary() { 23 | return gen::detail::DefaultArbitrary::arbitrary(); 24 | } 25 | }; 26 | 27 | } // namespace rc 28 | 29 | #include "Arbitrary.hpp" 30 | -------------------------------------------------------------------------------- /src/detail/MapParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace rc { 7 | namespace detail { 8 | 9 | /// Parses a configuration string into an `std::map`. 10 | /// 11 | /// @throws ParseException On parse failure. 12 | std::map parseMap(const std::string &str); 13 | 14 | /// Converts a map to a string. 15 | /// 16 | /// @param map The map to convert. 17 | /// @param doubleQuote Whether to use double quotes or single quotes. 18 | std::string mapToString(const std::map &map, 19 | bool doubleQuote = false); 20 | 21 | } // namespace detail 22 | } // namespace rc 23 | -------------------------------------------------------------------------------- /extras/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | option(RC_ENABLE_CATCH "Build Catch.hpp support" OFF) 2 | if (RC_ENABLE_CATCH OR RC_ENABLE_TESTS) 3 | add_subdirectory(catch) 4 | endif() 5 | 6 | option(RC_ENABLE_GMOCK "Build Google Mock integration" OFF) 7 | if (RC_ENABLE_GMOCK) 8 | add_subdirectory(gmock) 9 | endif() 10 | 11 | option(RC_ENABLE_GTEST "Build Google Test integration" OFF) 12 | if (RC_ENABLE_GTEST) 13 | add_subdirectory(gtest) 14 | endif() 15 | 16 | option(RC_ENABLE_BOOST "Build Boost support" OFF) 17 | if (RC_ENABLE_BOOST) 18 | add_subdirectory(boost) 19 | endif() 20 | 21 | option(RC_ENABLE_BOOST_TEST "Build Boost Test support" OFF) 22 | if (RC_ENABLE_BOOST_TEST) 23 | add_subdirectory(boost_test) 24 | endif() 25 | -------------------------------------------------------------------------------- /examples/mapparser/MapParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class ParseException : public std::exception { 8 | public: 9 | ParseException(std::string::size_type pos, const std::string &msg); 10 | std::string::size_type position() const; 11 | std::string message() const; 12 | const char *what() const noexcept override; 13 | 14 | private: 15 | std::string::size_type m_pos; 16 | std::string m_msg; 17 | std::string m_what; 18 | }; 19 | 20 | std::map parseMap(const std::string &str); 21 | 22 | std::string mapToString(const std::map &map, 23 | bool doubleQuote = false); 24 | -------------------------------------------------------------------------------- /examples/database/Database.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "User.h" 9 | 10 | class IDatabaseConnection; 11 | 12 | class Database { 13 | public: 14 | explicit Database(std::unique_ptr connection); 15 | 16 | void open(); 17 | void close(); 18 | void beginWrite(); 19 | void executeWrite(); 20 | void put(User user); 21 | bool get(const std::string &username, User &user); 22 | 23 | private: 24 | bool m_open; 25 | std::unique_ptr m_connection; 26 | std::map m_cache; 27 | bool m_hasBlock; 28 | std::vector m_queue; 29 | std::size_t m_hash; 30 | }; 31 | -------------------------------------------------------------------------------- /include/rapidcheck/detail/FuzzData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace rc { 8 | 9 | /// Wrapper around a std::stack. + nice c-tor. 10 | class FuzzData { 11 | public: 12 | using Ptr = std::shared_ptr; 13 | 14 | FuzzData(const uint8_t *Data, size_t Size); 15 | 16 | inline bool empty() const { return m_data.empty(); } 17 | 18 | /// Use top value from stack (so it's gone afterwards). 19 | inline uint64_t top_and_pop() { 20 | assert(!empty()); 21 | const auto value = m_data.top(); 22 | m_data.pop(); 23 | return value; 24 | } 25 | 26 | private: 27 | std::stack m_data; 28 | }; 29 | 30 | } // namespace rc 31 | -------------------------------------------------------------------------------- /include/rapidcheck/gen/Create.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rapidcheck/Gen.h" 4 | 5 | namespace rc { 6 | namespace gen { 7 | 8 | /// Returns a generator which always returns the given value with no shrinks. 9 | template 10 | Gen> just(T &&value); 11 | 12 | /// Creates from a callable that returns another generator. The callable is only 13 | /// called lazily on actual generation. This is useful when implementing 14 | /// recursive generators where a generator must reference itself. 15 | template 16 | Gen::type::ValueType> 17 | lazy(Callable &&callable); 18 | 19 | } // namespace gen 20 | } // namespace rc 21 | 22 | #include "Create.hpp" 23 | -------------------------------------------------------------------------------- /include/rapidcheck/Check.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace rc { 6 | 7 | /// Checks the given testable and returns `true` on success and `false` on 8 | /// failure. This method will also print information about the testing to 9 | /// stderr. 10 | template 11 | bool check(Testable &&testable, const uint8_t *Data, size_t Size); 12 | 13 | /// Same as `check(Testable &&)` but also takes a description of the property 14 | /// that is being tested as the first parameter. This will be used in the 15 | /// output. 16 | template 17 | bool check(const std::string &description, Testable &&testable, const uint8_t *Data, size_t Size); 18 | 19 | } // namespace rc 20 | 21 | #include "Check.hpp" 22 | -------------------------------------------------------------------------------- /include/rapidcheck/fn/Common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace rc { 4 | namespace fn { 5 | 6 | template 7 | class Constant { 8 | public: 9 | template , Constant>::value>::type> 12 | explicit Constant(Arg &&arg) 13 | : m_value(std::forward(arg)) {} 14 | 15 | template 16 | T operator()(Args &&... /*args*/) const { 17 | return m_value; 18 | } 19 | 20 | private: 21 | T m_value; 22 | }; 23 | 24 | template 25 | Constant> constant(T &&value) { 26 | return Constant>(std::forward(value)); 27 | } 28 | 29 | } // namespace fn 30 | } // namespace rc 31 | -------------------------------------------------------------------------------- /include/rapidcheck/Traits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "rapidcheck/detail/IntSequence.h" 6 | 7 | namespace rc { 8 | 9 | /// Convenience wrapper over std::decay, shorter to type. 10 | template 11 | using Decay = typename std::decay::type; 12 | 13 | /// Checks that all the parameters are true. 14 | template 15 | struct AllTrue 16 | : public std::is_same, 17 | detail::IntSequence> {}; 18 | 19 | /// Checks that all the types in `Ts` conforms to type trait `F`. 20 | template