File: ods.cc

package info (click to toggle)
yapet 2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,920 kB
  • sloc: cpp: 32,397; sh: 5,032; makefile: 880; ansic: 36; sed: 16
file content (99 lines) | stat: -rw-r--r-- 2,979 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <cppunit/CompilerOutputter.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>

#include "config.h"

#include "ods.hh"

class ODSTest : public CppUnit::TestFixture {
   public:
    static CppUnit::TestSuite *suite() {
        CppUnit::TestSuite *suiteOfTests =
            new CppUnit::TestSuite("On Disk Structure");

        suiteOfTests->addTest(new CppUnit::TestCaller<ODSTest>(
            "16bits integer to On-Disk-Structure", &ODSTest::toODS16));
        suiteOfTests->addTest(new CppUnit::TestCaller<ODSTest>(
            "16bits integer to host", &ODSTest::toHost16));

        suiteOfTests->addTest(new CppUnit::TestCaller<ODSTest>(
            "32bits integer to On-Disk-Structure", &ODSTest::toODS32));
        suiteOfTests->addTest(new CppUnit::TestCaller<ODSTest>(
            "32bits integer to host", &ODSTest::toHost32));

        suiteOfTests->addTest(new CppUnit::TestCaller<ODSTest>(
            "64bits integer to On-Disk-Structure", &ODSTest::toODS64));
        suiteOfTests->addTest(new CppUnit::TestCaller<ODSTest>(
            "64bits integer to host", &ODSTest::toHost64));
        return suiteOfTests;
    }

    void toODS16() {
        std::uint16_t subject = 0x0a0b;
#ifdef WORDS_BIGENDIAN
        std::uint16_t expected = 0x0a0b;
#else
        std::uint16_t expected = 0x0b0a;
#endif
        CPPUNIT_ASSERT_EQUAL(expected, yapet::toODS(subject));
    }

    void toHost16() {
        std::uint16_t subject = 0x0a0b;
#ifdef WORDS_BIGENDIAN
        std::uint16_t expected = 0x0a0b;
#else
        std::uint16_t expected = 0x0b0a;
#endif
        CPPUNIT_ASSERT_EQUAL(expected, yapet::toHost(subject));
    }

    void toODS32() {
        std::uint32_t subject = 0x0a0b0c0d;
#ifdef WORDS_BIGENDIAN
        std::uint32_t expected = 0x0a0b0c0d;
#else
        std::uint32_t expected = 0x0d0c0b0a;
#endif
        CPPUNIT_ASSERT_EQUAL(expected, yapet::toODS(subject));
    }

    void toHost32() {
        std::uint32_t subject = 0x0a0b0c0d;
#ifdef WORDS_BIGENDIAN
        std::uint32_t expected = 0x0a0b0c0d;
#else
        std::uint32_t expected = 0x0d0c0b0a;
#endif
        CPPUNIT_ASSERT_EQUAL(expected, yapet::toHost(subject));
    }

    void toODS64() {
        std::uint64_t subject = 0x0102030405060708;
#ifdef WORDS_BIGENDIAN
        std::uint64_t expected = 0x0102030405060708;
#else
        std::uint64_t expected = 0x0807060504030201;
#endif
        CPPUNIT_ASSERT_EQUAL(expected, yapet::toODS(subject));
    }

    void toHost64() {
        std::uint64_t subject = 0x0102030405060708;
#ifdef WORDS_BIGENDIAN
        std::uint64_t expected = 0x0102030405060708;
#else
        std::uint64_t expected = 0x0807060504030201;
#endif
        CPPUNIT_ASSERT_EQUAL(expected, yapet::toHost(subject));
    }
};

int main() {
    CppUnit::TextUi::TestRunner runner;
    runner.addTest(ODSTest::suite());
    return runner.run() ? 0 : 1;
}