Mercurial > code
diff C++/Tests/Pack/TestPack.cpp @ 223:c6513d9c696b
Pack: add unit tests
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 08 May 2014 23:51:07 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C++/Tests/Pack/TestPack.cpp Thu May 08 23:51:07 2014 +0200 @@ -0,0 +1,68 @@ +/* + * TestPack.cpp -- test the pack serializer + * + * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <cppunit/TextTestRunner.h> + +#include <Pack.h> + +#include "TestPack.h" + +void TestPack::simpleLittleEndian() +{ + uint8_t u8(1), r8; + uint16_t u16(2), r16; + uint32_t u32(3), r32; + uint64_t u64(4), r64; + + try { + Pack::write("simple-little.bin", Pack::Little, u8, u16, u32, u64); + Pack::read("simple-little.bin", Pack::Little, r8, r16, r32, r64); + + CPPUNIT_ASSERT_EQUAL(r8, u8); + CPPUNIT_ASSERT_EQUAL(r16, u16); + CPPUNIT_ASSERT_EQUAL(r32, u32); + CPPUNIT_ASSERT_EQUAL(r64, u64); + } catch (const std::runtime_error &) { } +} + +void TestPack::simpleBigEndian() +{ + uint8_t u8(1), r8; + uint16_t u16(2), r16; + uint32_t u32(3), r32; + uint64_t u64(4), r64; + + try { + Pack::write("simple-big.bin", Pack::Big, u8, u16, u32, u64); + Pack::read("simple-big.bin", Pack::Big, r8, r16, r32, r64); + + CPPUNIT_ASSERT_EQUAL(r8, u8); + CPPUNIT_ASSERT_EQUAL(r16, u16); + CPPUNIT_ASSERT_EQUAL(r32, u32); + CPPUNIT_ASSERT_EQUAL(r64, u64); + } catch (const std::runtime_error &) { } +} + +int main() +{ + CppUnit::TextTestRunner runnerText; + + runnerText.addTest(TestPack::suite()); + + return runnerText.run("", false) == 1 ? 0 : 1; +} \ No newline at end of file