Skip to content

Commit

Permalink
Splitting the TestAutomationPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
volkan-aslan committed Jan 2, 2024
1 parent 6735903 commit d640d4a
Show file tree
Hide file tree
Showing 22 changed files with 666 additions and 428 deletions.
5 changes: 3 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ project_version(1.0.0)
message("Setup ${PROJECT_NAME} v${PROJECT_VERSION}")

option(STORE_TEST "Utility to verify PersistentStore and Dictionary Plugin behaviour." OFF)
option(TEST_AUTOMATION_TOOLS "Utility to verify Thunder functions trigerred by Automation Test Tools." OFF)
option(TEST_AUTOMATION_TOOLS "Utility to verify Thunder functions trigerred by Automation Test Tools." ON)

if(STORE_TEST)
add_subdirectory(StoreTest)
endif()

if(TEST_AUTOMATION_TOOLS)
add_subdirectory(TestAutomationTools)
add_subdirectory(TestAutomationComRpc)
add_subdirectory(TestAutomationMemory)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

project(TestAutomationTools)
project(TestAutomationComRpc)

cmake_minimum_required(VERSION 3.3)

Expand All @@ -27,7 +27,7 @@ set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME})

message("Setup ${MODULE_NAME} v${PROJECT_VERSION}")

set(PLUGIN_TESTAUTOMATIONTOOLS_AUTOSTART true CACHE STRING "Automatically start TestAutomationTools plugin")
set(PLUGIN_TESTAUTOMATIONCOMRPC_AUTOSTART true CACHE STRING "Automatically start TestAutomationComRpc plugin")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

Expand All @@ -38,8 +38,8 @@ find_package(CompileSettingsDebug CONFIG REQUIRED)

add_library(${MODULE_NAME} SHARED
Module.cpp
TestAutomationTools.cpp
TestAutomationToolsImplementation.cpp)
TestAutomationComRpc.cpp
TestAutomationComRpcImplementation.cpp)

target_link_libraries(${MODULE_NAME}
PRIVATE
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#pragma once

#ifndef MODULE_NAME
#define MODULE_NAME Plugin_TestAutomationTools
#define MODULE_NAME Plugin_TestAutomationComRpc
#endif

#include <plugins/plugins.h>
Expand Down
7 changes: 7 additions & 0 deletions tests/TestAutomationComRpc/TestAutomationComRpc.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
autostart = "@PLUGIN_TESTAUTOMATIONCOMRPC_AUTOSTART@"

configuration = JSON()

rootobject = JSON()
rootobject.add("mode", "Local")
configuration.add("root", rootobject)
122 changes: 122 additions & 0 deletions tests/TestAutomationComRpc/TestAutomationComRpc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 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 "TestAutomationComRpc.h"


namespace WPEFramework {
namespace Plugin {

namespace {

static Metadata<TestAutomationComRpc> metadata(
// Version
1, 0, 0,
// Preconditions
{},
// Terminations
{},
// Controls
{}
);
}

const string TestAutomationComRpc::Initialize(PluginHost::IShell* service)
{
ASSERT (_service == nullptr);
ASSERT (service != nullptr);

_service = service;
_service->AddRef();

_implementation = _service->Root<Exchange::TestAutomation::IComRpc::IComRpcInternal>(_connectionId, 2000, _T("TestAutomationComRpcImplementation"));
Exchange::TestAutomation::JComRpc::Register(*this, this);

string result;
if (_implementation == nullptr) {
result = _T("Couldn't create TestAutomationComRpc instance");
} else {

if (_connectionId == 0){ //Running this plugin in process does not make any sense. It will not do proper test!
result = _T("Running this plugin in process does not make any sense. It will not do proper test!");
}
}
return (result);
}


void TestAutomationComRpc::Deinitialize(PluginHost::IShell* service VARIABLE_IS_NOT_USED)
{
ASSERT(_service == service);

Exchange::TestAutomation::JComRpc::Unregister(*this);
if (_implementation != nullptr) {
RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));

VARIABLE_IS_NOT_USED uint32_t result = _implementation->Release();
_implementation = nullptr;

ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);

if(connection != nullptr){
connection->Terminate();
connection->Release();
}
}

_service->Release();
_service = nullptr;

}

string TestAutomationComRpc::Information() const
{
return string();
}


void TestAutomationComRpc::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));
}
}

