Debian Codegraph @

olad/plugin_api/DmxSourceTest.cpp

raw
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * DmxSourceTest.cpp
17 * Test fixture for the DmxSource classes
18 * Copyright (C) 2005 Simon Newton
19 */
20
21 #include <cppunit/extensions/HelperMacros.h>
22 #include <string>
23 #include <vector>
24
25 #include "ola/Clock.h"
26 #include "ola/DmxBuffer.h"
27 #include "olad/DmxSource.h"
28 #include "ola/testing/TestUtils.h"
29
30
31
32 class DmxSourceTest: public CppUnit::TestFixture {
33 CPPUNIT_TEST_SUITE(DmxSourceTest);
34 CPPUNIT_TEST(testDmxSource);
35 CPPUNIT_TEST(testIsActive);
36 CPPUNIT_TEST_SUITE_END();
37
38 public:
39 void testDmxSource();
40 void testIsActive();
41
42 private:
43 ola::Clock m_clock;
44 };
45
46
47 CPPUNIT_TEST_SUITE_REGISTRATION(DmxSourceTest);
48
49 using ola::Clock;
50 using ola::DmxBuffer;
51 using ola::DmxSource;
52 using ola::TimeInterval;
53 using ola::TimeStamp;
54
55
56 /*
57 * Check that the base device class works correctly.
58 */
59 void DmxSourceTest::testDmxSource() {
60 DmxBuffer buffer("123456789");
61 TimeStamp timestamp;
62 m_clock.CurrentMonotonicTime(&timestamp);
63
64 DmxSource source(buffer, timestamp, 100);
65 OLA_ASSERT(source.IsSet());
66 OLA_ASSERT(buffer == source.Data());
67 OLA_ASSERT_EQ(timestamp, source.Timestamp());
68 OLA_ASSERT_EQ((uint8_t) 100, source.Priority());
69
70 DmxBuffer buffer2("987654321");
71 TimeStamp timestamp2;
72 m_clock.CurrentMonotonicTime(&timestamp2);
73 OLA_ASSERT_TRUE(timestamp <= timestamp2);
74
75 source.UpdateData(buffer2, timestamp2, 120);
76 OLA_ASSERT(buffer2 == source.Data());
77 OLA_ASSERT_EQ(timestamp2, source.Timestamp());
78 OLA_ASSERT_EQ((uint8_t) 120, source.Priority());
79
80 DmxSource empty_source;
81 OLA_ASSERT_FALSE(empty_source.IsSet());
82 }
83
84
85 /*
86 * Test the time based checks
87 */
88 void DmxSourceTest::testIsActive() {
89 DmxBuffer buffer("123456789");
90 TimeStamp timestamp;
91 m_clock.CurrentMonotonicTime(&timestamp);
92
93 DmxSource source(buffer, timestamp, 100);
94 OLA_ASSERT(source.IsSet());
95
96 OLA_ASSERT(source.IsActive(timestamp));
97 TimeInterval interval(1000000);
98 TimeStamp later = timestamp + interval;
99 OLA_ASSERT(source.IsActive(later));
100
101 later = timestamp + TimeInterval(2500000);
102 OLA_ASSERT_FALSE(source.IsActive(later));
103 }