File: UtilsTest.cpp

package info (click to toggle)
ola 0.10.9.nojsmin-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 17,440 kB
  • sloc: cpp: 132,294; python: 14,445; javascript: 7,109; sh: 4,713; ansic: 2,189; java: 518; xml: 253; makefile: 175
file content (89 lines) | stat: -rw-r--r-- 2,532 bytes parent folder | download | duplicates (7)
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
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * UtilsTest.cpp
 * Unittest for util functions.
 * Copyright (C) 2013 Peter Newman
 */

#include <cppunit/extensions/HelperMacros.h>

#include "ola/util/Utils.h"
#include "ola/testing/TestUtils.h"

using ola::utils::SplitUInt16;
using ola::utils::JoinUInt8;

class UtilsTest: public CppUnit::TestFixture {
  CPPUNIT_TEST_SUITE(UtilsTest);
  CPPUNIT_TEST(testSplitUInt16);
  CPPUNIT_TEST(testJoinUInt8);
  CPPUNIT_TEST_SUITE_END();

 public:
    void testSplitUInt16();
    void testJoinUInt8();
};


CPPUNIT_TEST_SUITE_REGISTRATION(UtilsTest);

/*
 * Test the SplitUInt16 function
 */
void UtilsTest::testSplitUInt16() {
  uint16_t input = 0xabcd;
  uint8_t high = 0x00;
  uint8_t low = 0x00;
  SplitUInt16(input, &high, &low);
  OLA_ASSERT_EQ(high, static_cast<uint8_t>(0xab));
  OLA_ASSERT_EQ(low, static_cast<uint8_t>(0xcd));

  input = 0x0000;
  SplitUInt16(input, &high, &low);
  OLA_ASSERT_EQ(high, static_cast<uint8_t>(0x00));
  OLA_ASSERT_EQ(low, static_cast<uint8_t>(0x00));

  input = 0xffff;
  SplitUInt16(input, &high, &low);
  OLA_ASSERT_EQ(high, static_cast<uint8_t>(0xff));
  OLA_ASSERT_EQ(low, static_cast<uint8_t>(0xff));

  input = 0x0001;
  SplitUInt16(input, &high, &low);
  OLA_ASSERT_EQ(high, static_cast<uint8_t>(0x00));
  OLA_ASSERT_EQ(low, static_cast<uint8_t>(0x01));
}

/*
 * Test the JoinUInt8 function
 */
void UtilsTest::testJoinUInt8() {
  uint8_t high = 0xab;
  uint8_t low = 0xcd;
  OLA_ASSERT_EQ(JoinUInt8(high, low), static_cast<uint16_t>(0xabcd));

  high = 0x00;
  low = 0x00;
  OLA_ASSERT_EQ(JoinUInt8(high, low), static_cast<uint16_t>(0x0000));

  high = 0xff;
  low = 0xff;
  OLA_ASSERT_EQ(JoinUInt8(high, low), static_cast<uint16_t>(0xffff));

  high = 0x00;
  low = 0x01;
  OLA_ASSERT_EQ(JoinUInt8(high, low), static_cast<uint16_t>(0x0001));
}