You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
4.4 KiB
C++
106 lines
4.4 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2018 by gempa GmbH *
|
|
* *
|
|
* All Rights Reserved. *
|
|
* *
|
|
* NOTICE: All information contained herein is, and remains *
|
|
* the property of gempa GmbH and its suppliers, if any. The intellectual *
|
|
* and technical concepts contained herein are proprietary to gempa GmbH *
|
|
* and its suppliers. *
|
|
* Dissemination of this information or reproduction of this material *
|
|
* is strictly forbidden unless prior written permission is obtained *
|
|
* from gempa GmbH. *
|
|
* *
|
|
* Author: Tracey Werner, Enrico Ellguth *
|
|
* Email: tracey.werner@gempa.de, enrico.ellguth@gempa.de *
|
|
***************************************************************************/
|
|
|
|
|
|
#define SEISCOMP_TEST_MODULE gempa
|
|
#include <seiscomp3/unittest/unittests.h>
|
|
|
|
#include <gempa/caps/endianess.h>
|
|
#include <gempa/caps/rawpacket.cpp>
|
|
|
|
|
|
namespace gce = Gempa::CAPS::Endianess;
|
|
namespace bu = boost::unit_test;
|
|
|
|
using namespace std;
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(gempa_common_caps_endianess)
|
|
|
|
|
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
BOOST_AUTO_TEST_CASE(converter) {
|
|
|
|
bu::unit_test_log.set_threshold_level(bu::log_warnings);
|
|
bu::unit_test_log.set_threshold_level(bu::log_messages);
|
|
|
|
// Check little_endian int16_t.
|
|
const int16_t k16Value{0x0123};
|
|
|
|
if(gce::Current::LittleEndian) {
|
|
BOOST_CHECK_EQUAL(gce::Converter::ToLittleEndian(k16Value), k16Value);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromLittleEndian(k16Value), k16Value);
|
|
int16_t g16Value = gce::Converter::ToBigEndian(k16Value);
|
|
BOOST_CHECK_EQUAL(g16Value, 8961);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromBigEndian(g16Value), k16Value);
|
|
gce::Converter::ToLittleEndian(&k16Value, 4);
|
|
BOOST_CHECK_EQUAL(291, k16Value);
|
|
}
|
|
else {
|
|
BOOST_CHECK_EQUAL(gce::Converter::ToBigEndian(k16Value), k16Value);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromBigEndian(k16Value), k16Value);
|
|
int16_t g16Value = gce::Converter::ToLittleEndian(k16Value);
|
|
BOOST_CHECK_EQUAL(g16Value, 291);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromLittleEndian(g16Value), k16Value);
|
|
}
|
|
|
|
// Check little_endian int32_t.
|
|
const int32_t k32Value{0x01234567};
|
|
if(gce::Current::LittleEndian) {
|
|
BOOST_CHECK_EQUAL(gce::Converter::ToLittleEndian(k32Value), k32Value);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromLittleEndian(k32Value), k32Value);
|
|
int32_t g32Value = gce::Converter::ToBigEndian(k32Value);
|
|
BOOST_CHECK_EQUAL(g32Value, 1732584193);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromBigEndian(g32Value), k32Value);
|
|
gce::Converter::ToLittleEndian(&k32Value, 11);
|
|
BOOST_CHECK_EQUAL(19088743, k32Value);
|
|
}
|
|
else {
|
|
BOOST_CHECK_EQUAL(gce::Converter::ToBigEndian(k32Value), k32Value);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromBigEndian(k32Value), k32Value);
|
|
int16_t g32Value = gce::Converter::ToLittleEndian(k32Value);
|
|
BOOST_CHECK_EQUAL(g32Value, 19088743);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromLittleEndian(g32Value), k32Value);
|
|
}
|
|
|
|
// Check little_endian int64_t.
|
|
const int64_t k64Value{0x0123456789abcdef};
|
|
if(gce::Current::LittleEndian) {
|
|
BOOST_CHECK_EQUAL(gce::Converter::ToLittleEndian(k64Value), k64Value);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromLittleEndian(k64Value), k64Value);
|
|
int64_t g32Value = gce::Converter::ToBigEndian(k64Value);
|
|
BOOST_CHECK_EQUAL(g32Value, -1167088121787636991);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromBigEndian(g32Value), k64Value);
|
|
gce::Converter::ToLittleEndian(&k64Value, 11);
|
|
BOOST_CHECK_EQUAL(81985529216486895, k64Value);
|
|
}
|
|
else {
|
|
BOOST_CHECK_EQUAL(gce::Converter::ToBigEndian(k64Value), k64Value);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromBigEndian(k64Value), k64Value);
|
|
int16_t g64Value = gce::Converter::ToLittleEndian(k64Value);
|
|
BOOST_CHECK_EQUAL(g64Value, 19088743);
|
|
BOOST_CHECK_EQUAL(gce::Converter::FromLittleEndian(g64Value), k64Value);
|
|
}
|
|
}
|
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
|
|
|
|
|
|
|
|
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
BOOST_AUTO_TEST_SUITE_END()
|