~j-rivero/+junk/ignition-gazebo

« back to all changes in this revision

Viewing changes to src/Primitives_TEST.cc

  • Committer: Jose Luis Rivero
  • Date: 2022-02-15 17:35:59 UTC
  • Revision ID: jrivero@osrfoundation.org-20220215173559-qyu3wjmqnrby30k7
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2021 Open Source Robotics Foundation
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 *
 
16
*/
 
17
 
 
18
#include <gtest/gtest.h>
 
19
 
 
20
#include <ignition/gazebo/Primitives.hh>
 
21
#include <sdf/Root.hh>
 
22
 
 
23
using PrimitiveShape = ignition::gazebo::PrimitiveShape;
 
24
using PrimitiveLight = ignition::gazebo::PrimitiveLight;
 
25
 
 
26
/////////////////////////////////////////////////
 
27
TEST(Primitives, shapes)
 
28
{
 
29
  auto primitives  = {
 
30
    PrimitiveShape::kBox,
 
31
    PrimitiveShape::kSphere,
 
32
    PrimitiveShape::kCylinder,
 
33
    PrimitiveShape::kCapsule,
 
34
    PrimitiveShape::kEllipsoid
 
35
  };
 
36
 
 
37
  for (auto prim : primitives)
 
38
  {
 
39
    auto sdfString = ignition::gazebo::getPrimitiveShape(prim);
 
40
    ASSERT_FALSE(sdfString.empty());
 
41
 
 
42
    /// Verify that string contains valid SDF
 
43
    sdf::Root root;
 
44
    auto errors = root.LoadSdfString(sdfString);
 
45
    EXPECT_TRUE(errors.empty()) << sdfString;
 
46
  }
 
47
}
 
48
 
 
49
/////////////////////////////////////////////////
 
50
TEST(Primitives, lights)
 
51
{
 
52
  auto primitives  = {
 
53
    PrimitiveLight::kDirectional,
 
54
    PrimitiveLight::kPoint,
 
55
    PrimitiveLight::kSpot,
 
56
  };
 
57
 
 
58
  for (auto prim : primitives)
 
59
  {
 
60
    auto sdfString = ignition::gazebo::getPrimitiveLight(prim);
 
61
    ASSERT_FALSE(sdfString.empty());
 
62
 
 
63
    /// Verify that string contains valid SDF
 
64
    sdf::Root root;
 
65
    auto errors = root.LoadSdfString(sdfString);
 
66
    EXPECT_TRUE(errors.empty()) << sdfString;
 
67
  }
 
68
}
 
69
 
 
70
/////////////////////////////////////////////////
 
71
TEST(Primitives, invalid)
 
72
{
 
73
  auto sdfString = ignition::gazebo::getPrimitive("foobar");
 
74
  ASSERT_TRUE(sdfString.empty());
 
75
}
 
76
 
 
77
/////////////////////////////////////////////////
 
78
TEST(Primitives, strings)
 
79
{
 
80
  auto primitives = {
 
81
    "box", "sphere", "cylinder", "capsule", "ellipsoid",
 
82
    "point", "directional", "spot"
 
83
  };
 
84
 
 
85
  for (auto prim : primitives)
 
86
  {
 
87
    auto sdfString = ignition::gazebo::getPrimitive(prim);
 
88
    ASSERT_FALSE(sdfString.empty());
 
89
 
 
90
    /// Verify that string contains valid SDF
 
91
    sdf::Root root;
 
92
    auto errors = root.LoadSdfString(sdfString);
 
93
    EXPECT_TRUE(errors.empty()) << sdfString;
 
94
  }
 
95
}