unittest_scanner_communication_interface.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #include <string>
17 #include <memory>
18 #include <chrono>
19 
20 #include <boost/asio.hpp>
21 #include <boost/array.hpp>
22 #include <gtest/gtest.h>
23 
27 
28 using namespace psen_scan;
29 
30 constexpr uint32_t UDP_PORT{ 55000 };
31 const std::string IP_ADDR{ "127.0.0.1" };
32 
33 TEST(ScannerCommunicationIntefaceTests, testFailingWriteOperation)
34 {
35  PSENscanUDPInterface comm_interface(IP_ADDR, UDP_PORT);
36 
37  boost::array<char, 10> write_buf = { "Hello!" };
38  ASSERT_THROW(comm_interface.write(boost::asio::buffer(write_buf)), ScannerWriteFailed);
39 }
40 
41 TEST(ScannerCommunicationIntefaceTests, testReadTimeout)
42 {
43  PSENscanUDPInterface comm_interface(IP_ADDR, UDP_PORT + 1);
44  comm_interface.open();
45 
46  constexpr auto read_timeout{ std::chrono::seconds(3) };
47  boost::array<char, 10> read_array;
48  auto read_buf{ boost::asio::buffer(read_array) };
49  ASSERT_THROW(comm_interface.read(read_buf, read_timeout), ScannerReadTimeout);
50 }
51 
52 TEST(ScannerCommunicationIntefaceTests, testScannerOpenFailedForCompleteCoverage)
53 {
54  const std::string except_str{ "DummyText" };
55  std::unique_ptr<ScannerOpenFailed> e(new ScannerOpenFailed(except_str));
56  EXPECT_EQ(except_str, e->what());
57 }
58 
59 TEST(ScannerCommunicationIntefaceTests, testScannerWriteFailedForCompleteCoverage)
60 {
61  const std::string except_str{ "DummyText" };
62  std::unique_ptr<ScannerWriteFailed> e(new ScannerWriteFailed(except_str));
63  EXPECT_EQ(except_str, e->what());
64 }
65 
66 TEST(ScannerCommunicationIntefaceTests, testScannerScannerReadTimeoutForCompleteCoverage)
67 {
68  const std::string except_str{ "DummyText" };
69  std::unique_ptr<ScannerReadTimeout> e(new ScannerReadTimeout(except_str));
70  EXPECT_EQ(except_str, e->what());
71 }
72 
73 TEST(ScannerCommunicationIntefaceTests, testScannerReadFailedForCompleteCoverage)
74 {
75  const std::string except_str{ "DummyText" };
76  std::unique_ptr<ScannerReadFailed> e(new ScannerReadFailed(except_str));
77  EXPECT_EQ(except_str, e->what());
78 }
79 
80 TEST(ScannerCommunicationIntefaceTests, testScannerCloseFailedForCompleteCoverage)
81 {
82  const std::string except_str{ "DummyText" };
83  std::unique_ptr<ScannerCloseFailed> e(new ScannerCloseFailed(except_str));
84  EXPECT_EQ(except_str, e->what());
85 }
std::size_t read(boost::asio::mutable_buffers_1 &buffer, const std::chrono::steady_clock::duration timeout) override
Receive data from the scanner.
const std::string IP_ADDR
TEST(ScannerCommunicationIntefaceTests, testFailingWriteOperation)
Class for the UDP communication with the scanner.
constexpr uint32_t UDP_PORT
void open() override
Opens the connection to the scanner device.
void write(const boost::asio::mutable_buffers_1 &buffer) override
Sends data to the scanner device.


psen_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:16:20