From 9364c094f4c0d6a24c79394baecd646883bbb484 Mon Sep 17 00:00:00 2001 From: elser Date: Tue, 17 Oct 2023 14:33:17 -0400 Subject: [PATCH] WIP writing more UsdUtil tests --- tests/src/ObjectPoolTests.cpp | 2 +- tests/src/UsdUtilTests.cpp | 50 ++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tests/src/ObjectPoolTests.cpp b/tests/src/ObjectPoolTests.cpp index b821a92d2..4619441a1 100644 --- a/tests/src/ObjectPoolTests.cpp +++ b/tests/src/ObjectPoolTests.cpp @@ -80,7 +80,7 @@ void testRandomSequenceOfCmds(MockObjectPool& opl, int numEvents, bool setCap) { if (maxActiveCount != 0) { expectedPercentActive = (float)numActive / (float)maxActiveCount; } else { - expectedPercentActive = 0; + expectedPercentActive = 1; } CHECK(opl.computePercentActive() <= expectedPercentActive); } diff --git a/tests/src/UsdUtilTests.cpp b/tests/src/UsdUtilTests.cpp index af394bd59..755af1aeb 100644 --- a/tests/src/UsdUtilTests.cpp +++ b/tests/src/UsdUtilTests.cpp @@ -3,9 +3,57 @@ #include "cesium/omniverse/UsdUtil.h" #include +#include +#include +#include +#include + +namespace cesium::omniverse::UsdUtil { TEST_SUITE("UsdUtil tests") { TEST_CASE("Check expected initial state") { - CHECK(cesium::omniverse::UsdUtil::primExists(pxr::SdfPath("/Cesium"))); + auto cesiumObjPath = pxr::SdfPath("/Cesium"); + CHECK(hasStage()); + CHECK(primExists(cesiumObjPath)); + // TODO can we check something invisible here too? + CHECK(isPrimVisible(cesiumObjPath)); + } + + TEST_CASE("Check glm/usd conversion functions") { + glm::dmat4 matrix(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + + // Round-trip conversion of usd/glm matrix + CHECK(matrix == usdToGlmMatrix(glmToUsdMatrix(matrix))); + } + + TEST_CASE("Tests that require prim creation") { + auto stage = getUsdStage(); + auto primPath = getPathUnique(getRootPath(), "CesiumTestPrim"); + auto prim = stage->DefinePrim(primPath); + + // Intentionally try the same prim name + auto cubePath = getPathUnique(getRootPath(), "CesiumTestPrim"); + // Tests getPathUnique actually returns unique paths + CHECK(primPath.GetPrimPath() != cubePath.GetPrimPath()); + + auto cube = pxr::UsdGeomCube::Define(stage, cubePath); + + auto xformApiCube = pxr::UsdGeomXformCommonAPI(cube); + xformApiCube.SetRotate({30, 60, 90}); + xformApiCube.SetScale({5, 12, 13}); + xformApiCube.SetTranslate({3, 4, 5}); + + auto xformableCube = pxr::UsdGeomXformable(cube); + + pxr::GfMatrix4d cubeXform; + bool xformStackResetNeeded [[maybe_unused]]; + + xformableCube.GetLocalTransformation(&cubeXform, &xformStackResetNeeded); + + CHECK(usdToGlmMatrix(cubeXform) == computeUsdLocalToWorldTransform(cubePath)); + + // stage->RemovePrim(primPath); + // stage->RemovePrim(cubePath); } } +} // namespace cesium::omniverse::UsdUtil