Commit a0899615 authored by Davis King's avatar Davis King

Added a unit test for the byte orderer component

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404220
parent 55784ffe
......@@ -26,6 +26,7 @@ set (tests
binary_search_tree_kernel_2a.cpp
binary_search_tree_mm1.cpp
binary_search_tree_mm2.cpp
byte_orderer.cpp
cmd_line_parser.cpp
cmd_line_parser_wchar_t.cpp
compress_stream.cpp
......
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <dlib/byte_orderer.h>
#include "tester.h"
namespace
{
using namespace test;
using namespace dlib;
using namespace std;
logger dlog("test.byte_orderer");
class byte_orderer_tester : public tester
{
public:
byte_orderer_tester (
) :
tester ("test_byte_orderer",
"Runs tests on the byte_orderer component.")
{}
void perform_test (
)
{
byte_orderer::kernel_1a bo;
union data
{
unsigned char b[4];
dlib::uint32 val;
};
data a;
a.val = 1;
if (bo.host_is_little_endian())
{
DLIB_TEST(a.b[0] == 1);
DLIB_TEST(a.b[1] == 0);
DLIB_TEST(a.b[2] == 0);
DLIB_TEST(a.b[3] == 0);
bo.host_to_big(a.val);
DLIB_TEST(a.b[0] == 0);
DLIB_TEST(a.b[1] == 0);
DLIB_TEST(a.b[2] == 0);
DLIB_TEST(a.b[3] == 1);
bo.big_to_host(a.val);
DLIB_TEST(a.b[0] == 1);
DLIB_TEST(a.b[1] == 0);
DLIB_TEST(a.b[2] == 0);
DLIB_TEST(a.b[3] == 0);
DLIB_TEST(a.val == 1);
bo.host_to_network(a.val);
DLIB_TEST(a.val == 0x01000000);
bo.network_to_host(a.val);
DLIB_TEST(a.val == 1);
}
else
{
DLIB_TEST(a.b[0] == 0);
DLIB_TEST(a.b[1] == 0);
DLIB_TEST(a.b[2] == 0);
DLIB_TEST(a.b[3] == 1);
bo.host_to_little(a.val);
DLIB_TEST(a.b[0] == 1);
DLIB_TEST(a.b[1] == 0);
DLIB_TEST(a.b[2] == 0);
DLIB_TEST(a.b[3] == 0);
bo.little_to_host(a.val);
DLIB_TEST(a.b[0] == 0);
DLIB_TEST(a.b[1] == 0);
DLIB_TEST(a.b[2] == 0);
DLIB_TEST(a.b[3] == 1);
DLIB_TEST(a.val == 1);
bo.network_to_host(a.val);
DLIB_TEST(a.val == 1);
bo.host_to_network(a.val);
DLIB_TEST(a.val == 1);
}
}
} a;
}
......@@ -36,6 +36,7 @@ SRC += binary_search_tree_kernel_1a.cpp
SRC += binary_search_tree_kernel_2a.cpp
SRC += binary_search_tree_mm1.cpp
SRC += binary_search_tree_mm2.cpp
SRC += byte_orderer.cpp
SRC += cmd_line_parser.cpp
SRC += cmd_line_parser_wchar_t.cpp
SRC += compress_stream.cpp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment