mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-18 20:40:03 +02:00
Add support for testing and add simple testcase for base58
This commit is contained in:
parent
d23aea0d19
commit
ae4dd4027f
4 changed files with 137 additions and 0 deletions
|
|
@ -71,6 +71,17 @@ target_include_directories( ${LIB_NAME}
|
||||||
${OPENSSL_INCLUDE_DIR}
|
${OPENSSL_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Tests
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
if (ENABLE_TESTING)
|
||||||
|
# enable testing functionality
|
||||||
|
include(CTest)
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory( tests )
|
||||||
|
endif (ENABLE_TESTING)
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Install
|
# Install
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
|
|
||||||
17
tests/CMakeLists.txt
Normal file
17
tests/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
add_executable(base58_encode_test base58_encode.cpp)
|
||||||
|
target_link_libraries(base58_encode_test PRIVATE ${LIB_NAME})
|
||||||
|
|
||||||
|
add_executable(is_base58_test is_base58.cpp)
|
||||||
|
target_link_libraries(is_base58_test PRIVATE ${LIB_NAME})
|
||||||
|
|
||||||
|
# define tests
|
||||||
|
add_test(
|
||||||
|
NAME base58_encode_test
|
||||||
|
COMMAND $<TARGET_FILE:base58_encode_test>
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME is_base58_test
|
||||||
|
COMMAND $<TARGET_FILE:is_base58_test>
|
||||||
|
)
|
||||||
32
tests/base58_encode.cpp
Normal file
32
tests/base58_encode.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include <libeosio/base58.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
typedef std::pair<std::string, std::string> testpair_t;
|
||||||
|
typedef std::array<testpair_t, 3> tests;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
tests input = {
|
||||||
|
testpair_t("",""),
|
||||||
|
testpair_t(
|
||||||
|
"Quisque ut ipsum lorem. Nullam ac justo elit. Sed gravida convallis mattis.",
|
||||||
|
"2nPTv2DT874jRaYBN4uhM9mT2iRiwdJuCXuX5buUHyyvWUSu6cX62i8HYo8PsWqgs9DHbwhpSpV5SVUnCqyLcpxcuGanH68eXgzZTGq"
|
||||||
|
),
|
||||||
|
testpair_t(
|
||||||
|
"Cras fringilla, eros et imperdiet tincidunt",
|
||||||
|
"5yAgp6rBagDHQZ3GacZSeaEPF2jfuwVHM21aNfXETJgn3EkArxc5UWSq1RM"
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
77
tests/is_base58.cpp
Normal file
77
tests/is_base58.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
#include <libeosio/base58.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
typedef std::pair<std::string, size_t> testpair_t;
|
||||||
|
typedef std::array<testpair_t, 6> tests;
|
||||||
|
|
||||||
|
int test_string() {
|
||||||
|
tests input = {
|
||||||
|
// Empty string is a valid base58 string.
|
||||||
|
testpair_t("", std::string::npos),
|
||||||
|
|
||||||
|
// Test Zero (0)
|
||||||
|
testpair_t("2SdasxuGGdVU5VVyrXiko4jKASeS57E0P9uokzUphZt7tZxt24bzsEwvre", 31),
|
||||||
|
|
||||||
|
// Test O
|
||||||
|
testpair_t("2RTAsaYN2fpxVEDzaQht8ZnAUmwRpJz9C18VXrAWypxQSijRb9295kw13MA8krpRzK5cj2N5p84qQh3OGJrucW8hkLNy3aaEd2rTVhYkekhFiQoQ41JiNScD5KjmpDDxy", 79),
|
||||||
|
|
||||||
|
// Test I
|
||||||
|
testpair_t("5hWrCBA55zLmKpIhZd3RS1DHsJ7SnZpnyBfmibqGpDCJ7QCJGkogvhqPvGuwMgwNHzuZFyR", 14),
|
||||||
|
|
||||||
|
// Test l
|
||||||
|
testpair_t("lHxVA2fQKawLAK9MCJSr2xaWyDpoquQxVP6MMchdhzY49TjTfti8LDR6YL", 0),
|
||||||
|
|
||||||
|
// All valid
|
||||||
|
testpair_t("2BCoJ2BqNWorSoQcSWCQNanB8teoKFaqjojWGEXPBCPPdoGyVN8dgmKRdw", std::string::npos),
|
||||||
|
};
|
||||||
|
|
||||||
|
for(tests::const_iterator it = input.begin(); it != input.end(); it++) {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
if (test_string() != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test_char() != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue