Commit b96b7707 authored by Marcin Siodelski's avatar Marcin Siodelski

[3360] Dynamically create the lease file parsed by unit tests.

parent 5d01646e
......@@ -54,6 +54,9 @@ public:
/// @return Absolute path to the test file.
static std::string absolutePath(const std::string& filename);
/// @brief Creates the lease file to be parsed by unit tests.
void writeSampleFile() const;
/// @brief Name of the test lease file.
std::string filename_;
......@@ -69,15 +72,28 @@ CSVLeaseFile4Test::CSVLeaseFile4Test()
std::string
CSVLeaseFile4Test::absolutePath(const std::string& filename) {
std::ostringstream s;
s << TEST_DATA_BUILDDIR << "/" << filename;
s << DHCP_DATA_DIR << "/" << filename;
return (s.str());
}
void
CSVLeaseFile4Test::writeSampleFile() const {
io_.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
"fqdn_fwd,fqdn_rev,hostname\n"
"192.0.2.1,06:07:08:09:0a:bc,,200,200,8,1,1,"
"host.example.com\n"
"192.0.2.1,,a:11:01:04,200,200,8,1,1,host.example.com\n"
"192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,100,100,7,"
"0,0,\n");
}
// This test checks the capability to read and parse leases from the file.
TEST_F(CSVLeaseFile4Test, parse) {
// Create a file to be parsed.
writeSampleFile();
// Open the lease file.
boost::scoped_ptr<CSVLeaseFile4>
lf(new CSVLeaseFile4(absolutePath("leases4_0.csv")));
boost::scoped_ptr<CSVLeaseFile4> lf(new CSVLeaseFile4(filename_));
ASSERT_NO_THROW(lf->open());
Lease4Ptr lease;
......
......@@ -60,6 +60,9 @@ public:
return (DuidPtr(new DUID(duid, size)));
}
/// @brief Create lease file that can be parsed by unit tests.
void writeSampleFile() const;
/// @brief Name of the test lease file.
std::string filename_;
......@@ -75,15 +78,31 @@ CSVLeaseFile6Test::CSVLeaseFile6Test()
std::string
CSVLeaseFile6Test::absolutePath(const std::string& filename) {
std::ostringstream s;
s << TEST_DATA_BUILDDIR << "/" << filename;
s << DHCP_DATA_DIR << "/" << filename;
return (s.str());
}
void
CSVLeaseFile6Test::writeSampleFile() const {
io_.writeFile("address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname\n"
"2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,200,8,100,0,7,0,1,1,host.example.com\n"
"2001:db8:1::1,,200,200,8,100,0,7,0,1,1,host.example.com\n"
"2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,300,300,6,150,"
"0,8,0,0,0,\n"
"3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,0,200,8,0,2,"
"16,64,0,0,\n");
}
// This test checks the capability to read and parse leases from the file.
TEST_F(CSVLeaseFile6Test, parse) {
// Create a file to be parsed.
writeSampleFile();
// Open the lease file.
boost::scoped_ptr<CSVLeaseFile6>
lf(new CSVLeaseFile6(absolutePath("leases6_0.csv")));
boost::scoped_ptr<CSVLeaseFile6> lf(new CSVLeaseFile6(filename_));
ASSERT_NO_THROW(lf->open());
Lease6Ptr lease;
......
......@@ -2,7 +2,4 @@ SUBDIRS = .
# CSV files are created by unit tests which check the CSVLeaseFile6
# and CSVLeaseFile4 classes.
CLEANFILES = leasefile*.csv
EXTRA_DIST = leases6_0.csv
CLEANFILES = *.csv
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname
192.0.2.1,06:07:08:09:0a:bc,,200,200,8,1,1,host.example.com
192.0.2.1,,a:11:01:04,200,200,8,1,1,host.example.com
192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,100,100,7,0,0,
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname
2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,200,8,100,0,7,0,1,1,host.example.com
2001:db8:1::1,,200,200,8,100,0,7,0,1,1,host.example.com
2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,300,300,6,150,0,8,0,0,0,
3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,0,200,8,0,2,16,64,0,0,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment