2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#include "util/ByteReverse.hxx"
21
#include "util/Macros.hxx"
24
#include <cppunit/TestFixture.h>
25
#include <cppunit/extensions/HelperMacros.h>
26
#include <cppunit/extensions/TestFactoryRegistry.h>
27
#include <cppunit/ui/text/TestRunner.h>
32
class ByteReverseTest : public CppUnit::TestFixture {
33
CPPUNIT_TEST_SUITE(ByteReverseTest);
34
CPPUNIT_TEST(TestByteReverse2);
35
CPPUNIT_TEST(TestByteReverse3);
36
CPPUNIT_TEST(TestByteReverse4);
37
CPPUNIT_TEST(TestByteReverse5);
38
CPPUNIT_TEST_SUITE_END();
41
void TestByteReverse2();
42
void TestByteReverse3();
43
void TestByteReverse4();
44
void TestByteReverse5();
47
CPPUNIT_TEST_SUITE_REGISTRATION(ByteReverseTest);
50
ByteReverseTest::TestByteReverse2()
52
static const char src[] = "123456";
53
static const char result[] = "214365";
54
static uint8_t dest[ARRAY_SIZE(src)];
56
reverse_bytes(dest, (const uint8_t *)src,
57
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 2);
58
CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0);
62
ByteReverseTest::TestByteReverse3()
64
static const char src[] = "123456";
65
static const char result[] = "321654";
66
static uint8_t dest[ARRAY_SIZE(src)];
68
reverse_bytes(dest, (const uint8_t *)src,
69
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 3);
70
CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0);
74
ByteReverseTest::TestByteReverse4()
76
static const char src[] = "12345678";
77
static const char result[] = "43218765";
78
static uint8_t dest[ARRAY_SIZE(src)];
80
reverse_bytes(dest, (const uint8_t *)src,
81
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 4);
82
CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0);
86
ByteReverseTest::TestByteReverse5()
88
static const char src[] = "1234567890";
89
static const char result[] = "5432109876";
90
static uint8_t dest[ARRAY_SIZE(src)];
92
reverse_bytes(dest, (const uint8_t *)src,
93
(const uint8_t *)(src + ARRAY_SIZE(src) - 1), 5);
94
CPPUNIT_ASSERT(strcmp(result, (const char *)dest) == 0);
98
main(gcc_unused int argc, gcc_unused char **argv)
100
CppUnit::TextUi::TestRunner runner;
101
auto ®istry = CppUnit::TestFactoryRegistry::getRegistry();
102
runner.addTest(registry.makeTest());
103
return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;