Refactoring API to be nice and clean!!
This commit is contained in:
33
main.cpp
33
main.cpp
@@ -14,21 +14,9 @@ void TestRoundTrip(const std::string& type_name, T original_value) {
|
||||
|
||||
std::cout << "Testing " << type_name << ": " << std::endl;
|
||||
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
std::cout << " Original: " << original_value << std::endl;
|
||||
std::cout << " Network (raw bits): 0x" << std::hex << std::setw(sizeof(T) * 2) << std::setfill('0');
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
std::cout << *reinterpret_cast<uint32_t*>(&network_value);
|
||||
} else { // double
|
||||
std::cout << *reinterpret_cast<uint64_t*>(&network_value);
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
std::cout << " Host: " << host_value << std::endl;
|
||||
} else {
|
||||
std::cout << " Original: 0x" << std::hex << original_value << std::dec << std::endl;
|
||||
std::cout << " Network: 0x" << std::hex << network_value << std::dec << std::endl;
|
||||
std::cout << " Host: 0x" << std::hex << host_value << std::dec << std::endl;
|
||||
}
|
||||
std::cout << " Original: " << std::hex << original_value << std::dec << std::endl;
|
||||
std::cout << " Network: " << std::hex << network_value << std::dec << std::endl;
|
||||
std::cout << " Host: " << std::hex << host_value << std::dec << std::endl;
|
||||
|
||||
|
||||
if (original_value == host_value) {
|
||||
@@ -45,8 +33,8 @@ void TestReverseByteOrder(const std::string& type_name, T original_value) {
|
||||
T reversed_value = Endianness::ReverseByteOrder(original_value);
|
||||
|
||||
std::cout << "Testing ReverseByteOrder for " << type_name << ": " << std::endl;
|
||||
std::cout << " Original: 0x" << std::hex << original_value << std::dec << std::endl;
|
||||
std::cout << " Reversed: 0x" << std::hex << reversed_value << std::dec << std::endl;
|
||||
std::cout << " Original: " << std::hex << original_value << std::dec << std::endl;
|
||||
std::cout << " Reversed: " << std::hex << reversed_value << std::dec << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
@@ -56,8 +44,8 @@ void TestReverseByteOrderIfLittleEndian(const std::string& type_name, T original
|
||||
T conditional_reversed_value = Endianness::ReverseByteOrderIfLittleEndian(original_value);
|
||||
|
||||
std::cout << "Testing ReverseByteOrderIfLittleEndian for " << type_name << ": " << std::endl;
|
||||
std::cout << " Original: 0x" << std::hex << original_value << std::dec << std::endl;
|
||||
std::cout << " Conditional Reversed: 0x" << std::hex << conditional_reversed_value << std::dec << std::endl;
|
||||
std::cout << " Original: " << std::hex << original_value << std::dec << std::endl;
|
||||
std::cout << " Conditional Reversed: " << std::hex << conditional_reversed_value << std::dec << std::endl;
|
||||
|
||||
if (Endianness::IsLittleEndian()) {
|
||||
T expected_reversed = Endianness::ReverseByteOrder(original_value);
|
||||
@@ -81,9 +69,10 @@ int main()
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
TestRoundTrip("u8", i);
|
||||
TestRoundTrip("u16", i*i);
|
||||
TestRoundTrip("u32", i*i*i);
|
||||
TestRoundTrip("u64", i*i*i*i);
|
||||
TestRoundTrip<uint16_t>("u16", i*i);
|
||||
TestRoundTrip<uint32_t>("u32", i*i*i);
|
||||
TestRoundTrip<uint64_t>("u64", i*i*i*i);
|
||||
TestRoundTrip<float>("float", i / 3.14159f);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user