Leosac  0.8.0
Open Source Access Control
RFIDCard.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 
21 #include "gtest/gtest.h"
22 
23 using namespace Leosac::Cred;
24 
25 namespace Leosac
26 {
27 namespace Test
28 {
29 // Number of bits is ignored
30 TEST(TestRFIDCard, convert_to_int)
31 {
32  RFIDCard c1("ff:ff:ff:ff", 32);
33  ASSERT_EQ(4294967295, c1.to_int());
34 
35  RFIDCard c2("aa:bb:cc:dd", 32);
36  ASSERT_EQ(2864434397, c2.to_int());
37 
38  RFIDCard c3("39:4B:C5:08", 32);
39  ASSERT_EQ(961266952, c3.to_int());
40 
41  RFIDCard c4("00:00:00:01", 32);
42  ASSERT_EQ(1, c4.to_int());
43 
44  RFIDCard c5("00:00:00:10", 32);
45  ASSERT_EQ(16, c5.to_int());
46 }
47 
48 TEST(TestRFIDCard, wiegand_26)
49 {
50  RFIDCard c1("80:80:33:80", 26);
51  ASSERT_EQ(103, c1.to_int());
52 
53  RFIDCard c2("80:80:33:40", 26);
54  ASSERT_EQ(102, c2.to_int());
55 
56  RFIDCard c3("80:80:40:00", 26);
57  ASSERT_EQ(128, c3.to_int());
58 
59  RFIDCard c4("80:80:41:40", 26);
60  ASSERT_EQ(130, c4.to_int());
61  // Without Wiegand26 format.
62  ASSERT_EQ(33685765, c4.to_raw_int());
63 
64  RFIDCard c5("80:80:41:80", 26);
65  ASSERT_EQ(131, c5.to_int());
66 
67  RFIDCard c6("80:80:43:00", 26);
68  ASSERT_EQ(134, c6.to_int());
69 }
70 
76 TEST(TestRFIDCard, bits_56)
77 {
78  RFIDCard c1("ff:ff:ff:ff", 56);
79  ASSERT_EQ(4294967295, c1.to_int());
80  ASSERT_EQ(4294967295, c1.to_raw_int());
81 
82  RFIDCard c2("aa:bb:cc:dd", 56);
83  ASSERT_EQ(2864434397, c2.to_int());
84 
85  RFIDCard c3("39:4B:C5:08", 56);
86  ASSERT_EQ(961266952, c3.to_int());
87  ASSERT_EQ(961266952, c3.to_raw_int());
88 
89  RFIDCard c4("00:00:00:01", 56);
90  ASSERT_EQ(1, c4.to_int());
91 
92  RFIDCard c5("00:00:00:10", 56);
93  ASSERT_EQ(16, c5.to_int());
94 }
95 }
96 }
RFIDCard.hpp
Leosac::Cred::RFIDCard
An RFID card credential.
Definition: RFIDCard.hpp:33
Leosac::Test::TEST
TEST(TestRFIDCard, bits_56)
Test when the reader returns 56 bits (7 bytes).
Definition: RFIDCard.cpp:76
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Cred::RFIDCard::to_int
virtual uint64_t to_int() const override
Returns the integer representation of the card ID.
Definition: RFIDCard.cpp:58
Leosac::Cred
Definition: Credential.hpp:31
Leosac::Cred::RFIDCard::to_raw_int
virtual uint64_t to_raw_int() const override
Convert the bits of the card to an integer.
Definition: RFIDCard.cpp:44