RTXI  2.4
The Real-Time eXperiment Interface Documentation
daq_tests.cpp
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
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 3 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
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  */
19 
20 
21 #include <gtest/gtest.h>
22 #include <gmock/gmock.h>
23 #include <daq_tests.h>
24 
26 {
28  cerr_original_buffer = std::cerr.rdbuf();
29  std::cerr.rdbuf(cerr_buffer.rdbuf());
30 }
31 
33 {
34  std::cerr.rdbuf(cerr_original_buffer);
35 }
36 
37 TEST_F(DAQManagerTest, getInstance)
38 {
39  ASSERT_EQ(daq_manager, DAQ::Manager::getInstance());
40  ASSERT_EQ(daq_manager->getInstance(), DAQ::Manager::getInstance());
41 }
42 
43 TEST_F(DAQManagerTest, loadDevice)
44 {
45  MockDAQDriver *testDriver = new MockDAQDriver("testDeviceDriver");
46  EXPECT_CALL(*testDriver, createDevice).Times(::testing::AtLeast(2));
47  std::list<std::string> deviceArgs1, deviceArgs2;
48  deviceArgs1.push_back("testDeviceArgs1");
49  daq_manager->loadDevice("testDeviceDriver", deviceArgs1);
50  deviceArgs2.push_back("testDeviceArgs2");
51  daq_manager->loadDevice("testDeviceDriver", deviceArgs2);
52 
53  // Check error message for missing drivers
54  std::list<std::string> deviceArgs3;
55  deviceArgs3.push_back("missingDriver");
56  daq_manager->loadDevice("missingDriver", deviceArgs3);
57  EXPECT_THAT(cerr_buffer.str(), ::testing::HasSubstr("does not exist"));
58  cerr_buffer.str("");
59 
60  // Check erro message for already initialized drivers
61  MockDAQDriver *anotherTestDriver = new MockDAQDriver("testDeviceDriver");
62  EXPECT_THAT(cerr_buffer.str(), ::testing::HasSubstr("Driver already registered"));
63  cerr_buffer.str("");
64 
65  delete anotherTestDriver;
66  delete testDriver;
67 
68 }
69 
70 TEST_F(DAQManagerTest, foreachDevice)
71 {
72  IO::channel_t inputchannel = {
73  "INPUT CHANNEL",
74  "INPUT CHANNEL DESCRIPTION",
75  IO::INPUT
76  };
77  IO::channel_t outputchannel = {
78  "OUTPUT CHANNEL",
79  "OUTPUT CHANNEL DESCRIPTION",
80  IO::OUTPUT
81  };
82  std::vector<IO::channel_t *> channelList;
83  std::vector<MockDAQDevice *> deviceList;
84 
85  for(int i = 0; i < 5; ++i)
86  {
87  channelList.push_back(new IO::channel_t[2]);
88  channelList[i][0] = inputchannel;
89  channelList[i][1] = outputchannel;
90  deviceList.push_back(new MockDAQDevice(std::to_string(i), channelList[i], (size_t) 2));
91  }
92 
93  for(auto it = deviceList.begin(); it != deviceList.end(); ++it)
94  {
95  EXPECT_CALL(**it, getChannelCount).Times(::testing::AtLeast(1));
96  }
97 
98  daq_manager->foreachDevice(callback, &deviceList);
99  for(int i = 0; i < 5; ++i)
100  {
101  delete[] channelList[i];
102  delete deviceList[i];
103  }
104 }
105 
106 
MockDAQDriver
Definition: daq_tests.h:32
DAQManagerTest::~DAQManagerTest
~DAQManagerTest()
Definition: daq_tests.cpp:32
DAQManagerTest::cerr_buffer
std::stringstream cerr_buffer
Definition: daq_tests.h:90
daq_tests.h
DAQ::Manager::getInstance
static Manager * getInstance(void)
Definition: daq.cpp:129
IO::channel_t
Definition: io.h:56
TEST_F
TEST_F(DAQManagerTest, getInstance)
Definition: daq_tests.cpp:37
DAQManagerTest::DAQManagerTest
DAQManagerTest()
Definition: daq_tests.cpp:25
DAQManagerTest::daq_manager
DAQ::Manager * daq_manager
Definition: daq_tests.h:89
MockDAQDevice
Definition: daq_tests.h:41
DAQManagerTest::cerr_original_buffer
std::streambuf * cerr_original_buffer
Definition: daq_tests.h:91
DAQManagerTest
Definition: daq_tests.h:80