Move Mujoco USD test fixture out of MJCF plugin directory and rename to test_utils.

PiperOrigin-RevId: 753183581
Change-Id: Iedd6594ac679ca026f8af29c647d18ae93003a53
This commit is contained in:
Sam Haves
2025-04-30 08:43:18 -07:00
committed by Copybara-Service
parent 177fce9fa1
commit bb07fa0c78
3 changed files with 8 additions and 2 deletions
@@ -1,64 +0,0 @@
// Copyright 2025 DeepMind Technologies Limited
//
// 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.
#include "test/experimental/usd/plugins/mjcf/fixture.h"
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <pxr/usd/sdf/assetPath.h>
#include <pxr/usd/sdf/declareHandles.h>
#include <pxr/usd/sdf/fileFormat.h>
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usd/common.h>
#include <pxr/usd/usd/modelAPI.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/mesh.h>
#include <pxr/usd/usdGeom/primvarsAPI.h>
namespace mujoco {
using pxr::SdfPath;
pxr::SdfLayerRefPtr LoadLayer(
const std::string& xml,
const pxr::SdfFileFormat::FileFormatArguments& args) {
auto layer = pxr::SdfLayer::CreateAnonymous(
"test_layer", pxr::SdfFileFormat::FindByExtension("xml"), args);
layer->ImportFromString(xml);
EXPECT_THAT(layer, testing::NotNull());
return layer;
}
template <>
void ExpectAttributeEqual<pxr::SdfAssetPath>(pxr::UsdStageRefPtr stage,
const char* path,
const pxr::SdfAssetPath& value) {
auto attr = stage->GetAttributeAtPath(pxr::SdfPath(path));
EXPECT_TRUE(attr.IsValid());
pxr::SdfAssetPath attr_value;
attr.Get(&attr_value);
EXPECT_EQ(attr_value.GetAssetPath(), value.GetAssetPath());
}
void ExpectAttributeHasConnection(pxr::UsdStageRefPtr stage, const char* path,
const char* connection_path) {
auto attr = stage->GetAttributeAtPath(SdfPath(path));
EXPECT_TRUE(attr.IsValid());
pxr::SdfPathVector sources;
attr.GetConnections(&sources);
EXPECT_EQ(sources.size(), 1);
EXPECT_EQ(sources[0], SdfPath(connection_path));
}
} // namespace mujoco
@@ -1,98 +0,0 @@
// Copyright 2025 DeepMind Technologies Limited
//
// 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.
#ifndef MUJOCO_TEST_EXPERIMENTAL_USD_PLUGINS_MJCF_FIXTURE_H_
#define MUJOCO_TEST_EXPERIMENTAL_USD_PLUGINS_MJCF_FIXTURE_H_
#include <string>
#include <gtest/gtest.h>
#include <pxr/usd/sdf/assetPath.h>
#include <pxr/usd/sdf/declareHandles.h>
#include <pxr/usd/sdf/fileFormat.h>
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usd/common.h>
#include <pxr/usd/usd/modelAPI.h>
#include <pxr/usd/usd/stage.h>
#define EXPECT_PRIM_VALID(stage, path) \
EXPECT_TRUE((stage)->GetPrimAtPath(SdfPath(path)).IsValid());
#define EXPECT_PRIM_IS_A(stage, path, type) \
{ \
EXPECT_TRUE((stage)->GetPrimAtPath(SdfPath(path)).IsA<type>()); \
}
#define EXPECT_PRIM_API_APPLIED(stage, path, api) \
{ \
EXPECT_TRUE((stage)->GetPrimAtPath(SdfPath(path)).HasAPI<api>()); \
}
#define EXPECT_PRIM_API_NOT_APPLIED(stage, path, api) \
{ \
EXPECT_FALSE((stage)->GetPrimAtPath(SdfPath(path)).HasAPI<api>()); \
}
#define EXPECT_PRIM_KIND(stage, path, kind) \
{ \
pxr::TfToken prim_kind; \
pxr::UsdModelAPI::Get(stage, SdfPath(path)).GetKind(&prim_kind); \
EXPECT_EQ(kind, prim_kind); \
}
#define EXPECT_PRIM_PURPOSE(stage, path, purpose) \
{ \
pxr::TfToken prim_purpose; \
pxr::UsdGeomImageable::Get(stage, SdfPath(path)) \
.GetPurposeAttr() \
.Get(&prim_purpose); \
EXPECT_EQ(prim_purpose, purpose); \
}
#define EXPECT_ATTRIBUTE_HAS_VALUE(stage, path) \
EXPECT_TRUE((stage)->GetAttributeAtPath(SdfPath(path)).HasValue());
#define EXPECT_ATTRIBUTE_HAS_NO_VALUE(stage, path) \
EXPECT_FALSE((stage)->GetAttributeAtPath(SdfPath(path)).HasValue());
namespace mujoco {
pxr::SdfLayerRefPtr LoadLayer(
const std::string& xml,
const pxr::SdfFileFormat::FileFormatArguments& args = {});
template <typename T>
void ExpectAttributeEqual(pxr::UsdStageRefPtr stage, const char* path,
const T& value) {
auto attr = stage->GetAttributeAtPath(pxr::SdfPath(path));
EXPECT_TRUE(attr.IsValid()) << "Attribute " << path << " is not valid";
T attr_value;
attr.Get(&attr_value);
EXPECT_EQ(attr_value, value) << "Attribute " << path << " has value "
<< attr_value << ". Expected: " << value;
}
// Specialization for SdfAssetPath, so that we can compare only the asset path
// and not care about whatever the resolved path is.
// Otherwise the default operator== would fail because it tests for equality of
// the asset path AND the resolved path.
template <>
void ExpectAttributeEqual<pxr::SdfAssetPath>(pxr::UsdStageRefPtr stage,
const char* path,
const pxr::SdfAssetPath& value);
void ExpectAttributeHasConnection(pxr::UsdStageRefPtr stage, const char* path,
const char* connection_path);
} // namespace mujoco
#endif // MUJOCO_TEST_EXPERIMENTAL_USD_PLUGINS_MJCF_FIXTURE_H_
@@ -17,7 +17,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "test/experimental/usd/plugins/mjcf/fixture.h"
#include "test/experimental/usd/test_utils.h"
#include "test/fixture.h"
#include <pxr/base/gf/vec2f.h>
#include <pxr/base/gf/vec3f.h>
@@ -56,6 +56,7 @@ TF_DEFINE_PRIVATE_TOKENS(_tokens,
PXR_NAMESPACE_CLOSE_SCOPE
namespace mujoco {
namespace usd {
namespace {
using pxr::SdfPath;
@@ -730,4 +731,5 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsColliders) {
}
} // namespace
} // namespace usd
} // namespace mujoco