switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / 80211Bundle / WLANBeaconPacket.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Thorsten Horstmann <tho@berlios.de>
27 //   Christian Niephaus <cni@berlios.de>
28
29 /** \file
30     \brief 802.11 WLAN Beacon Packet unit tests */
31
32 // Custom includes
33 #include "WLANBeaconPacket.hh"
34
35 #include <senf/Utils/auto_unit_test.hh>
36 #include <boost/test/test_tools.hpp>
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 SENF_AUTO_UNIT_TEST(WLANBeaconPacket_parse)
41 {
42     unsigned char data[] = {
43         0x3a, 0x30, 0xaa, 0x4c, 0x9c, 0x00, 0x00, 0x00, //timestamp
44         0x64, 0x00, //beacon interval
45         0x01, 0x05, //capability information
46         0x00, 0x05, 0x62, 0x6f, 0x78, 0x43, 0x31, //SSID
47         0x01, 0x08, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c, //supported rates
48         0x03, 0x01, 0x40, //DS parameter set
49         0x05, 0x04, 0x00, 0x01, 0x00, 0x00, //TIM
50         0x07, 0x2a, 0x4e, 0x41, 0x49, 0x24, 0x01, 0x11, 0x28, 0x01, 0x11,
51         0x2c, 0x01, 0x11, 0x30, 0x01, 0x11, 0x34, 0x01, 0x17, 0x38, 0x01,
52         0x17, 0x3c, 0x01, 0x17, 0x40, 0x01, 0x17, 0x95, 0x01, 0x1e, 0x99,
53         0x01, 0x1e, 0x9d, 0x01, 0x1e, 0xa1, 0x01, 0x1e, 0xa5, 0x01, 0x1e, //Country information
54         0x20, 0x01, 0x42, //power constraint
55         0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x88, 0x00, 0x02,
56         0xa3, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00,
57         0x62, 0x32, 0x2f, 0x00,  //vendor specific
58     };
59     senf::WLANBeaconPacket p (senf::WLANBeaconPacket::create(data));
60
61     BOOST_CHECK_EQUAL( p->timestamp(), 0x0000009C4CAA303AuLL);
62     BOOST_CHECK_EQUAL( p->beaconInterval(), 100u);
63     BOOST_CHECK_EQUAL( p->ssidIE().length(), 5);
64     BOOST_CHECK_EQUAL( p->ssidIE().value().value(), "boxC1");
65     BOOST_CHECK_EQUAL( p->ssid().value(), "boxC1");
66
67     typedef senf::WLANBeaconPacket::Parser::ieList_t::container ieListContainer_t;
68     ieListContainer_t ieListContainer (p->ieList());
69     BOOST_CHECK_EQUAL( ieListContainer.size(), 5);
70
71     ieListContainer_t::iterator i ( ieListContainer.begin());
72     BOOST_CHECK_EQUAL( i->type(), 0x03); //DS parameter set
73     ++i;
74     BOOST_CHECK_EQUAL( i->type(), 0x05); //TIM
75     ++i;
76     BOOST_CHECK_EQUAL( i->type(), 0x07); //Country information
77     ++i;
78     //power constraint
79     BOOST_CHECK_EQUAL( i->type(), senf::WLANPowerConstraintInfoElementParser::typeId+0);
80     BOOST_CHECK( i->is<senf::WLANPowerConstraintInfoElementParser>());
81     senf::WLANPowerConstraintInfoElementParser ie ( i->as<senf::WLANPowerConstraintInfoElementParser>());
82     BOOST_CHECK_EQUAL( ie.value(), 0x42);
83     ++i;
84     BOOST_CHECK_EQUAL( i->type(), 0xdd); //vendor specific
85     BOOST_CHECK_EQUAL( i->length(), 0x18);
86     BOOST_CHECK_EQUAL( boost::size(i->value()), 0x18);
87
88     unsigned char value[] = {
89             0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x88, 0x00,
90             0x02, 0xa3, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00,
91             0x42, 0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00
92     };
93     SENF_CHECK_EQUAL_COLLECTIONS( value, value+sizeof(value),
94             boost::begin(i->value()), boost::end(i->value()) );
95
96     std::ostringstream oss (std::ostringstream::out);
97     SENF_CHECK_NO_THROW( p.dump( oss ));
98 }
99
100 SENF_AUTO_UNIT_TEST(WLANBeaconPacket_create)
101 {
102     senf::WLANBeaconPacket p (senf::WLANBeaconPacket::create());
103     p->timestamp() << 0x0000009C4CAA303AuLL;
104     p->beaconInterval() << 100u;
105     p->ssidIE().value() << "boxC1";
106
107     typedef senf::WLANBeaconPacket::Parser::ieList_t::container ieListContainer_t;
108     ieListContainer_t ieListContainer (p->ieList());
109     senf::WLANPowerConstraintInfoElementParser ie (
110             ieListContainer.push_back_space().init<senf::WLANPowerConstraintInfoElementParser>() );
111     ie.value() << 0x42;
112
113     p.finalizeThis();
114
115     unsigned char data[] = {
116         0x3a, 0x30, 0xaa, 0x4c, 0x9c, 0x00, 0x00, 0x00, //timestamp
117         0x64, 0x00, //beacon interval
118         0x00, 0x00, //capability information
119         0x00, 0x05, 0x62, 0x6f, 0x78, 0x43, 0x31, //SSID
120         0x01, 0x00, //supported rates
121         0x20, 0x01, 0x42, //power constraint
122     };
123     SENF_CHECK_EQUAL_COLLECTIONS( p.data().begin(), p.data().end(),
124             data, data+sizeof(data) );
125 }
126
127 //-/////////////////////////////////////////////////////////////////////////////////////////////////
128
129 \f
130 // Local Variables:
131 // mode: c++
132 // fill-column: 100
133 // c-file-style: "senf"
134 // indent-tabs-mode: nil
135 // ispell-local-dictionary: "american"
136 // compile-command: "scons -u test"
137 // comment-column: 40
138 // End: