BornAgain
1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
|
Various common utils for unit tests. More...
Functions | |
std::vector< double > | binCenters (const QCPGraph *graph) |
Returns vector representing bin centers on QCPgraph. More... | |
std::vector< double > | binErrors (const QCPGraph *graph) |
Returns vector representing bin errors of QCPGraph. More... | |
std::vector< double > | binValues (const QCPGraph *graph) |
Returns vector representing y-values on QCPgraph. More... | |
template<typename T > | |
void | clean_items (T &items) |
Deletes items in the container and cleans container afterwards. More... | |
template<typename T > | |
auto | create_pointers (const std::vector< std::unique_ptr< T >> &vec) |
Creates vector of pointers from vector of unique_ptr. More... | |
template<typename B , typename D > | |
auto | create_row (int ncolumns) |
Creates vector of unique_ptr of given type. More... | |
std::string | CreateEmptyFile (const std::string &dirname, const std::string &fileName) |
Helper function to create empty file in a given directory (directory should exist). More... | |
std::string | CreateTestDirectory (const std::string &test_sub_dir) |
Creates test directory in main test folder and returns full path. More... | |
std::string | CreateTestFile (const std::string &dirname, const std::string &fileName) |
Helper function to create test file in a given directory (directory should exist). More... | |
template<typename G , typename T > | |
std::vector< double > | get_values (const G *graph, T operand) |
Returns vector representing bin centers/values on QCPGraph. More... | |
template<typename T > | |
T * | GetPlottable (QCustomPlot *custom_plot) |
Finds and returns specific plottable in QCustomPlot canvas. More... | |
QString | JsonToString (const QJsonObject &object) |
QJsonDocument | LoadJson (const std::string &fileName) |
QString | ModelToJsonString (ModelView::SessionModel &model) |
Returns string representing serialized json content of the model. More... | |
void | SaveJson (const QJsonArray &object, const std::string &fileName) |
void | SaveJson (const QJsonObject &object, const std::string &fileName) |
std::string | TestDirectoryPath (const std::string &test_sub_dir) |
Returns full path to the main test folder in CMAKE_BINARY_DIR. More... | |
std::string | TestFileName (const std::string &test_sub_dir, const std::string &file_name) |
Returns full path to the file in test directory. More... | |
std::string | TestOutputDir () |
Returns full path to the main test folder, as defined by CMake at compile time. More... | |
template<typename T , typename... Args> | |
std::vector< T > | toVector (Args &&... args) |
Creates vector of T from argument list. Used in EXPECT_EQ macros for convenience. More... | |
Various common utils for unit tests.
std::vector< double > TestUtils::binCenters | ( | const QCPGraph * | graph | ) |
Returns vector representing bin centers on QCPgraph.
Definition at line 18 of file customplot_test_utils.cpp.
References get_values().
Referenced by TEST_F().
std::vector< double > TestUtils::binErrors | ( | const QCPGraph * | graph | ) |
Returns vector representing bin errors of QCPGraph.
Definition at line 28 of file customplot_test_utils.cpp.
Referenced by TEST_F().
std::vector< double > TestUtils::binValues | ( | const QCPGraph * | graph | ) |
Returns vector representing y-values on QCPgraph.
Definition at line 23 of file customplot_test_utils.cpp.
References get_values().
Referenced by TEST_F().
void TestUtils::clean_items | ( | T & | items | ) |
Deletes items in the container and cleans container afterwards.
Definition at line 71 of file test_utils.h.
auto TestUtils::create_pointers | ( | const std::vector< std::unique_ptr< T >> & | vec | ) |
Creates vector of pointers from vector of unique_ptr.
Definition at line 90 of file test_utils.h.
Referenced by ViewItemTest::test_data(), and ViewModelBaseTest::test_data().
auto TestUtils::create_row | ( | int | ncolumns | ) |
Creates vector of unique_ptr of given type.
Definition at line 80 of file test_utils.h.
std::string TestUtils::CreateEmptyFile | ( | const std::string & | dirname, |
const std::string & | fileName | ||
) |
Helper function to create empty file in a given directory (directory should exist).
Returns full path of the file.
Definition at line 107 of file test_utils.cpp.
References FileSystemUtils::filename().
Referenced by TEST_F().
std::string TestUtils::CreateTestDirectory | ( | const std::string & | test_sub_dir | ) |
Creates test directory in main test folder and returns full path.
If directory exists, will do nothing.
Definition at line 40 of file test_utils.cpp.
References ModelView::Utils::create_directory(), and TestDirectoryPath().
Referenced by FolderBasedTest::FolderBasedTest().
std::string TestUtils::CreateTestFile | ( | const std::string & | dirname, |
const std::string & | fileName | ||
) |
Helper function to create test file in a given directory (directory should exist).
Returns full path of the file.
Definition at line 91 of file test_utils.cpp.
References FileSystemUtils::filename().
Referenced by TEST_F().
std::vector<double> TestUtils::get_values | ( | const G * | graph, |
T | operand | ||
) |
Returns vector representing bin centers/values on QCPGraph.
Definition at line 28 of file customplot_test_utils.h.
Referenced by binCenters(), and binValues().
T* TestUtils::GetPlottable | ( | QCustomPlot * | custom_plot | ) |
Finds and returns specific plottable in QCustomPlot canvas.
Definition at line 47 of file customplot_test_utils.h.
QString TestUtils::JsonToString | ( | const QJsonObject & | object | ) |
QJsonDocument TestUtils::LoadJson | ( | const std::string & | fileName | ) |
QString TestUtils::ModelToJsonString | ( | ModelView::SessionModel & | model | ) |
Returns string representing serialized json content of the model.
Definition at line 76 of file test_utils.cpp.
References ModelView::JsonUtils::ModelToJsonString().
void TestUtils::SaveJson | ( | const QJsonArray & | object, |
const std::string & | fileName | ||
) |
Definition at line 64 of file test_utils.cpp.
void TestUtils::SaveJson | ( | const QJsonObject & | object, |
const std::string & | fileName | ||
) |
Definition at line 58 of file test_utils.cpp.
Referenced by TEST_F().
std::string TestUtils::TestDirectoryPath | ( | const std::string & | test_sub_dir | ) |
Returns full path to the main test folder in CMAKE_BINARY_DIR.
Definition at line 47 of file test_utils.cpp.
References TestOutputDir().
Referenced by CreateTestDirectory(), TestFileName(), and FolderBasedTest::testPath().
std::string TestUtils::TestFileName | ( | const std::string & | test_sub_dir, |
const std::string & | file_name | ||
) |
Returns full path to the file in test directory.
Definition at line 52 of file test_utils.cpp.
References TestDirectoryPath().
Referenced by TEST_F().
std::string TestUtils::TestOutputDir | ( | ) |
Returns full path to the main test folder, as defined by CMake at compile time.
Shoud point to CMAKE_BINARY_DIR/test_output
Definition at line 35 of file test_utils.cpp.
Referenced by TEST_F(), and TestDirectoryPath().
std::vector<T> TestUtils::toVector | ( | Args &&... | args | ) |
Creates vector of T from argument list. Used in EXPECT_EQ macros for convenience.
Definition at line 100 of file test_utils.h.