Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JotaroOfRivia committed Mar 11, 2024
1 parent 7ef035b commit a9bb71c
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 248 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
37 changes: 9 additions & 28 deletions tests/jet_server_test.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#include <gtest/gtest.h>
#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<std::string> jetStatePaths = getJetStatePaths(jetStates);
// Get component IDs of openDAQ objects
std::vector<std::string> globalIds = getComponentIDs(rootDevice);
std::vector<std::string> globalIds = getComponentIDs();
// Get Jet state paths
std::vector<std::string> 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());
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -161,23 +146,21 @@ TEST_F(JetServerTest, TestListProperty)
std::string propertyName = "TestList";
rootDevice.addProperty(ListProperty(propertyName, List<std::string>("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<std::string>("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<std::string> 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);
}
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
}
Loading

0 comments on commit a9bb71c

Please sign in to comment.