From 385c5268ef5c60436ff6404c9c936c1750120c59 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Thu, 19 Nov 2020 17:52:04 +0100 Subject: [PATCH] rm test GUISaveLoad, outcommented since long --- Tests/Functional/GUI/CMakeLists.txt | 1 - Tests/Functional/GUI/Other/CMakeLists.txt | 12 - .../Functional/GUI/Other/SaveLoadProject.cpp | 227 ------------------ Tests/Functional/GUI/Other/SaveLoadProject.h | 56 ----- Tests/Functional/GUI/Other/Tests.cpp | 30 --- cmake/configurables/BATesting.h.in | 4 - 6 files changed, 330 deletions(-) delete mode 100644 Tests/Functional/GUI/Other/CMakeLists.txt delete mode 100644 Tests/Functional/GUI/Other/SaveLoadProject.cpp delete mode 100644 Tests/Functional/GUI/Other/SaveLoadProject.h delete mode 100644 Tests/Functional/GUI/Other/Tests.cpp diff --git a/Tests/Functional/GUI/CMakeLists.txt b/Tests/Functional/GUI/CMakeLists.txt index 7588b25b0eb..5ef52bcc33b 100644 --- a/Tests/Functional/GUI/CMakeLists.txt +++ b/Tests/Functional/GUI/CMakeLists.txt @@ -1,3 +1,2 @@ add_subdirectory(Std) add_subdirectory(Translate) -add_subdirectory(Other) diff --git a/Tests/Functional/GUI/Other/CMakeLists.txt b/Tests/Functional/GUI/Other/CMakeLists.txt deleted file mode 100644 index 6f21ecb9f3f..00000000000 --- a/Tests/Functional/GUI/Other/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -include(GoogleTest) # provides gtest_discover_tests - -set(test TestGUIOther) - -file(GLOB source_files "*.cpp") - -add_executable(${test} ${source_files} ${CMAKE_SOURCE_DIR}/Tests/GTestWrapper/TestAll.cpp) -target_include_directories(${test} - PUBLIC ${CMAKE_SOURCE_DIR}/ThirdParty/common/gtest/gtest-1.8.0/include) -target_link_libraries(${test} BornAgainGUI gtest) - -gtest_discover_tests(${test} DISCOVERY_TIMEOUT 300 TEST_PREFIX GUI.) diff --git a/Tests/Functional/GUI/Other/SaveLoadProject.cpp b/Tests/Functional/GUI/Other/SaveLoadProject.cpp deleted file mode 100644 index 3d635a05d6e..00000000000 --- a/Tests/Functional/GUI/Other/SaveLoadProject.cpp +++ /dev/null @@ -1,227 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/Functional/GUI/Other/SaveLoadProject.cpp -//! @brief Implements SaveLoadProject test. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "Tests/Functional/GUI/Other/SaveLoadProject.h" -#include "BATesting.h" -#include "Base/Utils/FileSystemUtils.h" -#include "GUI/coregui/Models/ApplicationModels.h" -#include "GUI/coregui/Models/DetectorItems.h" -#include "GUI/coregui/Models/DocumentModel.h" -#include "GUI/coregui/Models/GUIObjectBuilder.h" -#include "GUI/coregui/Models/InstrumentItems.h" -#include "GUI/coregui/Models/InstrumentModel.h" -#include "GUI/coregui/Models/JobItem.h" -#include "GUI/coregui/Models/JobModel.h" -#include "GUI/coregui/Models/SampleModel.h" -#include "GUI/coregui/Models/SimulationOptionsItem.h" -#include "GUI/coregui/mainwindow/ProjectUtils.h" -#include "GUI/coregui/mainwindow/projectdocument.h" -#include "GUI/coregui/utils/MessageService.h" -#include "Sample/Multilayer/MultiLayer.h" -#include "Sample/StandardSamples/SampleBuilderFactory.h" -#include <QCoreApplication> -#include <QElapsedTimer> -#include <QXmlStreamWriter> - -namespace -{ -const QString sample_name = "ParticleCompositionBuilder"; -const QString project_name = "untitled.pro"; -const int failure = 1; -const int success = 0; - -QString path(const QString& projectName) -{ - return QString::fromStdString( - FileSystemUtils::jointPath(BATesting::TestOutDir_GUI(), projectName.toStdString())); -} -} // namespace - -GUISaveLoadProject::GUISaveLoadProject() : m_models(new ApplicationModels) {} - -GUISaveLoadProject::~GUISaveLoadProject() = default; - -bool GUISaveLoadProject::runTest() -{ - int nerr(0); - - QString projectName1(path("test_GUISaveLoadProject_1")); - QString projectName2(path("test_GUISaveLoadProject_2")); - - // running simulation to fill models with fresh data - nerr += run_job(); - - // saving project - nerr += save_project(projectName1); - - // loading project back to models - nerr += load_project(projectName1); - - // saving under different name what we've just loaded - nerr += save_project(projectName2); - - // analyze difference - nerr += check_difference(projectName1, projectName2); - - return nerr == 0; -} - -int GUISaveLoadProject::run_job() -{ - resetModels(); - - std::cout << "GUISaveLoadProject::run_job()" << std::endl; - - SimulationOptionsItem* optionsItem = m_models->documentModel()->simulationOptionsItem(); - - SampleBuilderFactory factory; - const std::unique_ptr<MultiLayer> sample(factory.createSampleByName(sample_name.toStdString())); - - GUIObjectBuilder::populateSampleModel(m_models->sampleModel(), m_models->materialModel(), - *sample); - - auto instrument2DItem = - dynamic_cast<Instrument2DItem*>(m_models->instrumentModel()->instrumentItem()); - ASSERT(instrument2DItem); - instrument2DItem->detectorItem()->setXSize(50); - instrument2DItem->detectorItem()->setYSize(50); - - auto jobItem = - m_models->jobModel()->addJob(m_models->sampleModel()->multiLayerItem(), - m_models->instrumentModel()->instrumentItem(), 0, optionsItem); - - m_models->jobModel()->runJob(jobItem->index()); - - while (m_models->jobModel()->hasUnfinishedJobs()) { - QElapsedTimer timer; - timer.start(); - while (timer.elapsed() < 10) - QCoreApplication::processEvents(QEventLoop::AllEvents, 1); - } - - std::cout << "... job finished." << std::endl; - return jobItem->isCompleted() ? 0 : 1; -} - -//! Saves models to project directory and as xml string for later analysis. - -int GUISaveLoadProject::save_project(const QString& projectName) -{ - int nerr(0); - nerr += save_project_dir(projectName); - nerr += save_xml(projectName); - return nerr; -} - -//! Saves project in directory. - -int GUISaveLoadProject::save_project_dir(const QString& projectName) -{ - std::cout << "GUISaveLoadProject::save_project() -> Saving to " << projectName.toStdString() - << std::endl; - - if (ProjectUtils::exists(projectName)) - ProjectUtils::removeRecursively(projectName); - - FileSystemUtils::createDirectories(projectName.toStdString()); - - ProjectDocument document; - document.setApplicationModels(m_models.get()); - document.save(projectName + "/" + project_name); - - std::cout << "... saved." << std::endl; - - return success; -} - -//! Sets all model xml content to the map for later analysis. - -int GUISaveLoadProject::save_xml(const QString& projectName) -{ - for (auto model : m_models->modelList()) - m_results[projectName].push_back(dataXML(model)); - - return success; -} - -int GUISaveLoadProject::load_project(const QString& projectName) -{ - resetModels(); - - std::cout << "GUISaveLoadProject::load_project() -> Loading from " << projectName.toStdString() - << std::endl; - - MessageService logger; - ProjectDocument document; - document.setApplicationModels(m_models.get()); - document.setLogger(&logger); - document.load(projectName + "/" + project_name); - - std::cout << "... loaded." << std::endl; - return success; -} - -int GUISaveLoadProject::check_difference(const QString& projectName1, const QString& projectName2) -{ - std::cout << "GUISaveLoadProject::check_difference -> Checking difference of \n" - << projectName1.toStdString() << "' - initially saved project \n" - << projectName2.toStdString() << "' - loaded and then saved. \n"; - - auto project1 = m_results[projectName1]; - auto project2 = m_results[projectName2]; - - if (project1.size() != project2.size()) { - std::cout << "Number of models in project differs. Failed. \n"; - return failure; - } - - int err(0); - for (int i = 0; i < project1.size(); ++i) { - DataXML model_data1 = project1[i]; - DataXML model_data2 = project2[i]; - - if (model_data1.m_model_tag != model_data2.m_model_tag) { - std::cout << "Error, different tags. " << model_data1.m_model_tag.toStdString() - << model_data2.m_model_tag.toStdString() << "\n"; - err++; - } - - if (model_data1.m_model_xml != model_data2.m_model_xml) { - std::cout << "Error, different xml in model '" << model_data1.m_model_tag.toStdString() - << "'\n"; - err++; - } - } - - return err > 0 ? failure : success; -} - -//! Returns DataXML from the model. - -GUISaveLoadProject::DataXML GUISaveLoadProject::dataXML(SessionModel* model) -{ - DataXML result; - - result.m_model_tag = model->getModelTag(); - QXmlStreamWriter writer(&result.m_model_xml); - model->writeTo(&writer); - - return result; -} - -void GUISaveLoadProject::resetModels() -{ - m_models.reset(); // first have to delete original model - m_models.reset(new ApplicationModels); -} diff --git a/Tests/Functional/GUI/Other/SaveLoadProject.h b/Tests/Functional/GUI/Other/SaveLoadProject.h deleted file mode 100644 index 4d615012b4d..00000000000 --- a/Tests/Functional/GUI/Other/SaveLoadProject.h +++ /dev/null @@ -1,56 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/Functional/GUI/Other/SaveLoadProject.h -//! @brief Defines GUISaveLoadProject test. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_TESTS_FUNCTIONAL_GUI_OTHER_SAVELOADPROJECT_H -#define BORNAGAIN_TESTS_FUNCTIONAL_GUI_OTHER_SAVELOADPROJECT_H - -#include <QMap> -#include <QString> -#include <QVector> -#include <memory> - -class ApplicationModels; -class SessionModel; - -//! Functional test to check persistency of application models after save/load. - -class GUISaveLoadProject -{ -public: - GUISaveLoadProject(); - ~GUISaveLoadProject(); - - bool runTest(); - -private: - struct DataXML { - QString m_model_tag; - QString m_model_xml; - }; - - int run_job(); - int save_project(const QString& projectName); - int save_project_dir(const QString& projectName); - int save_xml(const QString& projectName); - int load_project(const QString& projectName); - int check_difference(const QString& projectName1, const QString& projectName2); - DataXML dataXML(SessionModel* model); - void resetModels(); - - std::unique_ptr<ApplicationModels> m_models; - //! Correspondance of projectname to collected xml data. - QMap<QString, QVector<DataXML>> m_results; -}; - -#endif // BORNAGAIN_TESTS_FUNCTIONAL_GUI_OTHER_SAVELOADPROJECT_H diff --git a/Tests/Functional/GUI/Other/Tests.cpp b/Tests/Functional/GUI/Other/Tests.cpp deleted file mode 100644 index 01ea7176da5..00000000000 --- a/Tests/Functional/GUI/Other/Tests.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/Functional/GUI/Other/Tests.cpp -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "Tests/Functional/GUI/Other/SaveLoadProject.h" -#include "Tests/GTestWrapper/google_test.h" - -class Other : public ::testing::Test -{ -}; - -/* TODO restore - currently times out, or when run interactively, writes: - GUISaveLoadProject::run_job() - QEventLoop: Cannot be used without QApplication - -TEST_F(Other, SaveLoad) -{ - EXPECT_TRUE(GUISaveLoadProject().runTest()); -} -*/ diff --git a/cmake/configurables/BATesting.h.in b/cmake/configurables/BATesting.h.in index ccb20f3a009..ea9403d824d 100644 --- a/cmake/configurables/BATesting.h.in +++ b/cmake/configurables/BATesting.h.in @@ -53,10 +53,6 @@ inline std::string TestOutDir_PyStd() { return "@TEST_OUTPUT_DIR@/PyStd"; } -inline std::string TestOutDir_GUI() -{ - return "@TEST_OUTPUT_DIR@/GUI"; -} } // namespace BATesting -- GitLab