diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 62269842c..7938690a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,6 +28,7 @@ option(STORE_TEST "Utility to verify PersistentStore and Dictionary Plugin behav option(TEST_AUTOMATION_TOOLS "Utility to verify Thunder functions trigerred by Automation Test Tools." OFF) option(PLUGIN_TESTCONTROLLER "Include TestController plugin" OFF) option(PLUGIN_TESTUTILITY "Include TestUtility plugin" OFF) +option(PLUGIN_TESTTEXTOPTIONS "Utility to verify the name of JSONRPC functions" OFF) if(STORE_TEST) add_subdirectory(StoreTest) @@ -47,3 +48,6 @@ if(PLUGIN_TESTUTILITY) add_subdirectory(TestUtility) endif() +if(PLUGIN_TESTTEXTOPTIONS) + add_subdirectory(TestTextOptions) +endif() \ No newline at end of file diff --git a/tests/TestTextOptions/CMakeLists.txt b/tests/TestTextOptions/CMakeLists.txt new file mode 100644 index 000000000..a39c67166 --- /dev/null +++ b/tests/TestTextOptions/CMakeLists.txt @@ -0,0 +1,66 @@ +# If not stated otherwise in this file or this component's license file the +# following copyright and licenses apply: +# +# Copyright 2025 Metrological +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +project(TestTextOptions) + +cmake_minimum_required(VERSION 3.15) + +find_package(Thunder) + +project_version(1.0.0) + +set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME}) + +message("Setup ${MODULE_NAME} v${PROJECT_VERSION}") + +set(PLUGIN_TESTTEXTOPTIONS_STARTMODE "Activated" CACHE STRING "Automatically start TestTextOptions plugin") +set(PLUGIN_TESTTEXTOPTIONS_MODE "Local" CACHE STRING "Controls if the plugin should run in its own process, in process, container or remote.") + +if(BUILD_REFERENCE) + add_definitions(-DBUILD_REFERENCE=${BUILD_REFERENCE}) +endif() + +find_package(${NAMESPACE}Plugins REQUIRED) +find_package(${NAMESPACE}Definitions REQUIRED) +find_package(${NAMESPACE}Messaging REQUIRED) +find_package(CompileSettingsDebug CONFIG REQUIRED) + +add_library(${MODULE_NAME} SHARED + TestTextOptions.cpp + TestTextOptionsImplementation.cpp + Module.cpp +) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +target_link_libraries(${MODULE_NAME} + PRIVATE + CompileSettingsDebug::CompileSettingsDebug + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}Definitions::${NAMESPACE}Definitions + ${NAMESPACE}Messaging::${NAMESPACE}Messaging) + +target_include_directories(${MODULE_NAME} + PRIVATE + $) + +install(TARGETS ${MODULE_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime) + +write_config() \ No newline at end of file diff --git a/tests/TestTextOptions/Module.cpp b/tests/TestTextOptions/Module.cpp new file mode 100644 index 000000000..56f802326 --- /dev/null +++ b/tests/TestTextOptions/Module.cpp @@ -0,0 +1,22 @@ +/* +* If not stated otherwise in this file or this component's LICENSE file the +* following copyright and licenses apply: +* +* Copyright 2025 Metrological +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "Module.h" + +MODULE_NAME_DECLARATION(BUILD_REFERENCE) \ No newline at end of file diff --git a/tests/TestTextOptions/Module.h b/tests/TestTextOptions/Module.h new file mode 100644 index 000000000..4a4037230 --- /dev/null +++ b/tests/TestTextOptions/Module.h @@ -0,0 +1,32 @@ +/* +* If not stated otherwise in this file or this component's LICENSE file the +* following copyright and licenses apply: +* +* Copyright 2025 Metrological +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#ifndef MODULE_NAME +#define MODULE_NAME Plugin_TestTextOptions +#endif + +#include +#include +#include +#include + +#undef EXTERNAL +#define EXTERNAL \ No newline at end of file diff --git a/tests/TestTextOptions/TestTextOptions.conf.in b/tests/TestTextOptions/TestTextOptions.conf.in new file mode 100644 index 000000000..3bdb0fc7f --- /dev/null +++ b/tests/TestTextOptions/TestTextOptions.conf.in @@ -0,0 +1,7 @@ +startmode = "@PLUGIN_TESTTEXTOPTIONS_STARTMODE@" + +configuration = JSON() + +root = JSON() +root.add("mode", "@PLUGIN_TESTTEXTOPTIONS_MODE@") +configuration.add("root", root) \ No newline at end of file diff --git a/tests/TestTextOptions/TestTextOptions.cpp b/tests/TestTextOptions/TestTextOptions.cpp new file mode 100644 index 000000000..1055cdefe --- /dev/null +++ b/tests/TestTextOptions/TestTextOptions.cpp @@ -0,0 +1,139 @@ +/* +* If not stated otherwise in this file or this component's LICENSE file the +* following copyright and licenses apply: +* +* Copyright 2025 Metrological +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "TestTextOptions.h" + +namespace Thunder { +namespace Plugin { + + namespace { + + static Metadatametadata( + // Version + 1, 0, 0, + // Preconditions + {}, + // Terminations + {}, + // Controls + {} + ); + } + + const string TestTextOptions::Initialize(PluginHost::IShell* service) { + string message; + + ASSERT(_service == nullptr); + ASSERT(service != nullptr); + ASSERT(_implTestTextOptions == nullptr); + ASSERT(_implTestLegacy == nullptr); + ASSERT(_implTestKeep == nullptr); + ASSERT(_implTestCustom == nullptr); + ASSERT(_connectionId == 0); + + _service = service; + _service->AddRef(); + _service->Register(&_notification); + + _implTestTextOptions = service->Root(_connectionId, timeout, _T("TestTextOptionsImplementation")); + if (_implTestTextOptions == nullptr) { + message = _T("Couldn't create instance of implTestTextOptions"); + } else { + QualityAssurance::JTestTextOptions::Register(*this, _implTestTextOptions); + _implTestLegacy = _implTestTextOptions->QueryInterface(); + if (_implTestLegacy == nullptr) { + message = _T("Couldn't create instance of _implITestLegacy"); + } else { + QualityAssurance::TestTextOptions::JTestLegacy::Register(*this, _implTestLegacy); + _implTestKeep = _implTestTextOptions->QueryInterface(); + if (_implTestKeep == nullptr) { + message = _T("Couldn't create instance of _implITestKeep"); + } else { + QualityAssurance::TestTextOptions::JTestKeep::Register(*this, _implTestKeep); + _implTestCustom = _implTestTextOptions->QueryInterface(); + if (_implTestCustom == nullptr) { + message = _T("Couldn't create instance of _implITestCustom"); + } else { + QualityAssurance::TestTextOptions::JTestCustom::Register(*this, _implTestCustom); + } + } + } + } + + return (message); + } + + void TestTextOptions::Deinitialize(PluginHost::IShell* service) { + + ASSERT(_service == service); + + _service->Unregister(&_notification); + + if (_implTestTextOptions != nullptr) { + QualityAssurance::JTestTextOptions::Unregister(*this); + + if (_implTestLegacy != nullptr) { + QualityAssurance::TestTextOptions::JTestLegacy::Unregister(*this); + _implTestLegacy->Release(); + _implTestLegacy = nullptr; + } + + if (_implTestKeep != nullptr) { + QualityAssurance::TestTextOptions::JTestKeep::Unregister(*this); + _implTestKeep->Release(); + _implTestKeep = nullptr; + } + + if (_implTestCustom != nullptr) { + QualityAssurance::TestTextOptions::JTestCustom::Unregister(*this); + _implTestCustom->Release(); + _implTestCustom = nullptr; + } + + RPC::IRemoteConnection* connection(service->RemoteConnection(_connectionId)); + VARIABLE_IS_NOT_USED uint32_t result = _implTestTextOptions->Release(); + _implTestTextOptions = nullptr; + + ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); + + // The process can disappear in the meantime... + if (connection != nullptr) { + // But if it did not disappear in the meantime, forcefully terminate it. Shoot to kill + connection->Terminate(); + connection->Release(); + } + } + _service->Release(); + _service = nullptr; + _connectionId = 0; + } + + string TestTextOptions::Information() const { + return (string()); + } + + + void TestTextOptions::Deactivated(RPC::IRemoteConnection* connection) { + if (connection->Id() == _connectionId) { + ASSERT(_service != nullptr); + Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); + } + } +} // Plugin +} // Thunder \ No newline at end of file diff --git a/tests/TestTextOptions/TestTextOptions.h b/tests/TestTextOptions/TestTextOptions.h new file mode 100644 index 000000000..37a1d7b87 --- /dev/null +++ b/tests/TestTextOptions/TestTextOptions.h @@ -0,0 +1,186 @@ +/* +* If not stated otherwise in this file or this component's LICENSE file the +* following copyright and licenses apply: +* +* Copyright 2025 Metrological +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#include "Module.h" +#include +#include +#include +#include +#include + +namespace Thunder { +namespace Plugin { + + class TestTextOptions : public PluginHost::IPlugin, public PluginHost::JSONRPC { + public: + TestTextOptions(const TestTextOptions&) = delete; + TestTextOptions& operator=(const TestTextOptions&) = delete; + TestTextOptions(TestTextOptions&&) = delete; + TestTextOptions& operator=(TestTextOptions&&) = delete; + + TestTextOptions() + : PluginHost::IPlugin() + , PluginHost::JSONRPC() + , _service(nullptr) + , _connectionId(0) + , _implTestTextOptions(nullptr) + , _implTestLegacy(nullptr) + , _implTestKeep(nullptr) + , _implTestCustom(nullptr) + , _notification(*this) + { + } + + ~TestTextOptions() override = default; + private: + class Notification; + + class NotificationTestTextOptions : public QualityAssurance::ITestTextOptions::INotification { + public: + explicit NotificationTestTextOptions(Notification& parent) + : _parent(parent) + { + } + + void TestEvent() override { + QualityAssurance::JTestTextOptions::Event::TestEvent(_parent.Parent()); + } + private: + Notification& _parent; + }; + + class NotificationTestLegacy : public QualityAssurance::ITestTextOptions::ITestLegacy::INotification { + public: + explicit NotificationTestLegacy(Notification& parent) + : _parent(parent) + { + } + + void TestEvent() override { + QualityAssurance::TestTextOptions::JTestLegacy::Event::TestEvent(_parent.Parent()); + } + private: + Notification& _parent; + }; + + class NotificationTestKeep : public QualityAssurance::ITestTextOptions::ITestKeep::INotification { + public: + explicit NotificationTestKeep(Notification& parent) + : _parent(parent) + { + } + + void TestEvent() override { + QualityAssurance::TestTextOptions::JTestKeep::Event::TestEvent(_parent.Parent()); + } + private: + Notification& _parent; + }; + + class NotificationTestCustom : public QualityAssurance::ITestTextOptions::ITestCustom::INotification { + public: + explicit NotificationTestCustom(Notification& parent) + : _parent(parent) + { + } + + void TestEvent() override { + QualityAssurance::TestTextOptions::JTestCustom::Event::TestEvent(_parent.Parent()); + } + private: + Notification& _parent; + }; + + class Notification : public RPC::IRemoteConnection::INotification, + public NotificationTestTextOptions, + public NotificationTestLegacy, + public NotificationTestKeep, + public NotificationTestCustom { + public: + Notification(const Notification&) = delete; + Notification& operator=(const Notification&) = delete; + Notification(Notification&&) = delete; + Notification& operator=(Notification&&) = delete; + Notification() = delete; + + explicit Notification(TestTextOptions& parent) + : RPC::IRemoteConnection::INotification() + , NotificationTestTextOptions(*this) + , NotificationTestLegacy(*this) + , NotificationTestKeep(*this) + , NotificationTestCustom(*this) + , _parent(parent) + { + } + + ~Notification() override = default; + + void Activated(RPC::IRemoteConnection*) override {} + void Deactivated(RPC::IRemoteConnection* connection) override { + _parent.Deactivated(connection); + } + + TestTextOptions& Parent() { + return _parent; + } + + BEGIN_INTERFACE_MAP(Notification) + INTERFACE_ENTRY(RPC::IRemoteConnection::INotification) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions::INotification) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions::ITestLegacy::INotification) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions::ITestKeep::INotification) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions::ITestCustom::INotification) + END_INTERFACE_MAP + + private: + TestTextOptions& _parent; + }; + public: + // IPlugin Methods + const string Initialize(PluginHost::IShell* service) override; + void Deinitialize(PluginHost::IShell* service) override; + string Information() const override; + + void Deactivated(RPC::IRemoteConnection* connection); + + BEGIN_INTERFACE_MAP(TestTextOptions) + INTERFACE_ENTRY(PluginHost::IPlugin) + INTERFACE_ENTRY(PluginHost::IDispatcher) + INTERFACE_AGGREGATE(QualityAssurance::ITestTextOptions, _implTestTextOptions) + INTERFACE_AGGREGATE(QualityAssurance::ITestTextOptions::ITestLegacy, _implTestLegacy) + INTERFACE_AGGREGATE(QualityAssurance::ITestTextOptions::ITestKeep, _implTestKeep) + INTERFACE_AGGREGATE(QualityAssurance::ITestTextOptions::ITestCustom, _implTestCustom) + END_INTERFACE_MAP + + private: + // Timeout (2000ms) may be changed if necassary, however, it must not exceed RPC::CommunicationTimeOut + static constexpr uint32_t timeout = 2000; + + PluginHost::IShell* _service; + uint32_t _connectionId; + QualityAssurance::ITestTextOptions* _implTestTextOptions; + QualityAssurance::ITestTextOptions::ITestLegacy* _implTestLegacy; + QualityAssurance::ITestTextOptions::ITestKeep* _implTestKeep; + QualityAssurance::ITestTextOptions::ITestCustom* _implTestCustom; + Core::SinkType _notification; + }; +} // Plugin +} // Thunder \ No newline at end of file diff --git a/tests/TestTextOptions/TestTextOptionsImplementation.cpp b/tests/TestTextOptions/TestTextOptionsImplementation.cpp new file mode 100644 index 000000000..acfa7547e --- /dev/null +++ b/tests/TestTextOptions/TestTextOptionsImplementation.cpp @@ -0,0 +1,80 @@ +/* +* If not stated otherwise in this file or this component's LICENSE file the +* following copyright and licenses apply: +* +* Copyright 2025 Metrological +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "Module.h" +#include + +namespace Thunder { +namespace Plugin { + + class TestTextOptionsImplementation : public QualityAssurance::ITestTextOptions, + public QualityAssurance::ITestTextOptions::ITestLegacy, + public QualityAssurance::ITestTextOptions::ITestKeep, + public QualityAssurance::ITestTextOptions::ITestCustom { + public: + TestTextOptionsImplementation(const TestTextOptionsImplementation&) = delete; + TestTextOptionsImplementation& operator=(const TestTextOptionsImplementation&) = delete; + TestTextOptionsImplementation(TestTextOptionsImplementation&&) = delete; + TestTextOptionsImplementation& operator=(TestTextOptionsImplementation&&) = delete; + + TestTextOptionsImplementation() + : QualityAssurance::ITestTextOptions() + , QualityAssurance::ITestTextOptions::ITestLegacy() + , QualityAssurance::ITestTextOptions::ITestKeep() + , QualityAssurance::ITestTextOptions::ITestCustom() + { + } + ~TestTextOptionsImplementation() override = default; + + public: + + BEGIN_INTERFACE_MAP(TestTextOptionsImplementation) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions::ITestLegacy) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions::ITestKeep) + INTERFACE_ENTRY(QualityAssurance::ITestTextOptions::ITestCustom) + END_INTERFACE_MAP + + // ITestTextOptions methods + Core::hresult TestStandart(const uint32_t firstTestParam VARIABLE_IS_NOT_USED, const uint32_t secondTestParam VARIABLE_IS_NOT_USED, + const QualityAssurance::ITestTextOptions::TestDetails& thirdTestParam VARIABLE_IS_NOT_USED, const QualityAssurance::ITestTextOptions::EnumTextOptions fourthTestParam VARIABLE_IS_NOT_USED) override { + return Core::ERROR_NONE; + } + + // ITestLegacy methods + Core::hresult TestLegacy(const uint32_t firstTestParam VARIABLE_IS_NOT_USED, const uint32_t secondTestParam VARIABLE_IS_NOT_USED, + const QualityAssurance::ITestTextOptions::ITestLegacy::TestDetails& thirdTestParam VARIABLE_IS_NOT_USED, const QualityAssurance::ITestTextOptions::ITestLegacy::EnumTextOptions fourthTestParam VARIABLE_IS_NOT_USED) override { + return Core::ERROR_NONE; + } + + // ITestKeep methods + Core::hresult TestKeeP(const uint32_t firstTestParaM VARIABLE_IS_NOT_USED, const uint32_t secondTestParaM VARIABLE_IS_NOT_USED, + const QualityAssurance::ITestTextOptions::ITestKeep::TestDetails& thirdTestParaM VARIABLE_IS_NOT_USED, const QualityAssurance::ITestTextOptions::ITestKeep::EnumTextOptions fourthTestParaM VARIABLE_IS_NOT_USED) override { + return Core::ERROR_NONE; + } + // ITestCustom methods + Core::hresult TestCustom(const uint32_t firstTestParam VARIABLE_IS_NOT_USED, const uint32_t secondTestParam VARIABLE_IS_NOT_USED, + const QualityAssurance::ITestTextOptions::ITestCustom::TestDetails& thirdTestParam VARIABLE_IS_NOT_USED, const QualityAssurance::ITestTextOptions::ITestCustom::EnumTextOptions fourthTestParam VARIABLE_IS_NOT_USED) override { + return Core::ERROR_NONE; + } + }; + + SERVICE_REGISTRATION(TestTextOptionsImplementation, 1, 0) +} // Plugin +} // Thunder \ No newline at end of file diff --git a/tests/TestTextOptions/TestTextOptionsPlugin.json b/tests/TestTextOptions/TestTextOptionsPlugin.json new file mode 100644 index 000000000..3ed3f750d --- /dev/null +++ b/tests/TestTextOptions/TestTextOptionsPlugin.json @@ -0,0 +1,16 @@ +{ + "$schema": "plugin.schema.json", + "info": { + "title": "TestTextOptions Plugin", + "callsign": "TestTextOptions", + "locator": "libThunderTestTextOptions.so", + "status": "development", + "description": [ + "" + ], + "version": "1.0" + }, + "interface": { + "$cppref": "{cppinterfacedir}/TestTextOptionsImplementation.h" + } +} \ No newline at end of file