added cross-coversion for JSON parser string->uint64_t
This commit is contained in:
parent
00dcaee48f
commit
d7dea2ad14
4 changed files with 37 additions and 3 deletions
|
|
@ -129,7 +129,20 @@ POP_VS_WARNINGS
|
|||
template<typename from_type, typename to_type>
|
||||
struct convert_to_integral<from_type, to_type, false>
|
||||
{
|
||||
static void convert(const from_type& from, to_type& to)
|
||||
static void convert(const const std::string& from, uint64_t& to)
|
||||
{
|
||||
//attempt to convert string to unsigned int
|
||||
try
|
||||
{
|
||||
to = std::stoull(from);
|
||||
}catch(...)
|
||||
{
|
||||
ASSERT_AND_THROW_WRONG_CONVERSION();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename from_type_t, typename to_type_t>
|
||||
static void convert(const from_type_t& from, to_type_t& to)
|
||||
{
|
||||
ASSERT_AND_THROW_WRONG_CONVERSION();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ int main(int argc, char* argv[])
|
|||
command_line::add_arg(desc_options, arg_crypto_tests);
|
||||
|
||||
|
||||
test_serialization();
|
||||
test_serialization2();
|
||||
|
||||
po::variables_map vm;
|
||||
bool r = command_line::handle_error_helper(desc_options, [&]()
|
||||
|
|
|
|||
|
|
@ -386,6 +386,26 @@ bool test_serialization()
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
struct test_serialization_2
|
||||
{
|
||||
uint64_t var1;
|
||||
uint64_t var2;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(var1)
|
||||
KV_SERIALIZE(var2)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
bool test_serialization2()
|
||||
{
|
||||
test_serialization_2 ee = {};
|
||||
std::string json_buf = "{\"var1\": 111, \"var2\": \"222\"}";
|
||||
epee::serialization::load_t_from_json(ee, json_buf);
|
||||
std::string json_buf2 = epee::serialization::store_t_to_json(ee);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool transactions_flow_test(
|
||||
std::wstring path_source_wallet, std::string source_wallet_pass,
|
||||
std::wstring path_terget_wallet, std::string target_wallet_pass,
|
||||
|
|
|
|||
|
|
@ -16,4 +16,5 @@ bool transactions_flow_test(
|
|||
std::string& daemon_addr_a,
|
||||
std::string& daemon_addr_b,
|
||||
size_t mix_in_factor, size_t action = TRANSACTIONS_FLOW_TESTACTION_DEFAULT, uint64_t max_tx_in_pool = 10000);
|
||||
bool test_serialization();
|
||||
bool test_serialization();
|
||||
bool test_serialization2();
|
||||
Loading…
Add table
Reference in a new issue