#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Joints/Joint.hpp>
#include <PlayRho/Common/Templates.hpp>
#include <PlayRho/Dynamics/Joints/JointConf.hpp>
#include <PlayRho/Dynamics/Joints/WheelJointConf.hpp>
#include <any>
#include <stdexcept>
#include <type_traits>
#define DEFINE_GETBODYA \
[[maybe_unused]] BodyID GetBodyA(const JointTester&) noexcept \
{ \
return InvalidBodyID; \
}
#define DEFINE_GETBODYB \
[[maybe_unused]] BodyID GetBodyB(const JointTester&) noexcept \
{ \
return InvalidBodyID; \
}
#define DEFINE_GETCOLLIDECONNECTED \
[[maybe_unused]] bool GetCollideConnected(const JointTester&) noexcept \
{ \
return false; \
}
#define DEFINE_SHIFTORIGIN \
[[maybe_unused]] bool ShiftOrigin(JointTester&, Length2) noexcept \
{ \
return false; \
}
#define DEFINE_INITVELOCITY \
[[maybe_unused]] void InitVelocity(JointTester&, std::vector<BodyConstraint>&, \
const StepConf&, const ConstraintSolverConf&) \
{ \
}
#define DEFINE_SOLVEVELOCITY \
[[maybe_unused]] bool SolveVelocity(JointTester&, std::vector<BodyConstraint>&, \
const StepConf&) \
{ \
return true; \
}
#define DEFINE_SOLVEPOSITION \
[[maybe_unused]] bool SolvePosition(const JointTester&, std::vector<BodyConstraint>&, \
const ConstraintSolverConf&) \
{ \
return true; \
}
#define DEFINE_EQUALS \
[[maybe_unused]] bool operator==(const JointTester& lhs, const JointTester& rhs) noexcept \
{ \
return lhs.number == rhs.number; \
}
namespace test {
namespace sans_none {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETBODYB;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_SHIFTORIGIN;
DEFINE_INITVELOCITY;
DEFINE_SOLVEVELOCITY;
DEFINE_SOLVEPOSITION;
DEFINE_EQUALS;
}
}
namespace sans_getbodya {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYB;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_SHIFTORIGIN;
DEFINE_INITVELOCITY;
DEFINE_SOLVEVELOCITY;
DEFINE_SOLVEPOSITION;
DEFINE_EQUALS;
}
}
namespace sans_getbodyb {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_SHIFTORIGIN;
DEFINE_INITVELOCITY;
DEFINE_SOLVEVELOCITY;
DEFINE_SOLVEPOSITION;
DEFINE_EQUALS;
}
}
namespace sans_getcollideconnected {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETBODYB;
DEFINE_SHIFTORIGIN;
DEFINE_INITVELOCITY;
DEFINE_SOLVEVELOCITY;
DEFINE_SOLVEPOSITION;
DEFINE_EQUALS;
}
}
namespace sans_shiftorigin {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETBODYB;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_INITVELOCITY;
DEFINE_SOLVEVELOCITY;
DEFINE_SOLVEPOSITION;
DEFINE_EQUALS;
}
}
namespace sans_initvelocity {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETBODYB;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_SHIFTORIGIN;
DEFINE_SOLVEVELOCITY;
DEFINE_SOLVEPOSITION;
DEFINE_EQUALS;
}
}
namespace sans_solvevelocity {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETBODYB;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_SHIFTORIGIN;
DEFINE_INITVELOCITY;
DEFINE_SOLVEPOSITION;
DEFINE_EQUALS;
}
}
namespace sans_solveposition {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETBODYB;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_SHIFTORIGIN;
DEFINE_INITVELOCITY;
DEFINE_SOLVEVELOCITY;
DEFINE_EQUALS;
}
}
namespace sans_equals {
namespace {
struct JointTester {
int number = 0;
};
DEFINE_GETBODYA;
DEFINE_GETBODYB;
DEFINE_GETCOLLIDECONNECTED;
DEFINE_SHIFTORIGIN;
DEFINE_INITVELOCITY;
DEFINE_SOLVEVELOCITY;
DEFINE_SOLVEPOSITION;
}
}
namespace sans_all {
namespace {
struct JointTester {
int number = 0;
};
}
}
}
{
}
{
const auto b =
static_cast<BodyID>(2);
}
{
const auto b =
static_cast<BodyID>(77);
}
{
const auto value = true;
}
{
switch (sizeof(void*)) {
case 4:
break;
case 8:
EXPECT_EQ(
sizeof(
Joint), std::size_t(8));
break;
default:
break;
}
}
{
EXPECT_TRUE(std::is_default_constructible<Joint>::value);
EXPECT_TRUE(std::is_nothrow_default_constructible<Joint>::value);
EXPECT_FALSE(std::is_trivially_default_constructible<Joint>::value);
EXPECT_TRUE(std::is_copy_constructible<Joint>::value);
EXPECT_FALSE(std::is_nothrow_copy_constructible<Joint>::value);
EXPECT_FALSE(std::is_trivially_copy_constructible<Joint>::value);
EXPECT_TRUE(std::is_copy_assignable<Joint>::value);
EXPECT_FALSE(std::is_nothrow_copy_assignable<Joint>::value);
EXPECT_FALSE(std::is_trivially_copy_assignable<Joint>::value);
EXPECT_TRUE(std::is_destructible<Joint>::value);
EXPECT_TRUE(std::is_nothrow_destructible<Joint>::value);
EXPECT_FALSE(std::is_trivially_destructible<Joint>::value);
EXPECT_TRUE((std::is_constructible<Joint, int>::value));
EXPECT_TRUE((std::is_constructible<Joint, char*>::value));
EXPECT_TRUE((std::is_constructible<Joint, test::sans_none::JointTester>::value));
}
TEST(
Joint, DefaultConstructor)
{
EXPECT_TRUE(joint == joint);
EXPECT_FALSE(joint != joint);
}
TEST(
Joint, LimitStateToStringFF)
{
const auto inactiveLimitString = std::string(
ToString(LimitState::e_inactiveLimit));
const auto upperLimitsString = std::string(
ToString(LimitState::e_atUpperLimit));
const auto lowerLimitsString = std::string(
ToString(LimitState::e_atLowerLimit));
EXPECT_FALSE(equalLimitsString.empty());
EXPECT_FALSE(inactiveLimitString.empty());
EXPECT_FALSE(upperLimitsString.empty());
EXPECT_FALSE(lowerLimitsString.empty());
std::set<std::string> names;
names.insert(equalLimitsString);
names.insert(inactiveLimitString);
names.insert(upperLimitsString);
names.insert(lowerLimitsString);
EXPECT_EQ(names.size(), decltype(names.size()){4});
}
{
int foo = 5;
std::any test{foo};
std::string roo = "wow";
test = roo;
test = std::any{foo};
{
const auto joint =
Joint{};
auto value = static_cast<const int*>(nullptr);
EXPECT_NO_THROW(value = TypeCast<const int>(&joint));
EXPECT_TRUE(value == nullptr);
}
{
auto value = static_cast<int*>(nullptr);
EXPECT_NO_THROW(value = TypeCast<int>(&joint));
EXPECT_TRUE(value == nullptr);
}
{
const auto joint =
Joint{};
EXPECT_THROW(TypeCast<int>(joint), std::bad_cast);
EXPECT_THROW(TypeCast<const int>(joint), std::bad_cast);
}
{
EXPECT_THROW(TypeCast<int>(joint), std::bad_cast);
EXPECT_THROW(TypeCast<const int>(joint), std::bad_cast);
}
{
auto number = 10;
const auto original = test::sans_none::JointTester{number};
EXPECT_EQ(original.number, number);
auto joint =
Joint{original};
EXPECT_THROW(TypeCast<int>(joint), std::bad_cast);
auto value = test::sans_none::JointTester{};
EXPECT_NO_THROW(value = TypeCast<test::sans_none::JointTester>(joint));
EXPECT_EQ(value.number, number);
EXPECT_NO_THROW(TypeCast<test::sans_none::JointTester&>(joint).number = 3);
EXPECT_EQ(TypeCast<const test::sans_none::JointTester&>(joint).number, 3);
EXPECT_NO_THROW(value = TypeCast<test::sans_none::JointTester>(joint));
EXPECT_EQ(value.number, 3);
EXPECT_NO_THROW(TypeCast<test::sans_none::JointTester>(&joint)->number = 4);
EXPECT_EQ(TypeCast<const test::sans_none::JointTester>(joint).number, 4);
EXPECT_TRUE(joint == joint);
EXPECT_FALSE(joint != joint);
}
}
TEST(
Joint, ForConstantDataTypeCastIsLikeAnyCast)
{
const auto foo =
Joint{test::sans_none::JointTester{1}};
const auto bar = std::any{test::sans_none::JointTester{1}};
EXPECT_TRUE(TypeCast<const test::sans_none::JointTester*>(&foo) == nullptr);
EXPECT_TRUE(std::any_cast<const test::sans_none::JointTester*>(&bar) == nullptr);
EXPECT_TRUE(TypeCast<test::sans_none::JointTester*>(&foo) == nullptr);
EXPECT_TRUE(std::any_cast<test::sans_none::JointTester*>(&bar) == nullptr);
EXPECT_TRUE(TypeCast<const test::sans_none::JointTester>(&foo) != nullptr);
EXPECT_TRUE(std::any_cast<const test::sans_none::JointTester>(&bar) != nullptr);
EXPECT_TRUE(TypeCast<test::sans_none::JointTester>(&foo) != nullptr);
EXPECT_TRUE(std::any_cast<test::sans_none::JointTester>(&bar) != nullptr);
}
TEST(
Joint, ForMutableDataTypeCastIsLikeAnyCast)
{
auto foo =
Joint{test::sans_none::JointTester{1}};
auto bar = std::any{test::sans_none::JointTester{1}};
EXPECT_TRUE(TypeCast<const test::sans_none::JointTester*>(&foo) == nullptr);
EXPECT_TRUE(std::any_cast<const test::sans_none::JointTester*>(&bar) == nullptr);
EXPECT_TRUE(TypeCast<test::sans_none::JointTester*>(&foo) == nullptr);
EXPECT_TRUE(std::any_cast<test::sans_none::JointTester*>(&bar) == nullptr);
EXPECT_TRUE(TypeCast<const test::sans_none::JointTester>(&foo) != nullptr);
EXPECT_TRUE(std::any_cast<const test::sans_none::JointTester>(&bar) != nullptr);
EXPECT_TRUE(TypeCast<test::sans_none::JointTester>(&foo) != nullptr);
EXPECT_TRUE(std::any_cast<test::sans_none::JointTester>(&bar) != nullptr);
}
{
}
{
}
TEST(
Joint, SetMotorSpeedThrows)
{
EXPECT_THROW(
SetMotorSpeed(joint, 1_rpm), std::invalid_argument);
}
TEST(
Joint, SetMaxMotorForceThrows)
{
}
TEST(
Joint, SetMaxMotorTorqueThrows)
{
}
TEST(
Joint, SetLinearLimitsThrows)
{
}
TEST(
Joint, SetAngularLimitsThrows)
{
}
TEST(
Joint, IsLimitEnabledThrows)
{
}
TEST(
Joint, EnableLimitThrows)
{
EXPECT_THROW(
EnableLimit(joint,
true), std::invalid_argument);
EXPECT_THROW(
EnableLimit(joint,
false), std::invalid_argument);
}
TEST(
Joint, IsMotorEnabledThrows)
{
}
TEST(
Joint, EnableMotorThrows)
{
EXPECT_THROW(
EnableMotor(joint,
true), std::invalid_argument);
EXPECT_THROW(
EnableMotor(joint,
false), std::invalid_argument);
}
TEST(
Joint, GetLimitStateThrows)
{
}
TEST(
Joint, EqualsOperator)
{
EXPECT_TRUE(j0 == j0);
{
const auto j1 =
Joint(conf);
EXPECT_TRUE(j1 == j1);
EXPECT_FALSE(j0 == j1);
}
{
const auto j1 =
Joint(conf);
EXPECT_TRUE(j1 == j1);
EXPECT_FALSE(j0 == j1);
}
{
const auto j1 =
Joint(conf);
EXPECT_TRUE(j1 == j1);
EXPECT_FALSE(j0 == j1);
}
}
TEST(
Joint, NotEqualsOperator)
{
EXPECT_FALSE(j0 != j0);
{
const auto j1 =
Joint(conf);
EXPECT_FALSE(j1 != j1);
EXPECT_TRUE(j0 != j1);
}
}