Leosac  0.8.0
Open Source Access Control
WiegandReader.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "core/Scheduler.hpp"
21 #include "core/auth/Auth.hpp"
22 #include "helper/TestHelper.hpp"
25 #include "tools/runtimeoptions.hpp"
26 
27 using namespace Leosac::Module::Wiegand;
28 using namespace Leosac::Test::Helper;
29 
30 namespace Leosac
31 {
32 namespace Test
33 {
35 {
36  private:
37  virtual bool run_module(zmqpp::socket *pipe) override
38  {
39  boost::property_tree::ptree cfg, module_cfg, readers_cfg, reader1_cfg;
40 
41  reader1_cfg.add("name", "WIEGAND_1");
42  reader1_cfg.add("high", "GPIO_HIGH");
43  reader1_cfg.add("low", "GPIO_LOW");
44 
45  readers_cfg.add_child("reader", reader1_cfg);
46  module_cfg.add_child("readers", readers_cfg);
47 
48  cfg.add("name", "WIEGAND_READER");
49  cfg.add_child("module_config", module_cfg);
50 
51  return test_run_module<WiegandReaderModule>(&ctx_, pipe, cfg);
52  }
53 
54  public:
56  : TestHelper()
57  , high_(ctx_, "GPIO_HIGH")
58  , low_(ctx_, "GPIO_LOW")
59  {
60  bus_sub_.subscribe("S_WIEGAND_1");
61  }
62 
64  {
65  }
66 
69 };
70 
72 {
73  for (int i = 0; i < 32; i++)
74  {
75  high_.interrupt(); // building card id ff:ff:ff:ff
76  }
77 
78  ASSERT_TRUE(bus_read(bus_sub_, "S_WIEGAND_1",
80  32));
81 
82  for (int i = 0; i < 32; i++)
83  {
84  if (i >= 24)
85  high_.interrupt();
86  else
87  low_.interrupt();
88 
89  // required because zmq sockets do fair-queuing.
90  // its not a problem either, because the hardware will pause too.
91  std::this_thread::sleep_for(std::chrono::milliseconds(2));
92  }
93 
94  ASSERT_TRUE(bus_read(bus_sub_, "S_WIEGAND_1",
96  32));
97 }
98 }
99 }
Leosac::Test::WiegandReaderTest::high_
FakeGPIO high_
Definition: WiegandReader.cpp:67
Leosac::Test::TEST_F
TEST_F(WiegandReaderTest, readCard)
Definition: WiegandReader.cpp:71
runtimeoptions.hpp
RuntimeOptions class declaration.
Auth.hpp
Leosac::Test::WiegandReaderTest
Definition: WiegandReader.cpp:34
Leosac::Test::WiegandReaderTest::low_
FakeGPIO low_
Definition: WiegandReader.cpp:68
Leosac::Test::WiegandReaderTest::WiegandReaderTest
WiegandReaderTest()
Definition: WiegandReader.cpp:55
Scheduler.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Test::WiegandReaderTest::run_module
virtual bool run_module(zmqpp::socket *pipe) override
Called in the module's actor's thread.
Definition: WiegandReader.cpp:37
TestHelper.hpp
WiegandConfig.hpp
Leosac::Test::Helper::bus_read
bool bus_read(zmqpp::socket &sub, Content... content)
Make a blocking read on the bus, return true if content match the message.
Definition: TestHelper.hpp:103
Leosac::Test::Helper
Unit testing utility class that helps writing test.
Definition: FakeGPIO.hpp:28
Leosac::Module::Wiegand
Provide support for Wiegand devices.
Definition: Autodetect.hpp:29
Leosac::Test::WiegandReaderTest::~WiegandReaderTest
~WiegandReaderTest()
Definition: WiegandReader.cpp:63
wiegand.hpp
Leosac::Test::Helper::TestHelper
Base class for test fixtures, it defines a ZMQ context, a BUS and a sub socket connect to the bus.
Definition: TestHelper.hpp:116
Leosac::Test::Helper::FakeGPIO
A test helper class that emulate a GPIO pin.
Definition: FakeGPIO.hpp:34
Leosac::Auth::SourceType::SIMPLE_WIEGAND
@ SIMPLE_WIEGAND
This define message formatting for data source SIMPLE_WIEGAND.