Core::hresult TestAutomationComRpc::TestBigString(const uint32_t length)
{
printf("TestAutomationComRpc::TestBigString -> Method called!\n");
ASSERT(_implementation != nullptr);
const uint32_t stringLength = length * 1024;
string bigString;
bigString.resize(stringLength, 'a');
bigString.replace(0, 8, "testaaaa");
bigString.replace(bigString.length() - 8, 8, "testzzzz");

TRACE(Trace::Information, (_T("InP: Length Of The String Is " + std::to_string(bigString.length()))));
TRACE(Trace::Information, (_T("InP: Content Of The String Is " + bigString)));

return _implementation->BigStringTest(bigString);

}

}
}
79 changes: 79 additions & 0 deletions tests/TestAutomationComRpc/TestAutomationComRpc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 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.
*/

#ifndef __TESTAUTOMATIONCOMRPC_H
#define __TESTAUTOMATIONCOMRPC_H


#include "Module.h"
#include <interfaces/ITestAutomation.h>
#include <interfaces/json/JTestAutomationComRpc.h>

namespace WPEFramework {
namespace Plugin {

class TestAutomationComRpc : public PluginHost::IPlugin, public Exchange::TestAutomation::IComRpc, public PluginHost::JSONRPC {
public:
TestAutomationComRpc(const TestAutomationComRpc&) = delete;
TestAutomationComRpc& operator=(const TestAutomationComRpc&) = delete;

TestAutomationComRpc()
: _implementation(nullptr)
, _connectionId(0)
, _service(nullptr)

{
}

~TestAutomationComRpc() override
{
}


BEGIN_INTERFACE_MAP(TestAutomationComRpc)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IDispatcher)
INTERFACE_ENTRY(Exchange::TestAutomation::IComRpc)
END_INTERFACE_MAP

// ITestAutomationComRpc Methods
Core::hresult TestBigString(const uint32_t length) override;

// IPlugin methods
// -------------------------------------------------------------------------------------------------------
const string Initialize(PluginHost::IShell* service) override;
void Deinitialize(PluginHost::IShell* service) override;
string Information() const override;

private:
void Deactivated(RPC::IRemoteConnection* connection);

Exchange::TestAutomation::IComRpc::IComRpcInternal* _implementation;

uint32_t _connectionId;
PluginHost::IShell* _service;

};

} // Namespace Plugin.
}// namespace WPEFramework



#endif // __TESTAUTOMATIONCOMRPC_H
77 changes: 77 additions & 0 deletions tests/TestAutomationComRpc/TestAutomationComRpcImplementation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 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 <interfaces/ITestAutomation.h>

namespace WPEFramework {
namespace Plugin {

class TestAutomationComRpcImplementation : public Exchange::TestAutomation::IComRpc::IComRpcInternal {

public:
TestAutomationComRpcImplementation(const TestAutomationComRpcImplementation&) = delete;
TestAutomationComRpcImplementation& operator=(const TestAutomationComRpcImplementation&) = delete;

TestAutomationComRpcImplementation()
{
}
~TestAutomationComRpcImplementation() override = default;

BEGIN_INTERFACE_MAP(TestAutomationComRpcImplementation)
INTERFACE_ENTRY(Exchange::TestAutomation::IComRpc::IComRpcInternal)
END_INTERFACE_MAP

// IComRpcInternal Methods
Core::hresult BigStringTest(const string& testString) override
{
TRACE(Trace::Information, (_T("OOP: Length Of The String Is " + std::to_string(testString.length()))));
string text = testString.c_str();
TRACE(Trace::Information, (_T("OOP: Content Of The String Is " + text)));

uint32_t result = Core::ERROR_NONE;

if (testString.length() >= 16){
string firstFourDigit = testString.substr(0, 8);
string lastFourDigit = testString.substr((testString.length() - 8), 8);

if (firstFourDigit == "testaaaa" && lastFourDigit == "testzzzz") {
TRACE(Trace::Information, (_T("Verification Done For " + std::to_string(testString.length()/1024))));
}

else {
TRACE(Trace::Information, (_T("Verification FAILED For " + std::to_string(testString.length()/1024))));
result = Core::ERROR_GENERAL;
}
}
else {

TRACE(Trace::Information, (_T("String size is lower than 16")));
result = Core::ERROR_GENERAL;
}

return result;
}

};

SERVICE_REGISTRATION(TestAutomationComRpcImplementation, 1, 0)
} // namespace Plugin
} // namespace WPEFramework
16 changes: 16 additions & 0 deletions tests/TestAutomationComRpc/TestAutomationComRpcPlugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "plugin.schema.json",
"info": {
"title": "TestAutomationComRpc Plugin",
"callsign": "TestAutomationComRpc",
"locator": "libWPEFrameworkTestAutomationComRpc.so",
"status": "production",
"description": "TestAutomationComRpc helps you to validate COMRPC messages via Automated Tests",
"version": "1.0"
},

"interface": {
"$cppref": "{cppinterfacedir}/ITestAutomation.h"
}
}

Loading

0 comments on commit d640d4a

Please sign in to comment.