Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marip8 committed Dec 13, 2024
1 parent 3af9919 commit f48851c
Show file tree
Hide file tree
Showing 25 changed files with 732 additions and 449 deletions.
24 changes: 16 additions & 8 deletions tesseract_urdf/test/tesseract_urdf_box_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ TEST(TesseractURDFUnit, parse_box) // NOLINT
{
std::string str = R"(<box size="1 2.0 3" extra="0 0 0"/>)";
tesseract_geometry::Box::Ptr geom;
EXPECT_TRUE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_TRUE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
EXPECT_NEAR(geom->getX(), 1, 1e-8);
EXPECT_NEAR(geom->getY(), 2, 1e-8);
EXPECT_NEAR(geom->getZ(), 3, 1e-8);
Expand All @@ -22,7 +23,8 @@ TEST(TesseractURDFUnit, parse_box) // NOLINT
{ // https://github.com/ros-industrial-consortium/tesseract_ros/issues/67
std::string str = R"(<box size="0.5 0.25 0.75" extra="0 0 0"/>)";
tesseract_geometry::Box::Ptr geom;
EXPECT_TRUE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_TRUE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
EXPECT_NEAR(geom->getX(), 0.5, 1e-8);
EXPECT_NEAR(geom->getY(), 0.25, 1e-8);
EXPECT_NEAR(geom->getZ(), 0.75, 1e-8);
Expand All @@ -31,37 +33,43 @@ TEST(TesseractURDFUnit, parse_box) // NOLINT
{
std::string str = R"(<box size="-1 2.0 3" extra="0 0 0"/>)";
tesseract_geometry::Box::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_FALSE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
}

{
std::string str = R"(<box size="1 -2.0 3" extra="0 0 0"/>)";
tesseract_geometry::Box::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_FALSE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
}

{
std::string str = R"(<box size="1 2.0 -3" extra="0 0 0"/>)";
tesseract_geometry::Box::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_FALSE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
}

{
std::string str = R"(<box size="1.0 2 a"/>)";
tesseract_geometry::Box::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_FALSE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
}

{
std::string str = R"(<box size="1 2"/>)";
tesseract_geometry::Box::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_FALSE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
}

{
std::string str = "<box />";
tesseract_geometry::Box::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, "box", 2));
EXPECT_FALSE(
runTest<tesseract_geometry::Box::Ptr>(geom, &tesseract_urdf::parseBox, str, tesseract_urdf::BOX_ELEMENT_NAME));
}
}

Expand Down
12 changes: 6 additions & 6 deletions tesseract_urdf/test/tesseract_urdf_calibration_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(TesseractURDFUnit, parse_calibration) // NOLINT
std::string str = R"(<calibration rising="1" falling="2" extra="0 0 0"/>)";
tesseract_scene_graph::JointCalibration::Ptr elem;
EXPECT_TRUE(runTest<tesseract_scene_graph::JointCalibration::Ptr>(
elem, &tesseract_urdf::parseCalibration, str, "calibration", 2));
elem, &tesseract_urdf::parseCalibration, str, tesseract_urdf::CALIBRATION_ELEMENT_NAME));
EXPECT_NEAR(elem->rising, 1, 1e-8);
EXPECT_NEAR(elem->falling, 2, 1e-8);
}
Expand All @@ -23,7 +23,7 @@ TEST(TesseractURDFUnit, parse_calibration) // NOLINT
std::string str = R"(<calibration rising="1"/>)";
tesseract_scene_graph::JointCalibration::Ptr elem;
EXPECT_TRUE(runTest<tesseract_scene_graph::JointCalibration::Ptr>(
elem, &tesseract_urdf::parseCalibration, str, "calibration", 2));
elem, &tesseract_urdf::parseCalibration, str, tesseract_urdf::CALIBRATION_ELEMENT_NAME));
EXPECT_NEAR(elem->rising, 1, 1e-8);
EXPECT_NEAR(elem->falling, 0, 1e-8);
}
Expand All @@ -32,7 +32,7 @@ TEST(TesseractURDFUnit, parse_calibration) // NOLINT
std::string str = R"(<calibration falling="2"/>)";
tesseract_scene_graph::JointCalibration::Ptr elem;
EXPECT_TRUE(runTest<tesseract_scene_graph::JointCalibration::Ptr>(
elem, &tesseract_urdf::parseCalibration, str, "calibration", 2));
elem, &tesseract_urdf::parseCalibration, str, tesseract_urdf::CALIBRATION_ELEMENT_NAME));
EXPECT_NEAR(elem->rising, 0, 1e-8);
EXPECT_NEAR(elem->falling, 2, 1e-8);
}
Expand All @@ -41,21 +41,21 @@ TEST(TesseractURDFUnit, parse_calibration) // NOLINT
std::string str = R"(<calibration rising="a" falling="2"/>)";
tesseract_scene_graph::JointCalibration::Ptr elem;
EXPECT_FALSE(runTest<tesseract_scene_graph::JointCalibration::Ptr>(
elem, &tesseract_urdf::parseCalibration, str, "calibration", 2));
elem, &tesseract_urdf::parseCalibration, str, tesseract_urdf::CALIBRATION_ELEMENT_NAME));
}

{
std::string str = R"(<calibration rising="1" falling="b"/>)";
tesseract_scene_graph::JointCalibration::Ptr elem;
EXPECT_FALSE(runTest<tesseract_scene_graph::JointCalibration::Ptr>(
elem, &tesseract_urdf::parseCalibration, str, "calibration", 2));
elem, &tesseract_urdf::parseCalibration, str, tesseract_urdf::CALIBRATION_ELEMENT_NAME));
}

{
std::string str = "<calibration/>";
tesseract_scene_graph::JointCalibration::Ptr elem;
EXPECT_FALSE(runTest<tesseract_scene_graph::JointCalibration::Ptr>(
elem, &tesseract_urdf::parseCalibration, str, "calibration", 2));
elem, &tesseract_urdf::parseCalibration, str, tesseract_urdf::CALIBRATION_ELEMENT_NAME));
}
}

Expand Down
49 changes: 29 additions & 20 deletions tesseract_urdf/test/tesseract_urdf_capsule_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,79 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
TEST(TesseractURDFUnit, parse_capsule) // NOLINT
{
{
std::string str = R"(<capsule radius="1" length="2" extra="0 0 0"/>)";
std::string str = R"(<tesseract:capsule radius="1" length="2" extra="0 0 0"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_TRUE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_TRUE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
EXPECT_NEAR(geom->getRadius(), 1, 1e-8);
EXPECT_NEAR(geom->getLength(), 2, 1e-8);
}

{ // https://github.com/ros-industrial-consortium/tesseract_ros/issues/67
std::string str = R"(<capsule radius="0.25" length="0.5" extra="0 0 0"/>)";
std::string str = R"(<tesseract:capsule radius="0.25" length="0.5" extra="0 0 0"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_TRUE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_TRUE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
EXPECT_NEAR(geom->getRadius(), 0.25, 1e-8);
EXPECT_NEAR(geom->getLength(), 0.5, 1e-8);
}

{
std::string str = R"(<capsule radius="-1" length="2" extra="0 0 0"/>)";
std::string str = R"(<tesseract:capsule radius="-1" length="2" extra="0 0 0"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
}

{
std::string str = R"(<capsule radius="1" length="-2" extra="0 0 0"/>)";
std::string str = R"(<tesseract:capsule radius="1" length="-2" extra="0 0 0"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
}

{
std::string str = R"(<capsule radius="a" length="2"/>)";
std::string str = R"(<tesseract:capsule radius="a" length="2"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
}

{
std::string str = R"(<capsule radius="1" length="a"/>)";
std::string str = R"(<tesseract:capsule radius="1" length="a"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
}

// TODO: I would expect this to fail but tinyxml2 still parses it so need to create an issue.
// {
// std::string str = R"(<capsule radius="1 2" length="2 3"/>)";
// std::string str = R"(<tesseract:capsule radius="1 2" length="2 3"/>)";
// tesseract_geometry::Capsule::Ptr geom;
// auto status = runTest<tesseract_geometry::Capsule::Ptr>(geom, str, "capsule");
// auto status = runTest<tesseract_geometry::Capsule::Ptr>(geom, str, tesseract_urdf::CAPSULE_ELEMENT_NAME);
// EXPECT_FALSE(*status);
// EXPECT_FALSE(status->message().empty());
// }

{
std::string str = R"(<capsule radius="1"/>)";
std::string str = R"(<tesseract:capsule radius="1"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
}

{
std::string str = R"(<capsule length="2"/>)";
std::string str = R"(<tesseract:capsule length="2"/>)";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
}

{
std::string str = "<capsule />";
std::string str = "<tesseract:capsule />";
tesseract_geometry::Capsule::Ptr geom;
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(geom, &tesseract_urdf::parseCapsule, str, "capsule", 2));
EXPECT_FALSE(runTest<tesseract_geometry::Capsule::Ptr>(
geom, &tesseract_urdf::parseCapsule, str, tesseract_urdf::CAPSULE_ELEMENT_NAME));
}
}

Expand Down
12 changes: 6 additions & 6 deletions tesseract_urdf/test/tesseract_urdf_collision_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEST(TesseractURDFUnit, parse_collision) // NOLINT
</collision>)";
tesseract_scene_graph::Collision::Ptr elem;
EXPECT_TRUE(runTest<tesseract_scene_graph::Collision::Ptr>(
elem, &tesseract_urdf::parseCollision, str, "collision", resource_locator, 2));
elem, &tesseract_urdf::parseCollision, str, tesseract_urdf::COLLISION_ELEMENT_NAME, resource_locator));
EXPECT_TRUE(elem->geometry != nullptr);
EXPECT_FALSE(elem->origin.isApprox(Eigen::Isometry3d::Identity(), 1e-8));
}
Expand All @@ -36,7 +36,7 @@ TEST(TesseractURDFUnit, parse_collision) // NOLINT
</collision>)";
tesseract_scene_graph::Collision::Ptr elem;
EXPECT_TRUE(runTest<tesseract_scene_graph::Collision::Ptr>(
elem, &tesseract_urdf::parseCollision, str, "collision", resource_locator, 2));
elem, &tesseract_urdf::parseCollision, str, tesseract_urdf::COLLISION_ELEMENT_NAME, resource_locator));
EXPECT_TRUE(elem->geometry != nullptr);
EXPECT_TRUE(elem->origin.isApprox(Eigen::Isometry3d::Identity(), 1e-8));
}
Expand All @@ -49,7 +49,7 @@ TEST(TesseractURDFUnit, parse_collision) // NOLINT
</collision>)";
tesseract_scene_graph::Collision::Ptr elem;
EXPECT_TRUE(runTest<tesseract_scene_graph::Collision::Ptr>(
elem, &tesseract_urdf::parseCollision, str, "collision", resource_locator, 2));
elem, &tesseract_urdf::parseCollision, str, tesseract_urdf::COLLISION_ELEMENT_NAME, resource_locator));
EXPECT_TRUE(elem->geometry != nullptr);
EXPECT_TRUE(elem->origin.isApprox(Eigen::Isometry3d::Identity(), 1e-8));
EXPECT_TRUE(elem->geometry->getType() == tesseract_geometry::GeometryType::COMPOUND_MESH);
Expand All @@ -65,7 +65,7 @@ TEST(TesseractURDFUnit, parse_collision) // NOLINT
</collision>)";
tesseract_scene_graph::Collision::Ptr elem;
EXPECT_FALSE(runTest<tesseract_scene_graph::Collision::Ptr>(
elem, &tesseract_urdf::parseCollision, str, "collision", resource_locator, 2));
elem, &tesseract_urdf::parseCollision, str, tesseract_urdf::COLLISION_ELEMENT_NAME, resource_locator));
EXPECT_TRUE(elem == nullptr);
}

Expand All @@ -77,7 +77,7 @@ TEST(TesseractURDFUnit, parse_collision) // NOLINT
</collision>)";
tesseract_scene_graph::Collision::Ptr elem;
EXPECT_FALSE(runTest<tesseract_scene_graph::Collision::Ptr>(
elem, &tesseract_urdf::parseCollision, str, "collision", resource_locator, 2));
elem, &tesseract_urdf::parseCollision, str, tesseract_urdf::COLLISION_ELEMENT_NAME, resource_locator));
EXPECT_TRUE(elem == nullptr);
}

Expand All @@ -86,7 +86,7 @@ TEST(TesseractURDFUnit, parse_collision) // NOLINT
</collision>)";
tesseract_scene_graph::Collision::Ptr elem;
EXPECT_FALSE(runTest<tesseract_scene_graph::Collision::Ptr>(
elem, &tesseract_urdf::parseCollision, str, "collision", resource_locator, 2));
elem, &tesseract_urdf::parseCollision, str, tesseract_urdf::COLLISION_ELEMENT_NAME, resource_locator));
EXPECT_TRUE(elem == nullptr);
}
}
Expand Down
41 changes: 16 additions & 25 deletions tesseract_urdf/test/tesseract_urdf_common_unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP

template <typename ElementType>
bool runTest(ElementType& type,
std::function<ElementType(const tinyxml2::XMLElement*, const int)> func,
std::function<ElementType(const tinyxml2::XMLElement*)> func,
const std::string& xml_string,
const std::string& element_name,
int version)
const std::string& element_name)
{
tinyxml2::XMLDocument xml_doc;
EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
Expand All @@ -32,7 +31,7 @@ bool runTest(ElementType& type,

try
{
type = func(element, version);
type = func(element);
}
catch (const std::exception& e)
{
Expand All @@ -46,12 +45,10 @@ bool runTest(ElementType& type,
template <typename ElementType>
bool runTest(
ElementType& type,
std::function<ElementType(const tinyxml2::XMLElement*, const tesseract_common::ResourceLocator&, bool, const int)>
func,
std::function<ElementType(const tinyxml2::XMLElement*, const tesseract_common::ResourceLocator&, bool)> func,
const std::string& xml_string,
const std::string& element_name,
const tesseract_common::ResourceLocator& locator,
int version,
bool visual)
{
tinyxml2::XMLDocument xml_doc;
Expand All @@ -62,7 +59,7 @@ bool runTest(

try
{
type = func(element, locator, visual, version);
type = func(element, locator, visual);
}
catch (const std::exception& e)
{
Expand All @@ -74,13 +71,11 @@ bool runTest(
}

template <typename ElementType>
bool runTest(
ElementType& type,
std::function<ElementType(const tinyxml2::XMLElement*, const tesseract_common::ResourceLocator&, const int)> func,
const std::string& xml_string,
const std::string& element_name,
const tesseract_common::ResourceLocator& locator,
int version)
bool runTest(ElementType& type,
std::function<ElementType(const tinyxml2::XMLElement*, const tesseract_common::ResourceLocator&)> func,
const std::string& xml_string,
const std::string& element_name,
const tesseract_common::ResourceLocator& locator)
{
tinyxml2::XMLDocument xml_doc;
EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
Expand All @@ -90,7 +85,7 @@ bool runTest(

try
{
type = func(element, locator, version);
type = func(element, locator);
}
catch (const std::exception& e)
{
Expand All @@ -105,13 +100,11 @@ template <typename ElementType>
bool runTest(ElementType& type,
std::function<ElementType(const tinyxml2::XMLElement*,
const tesseract_common::ResourceLocator&,
std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>&,
const int)> func,
std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>&)> func,
const std::string& xml_string,
const std::string& element_name,
const tesseract_common::ResourceLocator& locator,
std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>& available_materials,
int version)
std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>& available_materials)
{
tinyxml2::XMLDocument xml_doc;
EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
Expand All @@ -121,7 +114,7 @@ bool runTest(ElementType& type,

try
{
type = func(element, locator, available_materials, version);
type = func(element, locator, available_materials);
}
catch (const std::exception& e)
{
Expand All @@ -136,12 +129,10 @@ template <typename ElementType>
bool runTest(ElementType& type,
std::function<ElementType(const tinyxml2::XMLElement*,
std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>&,
bool,
const int)> func,
bool)> func,
const std::string& xml_string,
const std::string& element_name,
std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>& available_materials,
int version,
const bool visual)
{
tinyxml2::XMLDocument xml_doc;
Expand All @@ -152,7 +143,7 @@ bool runTest(ElementType& type,

try
{
type = func(element, available_materials, visual, version);
type = func(element, available_materials, visual);
}
catch (const std::exception& e)
{
Expand Down
Loading

0 comments on commit f48851c

Please sign in to comment.