// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
- \brief MACAddress.test unit tests */
+ \brief MACAddress unit tests */
//#include "MACAddress.test.hh"
//#include "MACAddress.test.ih"
{
using senf::MACAddress;
using senf::AddressSyntaxException;
-
+
std::string test ("A1-b2-C3:d4:E5:f6");
MACAddress mac (MACAddress::from_string(test));
BOOST_CHECK_EQUAL( mac[4], 0xE5u );
BOOST_CHECK_EQUAL( mac[5], 0xF6u );
- std::stringstream str;
- str << mac;
- BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
+ {
+ std::stringstream str;
+ str >> mac;
+ BOOST_CHECK( str.fail());
+ }
+ {
+ std::stringstream str ( "invalid_mac_address");
+ str >> mac;
+ BOOST_CHECK( str.fail());
+ }
+ {
+ std::stringstream str;
+ str << mac;
+ BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
+ str >> mac;
+ BOOST_CHECK( ! str.fail());
+ }
- str >> mac;
BOOST_CHECK_EQUAL(mac, MACAddress::from_string(test));
-
BOOST_CHECK( ! mac.local() );
BOOST_CHECK( mac.multicast() );
BOOST_CHECK( ! mac.broadcast() );
BOOST_CHECK_THROW( MACAddress::from_string("1:2:3:4:5:6"), AddressSyntaxException );
BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05"), AddressSyntaxException );
+ // test all invalid ascii ranges
BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:z6"), AddressSyntaxException );
+ BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:/6"), AddressSyntaxException );
+ BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:@6"), AddressSyntaxException );
+ BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:[6"), AddressSyntaxException );
BOOST_CHECK_EQUAL( mac, MACAddress::from_eui64(0xa1b2c3fffed4e5f6llu) );
BOOST_CHECK_THROW( MACAddress::from_eui64(0u), AddressSyntaxException );
-
+
BOOST_CHECK_EQUAL( MACAddress(0x1a2b3c4d5e6fULL).uint64(), 0x1a2b3c4d5e6fULL);
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100