From d58302b05ec7bbae91c9bceb62ec49fe4142e6cf Mon Sep 17 00:00:00 2001 From: Jonathan Stone Date: Sat, 6 Apr 2024 11:29:11 -0700 Subject: [PATCH] Add core utility unit tests This changelist adds a handful of new unit tests for core utilities, bringing the measured code coverage of MaterialX unit tests to 88.4%. --- source/MaterialXTest/MaterialXCore/CoreUtil.cpp | 8 ++++++++ source/MaterialXTest/MaterialXCore/Document.cpp | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/source/MaterialXTest/MaterialXCore/CoreUtil.cpp b/source/MaterialXTest/MaterialXCore/CoreUtil.cpp index a308354e25..11aa826d4f 100644 --- a/source/MaterialXTest/MaterialXCore/CoreUtil.cpp +++ b/source/MaterialXTest/MaterialXCore/CoreUtil.cpp @@ -28,6 +28,14 @@ TEST_CASE("String utilities", "[coreutil]") REQUIRE(mx::splitString("robot1, robot2", ", ") == (std::vector{"robot1", "robot2"})); REQUIRE(mx::splitString("[one...two...three]", "[.]") == (std::vector{"one", "two", "three"})); + + REQUIRE(mx::stringToLower("testName") == "testname"); + REQUIRE(mx::stringToLower("testName1") == "testname1"); + + REQUIRE(mx::stringStartsWith("testName", "test")); + REQUIRE(!mx::stringStartsWith("testName", "Name")); + REQUIRE(mx::stringEndsWith("testName", "Name")); + REQUIRE(!mx::stringEndsWith("testName", "test")); } TEST_CASE("Print utilities", "[coreutil]") diff --git a/source/MaterialXTest/MaterialXCore/Document.cpp b/source/MaterialXTest/MaterialXCore/Document.cpp index 9670c54283..fb35e58ccb 100644 --- a/source/MaterialXTest/MaterialXCore/Document.cpp +++ b/source/MaterialXTest/MaterialXCore/Document.cpp @@ -17,6 +17,13 @@ TEST_CASE("Document", "[document]") // Create a document. mx::DocumentPtr doc = mx::createDocument(); + // Test version strings. + REQUIRE(mx::stringStartsWith(mx::getVersionString(), doc->getVersionString())); + + // Test version integers. + REQUIRE(doc->getVersionIntegers().first == std::get<0>(mx::getVersionIntegers())); + REQUIRE(doc->getVersionIntegers().second == std::get<1>(mx::getVersionIntegers())); + // Create a node graph with a constant color output. mx::NodeGraphPtr nodeGraph = doc->addNodeGraph(); mx::NodePtr constant = nodeGraph->addNode("constant");