mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-18 20:40:03 +02:00
tests: Adding doctest framework.
This commit is contained in:
parent
35c2c2fe79
commit
dbbdc896e1
6 changed files with 7125 additions and 53 deletions
|
|
@ -1,13 +1,17 @@
|
||||||
|
|
||||||
function(test name)
|
set(TEST_SRC
|
||||||
add_executable(${name}_test ${name}.cpp)
|
main.cpp
|
||||||
target_link_libraries(${name}_test PRIVATE ${LIB_NAME})
|
|
||||||
|
|
||||||
# define tests
|
# Base58
|
||||||
add_test(
|
base58/encode.cpp
|
||||||
NAME ${name}_test
|
base58/is_base58.cpp
|
||||||
COMMAND $<TARGET_FILE:${name}_test>
|
)
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
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
|
||||||
|
)
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
|
|
||||||
test( base58_encode )
|
|
||||||
test( is_base58 )
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
#include <libeosio/base58.hpp>
|
#include <libeosio/base58.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <doctest.h>
|
||||||
|
|
||||||
typedef std::pair<std::string, std::string> testpair_t;
|
typedef std::pair<std::string, std::string> testpair_t;
|
||||||
typedef std::array<testpair_t, 3> tests;
|
typedef std::array<testpair_t, 3> tests;
|
||||||
|
|
||||||
int main() {
|
TEST_CASE("base58::base58_encode") {
|
||||||
|
|
||||||
tests input = {
|
tests input = {
|
||||||
testpair_t("",""),
|
testpair_t("",""),
|
||||||
|
|
@ -20,13 +21,6 @@ int main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
for(tests::const_iterator it = input.begin(); it != input.end(); it++) {
|
for(tests::const_iterator it = input.begin(); it != input.end(); it++) {
|
||||||
|
CHECK( libeosio::base58_encode(it->first) == it->second );
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
#include <libeosio/base58.hpp>
|
#include <libeosio/base58.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <doctest.h>
|
||||||
|
|
||||||
typedef std::pair<std::string, size_t> testpair_t;
|
typedef std::pair<std::string, size_t> testpair_t;
|
||||||
typedef std::array<testpair_t, 6> tests;
|
typedef std::array<testpair_t, 6> tests;
|
||||||
|
|
||||||
int test_string() {
|
TEST_CASE("base58::is_base58 [string]") {
|
||||||
tests input = {
|
tests input = {
|
||||||
// Empty string is a valid base58 string.
|
// Empty string is a valid base58 string.
|
||||||
testpair_t("", std::string::npos),
|
testpair_t("", std::string::npos),
|
||||||
|
|
@ -30,48 +31,22 @@ int test_string() {
|
||||||
|
|
||||||
size_t ret = libeosio::is_base58(it->first);
|
size_t ret = libeosio::is_base58(it->first);
|
||||||
|
|
||||||
if ( ret != it->second ) {
|
CHECK(ret == it->second);
|
||||||
std::cout << ret << " is not equalt to " << it->second << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
TEST_CASE("base58::is_base58 [char]") {
|
||||||
int test_char() {
|
|
||||||
|
|
||||||
std::string valid_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
std::string valid_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
std::string invalid_alphabet = "0OIl";
|
std::string invalid_alphabet = "0OIl";
|
||||||
|
|
||||||
for(int i = 0; i < valid_alphabet.length(); i++) {
|
for(int i = 0; i < valid_alphabet.length(); i++) {
|
||||||
char ch = valid_alphabet[i];
|
char ch = valid_alphabet[i];
|
||||||
|
|
||||||
if ( libeosio::is_base58(ch) == false ) {
|
CHECK(libeosio::is_base58(ch) == true);
|
||||||
std::cout << ch << " should be a valid base58 character " << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < invalid_alphabet.length(); i++) {
|
for(int i = 0; i < invalid_alphabet.length(); i++) {
|
||||||
char ch = invalid_alphabet[i];
|
char ch = invalid_alphabet[i];
|
||||||
|
|
||||||
if ( libeosio::is_base58(ch) ) {
|
CHECK(libeosio::is_base58(ch) == false);
|
||||||
std::cout << ch << " should be a invalid base58 character " << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
7091
tests/include/doctest.h
Normal file
File diff suppressed because it is too large
Load diff
11
tests/main.cpp
Normal file
11
tests/main.cpp
Normal 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();
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue