Skip to content
Snippets Groups Projects
Commit 5e82f0c3 authored by Benjamin Cumming's avatar Benjamin Cumming
Browse files

fix stale headers and namespaces in exporter tests

parent a35ea081
No related branches found
No related tags found
No related merge requests found
......@@ -8,21 +8,17 @@
#include <communication/communicator.hpp>
#include <communication/global_policy.hpp>
#include <communication/exporter_spike_file.hpp>
#include <io/exporter_spike_file.hpp>
class exporter_spike_file_fixture : public ::testing::Test
{
class exporter_spike_file_fixture : public ::testing::Test {
protected:
using time_type = float;
using communicator_type = nest::mc::communication::global_policy;
using spike_type =
nest::mc::communication::exporter_spike_file<time_type,
communicator_type>::spike_type;
using exporter_type =
nest::mc::io::exporter_spike_file<time_type, communicator_type>;
using spike_type = exporter_type::spike_type;
using exporter_type =
nest::mc::communication::exporter_spike_file<time_type,
communicator_type>;
std::string file_name;
std::string path;
std::string extention;
......@@ -35,68 +31,60 @@ protected:
index(0)
{}
std::string get_standard_file_name()
{
std::string get_standard_file_name() {
return exporter_type::create_output_file_path(
file_name, path, extention, 0);
}
void SetUp()
{
void SetUp() {
// code here will execute just before the test ensues
}
void TearDown()
{
void TearDown() {
// delete the start create file
std::remove(get_standard_file_name().c_str());
}
~exporter_spike_file_fixture()
~exporter_spike_file_fixture()
{}
};
TEST_F(exporter_spike_file_fixture, constructor)
{
TEST_F(exporter_spike_file_fixture, constructor) {
exporter_type exporter(file_name, path, extention, true);
//test if the file exist and depending on over_write throw or delete
std::ifstream f(get_standard_file_name());
EXPECT_TRUE(f.good());
// We now know the file exists, so create a new exporter with overwrite false
try
{
try {
exporter_type exporter1(file_name, path, extention, false);
FAIL() << "expected a file already exists error";
}
catch (std::runtime_error const & err)
{
EXPECT_EQ(err.what(), std::string("Tried opening file for writing but it exists and over_write is false: " +
get_standard_file_name()));
catch (std::runtime_error const & err) {
EXPECT_EQ(
err.what(),
std::string("Tried opening file for writing but it exists and over_write is false: " +
get_standard_file_name())
);
}
catch (...) {
FAIL() << "expected a file already exists error";
}
}
TEST_F(exporter_spike_file_fixture, create_output_file_path)
{
TEST_F(exporter_spike_file_fixture, create_output_file_path) {
// Create some random paths, no need for fancy tests here
std::string produced_filename =
exporter_type::create_output_file_path(
"spikes", "./", "gdf", 0);
exporter_type::create_output_file_path("spikes", "./", "gdf", 0);
EXPECT_STREQ(produced_filename.c_str(), "./spikes_0.gdf");
produced_filename =
exporter_type::create_output_file_path(
"a_name", "../../", "txt", 5);
exporter_type::create_output_file_path("a_name", "../../", "txt", 5);
EXPECT_STREQ(produced_filename.c_str(), "../../a_name_5.txt");
}
TEST_F(exporter_spike_file_fixture, do_export)
{
TEST_F(exporter_spike_file_fixture, do_export) {
{
exporter_type exporter(file_name, path, extention);
......@@ -108,8 +96,9 @@ TEST_F(exporter_spike_file_fixture, do_export)
spikes.push_back({ { 1, 0 }, 1.1 });
// now do the export
exporter.do_export(spikes);
} // Force destruction of exporter and explicit flush of the stream
exporter.output(spikes);
}
// Test if we have spikes in the file?
std::ifstream f(get_standard_file_name());
EXPECT_TRUE(f.good());
......
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