
3 changed files with 65 additions and 70 deletions
@ -1,24 +0,0 @@ |
|||
// This file is under GNU General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
#include <iostream> |
|||
#include <cassert> |
|||
|
|||
#include <pEp/pEpLog.hh> |
|||
#include <pEp/std_utils.hh> |
|||
|
|||
int main(int argc, char* argv[]) |
|||
{ |
|||
pEp::Adapter::pEpLog::set_enabled(true); |
|||
std::string filename = "test_rw.bin"; |
|||
|
|||
std::vector<char> v_out{}; |
|||
for (int i = 0; i < 1000; i++) { |
|||
v_out.push_back(pEp::Utils::random_char(0, 255)); |
|||
} |
|||
|
|||
pEp::Utils::file_write_bin(filename, v_out); |
|||
|
|||
std::vector<char> v_in = pEp::Utils::file_read_bin(filename); |
|||
|
|||
assert(v_in == v_out); |
|||
} |
@ -1,39 +0,0 @@ |
|||
#include <pEp/std_utils.hh> |
|||
#include <pEp/pEpLog.hh> |
|||
#include <iostream> |
|||
#include <cassert> |
|||
#include <pEp/pitytest11/PityTest.hh> |
|||
|
|||
using namespace pEp; |
|||
|
|||
int main() |
|||
{ |
|||
pEp::Adapter::pEpLog::set_enabled(true); |
|||
|
|||
{ |
|||
// Valid hex string
|
|||
std::string str_in{ "FFABCD00EF123200" }; |
|||
std::vector<unsigned char> bin = Utils::hex2bin<unsigned char>(str_in); |
|||
PITYASSERT(str_in.length() == bin.size() * 2, "Size error"); |
|||
|
|||
std::string str_out = pEp::Utils::bin2hex(bin); |
|||
pEpLog("Hex_IN : '" + Utils::to_lower(str_in) + "'"); |
|||
pEpLog("Hex_OUT : '" + Utils::to_lower(str_out) + "'"); |
|||
|
|||
PITYASSERT(Utils::to_lower(str_in) == Utils::to_lower(str_out), "roundtrip failed"); |
|||
} |
|||
|
|||
{ |
|||
// Uneven string throws
|
|||
std::string str_in{ "FFA" }; |
|||
PITYASSERT_THROWS(Utils::hex2bin<char>(str_in), "Uneven string should throw"); |
|||
} |
|||
|
|||
{ |
|||
// Non-hex chars
|
|||
std::string str_in{ "pEp!" }; |
|||
PITYASSERT_THROWS(Utils::hex2bin<char>(str_in), "Invalid hex chars should throw"); |
|||
} |
|||
|
|||
pEpLog("All tests passsed"); |
|||
} |
Loading…
Reference in new issue