From af0b60da8cf218385d2d75ff59a92dcc201c6630 Mon Sep 17 00:00:00 2001 From: Andrea Bontempi Date: Sun, 14 Dec 2014 11:57:31 +0100 Subject: [PATCH] Add test for mac address --- commons/macaddress.h | 10 ++++++++++ test/CMakeLists.txt | 1 + test/test_Macaddress.cpp | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 test/test_Macaddress.cpp diff --git a/commons/macaddress.h b/commons/macaddress.h index 90d68b8..71ac783 100644 --- a/commons/macaddress.h +++ b/commons/macaddress.h @@ -80,6 +80,16 @@ public: return memcmp(byte,otherMac.byte,sizeof(byte))==0; } + /** + * Override - Implements the comparison between mac address (not equal) + * \param otherMac This is the other mac address to be compared with the local one. + * \return true if the two addresses match. + */ + bool operator!= ( const mac_address& otherMac ) + { + return !operator==(otherMac); + } + }; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1987a1d..ab46d3e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,6 +22,7 @@ foreach(testSrc ${TEST_SRC}) # link to Boost libraries AND your targets and dependencies target_link_libraries(${testName} ${Boost_LIBRARIES}) + target_link_libraries(${testName} network) # Add test add_test(NAME ${testName} diff --git a/test/test_Macaddress.cpp b/test/test_Macaddress.cpp new file mode 100644 index 0000000..7b3af9f --- /dev/null +++ b/test/test_Macaddress.cpp @@ -0,0 +1,21 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "Mac address check" +#include "../commons/macaddress.h" +#include //VERY IMPORTANT - include this last + +BOOST_AUTO_TEST_CASE( mac_address_eq ) { + network::mac_address a("AA:AA:AA:AA:AA:AA"); + network::mac_address b("AA:AA:AA:AA:AA:AA"); + BOOST_CHECK( a == b ); +} + +BOOST_AUTO_TEST_CASE( mac_address_neq ) { + network::mac_address a("AA:AA:AA:AA:AA:AA"); + network::mac_address b("BB:BB:BB:BB:BB:BB"); + BOOST_CHECK( a != b ); +} + +BOOST_AUTO_TEST_CASE( mac_address_io ) { + network::mac_address a("aa:aa:aa:aa:aa:aa"); + BOOST_CHECK_EQUAL( a.to_string(), "aa:aa:aa:aa:aa:aa" ); +} \ No newline at end of file