#include <gtest/gtest.h>
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
using CharVec = std::vector<char>;
using std::string;
using std::cout;
using std::endl;
TEST(hex, hex_to_bin_all)
{
CharVec allbin(256, 0);
for (int i = 0; i < 256; i++)
{
allbin[i] = (char)i;
}
string hex;
Hex::bin_to_hex(allbin, hex);
cout << "Hex: " << hex << endl;
ASSERT_EQ(hex.size(), 512);
CharVec newbin;
Hex::hex_to_bin(hex, newbin);
ASSERT_EQ(newbin.size(), 256);
ASSERT_EQ(allbin, newbin);
cout << "bin to hex string:" << endl;
cout << Hex::bin_to_hexstr(allbin, ":", 20) << endl;
}
{
string z, s;
Hex::bin_to_hex(CharVec(z.begin(), z.end()), s);
ASSERT_EQ(s.size(), 0);
}
{
string bin = "this is a test";
string hex1 = "7468697320697320612074657374";
string hex2;
Hex::bin_to_hex(CharVec(bin.begin(), bin.end()), hex2);
ASSERT_EQ(hex1, hex2);
}
TEST(hex, hex_to_bin_part)
{
string corrupthex = "7468697......!";
string validbin = "thi";
CharVec bin, val(validbin.begin(), validbin.end());
Hex::hex_to_bin(corrupthex, bin);
ASSERT_EQ(val, bin);
}
Binary to hex string converter.
TEST(inet_example, client_server_stream_test)
[Inet client server]