IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 8a780a7d authored by ralfulrich's avatar ralfulrich
Browse files

more output testing

parent 8be20b2e
No related branches found
No related tags found
No related merge requests found
......@@ -12,13 +12,12 @@
#include <corsika/output/ParquetStreamer.hpp>
#include <corsika/framework/core/ParticleProperties.hpp>
#include <corsika/framework/core/PhysicalUnits.hpp>
#include <corsika/framework/geometry/QuantityVector.hpp>
namespace corsika {
class TrackWriterParquet : public BaseOutput {
ParquetStreamer output_; ///< The primary output file.
public:
/**
* Construct a new writer.
......@@ -53,6 +52,9 @@ namespace corsika {
QuantityVector<length_d> const& start,
QuantityVector<length_d> const& end);
private:
ParquetStreamer output_; ///< The primary output file.
}; // class TrackWriterParquet
} // namespace corsika
......
......@@ -7,6 +7,9 @@
*/
#pragma once
#include <corsika/framework/core/ParticleProperties.hpp>
#include <corsika/framework/core/PhysicalUnits.hpp>
namespace corsika {
/**
......
......@@ -3,8 +3,8 @@ set (test_output_sources
testOutputManager.cpp
testDummyOutputManager.cpp
testParquetStreamer.cpp
#testWriterObservationPlane.cpp
#testWriterTrack.cpp
testWriterObservationPlane.cpp
testWriterTracks.cpp
)
CORSIKA_ADD_TEST (testOutput SOURCES ${test_output_sources})
......
......@@ -10,11 +10,25 @@
#include <boost/filesystem.hpp>
#include <corsika/output/OutputManager.hpp>
#include <corsika/framework/core/Logging.hpp>
#include <corsika/output/OutputManager.hpp>
#include <corsika/output/NoOutput.hpp>
using namespace corsika;
struct DummyNoOutput : public NoOutput {
void check() {
NoOutput::startOfLibrary("./");
NoOutput::startOfShower();
NoOutput::endOfShower();
NoOutput::endOfLibrary();
NoOutput::getConfig();
NoOutput::getSummary();
}
void checkWrite() { NoOutput::write(Code::Unknown, 1_eV, 1_m, 1_m); }
};
struct DummyOutput : public BaseOutput {
mutable bool isConfig_ = false;
......@@ -26,7 +40,10 @@ struct DummyOutput : public BaseOutput {
void startOfLibrary(boost::filesystem::path const&) { startLibrary_ = true; }
void startOfShower() { startShower_ = true; }
void startOfShower() {
BaseOutput::startOfShower();
startShower_ = true;
}
void endOfShower() { endShower_ = true; }
......@@ -39,7 +56,7 @@ struct DummyOutput : public BaseOutput {
YAML::Node getSummary() {
isSummary_ = true;
return YAML::Node();
return BaseOutput::getSummary();
}
};
......@@ -86,6 +103,32 @@ TEST_CASE("OutputManager") {
CHECK(test.isSummary_);
test.isSummary_ = false;
test.endLibrary_ = false;
CHECK(boost::filesystem::exists("./out_test/check/test/summary.yaml"));
}
SECTION("auto-write") {
// preparation
if (boost::filesystem::exists("./out_test")) {
boost::filesystem::remove_all("./out_test");
}
// output manager performs nothing, no action, just interface
OutputManager* output = new OutputManager("check", "./out_test");
CHECK(boost::filesystem::is_directory("./out_test/check"));
DummyOutput test;
output->add("test", test);
output->startOfLibrary();
output->startOfShower();
// check support for closing automatically
delete output;
output = 0;
CHECK(boost::filesystem::exists("./out_test/check/test/summary.yaml"));
}
SECTION("failures") {
......@@ -129,4 +172,13 @@ TEST_CASE("OutputManager") {
// CHECK_THROWS(output.startOfShower());
// CHECK_THROWS(output.endOfLibrary());
}
SECTION("NoOutput") {
// this is one of the classes where testing is a bit useless, but we can at least make
// sure the interface exists.
DummyNoOutput nothing;
nothing.check();
nothing.checkWrite();
}
}
\ No newline at end of file
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*/
#include <catch2/catch.hpp>
#include <boost/filesystem.hpp>
#include <corsika/modules/writers/ObservationPlaneWriterParquet.hpp>
#include <corsika/framework/core/Logging.hpp>
#include <corsika/framework/geometry/QuantityVector.hpp>
using namespace corsika;
struct TestWriterPlane : public ObservationPlaneWriterParquet {
YAML::Node getConfig() const { return YAML::Node(); }
void checkWrite() {
ObservationPlaneWriterParquet::write(Code::Unknown, 1_eV, 2_m, 3_m);
}
};
TEST_CASE("ObservationPlaneWriterParquet") {
logging::set_level(logging::level::info);
SECTION("standard") {
// preparation
if (boost::filesystem::exists("./output_dir")) {
boost::filesystem::remove_all("./output_dir");
}
boost::filesystem::create_directory("./output_dir");
TestWriterPlane test;
test.startOfLibrary("./output_dir");
test.startOfShower();
test.checkWrite();
test.endOfShower();
test.endOfLibrary();
CHECK(boost::filesystem::exists("./output_dir/particles.parquet"));
}
}
......@@ -10,32 +10,40 @@
#include <boost/filesystem.hpp>
#include <corsika/output/ParquetStreamer.hpp>
#include <corsika/modules/writers/TrackWriterParquet.hpp>
#include <corsika/framework/core/Logging.hpp>
using namespace corsika;
TEST_CASE("ParquetStreamer") {
struct TestWriterTrack : public TrackWriterParquet {
YAML::Node getConfig() const { return YAML::Node(); }
void checkWrite() {
TrackWriterParquet::write(Code::Unknown, 1_eV, {2_m, 3_m, 4_m}, {5_m, 6_m, 7_m});
}
};
TEST_CASE("TrackWriterParquet") {
logging::set_level(logging::level::info);
SECTION("standard") {
// preparation
if (boost::filesystem::exists("./parquet_test.parquet")) {
boost::filesystem::remove_all("./parquet_test.parquet");
if (boost::filesystem::exists("./output_dir_tracks")) {
boost::filesystem::remove_all("./output_dir_tracks");
}
boost::filesystem::create_directory("./output_dir_tracks");
ParquetStreamer test;
test.initStreamer("./parquet_test.parquet");
test.addField();
test.enableCompression(5);
test.buildStreamer();
test.closeStreamer();
TestWriterTrack test;
test.startOfLibrary("./output_dir_tracks");
test.startOfShower();
test.checkWrite();
test.endOfShower();
test.endOfLibrary();
std::shared_ptr<parquet::StreamWriter> writer = test.getWriter();
CHECK(boost::filesystem::exists("./output_dir_tracks/tracks.parquet"));
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment