mirror of
https://github.com/OpenCoin/oc-mint-cpp.git
synced 2024-12-21 15:19:40 +01:00
added catch2 for unit tests and first test in test/test.cpp
This commit is contained in:
parent
4d9f373d62
commit
7a525a85ce
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
.idea
|
||||
cmake-build-debug
|
||||
|
||||
# ---> C++
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
@ -17,6 +17,7 @@ endif()
|
||||
project(oc-mint VERSION 0.0.1 LANGUAGES CXX)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
#
|
||||
# crow project Configuration variables
|
||||
#
|
||||
@ -45,6 +46,20 @@ if(NOT expected_POPULATED)
|
||||
FetchContent_Populate(expected)
|
||||
endif(NOT expected_POPULATED)
|
||||
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
set(CATCH_INSTALL_DOCS Off)
|
||||
set(CATCH_INSTALL_EXTRAS Off)
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.2.0
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
#add doxygen documentation
|
||||
find_package(Doxygen
|
||||
REQUIRED dot
|
||||
OPTIONAL_COMPONENTS mscgen dia)
|
||||
@ -52,9 +67,21 @@ set(DOXYGEN_HAVE_DOT YES)
|
||||
doxygen_add_docs(
|
||||
doc
|
||||
src
|
||||
COMMENT "Generate dcoumentation"
|
||||
COMMENT "Generate documentation"
|
||||
)
|
||||
set(API_SOURCES src/main.cpp src/model.cpp src/model.hpp)
|
||||
add_executable(oc-mint ${API_SOURCES})
|
||||
target_link_libraries(oc-mint PRIVATE Crow::Crow INTERFACE tl::expected::expected)
|
||||
target_include_directories(oc-mint PRIVATE ${expected_SOURCE_DIR}/include)
|
||||
|
||||
# build common library
|
||||
set(LIB_SOURCES src/model.cpp src/model.hpp)
|
||||
add_library(oc-mint-lib ${LIB_SOURCES})
|
||||
target_link_libraries(oc-mint-lib PUBLIC Crow::Crow)
|
||||
target_include_directories(oc-mint-lib PUBLIC ${expected_SOURCE_DIR}/include src)
|
||||
|
||||
add_executable(oc-mint src/main.cpp)
|
||||
target_link_libraries(oc-mint PRIVATE oc-mint-lib INTERFACE tl::expected::expected)
|
||||
|
||||
## these are unittests that can be run on any platform
|
||||
add_executable(tests test/test.cpp)
|
||||
target_link_libraries(tests
|
||||
oc-mint-lib
|
||||
Catch2::Catch2WithMain)
|
||||
add_test(tests tests)
|
||||
|
14
test/test.cpp
Normal file
14
test/test.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include "model.hpp"
|
||||
|
||||
TEST_CASE( "PublicKey::to_json", "[to_json]" ) {
|
||||
PublicKey k {"daaa63ddda38c189b8c49020c8276adbe0a695685a...",
|
||||
"65537" };
|
||||
|
||||
auto json = k.to_json();
|
||||
|
||||
REQUIRE( json["modulus"].dump() == "\"" + k.modulus + "\"" );
|
||||
REQUIRE( json["public_exponent"].dump() == "\"" + k.public_exponent+"\"" );
|
||||
REQUIRE( json["type"].dump() == "\"rsa public key\"" );
|
||||
REQUIRE( json.keys().size() == 3 );
|
||||
}
|
Loading…
Reference in New Issue
Block a user