From 2c517bc737e846b9b7e04b83788c1e8d5a32340c Mon Sep 17 00:00:00 2001 From: Sebastian Schildt Date: Fri, 1 Jul 2022 18:14:45 +0200 Subject: [PATCH] Add unittest for getDatattypeForPath Signed-off-by: Sebastian Schildt --- .../test/unit-test/VssDatabaseTests.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/kuksa-val-server/test/unit-test/VssDatabaseTests.cpp b/kuksa-val-server/test/unit-test/VssDatabaseTests.cpp index fe8921fcb..7c7f923da 100644 --- a/kuksa-val-server/test/unit-test/VssDatabaseTests.cpp +++ b/kuksa-val-server/test/unit-test/VssDatabaseTests.cpp @@ -483,5 +483,38 @@ BOOST_AUTO_TEST_CASE(applyDefaultValues_Recurse) { } +/** getDataTypeTests **/ +BOOST_AUTO_TEST_CASE(getDataTypeForSensor) { + db->initJsonTree(validFilename); + std::string path = "Vehicle.Speed"; + std::string dt = db->getDatatypeForPath(VSSPath::fromVSS(path)); + BOOST_TEST(dt == "int32"); +} + +BOOST_AUTO_TEST_CASE(getDataTypeForAttribute) { + db->initJsonTree(validFilename); + std::string path = "Vehicle/VehicleIdentification/VIN"; + std::string dt = db->getDatatypeForPath(VSSPath::fromVSS(path)); + BOOST_TEST(dt == "string"); +} + +BOOST_AUTO_TEST_CASE(getDataTypeForActuator) { + db->initJsonTree(validFilename); + std::string path = "Vehicle/Cabin/Door/Row1/Right/IsLocked"; + std::string dt = db->getDatatypeForPath(VSSPath::fromVSS(path)); + BOOST_TEST(dt == "boolean"); +} + +BOOST_AUTO_TEST_CASE(getDataTypeForBranch) { + db->initJsonTree(validFilename); + std::string path = "Vehicle/Body"; + BOOST_CHECK_THROW(db->getDatatypeForPath(VSSPath::fromVSS(path)), genException); +} + +BOOST_AUTO_TEST_CASE(getDataTypeForNonExistingPath) { + db->initJsonTree(validFilename); + std::string path = "Vehicle/FluxCapacitor/Charge"; + BOOST_CHECK_THROW(db->getDatatypeForPath(VSSPath::fromVSS(path)), noPathFoundonTree); +} BOOST_AUTO_TEST_SUITE_END()