diff options
author | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-20 11:46:11 +0000 |
---|---|---|
committer | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-20 11:46:11 +0000 |
commit | 8efa1313f3614f34ac0bac947314bb53e9a2412b (patch) | |
tree | 2752f8e6dfbb75bc53d56ea422482a8ec5870ffa /tests/unit_tests | |
parent | moved all stuff to github (diff) | |
download | monero-8efa1313f3614f34ac0bac947314bb53e9a2412b.tar.xz |
some fixes
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/base58.cpp | 13 | ||||
-rw-r--r-- | tests/unit_tests/decompose_amount_into_digits.cpp | 6 | ||||
-rw-r--r-- | tests/unit_tests/get_xtype_from_string.cpp | 133 |
3 files changed, 147 insertions, 5 deletions
diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp index 05bf5afc7..87afd5d0e 100644 --- a/tests/unit_tests/base58.cpp +++ b/tests/unit_tests/base58.cpp @@ -399,9 +399,12 @@ TEST_encode_decode_addr(PuT7GAdgbA83uoWF3eanGG1aRoG, 0x1122334455667788, "\x TEST_encode_decode_addr(PuT7GAdgbA83vT1umSHMYJ4oNVdu, 0x1122334455667788, "\x77\x77\x77\x77\x77\x77\x77"); TEST_encode_decode_addr(PuT7GAdgbA83w6XaVDyvpoGQBEWbB, 0x1122334455667788, "\x88\x88\x88\x88\x88\x88\x88\x88"); TEST_encode_decode_addr(PuT7GAdgbA83wk3FD1gW7J2KVGofA1r, 0x1122334455667788, "\x99\x99\x99\x99\x99\x99\x99\x99\x99"); +TEST_encode_decode_addr(15p2yAV, 0, ""); +TEST_encode_decode_addr(FNQ3D6A, 0x7F, ""); +TEST_encode_decode_addr(26k9QWweu, 0x80, ""); +TEST_encode_decode_addr(3BzAD7n3y, 0xFF, ""); TEST_encode_decode_addr(11efCaY6UjG7JrxuB, 0, "\x11\x22\x33\x44\x55\x66\x77"); TEST_encode_decode_addr(21rhHRT48LN4PriP9, 6, "\x11\x22\x33\x44\x55\x66\x77"); -TEST_encode_decode_addr(3BzAD7n3y, 0xFF, ""); #define TEST_decode_addr_neg(addr, test_name) \ @@ -421,6 +424,14 @@ TEST_decode_addr_neg("\0uT7GAdgbA819VwdWVDP", decode_fails_due_invalid_char_00); TEST_decode_addr_neg("PuT7GAdgbA819VwdWVD", decode_fails_due_invalid_lenght); TEST_decode_addr_neg("11efCaY6UjG7JrxuC", handles_invalid_checksum); TEST_decode_addr_neg("jerj2e4mESo", handles_non_correct_tag); // "jerj2e4mESo" == "\xFF\x00\xFF\xFF\x5A\xD9\xF1\x1C" +TEST_decode_addr_neg("1", decode_fails_due_invalid_block_len_0); +TEST_decode_addr_neg("1111", decode_fails_due_invalid_block_len_1); +TEST_decode_addr_neg("11", decode_fails_due_address_too_short_0); +TEST_decode_addr_neg("111", decode_fails_due_address_too_short_1); +TEST_decode_addr_neg("11111", decode_fails_due_address_too_short_2); +TEST_decode_addr_neg("111111", decode_fails_due_address_too_short_3); +TEST_decode_addr_neg("999999", decode_fails_due_address_too_short_4); +TEST_decode_addr_neg("ZZZZZZ", decode_fails_due_address_too_short_5); namespace { diff --git a/tests/unit_tests/decompose_amount_into_digits.cpp b/tests/unit_tests/decompose_amount_into_digits.cpp index d7c66cc73..319b39e2f 100644 --- a/tests/unit_tests/decompose_amount_into_digits.cpp +++ b/tests/unit_tests/decompose_amount_into_digits.cpp @@ -56,8 +56,7 @@ namespace TEST_F(decompose_amount_into_digits_test, is_correct_0) { - uint64_t expected_chunks_arr[] = {0}; - VEC_FROM_ARR(expected_chunks); + std::vector<uint64_t> expected_chunks; cryptonote::decompose_amount_into_digits(0, 0, m_chunk_handler, m_dust_handler); ASSERT_EQ(m_chunk_handler.m_chunks, expected_chunks); ASSERT_EQ(m_dust_handler.m_has_dust, false); @@ -65,8 +64,7 @@ TEST_F(decompose_amount_into_digits_test, is_correct_0) TEST_F(decompose_amount_into_digits_test, is_correct_1) { - uint64_t expected_chunks_arr[] = {0}; - VEC_FROM_ARR(expected_chunks); + std::vector<uint64_t> expected_chunks; cryptonote::decompose_amount_into_digits(0, 10, m_chunk_handler, m_dust_handler); ASSERT_EQ(m_chunk_handler.m_chunks, expected_chunks); ASSERT_EQ(m_dust_handler.m_has_dust, false); diff --git a/tests/unit_tests/get_xtype_from_string.cpp b/tests/unit_tests/get_xtype_from_string.cpp new file mode 100644 index 000000000..0ba80fb3d --- /dev/null +++ b/tests/unit_tests/get_xtype_from_string.cpp @@ -0,0 +1,133 @@ +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "gtest/gtest.h" + +#include <string_tools.h> + +using namespace epee::string_tools; + +namespace +{ + template<typename T> + void do_pos_test(T expected, const std::string& str) + { + T val; + ASSERT_TRUE(get_xtype_from_string(val, str)); + ASSERT_EQ(expected, val); + } + + template<typename T> + void do_neg_test(const std::string& str) + { + T val; + ASSERT_FALSE(get_xtype_from_string(val, str)); + } +} + +#define TEST_pos(int_type, expected, str) \ + TEST(get_xtype_from_string, handles_pos_ ## int_type ## _ ## expected) \ + { \ + do_pos_test<int_type>(expected, str); \ + } + +#define DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln) prefix ## int_type ## _ ## ln +#define MAKE_NEG_TEST_NAME(prefix, int_type, ln) DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln) + +#define TEST_neg(int_type, str) \ + TEST(get_xtype_from_string, MAKE_NEG_TEST_NAME(handles_neg, int_type, __LINE__)) \ + { \ + do_neg_test<int_type>(str); \ + } + +TEST_pos(uint16_t, 0, "0"); +TEST_pos(uint16_t, 1, "1"); +TEST_pos(uint16_t, 65535, "65535"); + +TEST_neg(uint16_t, "+0"); +TEST_neg(uint16_t, "+1"); +TEST_neg(uint16_t, "+65535"); +TEST_neg(uint16_t, "+65536"); + +TEST_neg(uint16_t, "-0"); +TEST_neg(uint16_t, "-1"); +TEST_neg(uint16_t, "-65535"); +TEST_neg(uint16_t, "-65536"); + +TEST_neg(uint16_t, ".0"); +TEST_neg(uint16_t, ".1"); +TEST_neg(uint16_t, "0.0"); +TEST_neg(uint16_t, "0.1"); +TEST_neg(uint16_t, "1.0"); +TEST_neg(uint16_t, "1.1"); + +TEST_neg(uint16_t, "w"); +TEST_neg(uint16_t, "0w"); +TEST_neg(uint16_t, "1w"); +TEST_neg(uint16_t, "1w1"); +TEST_neg(uint16_t, "65535w"); + +TEST_neg(uint16_t, "65536"); +TEST_neg(uint16_t, "4294967296"); +TEST_neg(uint16_t, "18446744073709551616"); + + +TEST_pos(uint32_t, 0, "0"); +TEST_pos(uint32_t, 1, "1"); +TEST_pos(uint32_t, 4294967295, "4294967295"); + +TEST_neg(uint32_t, "+0"); +TEST_neg(uint32_t, "+1"); +TEST_neg(uint32_t, "+4294967295"); +TEST_neg(uint32_t, "+4294967296"); + +TEST_neg(uint32_t, "-0"); +TEST_neg(uint32_t, "-1"); +TEST_neg(uint32_t, "-4294967295"); +TEST_neg(uint32_t, "-4294967296"); + +TEST_neg(uint32_t, ".0"); +TEST_neg(uint32_t, ".1"); +TEST_neg(uint32_t, "0.0"); +TEST_neg(uint32_t, "0.1"); +TEST_neg(uint32_t, "1.0"); +TEST_neg(uint32_t, "1.1"); + +TEST_neg(uint32_t, "w"); +TEST_neg(uint32_t, "0w"); +TEST_neg(uint32_t, "1w"); +TEST_neg(uint32_t, "1w1"); +TEST_neg(uint32_t, "4294967295w"); + +TEST_neg(uint32_t, "4294967296"); +TEST_neg(uint32_t, "18446744073709551616"); + +TEST_pos(uint64_t, 0, "0"); +TEST_pos(uint64_t, 1, "1"); +TEST_pos(uint64_t, 18446744073709551615ULL, "18446744073709551615"); + +TEST_neg(uint64_t, "+0"); +TEST_neg(uint64_t, "+1"); +TEST_neg(uint64_t, "+18446744073709551615"); +TEST_neg(uint64_t, "+18446744073709551616"); + +TEST_neg(uint64_t, "-0"); +TEST_neg(uint64_t, "-1"); +TEST_neg(uint64_t, "-18446744073709551615"); +TEST_neg(uint64_t, "-18446744073709551616"); + +TEST_neg(uint64_t, ".0"); +TEST_neg(uint64_t, ".1"); +TEST_neg(uint64_t, "0.0"); +TEST_neg(uint64_t, "0.1"); +TEST_neg(uint64_t, "1.0"); +TEST_neg(uint64_t, "1.1"); + +TEST_neg(uint64_t, "w"); +TEST_neg(uint64_t, "0w"); +TEST_neg(uint64_t, "1w"); +TEST_neg(uint64_t, "1w1"); +TEST_neg(uint64_t, "18446744073709551615w"); + +TEST_neg(uint64_t, "18446744073709551616"); |