From 247273e086e80e86c155a6823a373185b24a65fe Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Mon, 18 Mar 2013 13:32:34 -0300 Subject: [PATCH] Added constructor from buffer test for Dot11BlockAckRequest. --- include/dot11.h | 6 ++--- src/dot11.cpp | 8 +++++-- tests/src/dot11/block_ack_request.cpp | 33 ++++++++++++--------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/dot11.h b/include/dot11.h index d54b242..03da82d 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -2874,7 +2874,7 @@ namespace Tins { /** * \brief Getter for the control ta additional fields size. */ - uint32_t controlta_size() const { return sizeof(_taddr) + sizeof(ieee80211_header); } + uint32_t controlta_size() const { return _taddr.size() + sizeof(ieee80211_header); } uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); private: @@ -3258,8 +3258,8 @@ namespace Tins { private: TINS_BEGIN_PACK struct BarControl { - uint16_t reserved:12, - tid:4; + uint16_t tid:4, + reserved:12; } TINS_END_PACK; TINS_BEGIN_PACK diff --git a/src/dot11.cpp b/src/dot11.cpp index 552e4f6..cf8c743 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -1464,7 +1464,9 @@ Dot11Ack::Dot11Ack(const address_type &dst_addr, PDU* child) subtype(ACK); } -Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) { +Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) +: Dot11Control(buffer, total_sz) +{ } @@ -1477,7 +1479,9 @@ Dot11BlockAckRequest::Dot11BlockAckRequest(const address_type &dst_addr, init_block_ack(); } -Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { +Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz) +: Dot11ControlTA(buffer, total_sz) +{ uint32_t padding = controlta_size(); buffer += padding; total_sz -= padding; diff --git a/tests/src/dot11/block_ack_request.cpp b/tests/src/dot11/block_ack_request.cpp index 41e5cf6..2ecdee8 100644 --- a/tests/src/dot11/block_ack_request.cpp +++ b/tests/src/dot11/block_ack_request.cpp @@ -5,10 +5,6 @@ #include "dot11.h" #include "tests/dot11.h" -/* PLZ PLZ I need some BLOCK ACK REQUEST packet dump, - * in order to check the constructor from buffer. - */ - using namespace std; using namespace Tins; @@ -20,23 +16,24 @@ public: static const address_type empty_addr, hwaddr; static const uint8_t expected_packet[]; }; -/*const uint8_t Dot11BlockAckRequestTest::expected_packet[] = { - '\x00', '\x00', ' ', '\x00', 'o', 'H', '\x00', '\x00', 's', 'H', '\xbf', '4', '\x00', '\x00', '\x00', '\x00', '\x10', '\x02', 'l', '\t', '\xdf', '\x00', '\xdc', '\xe0', '\x01', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xfb', '\x00', '\xcf', '\x01', '\x00', '!', 'k', '\x02', '\xe5', '\x99', '\x00', '\x1c', '\xa0', '\xa8', '\r', 'U', '\x04', '\x00', '\xcf', '!', '\xc7', '\xf3', '\x00', ';' -};*/ + +const uint8_t Dot11BlockAckRequestTest::expected_packet[] = { + 132, 0, 176, 1, 0, 33, 107, 2, 154, 230, 0, 28, 223, 215, 13, 85, 4, + 0, 176, 33 +}; void test_equals(const Dot11BlockAckRequest &dot1, const Dot11BlockAckRequest &dot2) { EXPECT_EQ(dot1.fragment_number(), dot2.fragment_number()); EXPECT_EQ(dot1.start_sequence(), dot2.start_sequence()); EXPECT_EQ(dot1.bar_control(), dot2.bar_control()); - } void test_equals_expected(const Dot11BlockAckRequest &dot11) { EXPECT_EQ(dot11.type(), Dot11::CONTROL); EXPECT_EQ(dot11.subtype(), Dot11::BLOCK_ACK_REQ); - EXPECT_EQ(dot11.fragment_number(), 6); - EXPECT_EQ(dot11.start_sequence(), 0x294); - EXPECT_EQ(dot11.bar_control(), 0x92f); + EXPECT_EQ(dot11.bar_control(), 4); + EXPECT_EQ(dot11.start_sequence(), 539); + EXPECT_EQ(dot11.fragment_number(), 0); } TEST_F(Dot11BlockAckRequestTest, Constructor) { @@ -48,10 +45,10 @@ TEST_F(Dot11BlockAckRequestTest, Constructor) { EXPECT_EQ(dot11.bar_control(), 0); } -/*TEST_F(Dot11BlockAckRequestTest, ConstructorFromBuffer) { +TEST_F(Dot11BlockAckRequestTest, ConstructorFromBuffer) { Dot11BlockAckRequest dot11(expected_packet, sizeof(expected_packet)); test_equals_expected(dot11); -}*/ +} TEST_F(Dot11BlockAckRequestTest, CopyConstructor) { @@ -82,17 +79,17 @@ TEST_F(Dot11BlockAckRequestTest, ClonePDU) { test_equals(dot1, *dot2); } -/*TEST_F(Dot11BlockAckRequestTest, FromBytes) { +TEST_F(Dot11BlockAckRequestTest, FromBytes) { std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); ASSERT_TRUE(dot11.get()); - const Dot11BlockAckRequest *inner = dot11->find_inner_pdu(); + const Dot11BlockAckRequest *inner = dot11->find_pdu(); ASSERT_TRUE(inner); test_equals_expected(*inner); -}*/ +} -/*TEST_F(Dot11BlockAckRequestTest, Serialize) { +TEST_F(Dot11BlockAckRequestTest, Serialize) { Dot11BlockAckRequest pdu(expected_packet, sizeof(expected_packet)); PDU::serialization_type buffer = pdu.serialize(); ASSERT_EQ(sizeof(expected_packet), buffer.size()); EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); -}*/ +}