ROOT
ROOT project
Loading...
Searching...
No Matches
writer_tester.hpp
Go to the documentation of this file.
1
9#ifndef WRITER_TESTS_HPP
10#define WRITER_TESTS_HPP
11
12#include <gtest/gtest.h>
13
14#include <filesystem>
15#include <fstream>
16
17#include "ROOT/writer.hpp"
18
22class WriterBaseTester : public ::testing::Test {
23 public:
24 template <typename T>
25 void testBuildPrinter(const T& values, WritingMethod method,
26 std::unique_ptr<PrinterBase<Eigen::Vector2d>>& printer) {
27 Writer<T> writer(values, method);
28 writer.build_printer(printer);
29
30 switch (method) {
32 EXPECT_NE(dynamic_cast<PrinterCLI<Eigen::Vector2d>*>(printer.get()), nullptr);
33 break;
35 EXPECT_NE(dynamic_cast<PrinterCSV<Eigen::Vector2d>*>(printer.get()), nullptr);
36 break;
38 EXPECT_NE(dynamic_cast<PrinterDAT<Eigen::Vector2d>*>(printer.get()), nullptr);
39 break;
41 EXPECT_NE(dynamic_cast<PrinterGNUPlot<Eigen::Vector2d>*>(printer.get()), nullptr);
42 break;
43 default:
44 FAIL() << "Unknown WritingMethod";
45 }
46 }
47
48 template <typename T>
49 void testWrite(const T& values, WritingMethod method) {
50 Writer<T> writer(values, method);
51 writer.write();
52 EXPECT_NO_THROW(writer.write());
53 // check if the method is CLI it is written on CLI
54 switch (method) {
56 // CLI output is not easily testable; assume success if no exceptions are thrown
57 break;
59 // check if the method is CSV file is created
60 EXPECT_TRUE(std::filesystem::exists("output.csv"));
61 std::filesystem::remove("output.csv");
62 break;
64 // check if the method is DAT file is created
65 EXPECT_TRUE(std::filesystem::exists("output.dat"));
66 std::filesystem::remove("output.dat");
67 break;
69 // check if the method is GNUPLOT file is created and gnuplot script is generated
70 EXPECT_TRUE(std::filesystem::exists("output.dat"));
71 std::filesystem::remove("output.dat");
72 EXPECT_TRUE(std::filesystem::exists("output.plt"));
73 std::filesystem::remove("output.plt");
74 EXPECT_TRUE(std::filesystem::exists("output.png"));
75 std::filesystem::remove("output.png");
76 break;
77 default:
78 FAIL() << "Unknown WritingMethod";
79 }
80 }
81};
82
83#endif
Abstract Printer class.
Definition writer_def.hpp:69
The class to print out the values in the CLI.
Definition writer_def.hpp:84
Class to write on .csv the result.
Definition writer_def.hpp:132
Class to write on .dat the result - daughter of FilePrinter and Mother of GnuPlotPrinter.
Definition writer_def.hpp:115
Class Daughter of PrinterDAT to write on .dat (inherited) and produce a gnu plot for the results.
Definition writer_def.hpp:155
Tester class for Writer class unit tests.
Definition writer_tester.hpp:22
void testBuildPrinter(const T &values, WritingMethod method, std::unique_ptr< PrinterBase< Eigen::Vector2d > > &printer)
Definition writer_tester.hpp:25
void testWrite(const T &values, WritingMethod method)
Definition writer_tester.hpp:49
Class to store required arguments and handle the printing flow.
Definition writer_def.hpp:33
void build_printer(std::unique_ptr< PrinterBase< V > > &printer)
Method to convert the generic Printer into a typed one for a specific output destination.
Definition writer.hpp:47
void write()
Method to run the printing loop and correctly initialize the Printer.
WritingMethod
Definition writer_def.hpp:24
@ CONSOLE
Definition writer_def.hpp:24
@ CSV
Definition writer_def.hpp:24
@ DAT
Definition writer_def.hpp:24
@ GNUPLOT
Definition writer_def.hpp:24