~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to test/test_byte_reverse.cxx

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
 
3
 * http://www.musicpd.org
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include "util/ByteReverse.hxx"
 
21
#include "util/Macros.hxx"
 
22
#include "Compiler.h"
 
23
 
 
24
#include <cppunit/TestFixture.h>
 
25
#include <cppunit/extensions/HelperMacros.h>
 
26
#include <cppunit/extensions/TestFactoryRegistry.h>
 
27
#include <cppunit/ui/text/TestRunner.h>
 
28
 
 
29
#include <string.h>
 
30
#include <stdlib.h>
 
31
 
 
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();
 
39
 
 
40
public:
 
41
        void TestByteReverse2();
 
42
        void TestByteReverse3();
 
43
        void TestByteReverse4();
 
44
        void TestByteReverse5();
 
45
};
 
46
 
 
47
CPPUNIT_TEST_SUITE_REGISTRATION(ByteReverseTest);
 
48
 
 
49
void
 
50
ByteReverseTest::TestByteReverse2()
 
51
{
 
52
        static const char src[] = "123456";
 
53
        static const char result[] = "214365";
 
54
        static uint8_t dest[ARRAY_SIZE(src)];
 
55
 
 
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);
 
59
}
 
60
 
 
61
void
 
62
ByteReverseTest::TestByteReverse3()
 
63
{
 
64
        static const char src[] = "123456";
 
65
        static const char result[] = "321654";
 
66
        static uint8_t dest[ARRAY_SIZE(src)];
 
67
 
 
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);
 
71
}
 
72
 
 
73
void
 
74
ByteReverseTest::TestByteReverse4()
 
75
{
 
76
        static const char src[] = "12345678";
 
77
        static const char result[] = "43218765";
 
78
        static uint8_t dest[ARRAY_SIZE(src)];
 
79
 
 
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);
 
83
}
 
84
 
 
85
void
 
86
ByteReverseTest::TestByteReverse5()
 
87
{
 
88
        static const char src[] = "1234567890";
 
89
        static const char result[] = "5432109876";
 
90
        static uint8_t dest[ARRAY_SIZE(src)];
 
91
 
 
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);
 
95
}
 
96
 
 
97
int
 
98
main(gcc_unused int argc, gcc_unused char **argv)
 
99
{
 
100
        CppUnit::TextUi::TestRunner runner;
 
101
        auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
 
102
        runner.addTest(registry.makeTest());
 
103
        return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
 
104
}