|
| 1 | +// Mantid Repository : https://github.com/mantidproject/mantid |
| 2 | +// |
| 3 | +// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, |
| 4 | +// NScD Oak Ridge National Laboratory, European Spallation Source, |
| 5 | +// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS |
| 6 | +// SPDX - License - Identifier: GPL - 3.0 + |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include <cxxtest/TestSuite.h> |
| 10 | +#include <gmock/gmock.h> |
| 11 | + |
| 12 | +#include <QString> |
| 13 | +#include <QUrl> |
| 14 | + |
| 15 | +#include "MantidQtWidgets/Common/PythonHelpBridge.h" |
| 16 | +#include "MantidQtWidgets/Common/PythonHelpWindow.h" |
| 17 | + |
| 18 | +#include "MantidKernel/WarningSuppressions.h" |
| 19 | +GNU_DIAG_OFF_SUGGEST_OVERRIDE |
| 20 | + |
| 21 | +using namespace MantidQt::API; |
| 22 | +using namespace MantidQt::MantidWidgets; |
| 23 | +using namespace testing; |
| 24 | + |
| 25 | +GNU_DIAG_ON_SUGGEST_OVERRIDE |
| 26 | + |
| 27 | +class PythonHelpWindowTest : public CxxTest::TestSuite { |
| 28 | +public: |
| 29 | + void setUp() override {} |
| 30 | + |
| 31 | + void tearDown() override {} |
| 32 | + |
| 33 | + // 1) Test the constructor doesn't throw and creates a valid object |
| 34 | + void testConstructorDoesNotThrow() { TS_ASSERT_THROWS_NOTHING(PythonHelpWindow helpWin); } |
| 35 | + |
| 36 | + // 2) Test showPage(std::string) with an empty string |
| 37 | + void testShowPageWithEmptyString() { |
| 38 | + PythonHelpWindow helpWin; |
| 39 | + TS_ASSERT_THROWS_NOTHING(helpWin.showPage(std::string{})); |
| 40 | + } |
| 41 | + |
| 42 | + // 3) Test showPage(std::string) with a non-empty string |
| 43 | + void testShowPageWithNonEmptyString() { |
| 44 | + PythonHelpWindow helpWin; |
| 45 | + TS_ASSERT_THROWS_NOTHING(helpWin.showPage("custom_page.html")); |
| 46 | + } |
| 47 | + |
| 48 | + // 4) Test showPage(QString) with an empty string |
| 49 | + void testShowPage_QString_Empty() { |
| 50 | + PythonHelpWindow helpWin; |
| 51 | + TS_ASSERT_THROWS_NOTHING(helpWin.showPage(QString())); |
| 52 | + } |
| 53 | + |
| 54 | + // 5) Test showPage(QUrl) with an empty URL |
| 55 | + void testShowPage_QUrl_Empty() { |
| 56 | + PythonHelpWindow helpWin; |
| 57 | + TS_ASSERT_THROWS_NOTHING(helpWin.showPage(QUrl())); |
| 58 | + } |
| 59 | + |
| 60 | + // 6) Test showAlgorithm(std::string) with empty name and version |
| 61 | + void testShowAlgorithm_NoName() { |
| 62 | + PythonHelpWindow helpWin; |
| 63 | + TS_ASSERT_THROWS_NOTHING(helpWin.showAlgorithm("", -1)); |
| 64 | + } |
| 65 | + |
| 66 | + // 7) Test showAlgorithm(std::string) with valid name and version |
| 67 | + void testShowAlgorithm_NameAndVersion() { |
| 68 | + PythonHelpWindow helpWin; |
| 69 | + TS_ASSERT_THROWS_NOTHING(helpWin.showAlgorithm("Load", 2)); |
| 70 | + } |
| 71 | + |
| 72 | + // 8) Test showConcept(std::string) with empty name |
| 73 | + void testShowConceptEmpty() { |
| 74 | + PythonHelpWindow helpWin; |
| 75 | + TS_ASSERT_THROWS_NOTHING(helpWin.showConcept("")); |
| 76 | + } |
| 77 | + |
| 78 | + // 9) Test showFitFunction(std::string) with a name |
| 79 | + void testShowFitFunctionName() { |
| 80 | + PythonHelpWindow helpWin; |
| 81 | + TS_ASSERT_THROWS_NOTHING(helpWin.showFitFunction("GaussPeak")); |
| 82 | + } |
| 83 | + |
| 84 | + // 10) Test showCustomInterface(std::string) with name, area, section |
| 85 | + void testShowCustomInterface() { |
| 86 | + PythonHelpWindow helpWin; |
| 87 | + TS_ASSERT_THROWS_NOTHING(helpWin.showCustomInterface("Reflectometry", "ISISReflectometry", "Usage")); |
| 88 | + } |
| 89 | + |
| 90 | + // 11) Test the shutdown method (currently a no-op) |
| 91 | + void testShutdownDoesNotThrow() { |
| 92 | + PythonHelpWindow helpWin; |
| 93 | + TS_ASSERT_THROWS_NOTHING(helpWin.shutdown()); |
| 94 | + } |
| 95 | +}; |
0 commit comments