File indexing completed on 2024-05-19 05:42:27
0001 // ct_lvtqtw_plugineditor.t.cpp -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #include <ct_lvtqtc_graphicsview.h> 0021 #include <ct_lvtqtc_testing_utils.h> 0022 0023 #include <ct_lvtplg_pluginmanager.h> 0024 #include <ct_lvtqtw_plugineditor.h> 0025 0026 #include <ct_lvttst_fixture_qt.h> 0027 0028 #include <catch2-local-includes.h> 0029 0030 #include <QFileInfo> 0031 #include <QTemporaryDir> 0032 #include <qtemporarydir.h> 0033 0034 using namespace Codethink::lvtqtw; 0035 0036 TEST_CASE_METHOD(QTApplicationFixture, "Test Plugin Editor without Manager") 0037 { 0038 QTemporaryDir tempDir; 0039 0040 auto *editor = new PluginEditor(); 0041 editor->setBasePluginPath(tempDir.path()); 0042 0043 int numErrorMessages = 0; 0044 0045 QObject::connect(editor, 0046 &Codethink::lvtqtw::PluginEditor::sendErrorMsg, 0047 editor, 0048 [&numErrorMessages](const QString& s) { 0049 qDebug() << s; 0050 numErrorMessages += 1; 0051 }); 0052 0053 editor->createPythonPlugin(tempDir.path() + QDir::separator() + "test"); 0054 auto res = editor->save(); 0055 0056 // Error required because here the dialog has no plugin manager. 0057 REQUIRE(res.has_error()); 0058 editor->reloadPlugin(); 0059 editor->close(); 0060 0061 REQUIRE(numErrorMessages == 4); 0062 0063 numErrorMessages = 0; 0064 Codethink::lvtplg::PluginManager manager; 0065 editor->setPluginManager(&manager); 0066 0067 editor->createPythonPlugin(tempDir.path() + QDir::separator() + "test2"); 0068 res = editor->save(); 0069 // And here it should pass because we do have a plugin manager. 0070 std::cout << res.error().errStr << "\n"; 0071 REQUIRE_FALSE(res.has_error()); 0072 0073 editor->reloadPlugin(); 0074 editor->close(); 0075 0076 REQUIRE(numErrorMessages == 0); 0077 }