2013-06-22 23:30:17 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* http://code.lm7.fr/p/owlps/source/tree/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.
|
|
|
|
*/
|
|
|
|
|
2010-02-11 11:15:57 +01:00
|
|
|
#include "testutil.hh"
|
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
2013-06-22 23:10:38 +02:00
|
|
|
#include "stock.hh"
|
|
|
|
#include "userinterface.hh"
|
2010-02-25 13:51:35 +01:00
|
|
|
#include "calibrationrequest.hh"
|
2010-03-08 17:28:47 +01:00
|
|
|
#include "realposition.hh"
|
2010-02-25 13:51:35 +01:00
|
|
|
|
2010-02-11 11:15:57 +01:00
|
|
|
#include <fstream>
|
2010-02-15 20:39:08 +01:00
|
|
|
#include <sstream>
|
2010-02-16 16:19:39 +01:00
|
|
|
#include <sys/stat.h>
|
2010-02-11 11:15:57 +01:00
|
|
|
|
|
|
|
using namespace std ;
|
2010-02-15 20:39:08 +01:00
|
|
|
|
2013-06-16 03:02:40 +02:00
|
|
|
vector<CapturePoint> TestUtil::aps ;
|
2010-02-15 20:39:08 +01:00
|
|
|
vector<Mobile> TestUtil::mobiles ;
|
2010-02-25 13:51:35 +01:00
|
|
|
vector<Request*> TestUtil::requests ;
|
2010-03-08 17:28:47 +01:00
|
|
|
vector<Result> TestUtil::results ;
|
2010-02-25 13:51:35 +01:00
|
|
|
vector<ReferencePoint> TestUtil::reference_points ;
|
2010-02-15 20:39:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
void TestUtil::tear_down()
|
|
|
|
{
|
2013-06-22 23:10:38 +02:00
|
|
|
Stock::clear() ;
|
|
|
|
|
2010-02-15 20:39:08 +01:00
|
|
|
aps.clear() ;
|
|
|
|
mobiles.clear() ;
|
2010-02-25 13:51:35 +01:00
|
|
|
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = requests.begin() ; i != requests.end() ; ++i)
|
2010-02-25 13:51:35 +01:00
|
|
|
delete *i ;
|
2010-02-15 20:39:08 +01:00
|
|
|
requests.clear() ;
|
2010-03-08 17:28:47 +01:00
|
|
|
|
|
|
|
results.clear() ;
|
|
|
|
reference_points.clear() ;
|
2010-02-15 20:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TestUtil::set_up()
|
|
|
|
{
|
|
|
|
tear_down() ;
|
2010-03-08 17:28:47 +01:00
|
|
|
create_mobile_list() ;
|
2013-06-16 03:02:40 +02:00
|
|
|
create_cp_list() ;
|
2010-03-08 17:28:47 +01:00
|
|
|
create_request_list() ;
|
|
|
|
create_result_list() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
setup_configuration() ;
|
2010-03-08 17:28:47 +01:00
|
|
|
}
|
2010-02-15 20:39:08 +01:00
|
|
|
|
2010-03-08 17:28:47 +01:00
|
|
|
void TestUtil::create_mobile_list()
|
|
|
|
{
|
2010-02-16 16:19:39 +01:00
|
|
|
Mobile mobile1 ;
|
2013-06-17 18:19:38 +02:00
|
|
|
mobile1.set_mac_addr("AA:BB:CC:DD:EE:FF") ;
|
2010-02-16 16:19:39 +01:00
|
|
|
mobiles.push_back(mobile1) ;
|
2013-06-17 18:19:38 +02:00
|
|
|
mobile1.set_mac_addr("AA:BB:CC:DD:EE:77") ;
|
2010-02-16 16:19:39 +01:00
|
|
|
mobiles.push_back(mobile1) ;
|
2010-03-08 17:28:47 +01:00
|
|
|
}
|
2010-02-15 20:39:08 +01:00
|
|
|
|
2013-06-16 03:02:40 +02:00
|
|
|
void TestUtil::create_cp_list()
|
2010-03-08 17:28:47 +01:00
|
|
|
{
|
2013-06-16 03:02:40 +02:00
|
|
|
CapturePoint ap1 ;
|
2010-02-16 16:19:39 +01:00
|
|
|
ap1.set_mac_addr("11:22:33:44:55:01") ;
|
|
|
|
aps.push_back(ap1) ;
|
|
|
|
ap1.set_mac_addr("11:22:33:44:55:02") ;
|
|
|
|
aps.push_back(ap1) ;
|
|
|
|
ap1.set_mac_addr("11:22:33:44:55:03") ;
|
|
|
|
aps.push_back(ap1) ;
|
2010-03-08 17:28:47 +01:00
|
|
|
}
|
2010-02-15 20:39:08 +01:00
|
|
|
|
2010-03-08 17:28:47 +01:00
|
|
|
void TestUtil::create_request_list()
|
|
|
|
{
|
|
|
|
// Create measurement list
|
2010-02-15 20:39:08 +01:00
|
|
|
vector < unordered_map<string,Measurement> > measurements(3) ;
|
|
|
|
Measurement measurement1 ;
|
|
|
|
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -58) ;
|
|
|
|
measurement1.add_ss(2, -55) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[0]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[0][aps[0].get_mac_addr()] = measurement1 ;
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -50) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[2]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[0][aps[2].get_mac_addr()] = measurement1 ;
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -42) ;
|
|
|
|
measurement1.add_ss(2, -37) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[1]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[0][aps[1].get_mac_addr()] = measurement1 ;
|
|
|
|
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -51) ;
|
|
|
|
measurement1.add_ss(2, -19) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[0]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[1][aps[0].get_mac_addr()] = measurement1 ;
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -70) ;
|
|
|
|
measurement1.add_ss(2, -21) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[1]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[1][aps[1].get_mac_addr()] = measurement1 ;
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -59) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[2]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[1][aps[2].get_mac_addr()] = measurement1 ;
|
|
|
|
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -54) ;
|
|
|
|
measurement1.add_ss(2, -32) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[0]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[2][aps[0].get_mac_addr()] = measurement1 ;
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -45) ;
|
|
|
|
measurement1.add_ss(2, -23) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[1]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[2][aps[1].get_mac_addr()] = measurement1 ;
|
|
|
|
measurement1.clear() ;
|
2013-06-17 18:19:38 +02:00
|
|
|
measurement1.add_ss(1, -56) ;
|
2013-06-16 03:02:40 +02:00
|
|
|
measurement1.set_cp(&aps[2]) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
measurements[2][aps[2].get_mac_addr()] = measurement1 ;
|
|
|
|
|
|
|
|
// Create timestamp list
|
|
|
|
vector<Timestamp> timestamps ;
|
|
|
|
timestamps.push_back(Timestamp(1265120910725)) ;
|
|
|
|
timestamps.push_back(Timestamp(1265120911234)) ;
|
|
|
|
timestamps.push_back(Timestamp(1265120912345)) ;
|
|
|
|
|
|
|
|
// Create request list
|
2010-02-25 13:51:35 +01:00
|
|
|
requests.push_back(new Request(&mobiles[0], timestamps[0],
|
|
|
|
measurements[0])) ;
|
|
|
|
|
|
|
|
Request request2(&mobiles[1], timestamps[1], measurements[1]) ;
|
|
|
|
reference_points.push_back(ReferencePoint(3.2, 4.1, 3.4)) ;
|
|
|
|
requests.push_back(new CalibrationRequest(
|
|
|
|
request2, &reference_points.at(0),
|
2013-06-17 18:19:38 +02:00
|
|
|
Direction(2), OWL_REQUEST_CALIBRATION)) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
|
|
|
|
CalibrationRequest *calibration_request =
|
|
|
|
dynamic_cast<CalibrationRequest*>(requests.at(1)) ;
|
2014-05-13 23:29:08 +02:00
|
|
|
if (calibration_request)
|
2010-02-25 13:51:35 +01:00
|
|
|
calibration_request->reference_point_backward_link() ;
|
|
|
|
|
|
|
|
requests.push_back(new Request(&mobiles[0], timestamps[2],
|
|
|
|
measurements[2])) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
}
|
2010-02-11 11:15:57 +01:00
|
|
|
|
2010-03-08 17:28:47 +01:00
|
|
|
void TestUtil::create_result_list()
|
|
|
|
{
|
|
|
|
RealPosition algo ;
|
|
|
|
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = requests.begin() ; i != requests.end() ; ++i)
|
2010-03-08 17:28:47 +01:00
|
|
|
{
|
|
|
|
CalibrationRequest *calibration_request =
|
|
|
|
dynamic_cast<CalibrationRequest*>(*i) ;
|
|
|
|
Result result ;
|
2014-05-13 23:29:08 +02:00
|
|
|
if (calibration_request)
|
2010-03-08 17:28:47 +01:00
|
|
|
result = algo.compute(*calibration_request) ;
|
|
|
|
else
|
|
|
|
result = algo.compute(**i) ;
|
|
|
|
results.push_back(result) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-22 23:10:38 +02:00
|
|
|
void TestUtil::setup_configuration()
|
|
|
|
{
|
|
|
|
const std::string config_file_name("/dev/null") ;
|
|
|
|
const char *argv[] =
|
|
|
|
{
|
|
|
|
"owlps-positionerd", // program name
|
|
|
|
"--config-file", config_file_name.c_str(),
|
|
|
|
"--positioning.area-start", "0;0;0",
|
|
|
|
"--positioning.area-stop", "10;15;3",
|
|
|
|
"--positioning.accept-new-mobiles", "true",
|
|
|
|
"--positioning.accept-new-cps", "true"
|
|
|
|
} ;
|
|
|
|
int argc = 11 ;
|
|
|
|
|
|
|
|
UserInterface ui(argc, argv) ;
|
|
|
|
}
|
|
|
|
|
2010-02-11 11:15:57 +01:00
|
|
|
|
|
|
|
// Create the file output_file_name and fill it with the contents of
|
|
|
|
// output_lines
|
|
|
|
void TestUtil::fill_file(const string &output_file_name,
|
|
|
|
const vector<string> output_lines)
|
|
|
|
{
|
|
|
|
// Open the file
|
|
|
|
std::ofstream output_file ;
|
|
|
|
output_file.open(output_file_name.c_str()) ;
|
|
|
|
if (! output_file)
|
|
|
|
TS_FAIL("Cannot open test file `"+ output_file_name
|
|
|
|
+"` for creation!") ;
|
|
|
|
|
|
|
|
// Write contents to the file
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = output_lines.begin() ; i != output_lines.end() ; ++i)
|
2010-02-11 11:15:57 +01:00
|
|
|
output_file << *i ;
|
|
|
|
|
|
|
|
output_file.close() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TestUtil::remove_file(const string &file_name)
|
|
|
|
{
|
|
|
|
if (remove(file_name.c_str()) == -1)
|
|
|
|
TS_WARN("Cannot remove test file `"+ file_name +"`!") ;
|
|
|
|
}
|
2010-02-12 16:45:04 +01:00
|
|
|
|
|
|
|
|
2010-02-15 20:39:08 +01:00
|
|
|
void TestUtil::
|
|
|
|
create_test_csv_file(const string &file_name, bool with_spaces)
|
2010-02-12 16:45:04 +01:00
|
|
|
{
|
|
|
|
// Fill name and contents of the test CSV file
|
|
|
|
vector<string> csv_lines ;
|
2010-02-15 20:39:08 +01:00
|
|
|
ostringstream line ;
|
2013-06-22 23:10:38 +02:00
|
|
|
constexpr unsigned int csv_format = OWL_LATEST_AGGREGATION_CSV_FORMAT ;
|
|
|
|
|
|
|
|
/* The CSV format to use is documented in the header of InputCSV */
|
2010-02-15 20:39:08 +01:00
|
|
|
|
|
|
|
if (with_spaces)
|
|
|
|
line << "\n \n " ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << csv_format ;
|
|
|
|
line << ';' << mobiles[0].get_mac_addr() ;
|
|
|
|
line << ';' << static_cast<uint_fast16_t>(requests.at(0)->get_type()) ;
|
|
|
|
line << ';' << requests.at(0)->get_nb_packets() ;
|
2010-03-05 18:14:33 +01:00
|
|
|
line << ';' << requests.at(0)->get_time_sent() ;
|
2010-02-15 20:39:08 +01:00
|
|
|
line << ";0;0;0;0;" ;
|
|
|
|
line << aps[0].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(0)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[0].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[2].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(0)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[2].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[1].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(0)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[1].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[0].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 2 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(0)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[0].get_mac_addr()).get_ss(2) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[1].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 2 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(0)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[1].get_mac_addr()).get_ss(2) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
line << '\n' ;
|
|
|
|
csv_lines.push_back(line.str()) ;
|
|
|
|
|
|
|
|
line.str("") ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << csv_format ;
|
|
|
|
line << ';' << mobiles[1].get_mac_addr() ;
|
2010-02-25 13:51:35 +01:00
|
|
|
CalibrationRequest *calibration_request =
|
|
|
|
dynamic_cast<CalibrationRequest*>(requests.at(1)) ;
|
|
|
|
assert(calibration_request) ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << static_cast<uint_fast16_t>(calibration_request->get_type()) ;
|
|
|
|
line << ';' << calibration_request->get_nb_packets() ;
|
2010-03-05 18:14:33 +01:00
|
|
|
line << ';' << calibration_request->get_time_sent() ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << reference_points.at(0).get_x() ;
|
|
|
|
line << ';' << reference_points.at(0).get_y() ;
|
|
|
|
line << ';' << reference_points.at(0).get_z() ;
|
|
|
|
line << ';' << static_cast<int>(calibration_request->get_direction()) ;
|
|
|
|
line << ';' << aps[2].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << calibration_request->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[2].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[0].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << calibration_request->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[0].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[1].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << calibration_request->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[1].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[1].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 2 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << calibration_request->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[1].get_mac_addr()).get_ss(2) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[0].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 2 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << calibration_request->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[0].get_mac_addr()).get_ss(2) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
line << '\n' ;
|
|
|
|
if (with_spaces)
|
|
|
|
line << " \n\
|
2010-02-12 16:45:04 +01:00
|
|
|
\n\t\n\
|
|
|
|
\n \t \n\
|
2010-02-15 20:39:08 +01:00
|
|
|
\n" ;
|
|
|
|
csv_lines.push_back(line.str()) ;
|
|
|
|
|
|
|
|
line.str("") ;
|
|
|
|
if (with_spaces)
|
|
|
|
line << '\t' ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << csv_format ;
|
|
|
|
line << ';' << mobiles[0].get_mac_addr() ;
|
|
|
|
line << ';' << static_cast<uint_fast16_t>(requests.at(2)->get_type()) ;
|
|
|
|
line << ';' << requests.at(2)->get_nb_packets() ;
|
2010-03-05 18:14:33 +01:00
|
|
|
line << ';' << requests.at(2)->get_time_sent() ;
|
2010-02-15 20:39:08 +01:00
|
|
|
line << ";0;0;0;0;" ;
|
|
|
|
line << aps[2].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(2)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[2].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[1].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(2)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[1].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[0].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 1 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(2)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[0].get_mac_addr()).get_ss(1) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[1].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 2 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(2)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[1].get_mac_addr()).get_ss(2) ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << aps[0].get_mac_addr() ;
|
2013-06-22 23:10:38 +02:00
|
|
|
line << ';' << 2 ;
|
2010-02-25 13:51:35 +01:00
|
|
|
line << ';' << requests.at(2)->get_measurements()
|
2013-06-17 18:19:38 +02:00
|
|
|
.at(aps[0].get_mac_addr()).get_ss(2) ;
|
2010-02-15 20:39:08 +01:00
|
|
|
line << '\n' ;
|
|
|
|
if (with_spaces)
|
|
|
|
line << "\n\t\n" ;
|
|
|
|
csv_lines.push_back(line.str()) ;
|
2010-02-12 16:45:04 +01:00
|
|
|
|
|
|
|
// Create and fill the test CSV file
|
|
|
|
fill_file(file_name, csv_lines) ;
|
|
|
|
}
|
2010-02-16 16:19:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Test equality of two Request comparing pointed values instead of
|
|
|
|
// pointers and taking care of the unordered_map
|
|
|
|
bool TestUtil::request_equals(const Request &first,
|
|
|
|
const Request &second)
|
|
|
|
{
|
|
|
|
// Try a classical comparison
|
|
|
|
if (first == second)
|
|
|
|
return true ;
|
|
|
|
|
|
|
|
// Compare timestamp
|
2010-03-05 18:14:33 +01:00
|
|
|
if (first.get_time_sent() != second.get_time_sent())
|
2010-02-16 16:19:39 +01:00
|
|
|
return false ;
|
|
|
|
|
|
|
|
// Compare mobile values
|
2014-05-13 23:29:08 +02:00
|
|
|
if (! (first.get_mobile() && second.get_mobile()))
|
2010-02-16 16:19:39 +01:00
|
|
|
{
|
2014-05-13 23:29:08 +02:00
|
|
|
if (first.get_mobile() || second.get_mobile())
|
2010-02-16 16:19:39 +01:00
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
else if (*first.get_mobile() != *second.get_mobile())
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
// Compare measurements
|
|
|
|
if (first.get_measurements() != second.get_measurements())
|
|
|
|
if (! measurements_unordered_map_equals(first.get_measurements(),
|
|
|
|
second.get_measurements()))
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test equality of two unordered_map<string,Measurement>
|
|
|
|
bool TestUtil::
|
|
|
|
measurements_unordered_map_equals(
|
|
|
|
unordered_map<string,Measurement> first,
|
|
|
|
unordered_map<string,Measurement> second)
|
|
|
|
{
|
|
|
|
if (first.size() != second.size())
|
|
|
|
return false ;
|
|
|
|
|
|
|
|
// For each element in 'first', we look for the same element
|
|
|
|
// in 'second'
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = first.begin() ; i != first.end() ; ++i)
|
2010-02-16 16:19:39 +01:00
|
|
|
{
|
2013-10-02 22:22:20 +02:00
|
|
|
auto second_measurement = second.find(i->first) ;
|
2010-02-16 16:19:39 +01:00
|
|
|
if (second_measurement == second.end())
|
|
|
|
return false ;
|
|
|
|
if (! measurement_equals(i->second, second_measurement->second))
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test equality of two Measurement comparing pointed values instead of
|
|
|
|
// pointers
|
|
|
|
bool TestUtil::measurement_equals(const Measurement &first,
|
|
|
|
const Measurement &second)
|
|
|
|
{
|
|
|
|
// Try a classical comparison
|
|
|
|
if (first == second)
|
|
|
|
return true ;
|
|
|
|
|
2012-02-03 11:55:24 +01:00
|
|
|
// Compare average_dbm
|
|
|
|
if (first.get_average_dbm() != second.get_average_dbm())
|
2010-02-16 16:19:39 +01:00
|
|
|
return false ;
|
|
|
|
|
|
|
|
// Compare ap values
|
2014-05-13 23:29:08 +02:00
|
|
|
if (! (first.get_cp() && second.get_cp()))
|
2010-02-16 16:19:39 +01:00
|
|
|
{
|
2014-05-13 23:29:08 +02:00
|
|
|
if (first.get_cp() || second.get_cp())
|
2010-02-16 16:19:39 +01:00
|
|
|
return false ;
|
|
|
|
}
|
2013-06-16 03:02:40 +02:00
|
|
|
else if (*first.get_cp() != *second.get_cp())
|
2010-02-16 16:19:39 +01:00
|
|
|
return false ;
|
|
|
|
|
|
|
|
// Compare ss_list
|
2013-06-17 18:19:38 +02:00
|
|
|
/*
|
2010-02-16 16:19:39 +01:00
|
|
|
if (first.get_ss_list() != second.get_ss_list())
|
|
|
|
return false ;
|
2013-06-17 18:19:38 +02:00
|
|
|
*/
|
2010-02-16 16:19:39 +01:00
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TestUtil::file_size_equals(const string &file1_name,
|
|
|
|
const string &file2_name)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return (file_size(file1_name) == file_size(file2_name)) ;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
off_t TestUtil::file_size(const string &file_name)
|
|
|
|
{
|
|
|
|
struct stat file_info ;
|
|
|
|
if (stat(file_name.c_str(), &file_info) != 0)
|
|
|
|
throw "Cannot get information for file `" + file_name + "`!" ;
|
|
|
|
return file_info.st_size ;
|
|
|
|
}
|