82 lines
2.1 KiB
C++
82 lines
2.1 KiB
C++
#include "testutil.hh"
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
#include <fstream>
|
|
|
|
using namespace std ;
|
|
|
|
|
|
// 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
|
|
for (std::vector<std::string>::const_iterator i = output_lines.begin() ;
|
|
i != output_lines.end() ; ++i)
|
|
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 +"`!") ;
|
|
}
|
|
|
|
|
|
vector<AccessPoint> TestUtil::
|
|
create_test_csv_file(const string &file_name)
|
|
{
|
|
// Create AP list
|
|
vector<AccessPoint> aps ;
|
|
aps.push_back(AccessPoint(Point3D(1,2,3), "11:22:33:44:55:01")) ;
|
|
aps.push_back(AccessPoint(Point3D(4,5,6), "11:22:33:44:55:02")) ;
|
|
aps.push_back(AccessPoint(Point3D(7,8,9), "11:22:33:44:55:03")) ;
|
|
|
|
// Fill name and contents of the test CSV file
|
|
vector<string> csv_lines ;
|
|
csv_lines.push_back("\
|
|
\n \n\
|
|
aa:bb:cc:dd:ee:ff;1265120910725;0;0;0;0\
|
|
;" + aps[0].get_mac_addr() + ";-58\
|
|
;" + aps[2].get_mac_addr() + ";-50\
|
|
;" + aps[1].get_mac_addr() + ";-42\
|
|
;" + aps[0].get_mac_addr() + ";-55\
|
|
;" + aps[1].get_mac_addr() + ";-37\
|
|
\n") ;
|
|
csv_lines.push_back("\
|
|
aa:bb:cc:dd:ee:77;1265120911234;0;0;0;0\
|
|
;" + aps[2].get_mac_addr() + ";-59\
|
|
;" + aps[0].get_mac_addr() + ";-51\
|
|
;" + aps[1].get_mac_addr() + ";-70\
|
|
;" + aps[1].get_mac_addr() + ";-21\
|
|
;" + aps[0].get_mac_addr() + ";-19\
|
|
\n \n\
|
|
\n\t\n\
|
|
\n \t \n\
|
|
\n") ;
|
|
csv_lines.push_back("\
|
|
\taa:bb:cc:dd:ee:ff;1265120912345;0;0;0;0\
|
|
;" + aps[2].get_mac_addr() + ";-56\
|
|
;" + aps[1].get_mac_addr() + ";-45\
|
|
;" + aps[0].get_mac_addr() + ";-54\
|
|
;" + aps[1].get_mac_addr() + ";-23\
|
|
;" + aps[0].get_mac_addr() + ";-32\
|
|
\n\n\t\n") ;
|
|
|
|
// Create and fill the test CSV file
|
|
fill_file(file_name, csv_lines) ;
|
|
|
|
return aps ;
|
|
}
|