a298f661f5fe05b6fec38ad06617a992e837004b
[senf.git] / senf / Packets / 80211Bundle / WLANBeaconPacket.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Christian Niephaus <cni@berlios.de>
7 //     Thorsten Horstmann <tho@berlios.de>
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the
21 // Free Software Foundation, Inc.,
22 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
24 /** \file
25     \brief 802.11 WLAN Beacon Packet unit tests */
26
27 // Custom includes
28 #include "WLANBeaconPacket.hh"
29
30 #include <senf/Utils/auto_unit_test.hh>
31 #include <boost/test/test_tools.hpp>
32
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34
35 SENF_AUTO_UNIT_TEST(WLANBeaconPacket_parse)
36 {
37     unsigned char data[] = {
38         0x3a, 0x30, 0xaa, 0x4c, 0x9c, 0x00, 0x00, 0x00, //timestamp
39         0x64, 0x00, //beacon interval
40         0x01, 0x05, //capability information
41         0x00, 0x05, 0x62, 0x6f, 0x78, 0x43, 0x31, //SSID
42         0x01, 0x08, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c, //supported rates
43         0x03, 0x01, 0x40, //DS parameter set
44         0x05, 0x04, 0x00, 0x01, 0x00, 0x00, //TIM
45         0x07, 0x2a, 0x4e, 0x41, 0x49, 0x24, 0x01, 0x11, 0x28, 0x01, 0x11,
46         0x2c, 0x01, 0x11, 0x30, 0x01, 0x11, 0x34, 0x01, 0x17, 0x38, 0x01,
47         0x17, 0x3c, 0x01, 0x17, 0x40, 0x01, 0x17, 0x95, 0x01, 0x1e, 0x99,
48         0x01, 0x1e, 0x9d, 0x01, 0x1e, 0xa1, 0x01, 0x1e, 0xa5, 0x01, 0x1e, //Country information
49         0x20, 0x01, 0x42, //power constraint
50         0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x88, 0x00, 0x02,
51         0xa3, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00,
52         0x62, 0x32, 0x2f, 0x00,  //vendor specific
53     };
54     senf::WLANBeaconPacket p (senf::WLANBeaconPacket::create(data));
55
56     BOOST_CHECK_EQUAL( p->timestamp(), 0x0000009C4CAA303AuLL);
57     BOOST_CHECK_EQUAL( p->beaconInterval(), 100u);
58     BOOST_CHECK_EQUAL( p->ssidIE().length(), 5);
59     BOOST_CHECK_EQUAL( p->ssidIE().value().value(), "boxC1");
60     BOOST_CHECK_EQUAL( p->ssid().value(), "boxC1");
61
62     typedef senf::WLANBeaconPacket::Parser::ieList_t::container ieListContainer_t;
63     ieListContainer_t ieListContainer (p->ieList());
64     BOOST_CHECK_EQUAL( ieListContainer.size(), 5);
65
66     ieListContainer_t::iterator i ( ieListContainer.begin());
67     BOOST_CHECK_EQUAL( i->type(), 0x03); //DS parameter set
68     ++i;
69     BOOST_CHECK_EQUAL( i->type(), 0x05); //TIM
70     ++i;
71     BOOST_CHECK_EQUAL( i->type(), 0x07); //Country information
72     ++i;
73     //power constraint
74     BOOST_CHECK_EQUAL( i->type(), senf::WLANPowerConstraintInfoElementParser::typeId+0);
75     BOOST_CHECK( i->is<senf::WLANPowerConstraintInfoElementParser>());
76     senf::WLANPowerConstraintInfoElementParser ie ( i->as<senf::WLANPowerConstraintInfoElementParser>());
77     BOOST_CHECK_EQUAL( ie.value(), 0x42);
78     ++i;
79     BOOST_CHECK_EQUAL( i->type(), 0xdd); //vendor specific
80     BOOST_CHECK_EQUAL( i->length(), 0x18);
81     BOOST_CHECK_EQUAL( boost::size(i->value()), 0x18);
82
83     unsigned char value[] = {
84             0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x88, 0x00,
85             0x02, 0xa3, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00,
86             0x42, 0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00
87     };
88     SENF_CHECK_EQUAL_COLLECTIONS( value, value+sizeof(value),
89             boost::begin(i->value()), boost::end(i->value()) );
90
91     std::ostringstream oss (std::ostringstream::out);
92     SENF_CHECK_NO_THROW( p.dump( oss ));
93 }
94
95 SENF_AUTO_UNIT_TEST(WLANBeaconPacket_create)
96 {
97     senf::WLANBeaconPacket p (senf::WLANBeaconPacket::create());
98     p->timestamp() << 0x0000009C4CAA303AuLL;
99     p->beaconInterval() << 100u;
100     p->ssidIE().value() << "boxC1";
101
102     typedef senf::WLANBeaconPacket::Parser::ieList_t::container ieListContainer_t;
103     ieListContainer_t ieListContainer (p->ieList());
104     senf::WLANPowerConstraintInfoElementParser ie (
105             ieListContainer.push_back_space().init<senf::WLANPowerConstraintInfoElementParser>() );
106     ie.value() << 0x42;
107
108     p.finalizeThis();
109
110     unsigned char data[] = {
111         0x3a, 0x30, 0xaa, 0x4c, 0x9c, 0x00, 0x00, 0x00, //timestamp
112         0x64, 0x00, //beacon interval
113         0x00, 0x00, //capability information
114         0x00, 0x05, 0x62, 0x6f, 0x78, 0x43, 0x31, //SSID
115         0x01, 0x00, //supported rates
116         0x20, 0x01, 0x42, //power constraint
117     };
118     SENF_CHECK_EQUAL_COLLECTIONS( p.data().begin(), p.data().end(),
119             data, data+sizeof(data) );
120 }
121
122 //-/////////////////////////////////////////////////////////////////////////////////////////////////
123
124 \f
125 // Local Variables:
126 // mode: c++
127 // fill-column: 100
128 // c-file-style: "senf"
129 // indent-tabs-mode: nil
130 // ispell-local-dictionary: "american"
131 // compile-command: "scons -u test"
132 // comment-column: 40
133 // End: