Skip to content

Commit 7a4ce0a

Browse files
committed
add tests
Signed-off-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com>
1 parent 238ee64 commit 7a4ce0a

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

test/usd/upAxisZ.usda

+12
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def Xform "box" (
121121
uniform token[] xformOpOrder = ["xformOp:scale"]
122122
}
123123
}
124+
125+
def DiskLight "boxModelLight" (
126+
prepend apiSchemas = ["ShapingAPI"]
127+
kind = "model"
128+
)
129+
{
130+
float inputs:intensity = 3000
131+
float inputs:specular = 0.5
132+
float3 xformOp:rotateZYX = (0, 0, 45)
133+
float3 xformOp:translate = (0, 0, 1000)
134+
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateZYX"]
135+
}
124136
}
125137
}
126138

usd/src/usd_parser/usd2sdf_TEST.cc

+31-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <ignition/utilities/ExtraTestMacros.hh>
2727

28+
#include "sdf/Light.hh"
29+
#include "sdf/Link.hh"
2830
#include "sdf/Model.hh"
2931
#include "sdf/Root.hh"
3032
#include "sdf/World.hh"
@@ -121,6 +123,16 @@ TEST(check_cmd, IGN_UTILS_TEST_DISABLED_ON_WIN32(SDF))
121123
EXPECT_EQ(
122124
"ignition-gazebo-scene-broadcaster-system", plugins[3].Filename());
123125

126+
// the world should have lights attached to it
127+
std::set<std::string> savedLightNames;
128+
for (unsigned int i = 0; i < world->LightCount(); ++i)
129+
savedLightNames.insert(world->LightByIndex(i)->Name());
130+
EXPECT_EQ(3u, savedLightNames.size());
131+
132+
EXPECT_NE(savedLightNames.end(), savedLightNames.find("defaultLight"));
133+
EXPECT_NE(savedLightNames.end(), savedLightNames.find("diskLight"));
134+
EXPECT_NE(savedLightNames.end(), savedLightNames.find("sun"));
135+
124136
// make sure all models in the USD file were correctly parsed to SDF
125137
std::set<std::string> savedModelNames;
126138
for (unsigned int i = 0; i < world->ModelCount(); ++i)
@@ -140,20 +152,30 @@ TEST(check_cmd, IGN_UTILS_TEST_DISABLED_ON_WIN32(SDF))
140152
ASSERT_NE(nullptr, world->ModelByName("box"));
141153
EXPECT_FALSE(world->ModelByName("box")->Static());
142154

143-
// check that models have the right links
144-
std::function<void(const std::string &, const std::string &)> checkLink =
145-
[&world](const std::string &_modelName, const std::string &_linkName)
155+
// Check that models have the right links.
156+
// If a link should have a light attached to it, check that as well
157+
std::function<void(const std::string &, const std::string &,
158+
const std::string &)> checkLink =
159+
[&world](const std::string &_modelName, const std::string &_linkName,
160+
const std::string &_lightLinkName)
146161
{
147162
const auto modelPtr = world->ModelByName(_modelName);
148163
ASSERT_NE(nullptr, modelPtr);
149164
EXPECT_EQ(1u, modelPtr->LinkCount());
150165
EXPECT_NE(nullptr, modelPtr->LinkByName(_linkName));
166+
167+
if (!_lightLinkName.empty())
168+
{
169+
auto modelLink = modelPtr->LinkByName(_linkName);
170+
ASSERT_NE(nullptr, modelLink);
171+
EXPECT_NE(nullptr, modelLink->LightByName(_lightLinkName));
172+
}
151173
};
152-
checkLink("ground_plane", "link");
153-
checkLink("box", "box_link");
154-
checkLink("cylinder", "cylinder_link");
155-
checkLink("sphere", "sphere_link");
156-
checkLink("capsule", "capsule_link");
157-
checkLink("ellipsoid", "ellipsoid_link");
174+
checkLink("ground_plane", "link", "");
175+
checkLink("box", "box_link", "boxModelLight");
176+
checkLink("cylinder", "cylinder_link", "");
177+
checkLink("sphere", "sphere_link", "");
178+
checkLink("capsule", "capsule_link", "");
179+
checkLink("ellipsoid", "ellipsoid_link", "");
158180
}
159181
}

0 commit comments

Comments
 (0)