1
0
Fork 0
mirror of https://github.com/eosswedenorg/libantelope synced 2026-06-16 03:34:56 +02:00

tests: Adding doctest framework.

This commit is contained in:
Henrik Hautakoski 2023-03-09 17:40:46 +01:00
parent 35c2c2fe79
commit dbbdc896e1
6 changed files with 7125 additions and 53 deletions

View file

@ -1,13 +1,17 @@
function(test name)
add_executable(${name}_test ${name}.cpp)
target_link_libraries(${name}_test PRIVATE ${LIB_NAME})
set(TEST_SRC
main.cpp
# define tests
add_test(
NAME ${name}_test
COMMAND $<TARGET_FILE:${name}_test>
)
endfunction()
# Base58
base58/encode.cpp
base58/is_base58.cpp
)
add_subdirectory( base58 )
add_executable(doctest ${TEST_SRC})
target_link_libraries(doctest PRIVATE ${LIB_NAME})
target_include_directories(doctest PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
add_test(
NAME doctest
COMMAND $<TARGET_FILE:doctest> -ni -fc
)

View file

@ -1,3 +0,0 @@
test( base58_encode )
test( is_base58 )

View file

@ -1,11 +1,12 @@
#include <libeosio/base58.hpp>
#include <iostream>
#include <array>
#include <doctest.h>
typedef std::pair<std::string, std::string> testpair_t;
typedef std::array<testpair_t, 3> tests;
int main() {
TEST_CASE("base58::base58_encode") {
tests input = {
testpair_t("",""),
@ -20,13 +21,6 @@ int main() {
};
for(tests::const_iterator it = input.begin(); it != input.end(); it++) {
std::string result = libeosio::base58_encode(it->first);
if ( result != it->second ) {
std::cout << result << " is not equalt to " << it->second << std::endl;
return 1;
}
CHECK( libeosio::base58_encode(it->first) == it->second );
}
return 0;
}

View file

@ -1,11 +1,12 @@
#include <libeosio/base58.hpp>
#include <iostream>
#include <array>
#include <doctest.h>
typedef std::pair<std::string, size_t> testpair_t;
typedef std::array<testpair_t, 6> tests;
int test_string() {
TEST_CASE("base58::is_base58 [string]") {
tests input = {
// Empty string is a valid base58 string.
testpair_t("", std::string::npos),
@ -30,48 +31,22 @@ int test_string() {
size_t ret = libeosio::is_base58(it->first);
if ( ret != it->second ) {
std::cout << ret << " is not equalt to " << it->second << std::endl;
return 1;
}
CHECK(ret == it->second);
}
return 0;
}
int test_char() {
TEST_CASE("base58::is_base58 [char]") {
std::string valid_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
std::string invalid_alphabet = "0OIl";
for(int i = 0; i < valid_alphabet.length(); i++) {
char ch = valid_alphabet[i];
if ( libeosio::is_base58(ch) == false ) {
std::cout << ch << " should be a valid base58 character " << std::endl;
return 1;
}
CHECK(libeosio::is_base58(ch) == true);
}
for(int i = 0; i < invalid_alphabet.length(); i++) {
char ch = invalid_alphabet[i];
if ( libeosio::is_base58(ch) ) {
std::cout << ch << " should be a invalid base58 character " << std::endl;
return 1;
}
CHECK(libeosio::is_base58(ch) == false);
}
return 0;
}
int main() {
if (test_string() != 0) {
return 1;
}
if (test_char() != 0) {
return 1;
}
return 0;
}

7091
tests/include/doctest.h Normal file

File diff suppressed because it is too large Load diff

11
tests/main.cpp Normal file
View file

@ -0,0 +1,11 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest.h>
int main(int argc, char** argv) {
doctest::Context context;
context.applyCommandLine(argc, argv);
return context.run();
}