| 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 |
* DeviceTest.cpp |
| 17 |
* Test fixture for the Device class. |
| 18 |
* Copyright (C) 2005 Simon Newton |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <cppunit/extensions/HelperMacros.h> |
| 22 |
#include <string> |
| 23 |
#include <vector> |
| 24 |
|
| 25 |
#include "olad/Device.h" |
| 26 |
#include "olad/Plugin.h" |
| 27 |
#include "olad/Port.h" |
| 28 |
#include "olad/Preferences.h" |
| 29 |
#include "olad/plugin_api/TestCommon.h" |
| 30 |
#include "ola/testing/TestUtils.h" |
| 31 |
|
| 32 |
|
| 33 |
using ola::AbstractDevice; |
| 34 |
using ola::AbstractPlugin; |
| 35 |
using ola::InputPort; |
| 36 |
using ola::OutputPort; |
| 37 |
using std::string; |
| 38 |
using std::vector; |
| 39 |
|
| 40 |
|
| 41 |
class DeviceTest: public CppUnit::TestFixture { |
| 42 |
CPPUNIT_TEST_SUITE(DeviceTest); |
| 43 |
CPPUNIT_TEST(testDevice); |
| 44 |
CPPUNIT_TEST_SUITE_END(); |
| 45 |
|
| 46 |
public: |
| 47 |
void testDevice(); |
| 48 |
|
| 49 |
private: |
| 50 |
void AddPortsToDeviceAndCheck(ola::Device *device); |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
CPPUNIT_TEST_SUITE_REGISTRATION(DeviceTest); |
| 55 |
|
| 56 |
|
| 57 |
/* |
| 58 |
* Check that the base device class works correctly. |
| 59 |
*/ |
| 60 |
void DeviceTest::testDevice() { |
| 61 |
string device_name = "test"; |
| 62 |
MockDevice orphaned_device(NULL, device_name); |
| 63 |
|
| 64 |
OLA_ASSERT_EQ(device_name, orphaned_device.Name()); |
| 65 |
OLA_ASSERT_EQ(static_cast<AbstractPlugin*>(NULL), |
| 66 |
orphaned_device.Owner()); |
| 67 |
OLA_ASSERT_EQ(string(""), orphaned_device.UniqueId()); |
| 68 |
AddPortsToDeviceAndCheck(&orphaned_device); |
| 69 |
|
| 70 |
// Non orphaned device |
| 71 |
TestMockPlugin plugin(NULL, ola::OLA_PLUGIN_ARTNET); |
| 72 |
MockDevice device(&plugin, device_name); |
| 73 |
OLA_ASSERT_EQ(device.Name(), device_name); |
| 74 |
OLA_ASSERT_EQ(static_cast<AbstractPlugin*>(&plugin), device.Owner()); |
| 75 |
OLA_ASSERT_EQ(string("2-test"), device.UniqueId()); |
| 76 |
AddPortsToDeviceAndCheck(&device); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
void DeviceTest::AddPortsToDeviceAndCheck(ola::Device *device) { |
| 81 |
// check we don't have any ports yet. |
| 82 |
vector<InputPort*> input_ports; |
| 83 |
device->InputPorts(&input_ports); |
| 84 |
OLA_ASSERT_EQ((size_t) 0, input_ports.size()); |
| 85 |
vector<OutputPort*> output_ports; |
| 86 |
device->OutputPorts(&output_ports); |
| 87 |
OLA_ASSERT_EQ((size_t) 0, output_ports.size()); |
| 88 |
|
| 89 |
// add two input ports and an output port |
| 90 |
TestMockInputPort input_port1(device, 1, NULL); |
| 91 |
TestMockInputPort input_port2(device, 2, NULL); |
| 92 |
TestMockOutputPort output_port1(device, 1); |
| 93 |
device->AddPort(&input_port1); |
| 94 |
device->AddPort(&input_port2); |
| 95 |
device->AddPort(&output_port1); |
| 96 |
|
| 97 |
device->InputPorts(&input_ports); |
| 98 |
OLA_ASSERT_EQ((size_t) 2, input_ports.size()); |
| 99 |
device->OutputPorts(&output_ports); |
| 100 |
OLA_ASSERT_EQ((size_t) 1, output_ports.size()); |
| 101 |
|
| 102 |
InputPort *input_port = device->GetInputPort(1); |
| 103 |
OLA_ASSERT(input_port); |
| 104 |
OLA_ASSERT_EQ((unsigned int) 1, input_port->PortId()); |
| 105 |
input_port = device->GetInputPort(2); |
| 106 |
OLA_ASSERT(input_port); |
| 107 |
OLA_ASSERT_EQ((unsigned int) 2, input_port->PortId()); |
| 108 |
OutputPort *output_port = device->GetOutputPort(1); |
| 109 |
OLA_ASSERT(output_port); |
| 110 |
OLA_ASSERT_EQ((unsigned int) 1, output_port->PortId()); |
| 111 |
} |