15 #ifndef BORNAGAIN_MVVM_TESTS_LIBTESTMACHINERY_TEST_UTILS_H
16 #define BORNAGAIN_MVVM_TESTS_LIBTESTMACHINERY_TEST_UTILS_H
48 std::string
TestFileName(
const std::string& test_sub_dir,
const std::string& file_name);
50 void SaveJson(
const QJsonObject&
object,
const std::string& fileName);
52 void SaveJson(
const QJsonArray&
object,
const std::string& fileName);
59 QJsonDocument
LoadJson(
const std::string& fileName);
63 std::string
CreateTestFile(
const std::string& dirname,
const std::string& fileName);
67 std::string
CreateEmptyFile(
const std::string& dirname,
const std::string& fileName);
73 for (
auto item : items)
80 template <
typename B,
typename D>
auto create_row(
int ncolumns)
82 std::vector<std::unique_ptr<B>> result;
83 for (
int i = 0; i < ncolumns; ++i)
84 result.emplace_back(std::make_unique<D>());
90 template <
typename T>
auto create_pointers(
const std::vector<std::unique_ptr<T>>& vec)
92 std::vector<T*> result;
93 std::transform(vec.begin(), vec.end(), std::back_inserter(result),
94 [](
auto& x) { return x.get(); });
100 template <
typename T,
typename... Args> std::vector<T>
toVector(Args&&... args)
103 (v.push_back(T(args)), ...);
Main class to hold hierarchy of SessionItem objects.
materialitems.h Collection of materials to populate MaterialModel.
Various common utils for unit tests.
auto create_pointers(const std::vector< std::unique_ptr< T >> &vec)
Creates vector of pointers from vector of unique_ptr.
auto create_row(int ncolumns)
Creates vector of unique_ptr of given type.
std::string CreateEmptyFile(const std::string &dirname, const std::string &fileName)
Helper function to create empty file in a given directory (directory should exist).
std::vector< T > toVector(Args &&... args)
Creates vector of T from argument list. Used in EXPECT_EQ macros for convenience.
std::string TestFileName(const std::string &test_sub_dir, const std::string &file_name)
Returns full path to the file in test directory.
void clean_items(T &items)
Deletes items in the container and cleans container afterwards.
std::string TestDirectoryPath(const std::string &test_sub_dir)
Returns full path to the main test folder in CMAKE_BINARY_DIR.
std::string CreateTestFile(const std::string &dirname, const std::string &fileName)
Helper function to create test file in a given directory (directory should exist).
void SaveJson(const QJsonObject &object, const std::string &fileName)
std::string CreateTestDirectory(const std::string &test_sub_dir)
Creates test directory in main test folder and returns full path.
QJsonDocument LoadJson(const std::string &fileName)
QString JsonToString(const QJsonObject &object)
std::string TestOutputDir()
Returns full path to the main test folder, as defined by CMake at compile time.
QString ModelToJsonString(ModelView::SessionModel &model)
Returns string representing serialized json content of the model.