Skip to content

Test plugin to verify the names of the JSON-RPC functions #898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,3 +48,6 @@ if(PLUGIN_TESTUTILITY)
add_subdirectory(TestUtility)
endif()

if(PLUGIN_TESTTEXTOPTIONS)
add_subdirectory(TestTextOptions)
endif()
66 changes: 66 additions & 0 deletions tests/TestTextOptions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)

install(TARGETS ${MODULE_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime)

write_config()
22 changes: 22 additions & 0 deletions tests/TestTextOptions/Module.cpp
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions tests/TestTextOptions/Module.h
Original file line number Diff line number Diff line change
@@ -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 <core/core.h>
#include <plugins/plugins.h>
#include <messaging/messaging.h>
#include <definitions/definitions.h>

#undef EXTERNAL
#define EXTERNAL
7 changes: 7 additions & 0 deletions tests/TestTextOptions/TestTextOptions.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
startmode = "@PLUGIN_TESTTEXTOPTIONS_STARTMODE@"

configuration = JSON()

root = JSON()
root.add("mode", "@PLUGIN_TESTTEXTOPTIONS_MODE@")
configuration.add("root", root)
139 changes: 139 additions & 0 deletions tests/TestTextOptions/TestTextOptions.cpp
Original file line number Diff line number Diff line change
@@ -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 Metadata<TestTextOptions>metadata(
// 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<QualityAssurance::ITestTextOptions>(_connectionId, timeout, _T("TestTextOptionsImplementation"));
if (_implTestTextOptions == nullptr) {
message = _T("Couldn't create instance of implTestTextOptions");
} else {
QualityAssurance::JTestTextOptions::Register(*this, _implTestTextOptions);
_implTestLegacy = _implTestTextOptions->QueryInterface<QualityAssurance::ITestTextOptions::ITestLegacy>();
if (_implTestLegacy == nullptr) {
message = _T("Couldn't create instance of _implITestLegacy");
} else {
QualityAssurance::TestTextOptions::JTestLegacy::Register(*this, _implTestLegacy);
_implTestKeep = _implTestTextOptions->QueryInterface<QualityAssurance::ITestTextOptions::ITestKeep>();
if (_implTestKeep == nullptr) {
message = _T("Couldn't create instance of _implITestKeep");
} else {
QualityAssurance::TestTextOptions::JTestKeep::Register(*this, _implTestKeep);
_implTestCustom = _implTestTextOptions->QueryInterface<QualityAssurance::ITestTextOptions::ITestCustom>();
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
Loading
Loading