From a9bb71c9fd0b34a6a380773abb7b41aef34cac4a Mon Sep 17 00:00:00 2001 From: Nick Putkaradze Date: Thu, 7 Mar 2024 20:33:44 +0400 Subject: [PATCH] update tests --- .vscode/launch.json | 4 +- README.md | 6 +- tests/CMakeLists.txt | 10 +- tests/jet_server_test.cpp | 37 ++--- tests/jet_server_test.h | 251 +++++++----------------------- tests/property_converter_test.cpp | 23 ++- tests/property_converter_test.h | 35 +++++ 7 files changed, 118 insertions(+), 248 deletions(-) create mode 100644 tests/property_converter_test.h diff --git a/.vscode/launch.json b/.vscode/launch.json index dd4c0fc..cec463f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -54,10 +54,10 @@ "miDebuggerPath": "/usr/bin/gdb" }, { - "name": "Debug ConvertersTest", + "name": "Debug PropertyConverterTest", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/build/tests/ConvertersTest", + "program": "${workspaceFolder}/build/tests/PropertyConverterTest", "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], diff --git a/README.md b/README.md index 07be836..8fecc1c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Jet module is an integration of Jet protocol with openDAQ SDK. It publishes devi - After a device has been instantiated, create `JetServer` object: ```c++ - daq::modules::jet_module::JetServer jetServer = JetServer(device); + daq::modules::jet_module::JetServer jetServer = JetServer(opendaqInstance); ``` - Call `JetServer::publishJetStates()` to publish device structure as Jet states: @@ -22,7 +22,9 @@ Jet states are updated automatically if some property value is changed. ### CMake options -`COMPILE_REFERENCE_APPLICATION` - Compiles reference application when ON. +`COMPILE_REFERENCE_APPLICATION` - Compiles reference application when ON.\ +`JET_MODULE_ENABLE_TESTS` - Compiles tests if enabled.\ +`IGNORE_INSTALLED_SDK` - Ignores loccally installed SDK and fetches it if enabled. ## Build diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 03bd1ef..75a24a4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,19 +3,19 @@ cmake_minimum_required(VERSION 3.24) enable_testing() set(JET_SERVER_TEST_NAME JetServerTest) -set(CONVERTERS_TEST_NAME ConvertersTest) +set(PROPERTY_CONVERTER_TEST_NAME PropertyConverterTest) set(JET_SERVER_TEST_SOURCE jet_server_test.cpp) -set(CONVERTERS_TEST_SOURCE converters_test.cpp) +set(PROPERTY_CONVERTER_TEST_SOURCE property_converter_test.cpp) add_executable(${JET_SERVER_TEST_NAME} ${JET_SERVER_TEST_SOURCE}) target_link_libraries(${JET_SERVER_TEST_NAME} PUBLIC GTest::gtest_main JetModule daq::opendaq hbk jetpeer jetpeerasync jsoncpp_lib pugixml) add_compile_definitions(MODULE_PATH="${CMAKE_BINARY_DIR}") -add_executable(${CONVERTERS_TEST_NAME} ${CONVERTERS_TEST_SOURCE}) -target_link_libraries(${CONVERTERS_TEST_NAME} PUBLIC GTest::gtest_main JetModule daq::opendaq hbk jetpeer jetpeerasync jsoncpp_lib pugixml) +add_executable(${PROPERTY_CONVERTER_TEST_NAME} ${PROPERTY_CONVERTER_TEST_SOURCE}) +target_link_libraries(${PROPERTY_CONVERTER_TEST_NAME} PUBLIC GTest::gtest_main JetModule daq::opendaq hbk jetpeer jetpeerasync jsoncpp_lib pugixml) add_compile_definitions(MODULE_PATH="${CMAKE_BINARY_DIR}") include(GoogleTest) -gtest_discover_tests(${JET_SERVER_TEST_NAME} ${CONVERTERS_TEST_NAME} +gtest_discover_tests(${JET_SERVER_TEST_NAME} ${PROPERTY_CONVERTER_TEST_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests ) diff --git a/tests/jet_server_test.cpp b/tests/jet_server_test.cpp index 12171e9..4ebec02 100644 --- a/tests/jet_server_test.cpp +++ b/tests/jet_server_test.cpp @@ -1,20 +1,13 @@ #include #include "jet_server_test.h" -#include "opendaq_to_json_converters.h" -#include "json_to_opendaq_converters.h" // Checks whether all of the required Jet states are present TEST_F(JetServerTest, CheckStatePresence) { - // Publish device structure as Jet states - jetServer->publishJetStates(); - - // Read Jet states - Json::Value jetStates = readJetStates(); - // Get Jet state paths - std::vector jetStatePaths = getJetStatePaths(jetStates); // Get component IDs of openDAQ objects - std::vector globalIds = getComponentIDs(rootDevice); + std::vector globalIds = getComponentIDs(); + // Get Jet state paths + std::vector jetStatePaths = getJetStatePaths(); // Check whether there same amount of states in Jet as there are high level objects in openDAQ ASSERT_EQ(jetStatePaths.size(), globalIds.size()); @@ -37,8 +30,6 @@ TEST_F(JetServerTest, TestBoolProperty) std::string propertyName = "TestBool"; rootDevice.addProperty(BoolProperty(propertyName, true)); - jetServer->publishJetStates(); - // Check whether values are equal initially valueInJet = getPropertyValueInJet(propertyName).asBool(); valueInOpendaq = rootDevice.getPropertyValue(propertyName); @@ -68,8 +59,6 @@ TEST_F(JetServerTest, TestIntProperty) std::string propertyName = "TestInt"; rootDevice.addProperty(IntProperty(propertyName, 69420)); - jetServer->publishJetStates(); - // Check whether values are equal initially valueInJet = getPropertyValueInJet(propertyName).asInt64(); valueInOpendaq = rootDevice.getPropertyValue(propertyName); @@ -99,8 +88,6 @@ TEST_F(JetServerTest, TestFloatProperty) std::string propertyName = "TestFloat"; rootDevice.addProperty(FloatProperty(propertyName, 69420.69)); - jetServer->publishJetStates(); - // Check whether values are equal initially valueInJet = getPropertyValueInJet(propertyName).asDouble(); valueInOpendaq = rootDevice.getPropertyValue(propertyName); @@ -130,8 +117,6 @@ TEST_F(JetServerTest, TestStringProperty) std::string propertyName = "TestString"; rootDevice.addProperty(StringProperty(propertyName, "Richard Feynman")); - jetServer->publishJetStates(); - // Check whether values are equal initially valueInJet = getPropertyValueInJet(propertyName).asString(); std::string valueInOpendaq1 = rootDevice.getPropertyValue(propertyName); @@ -161,23 +146,21 @@ TEST_F(JetServerTest, TestListProperty) std::string propertyName = "TestList"; rootDevice.addProperty(ListProperty(propertyName, List("Georgia", "is", "beautiful"))); - jetServer->publishJetStates(); - // Check whether values are equal initially - valueInJet = convertJsonArrayToOpendaqList(getPropertyValueInJet(propertyName)); + valueInJet = propertyConverter.convertJsonArrayToOpendaqList(getPropertyValueInJet(propertyName)); valueInOpendaq = rootDevice.getPropertyValue(propertyName); ASSERT_EQ(valueInJet, valueInOpendaq); // Check whether property value updated from openDAQ updates value in Jet rootDevice.setPropertyValue(propertyName, List("Optimus", "Prime")); - valueInJet = convertJsonArrayToOpendaqList(getPropertyValueInJet(propertyName)); + valueInJet = propertyConverter.convertJsonArrayToOpendaqList(getPropertyValueInJet(propertyName)); valueInOpendaq = rootDevice.getPropertyValue(propertyName); EXPECT_EQ(valueInJet, valueInOpendaq); // Check whether property value updated from Jet updates value in openDAQ std::vector newValue = {"The", "first", "principle", "is", "that", "you", "must", "not", "fool", "yourself", "and", "you", "are", "the", "easiest", "person", "to", "fool."}; setPropertyListInJet(propertyName, newValue); - valueInJet = convertJsonArrayToOpendaqList(getPropertyValueInJetTimeout(propertyName, convertVectorToJson(newValue))); + valueInJet = propertyConverter.convertJsonArrayToOpendaqList(getPropertyValueInJetTimeout(propertyName, convertVectorToJson(newValue))); valueInOpendaq = rootDevice.getPropertyValue(propertyName); EXPECT_EQ(valueInJet, valueInOpendaq); } @@ -196,10 +179,8 @@ TEST_F(JetServerTest, TestDictProperty) dict.set("C", 3); rootDevice.addProperty(DictProperty(propertyName, dict)); - jetServer->publishJetStates(); - // Check whether values are equal initially - valueInJet = convertJsonDictToOpendaqDict(getPropertyValueInJet(propertyName)); + valueInJet = propertyConverter.convertJsonDictToOpendaqDict(getPropertyValueInJet(propertyName)); valueInOpendaq = rootDevice.getPropertyValue(propertyName); ASSERT_EQ(valueInJet, valueInOpendaq); @@ -209,7 +190,7 @@ TEST_F(JetServerTest, TestDictProperty) dict.set("FirstElement", 321321); dict.set("SecondElement", 666777); rootDevice.setPropertyValue(propertyName, dict); - valueInJet = convertJsonDictToOpendaqDict(getPropertyValueInJet(propertyName)); + valueInJet = propertyConverter.convertJsonDictToOpendaqDict(getPropertyValueInJet(propertyName)); valueInOpendaq = rootDevice.getPropertyValue(propertyName); EXPECT_EQ(valueInJet, valueInOpendaq); @@ -219,7 +200,7 @@ TEST_F(JetServerTest, TestDictProperty) dictJson["Element2"] = 3; dictJson["Element3"] = 5; setPropertyValueInJet(propertyName, dictJson); - valueInJet = convertJsonDictToOpendaqDict(getPropertyValueInJetTimeout(propertyName, dictJson)); + valueInJet = propertyConverter.convertJsonDictToOpendaqDict(getPropertyValueInJetTimeout(propertyName, dictJson)); valueInOpendaq = rootDevice.getPropertyValue(propertyName); EXPECT_EQ(valueInJet, valueInOpendaq); } diff --git a/tests/jet_server_test.h b/tests/jet_server_test.h index db8b9b5..1f71fff 100644 --- a/tests/jet_server_test.h +++ b/tests/jet_server_test.h @@ -16,11 +16,14 @@ #pragma once #include #include -#include #include #include #include #include +#include "jet_server.h" +#include "jet_peer_wrapper.h" +#include "property_converter.h" +#include "jet_event_handler.h" #define JET_GET_VALUE_TIMEOUT (1) // 1 second @@ -29,22 +32,6 @@ using namespace daq; using namespace daq::modules::jet_module; using namespace hbk::jet; - -/****************************************************************************************** - * Function prototypes -*******************************************************************************************/ - -Json::Value readJetStates(); -static void readJetStatesCb(std::promise& promise, const Json::Value& value); -std::vector getJetStatePaths(const Json::Value& jetStates); -std::vector getComponentIDs(const FolderPtr& parentFolder); -void parseFolder(const FolderPtr& parentFolder, std::vector& globalIdVector); -void modifyJetState(const char* valueType, const std::string& path, const char* newValue); - - -// Used to read Jet states from PeerAsync -static hbk::sys::EventLoop eventloop; - /** * @brief Creates openDAQ instance using device from openDAQ's 'ref_device_module'. * Creates a JetServer object which can be used to publish openDAQ device structure as Jet states. @@ -55,13 +42,18 @@ class JetServerTest : public ::testing::Test { daq::InstancePtr instance; daq::DevicePtr rootDevice; JetServer* jetServer; + JetPeerWrapper& jetPeerWrapper = JetPeerWrapper::getInstance(); + PropertyConverter propertyConverter; + JetEventHandler jetEventHandler; std::string rootDevicePath; virtual void SetUp() { instance = daq::Instance(MODULE_PATH); instance.setRootDevice("daqref://device0"); rootDevice = instance.getRootDevice(); - jetServer = new JetServer(rootDevice); + jetServer = new JetServer(instance); + jetServer->publishJetStates(); + rootDevicePath = toStdString(rootDevice.getGlobalId()); } @@ -71,10 +63,12 @@ class JetServerTest : public ::testing::Test { Json::Value getPropertyValueInJet(const std::string& propertyName); Json::Value getPropertyValueInJetTimeout(const std::string& propertyName, const Json::Value& expectedValue); - Json::Value getPropertyListInJet(const std::string& propertyName); - Json::Value getPropertyListInJetTimeout(const std::string& propertyName, const std::vector& expectedValueVector); void setPropertyValueInJet(const std::string& propertyName, const Json::Value& newValue); void setPropertyListInJet(const std::string& propertyName, const std::vector& newValue); + + std::vector getComponentIDs(); + std::vector getJetStatePaths(); + void parseOpendaqInstance(const FolderPtr& parentFolder, std::vector& globalIdVector); }; /** @@ -85,7 +79,7 @@ class JetServerTest : public ::testing::Test { */ Json::Value JetServerTest::getPropertyValueInJet(const std::string& propertyName) { - Json::Value jetState = jetServer->readJetState(rootDevice.getGlobalId()); + Json::Value jetState = jetPeerWrapper.readJetState(rootDevice.getGlobalId()); Json::Value valueInJet = jetState.get(propertyName, Json::Value()); // default value is empty Json return valueInJet; } @@ -115,56 +109,6 @@ Json::Value JetServerTest::getPropertyValueInJetTimeout(const std::string& prope return valueInJet; } -/** - * @brief Gets a list property value from a Jet state. - * - * @param propertyName Name of the property. - * @return Json::Value object which contains the property value in the Jet state. - */ -Json::Value JetServerTest::getPropertyListInJet(const std::string& propertyName) -{ - Json::Value jetStates = readJetStates(); - for (const Json::Value& item : jetStates) { - if (item[hbk::jet::PATH] == rootDevicePath) { - Json::Value valueInJet = item[hbk::jet::VALUE]; - return valueInJet; - } - } - return Json::Value(); // Return empty json if not found -} - -/** - * @brief Gets a list property value from a Jet state. Expected value is passed to repeteadly read a Jet state for a given time. This is needed - * in cases where value change in Jet needs some time to be propagated. - * - * @param propertyName Name of the property. - * @param expectedValueVector Value expected to be read from a Jet state. - * @return Json::Value object which contains the property value in the Jet state. - */ -Json::Value JetServerTest::getPropertyListInJetTimeout(const std::string& propertyName, const std::vector& expectedValueVector) -{ - Json::Value expectedValueJson; - Json::Value array(Json::arrayValue); - for (auto val : expectedValueVector) { - array.append(val); - } - expectedValueJson[propertyName] = array; - - Json::Value valueInJet; - - auto startTime = std::chrono::high_resolution_clock::now(); - auto timeout = std::chrono::seconds(JET_GET_VALUE_TIMEOUT); - do { - valueInJet = getPropertyListInJet(propertyName); - if (valueInJet == expectedValueJson) { - break; - } - std::this_thread::sleep_for(std::chrono::milliseconds(50)); // Wait a bit before retrying - } while (std::chrono::high_resolution_clock::now() - startTime < timeout); - - return valueInJet; -} - /** * @brief Sets a property value in a Jet state. * @@ -173,11 +117,7 @@ Json::Value JetServerTest::getPropertyListInJetTimeout(const std::string& proper */ void JetServerTest::setPropertyValueInJet(const std::string& propertyName, const Json::Value& newValue) { - Json::Value root; - root[propertyName] = newValue; - Json::StreamWriterBuilder builder; - const std::string jsonValue = Json::writeString(builder, root); - modifyJetState("json", rootDevicePath, jsonValue.c_str()); + jetEventHandler.updateProperty(rootDevice, propertyName, newValue); } /** @@ -188,59 +128,11 @@ void JetServerTest::setPropertyValueInJet(const std::string& propertyName, const */ void JetServerTest::setPropertyListInJet(const std::string& propertyName, const std::vector& newValue) { - Json::Value root; Json::Value array(Json::arrayValue); for (auto val : newValue) { array.append(val); } - root[propertyName] = array; - Json::StreamWriterBuilder builder; - const std::string jsonValue = Json::writeString(builder, root); - modifyJetState("json", rootDevicePath, jsonValue.c_str()); -} - -/** - * @brief Reads all of the published Jet states. - * - * @return Object containg Jet states. - */ -Json::Value readJetStates() -{ - std::string address("127.0.0.1"); - unsigned int port = hbk::jet::JETD_TCP_PORT; - hbk::jet::matcher_t match; - hbk::jet::PeerAsync peer(eventloop, address, port); - - // Create a promise and future - std::promise promise; - std::future future = promise.get_future(); - - // Calls the callback function with the promise - peer.getAsync(match, [&promise](const Json::Value& value) { - readJetStatesCb(promise, value); - }); - - eventloop.execute(); - - // Wait for the future to get the value - Json::Value result = future.get(); - return result; -} - -/** - * @brief Callback function for readJetStates function. It gets Jet states from PeerAsync. - * - * @param promise Value which will be set once Jet states are read from PeerAsync. - * @param value Json::Value which contains Jet states. - */ -static void readJetStatesCb(std::promise& promise, const Json::Value& value) -{ - // value contains the data as an array of objects - Json::Value publishedJsonValue = value[hbk::jsonrpc::RESULT]; - promise.set_value(publishedJsonValue); - - // Stop the event loop - eventloop.stop(); + jetEventHandler.updateProperty(rootDevice, propertyName, array); } /** @@ -250,8 +142,9 @@ static void readJetStatesCb(std::promise& promise, const Json::Valu * @param jetStates Json::Value objects which contain whole Jet states. * @return Vector containing paths of the Jet states. */ -std::vector getJetStatePaths(const Json::Value& jetStates) +std::vector JetServerTest::getJetStatePaths() { + Json::Value jetStates = jetPeerWrapper.readAllJetStates(); // Vector which will be filled with paths of Jet states std::vector jetStatePaths; for (const Json::Value &item : jetStates) { @@ -267,15 +160,15 @@ std::vector getJetStatePaths(const Json::Value& jetStates) * @param parentFolder Root device, which is parsed to retrieve all objects under it. * @return Vector containing Global IDs of openDAQ components. */ -std::vector getComponentIDs(const FolderPtr& parentFolder) +std::vector JetServerTest::getComponentIDs() { // Vector which is filled with global IDs of components std::vector globalIdVector; // We have to add global ID of the root device manually as it's not added when it is parsed - globalIdVector.push_back(parentFolder.asPtrOrNull().getGlobalId()); + globalIdVector.push_back(rootDevice.getGlobalId()); // Get IDs of the components under the device - parseFolder(parentFolder, globalIdVector); + parseOpendaqInstance(instance, globalIdVector); return globalIdVector; } @@ -286,87 +179,47 @@ std::vector getComponentIDs(const FolderPtr& parentFolder) * @param parentFolder Root device, which is parsed to retrieve all objects under it. * @param globalIdVector Vector of strings which is filled with Global IDs. */ -void parseFolder(const FolderPtr& parentFolder, std::vector& globalIdVector) +void JetServerTest::parseOpendaqInstance(const FolderPtr& parentFolder, std::vector& globalIdVector) { - auto items = parentFolder.getItems(); + auto items = parentFolder.getItems(search::Any()); for(const auto& item : items) { auto folder = item.asPtrOrNull(); - auto channel = item.asPtrOrNull(); auto component = item.asPtrOrNull(); + auto device = item.asPtrOrNull(); + auto functionBlock = item.asPtrOrNull(); + auto channel = item.asPtrOrNull(); + auto signal = item.asPtrOrNull(); + auto inputPort = item.asPtrOrNull(); - if (channel.assigned()) - { - std::string globalId = channel.getGlobalId(); - globalIdVector.push_back(globalId); + if(device.assigned()) { + globalIdVector.push_back(device.getGlobalId()); } - else if (folder.assigned()) // It is important to test for folder last as a channel also is a folder! - { - parseFolder(folder, globalIdVector); // Folders are recursively parsed until non-folder items are identified in them + else if(channel.assigned()) { + globalIdVector.push_back(channel.getGlobalId()); } - else if (component.assigned()) // It is important to test for component after folder! - { - std::string globalId = component.getGlobalId(); - globalIdVector.push_back(globalId); + else if(functionBlock.assigned()) { + globalIdVector.push_back(functionBlock.getGlobalId()); } - } -} - -/** - * @brief Modifies Jet state. - * - * @param valueType Type of the value that has to be modified. As all of the Jet states besides the methods are published with Json types, - * use "json" as an argument. - * @param path Path of the Jet state that is needed to be modified. - * @param newValue New value of the Jet state. - */ -void modifyJetState(const char* valueType, const std::string& path, const char* newValue) -{ - unsigned int port = hbk::jet::JETD_TCP_PORT; - std::string address("127.0.0.1"); - hbk::jet::Peer peer(address, port); - // hbk::jet::PeerAsync peer(eventloop, address, port); - if(strcmp(valueType, "bool") == 0) - { - if(strcmp(newValue, "false") == 0) - { - peer.setStateValue(path, false, 2.71828182846); - } - else if (strcmp(newValue, "true") == 0) - { - peer.setStateValue(path, true, 2.71828182846); - } - else - { - std::cerr << "invalid value for boolean expecting 'true'', or 'false'" << std::endl; + else if(signal.assigned()) { + globalIdVector.push_back(signal.getGlobalId()); + } + else if(inputPort.assigned()) { + globalIdVector.push_back(inputPort.getGlobalId()); + } + else if(folder.assigned()) { // It is important to test for folder last as everything besides component is a folder as well + // We do nothing here because we want to identify pure components (not its descendants) + // Recursion is done in separate if statement + } + else if(component.assigned()) { // It is important to test for component after folder! + globalIdVector.push_back(component.getGlobalId()); + } + else { + // throwJetModuleException(JM_UNSUPPORTED_ITEM); } - } - else if(strcmp(valueType,"int")==0) - { - int value = atoi(newValue); - peer.setStateValue(path, value, 2.71828182846); - } - else if(strcmp(valueType, "double")==0) - { - double value = strtod(newValue, nullptr); - peer.setStateValue(path, value, 2.71828182846); - } - else if(strcmp(valueType,"string")==0) - { - peer.setStateValue(path, newValue, 2.71828182846); - } - else if(strcmp(valueType,"json")==0) - { - Json::Value params; - Json::CharReaderBuilder rBuilder; - if(rBuilder.newCharReader()->parse(newValue, newValue+strlen(newValue), ¶ms, nullptr)) - { - peer.setStateValue(path, params, 2.71828182846); - } - else - { - std::cerr << "error while parsing json!" << std::endl; + if(folder.assigned()) { + parseOpendaqInstance(folder, globalIdVector); } } } diff --git a/tests/property_converter_test.cpp b/tests/property_converter_test.cpp index a3e6a0e..5e78bb2 100644 --- a/tests/property_converter_test.cpp +++ b/tests/property_converter_test.cpp @@ -1,16 +1,15 @@ +#include "property_converter_test.h" #include -#include -#include "json_to_opendaq_converters.h" using namespace daq; -TEST(OpendaqToJsonConverters, TestListConversion) +TEST_F(PropertyConverterTest, OpendaqListToJsonArray) { ListPtr opendaqList = List(33, 69, 42, 420, 37); CoreType listItemType = CoreType::ctInt; - Json::Value jsonArray = convertOpendaqListToJsonArray(opendaqList, listItemType); + Json::Value jsonArray = propertyConverter.convertOpendaqListToJsonArray(opendaqList, listItemType); // Ensure that arrays contain same number of elements ASSERT_EQ(jsonArray.size(), opendaqList.getCount()); @@ -23,7 +22,7 @@ TEST(OpendaqToJsonConverters, TestListConversion) } } -TEST(OpendaqToJsonConverters, TestDictConversion) +TEST_F(PropertyConverterTest, OpendaqDictToJsonDict) { DictPtr opendaqDict = Dict(); opendaqDict.set("number2", 33); @@ -33,7 +32,7 @@ TEST(OpendaqToJsonConverters, TestDictConversion) opendaqDict.set("number5", 37); CoreType dictItemType = CoreType::ctInt; - Json::Value jsonDict = convertOpendaqDictToJsonDict(opendaqDict, dictItemType); + Json::Value jsonDict = propertyConverter.convertOpendaqDictToJsonDict(opendaqDict, dictItemType); ListPtr keyList = opendaqDict.getKeyList(); @@ -49,7 +48,7 @@ TEST(OpendaqToJsonConverters, TestDictConversion) } } -TEST(JsonToOpendaqConverters, TestListConversion) +TEST_F(PropertyConverterTest, JsonArrayToOpendaqList) { Json::Value jsonArray(Json::arrayValue); jsonArray.append("Khachapuri"); @@ -58,7 +57,7 @@ TEST(JsonToOpendaqConverters, TestListConversion) jsonArray.append("Kharcho"); jsonArray.append("Churchkhela"); - ListPtr opendaqList = convertJsonArrayToOpendaqList(jsonArray); + ListPtr opendaqList = propertyConverter.convertJsonArrayToOpendaqList(jsonArray); // Ensure that arrays contain same number of elements ASSERT_EQ(jsonArray.size(), opendaqList.getCount()); @@ -71,14 +70,14 @@ TEST(JsonToOpendaqConverters, TestListConversion) } } -TEST(JsonToOpendaqConverters, TestDictConversion) +TEST_F(PropertyConverterTest, JsonDictToOpendaqDict) { Json::Value jsonDict; jsonDict["animal1"] = "Tortoise"; jsonDict["animal2"] = "Penguin"; jsonDict["animal3"] = "Alligator"; - DictPtr opendaqDict = convertJsonDictToOpendaqDict(jsonDict); + DictPtr opendaqDict = propertyConverter.convertJsonDictToOpendaqDict(jsonDict); ListPtr keyList = opendaqDict.getKeyList(); @@ -95,7 +94,7 @@ TEST(JsonToOpendaqConverters, TestDictConversion) } -TEST(JsonToOpendaqConverters, TestObjectConversion) +TEST_F(PropertyConverterTest, JsonObjectToOpendaqObject) { Json::Value grandparent; Json::Value parent; @@ -105,7 +104,7 @@ TEST(JsonToOpendaqConverters, TestObjectConversion) parent["Child"] = child; grandparent["Parent"] = parent; - PropertyObjectPtr propertyObject = convertJsonObjectToOpendaqObject(grandparent, ""); + PropertyObjectPtr propertyObject = propertyConverter.convertJsonObjectToOpendaqObject(grandparent, ""); // Creating the same openDAQ property object manually. It can't be used in GTest for a direct comparison // auto childOpendaq = PropertyObject(); diff --git a/tests/property_converter_test.h b/tests/property_converter_test.h new file mode 100644 index 0000000..38aa28c --- /dev/null +++ b/tests/property_converter_test.h @@ -0,0 +1,35 @@ +/* + * Copyright 2022-2023 Blueberry d.o.o. + * + * 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 +#include +#include "property_converter.h" + +using namespace daq; +using namespace daq::modules::jet_module; +// using namespace hbk::jet; + +class PropertyConverterTest : public ::testing::Test { +protected: + PropertyConverter propertyConverter; + + virtual void SetUp() { + propertyConverter = PropertyConverter(); + } + + virtual void TearDown() { + } +}; \ No newline at end of file