owlps/owlps-positioner/tests/mobile_test.hh

103 lines
2.9 KiB
C++

/*
* This file is part of the Owl Positioning System (OwlPS) project.
* It is subject to the copyright notice and license terms in the
* COPYRIGHT.t2t file found in the top-level directory of this
* distribution and at
* https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
* No part of the OwlPS Project, including this file, may be copied,
* modified, propagated, or distributed except according to the terms
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
* distributed along with this file, either separately or by replacing
* this notice by the COPYRIGHT.t2t file's contents.
*/
#include <cxxtest/TestSuite.h>
#include "mobile.hh"
class Mobile_test: public CxxTest::TestSuite
{
public:
void test_constructors(void)
{
// Default constructor
Mobile mobile1 ;
Mobile mobile2("", "",
MOBILE_DEFAULT_ANTENNA_GAIN,
WIFIDEVICE_DEFAULT_TRX_POWER) ;
TS_ASSERT_EQUALS(mobile1, mobile2) ;
// Copy constructor
Mobile mobile3("192.168.0.1", "AA:BB:CC:DD:EE:FF", 5, 32) ;
Mobile mobile4(mobile3) ;
TS_ASSERT_EQUALS(mobile3, mobile4) ;
// Now add some results
Result r;
ResultList rl;
rl.add(r);
mobile4.set_last_results(rl);
Mobile mobile5(mobile4);
TS_ASSERT_EQUALS(mobile4, mobile5);
}
void test_accessors(void)
{
// Simple read accessors
Mobile mobile1("192.168.0.1", "AA:BB:CC:DD:EE:FF", 6, 38) ;
TS_ASSERT_EQUALS(mobile1.get_ip_addr(), "192.168.0.1") ;
TS_ASSERT_EQUALS(mobile1.get_mac_addr(), "AA:BB:CC:DD:EE:FF") ;
TS_ASSERT_EQUALS(mobile1.get_antenna_gain(), 6) ;
TS_ASSERT_EQUALS(mobile1.get_trx_power(), 38) ;
// Write & read accessors
mobile1.set_ip_addr("10.0.8.42") ;
TS_ASSERT_EQUALS(mobile1.get_ip_addr(), "10.0.8.42") ;
mobile1.set_mac_addr("00:11:22:33:44:55") ;
TS_ASSERT_EQUALS(mobile1.get_mac_addr(), "00:11:22:33:44:55") ;
mobile1.set_antenna_gain(12.4) ;
TS_ASSERT_DELTA(mobile1.get_antenna_gain(), 12.4, 0.00001) ;
mobile1.set_trx_power(22.7) ;
TS_ASSERT_DELTA(mobile1.get_trx_power(), 22.7, 0.00001) ;
}
void test_operators(void)
{
// ==
Mobile mobile1("192.168.0.1", "AA:BB:CC:DD:EE:FF", 6, 38) ;
Mobile mobile2("192.168.0.1", "AA:BB:CC:DD:EE:FF", 6, 38) ;
TS_ASSERT_EQUALS(mobile1, mobile2) ;
// !=
Mobile mobile3("192.168.0.2", "AA:BB:CC:DD:EE:AA", 6, 38) ;
TS_ASSERT(mobile2 != mobile3) ;
// =
mobile2 = mobile3 ;
TS_ASSERT_EQUALS(mobile2, mobile3) ;
/* Now with some results */
Result r;
ResultList rl;
rl.add(r);
// !=
mobile2.set_last_results(rl);
TS_ASSERT_DIFFERS(mobile2, mobile3);
// ==
mobile3.set_last_results(rl);
TS_ASSERT_EQUALS(mobile2, mobile3);
// =
Mobile mobile4(mobile1);
TS_ASSERT_DIFFERS(mobile3, mobile4);
mobile4 = mobile3;
TS_ASSERT_EQUALS(mobile3, mobile4);
}
} ;