20 #include "testconfig.h"
22 #include <QJsonDocument>
23 #include <QJsonObject>
25 #include <QTextStream>
32 void SaveDocument(
const QJsonDocument& document,
const std::string& fileName);
60 QJsonDocument document(
object);
61 SaveDocument(document, fileName);
66 QJsonDocument document(
object);
67 SaveDocument(document, fileName);
72 QJsonDocument document(
object);
73 return QString(document.toJson(QJsonDocument::Compact));
83 QFile jsonFile(QString::fromStdString(fileName));
85 if (!jsonFile.open(QIODevice::ReadOnly))
86 throw std::runtime_error(
"TestUtils::LoadJson() -> Can't read file");
88 return QJsonDocument().fromJson(jsonFile.readAll());
93 std::string
filename = dirname.empty() ? fileName : dirname +
"/" + fileName;
95 QFile file(QString::fromStdString(
filename));
96 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
97 throw std::runtime_error(
"TestFileUtils::createTestFile() -> Error. "
100 QTextStream out(&file);
101 out <<
"Test file " << 42 <<
"\n";
109 std::string
filename = dirname.empty() ? fileName : dirname +
"/" + fileName;
111 QFile file(QString::fromStdString(
filename));
112 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
113 throw std::runtime_error(
"TestFileUtils::createTestFile() -> Error. "
114 "Can't create file");
120 void SaveDocument(
const QJsonDocument& document,
const std::string& fileName)
122 QFile saveFile(QString::fromStdString(fileName));
124 if (!saveFile.open(QIODevice::WriteOnly))
125 throw std::runtime_error(
"TestUtils::SaveDocument() -> Can't save file");
127 saveFile.write(document.toJson());
Main class to hold hierarchy of SessionItem objects.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
MVVM_MODEL_EXPORT std::string ModelToJsonString(const SessionModel &model)
Returns multiline string representing model content as json.
MVVM_MODEL_EXPORT bool create_directory(const std::string &path)
Create directory, parent directory must exist.
materialitems.h Collection of materials to populate MaterialModel.
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::string TestFileName(const std::string &test_sub_dir, const std::string &file_name)
Returns full path to the file in test directory.
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.