From b8bccc0328876364a55ea70a66f4cc024d6fe27c Mon Sep 17 00:00:00 2001 From: LolaSegura Date: Thu, 15 Jul 2021 13:22:00 -0300 Subject: [PATCH] Addressed test comments. One left to resolve. Signed-off-by: LolaSegura --- src/plugins/teleop/Teleop.cc | 44 +++++++++++++++---------------- src/plugins/teleop/Teleop_TEST.cc | 31 +++++++++++----------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/plugins/teleop/Teleop.cc b/src/plugins/teleop/Teleop.cc index e8c319cc0..1d4764255 100644 --- a/src/plugins/teleop/Teleop.cc +++ b/src/plugins/teleop/Teleop.cc @@ -39,16 +39,16 @@ namespace gui { namespace plugins { - enum class keyLinear{ - kforward, - kbackward, - kstop, + enum class KeyLinear{ + kForward, + kBackward, + kStop, }; - enum class keyAngular{ - kleft, - kright, - kstop, + enum class KeyAngular{ + kLeft, + kRight, + kStop, }; class TeleopPrivate @@ -73,9 +73,9 @@ namespace plugins public: int angularDir = 0; /// \brief Linear state setted by keyboard input. - public: keyLinear linearState = keyLinear::kstop; + public: KeyLinear linearState = KeyLinear::kStop; /// \brief Angular state setted by keyboard input. - public: keyAngular angularState = keyAngular::kstop; + public: KeyAngular angularState = KeyAngular::kStop; /// \brief Indicates if the keyboard is enabled or /// disabled. @@ -192,16 +192,16 @@ bool Teleop::eventFilter(QObject *_obj, QEvent *_event) switch(keyEvent->key()) { case Qt::Key_W: - this->dataPtr->linearState = keyLinear::kforward; + this->dataPtr->linearState = KeyLinear::kForward; break; case Qt::Key_A: - this->dataPtr->angularState = keyAngular::kleft; + this->dataPtr->angularState = KeyAngular::kLeft; break; case Qt::Key_D: - this->dataPtr->angularState = keyAngular::kright; + this->dataPtr->angularState = KeyAngular::kRight; break; case Qt::Key_S: - this->dataPtr->linearState = keyLinear::kbackward; + this->dataPtr->linearState = KeyLinear::kBackward; break; default: break; @@ -216,16 +216,16 @@ bool Teleop::eventFilter(QObject *_obj, QEvent *_event) switch(keyEvent->key()) { case Qt::Key_W: - this->dataPtr->linearState = keyLinear::kstop; + this->dataPtr->linearState = KeyLinear::kStop; break; case Qt::Key_A: - this->dataPtr->angularState = keyAngular::kstop; + this->dataPtr->angularState = KeyAngular::kStop; break; case Qt::Key_D: - this->dataPtr->angularState = keyAngular::kstop; + this->dataPtr->angularState = KeyAngular::kStop; break; case Qt::Key_S: - this->dataPtr->linearState = keyLinear::kstop; + this->dataPtr->linearState = KeyLinear::kStop; break; default: break; @@ -241,12 +241,12 @@ bool Teleop::eventFilter(QObject *_obj, QEvent *_event) void Teleop::SetKeyDirection() { this->dataPtr->linearDir = this->dataPtr->linearState == - keyLinear::kforward ? 1 : this->dataPtr->linearState == - keyLinear::kbackward ? -1 : 0; + KeyLinear::kForward ? 1 : this->dataPtr->linearState == + KeyLinear::kBackward ? -1 : 0; this->dataPtr->angularDir = this->dataPtr->angularState == - keyAngular::kleft ? 1 : this->dataPtr->angularState == - keyAngular::kright ? -1 : 0; + KeyAngular::kLeft ? 1 : this->dataPtr->angularState == + KeyAngular::kRight ? -1 : 0; } ///////////////////////////////////////////////// diff --git a/src/plugins/teleop/Teleop_TEST.cc b/src/plugins/teleop/Teleop_TEST.cc index 766318dde..894a647f9 100644 --- a/src/plugins/teleop/Teleop_TEST.cc +++ b/src/plugins/teleop/Teleop_TEST.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Open Source Robotics Foundation + * Copyright (C) 2021 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ #include "ignition/gui/Application.hh" #include "ignition/gui/Plugin.hh" #include "ignition/gui/MainWindow.hh" -#include +#include "ignition/gui/qt.h" #include "Teleop.hh" @@ -40,10 +40,11 @@ char **g_argv = new char *[g_argc]; using namespace ignition; using namespace gui; -class TeleopTest : public ::testing::Test { - - protected: - void SetUp() override { +class TeleopTest : public ::testing::Test +{ + protected: + void SetUp() override + { common::Console::SetVerbosity(4); } @@ -77,7 +78,7 @@ class TeleopTest : public ::testing::Test { auto plugins = win->findChildren(); EXPECT_EQ(plugins.size(), 1); - auto plugin = plugins[0]; + const auto plugin = plugins[0]; EXPECT_EQ(plugin->Title(), "Teleop!"); plugin->OnTopicSelection(QString::fromStdString(_topic)); @@ -88,8 +89,8 @@ class TeleopTest : public ::testing::Test { EXPECT_EQ(plugin->AngularDirection(), 0); // Define velocity values. - double linearVel = 1.0; - double angularVel = 0.5; + const double linearVel = 1.0; + const double angularVel = 0.5; // Set velocity value and movement direction. // Forward and left movement. @@ -115,7 +116,7 @@ class TeleopTest : public ::testing::Test { plugin->OnTeleopTwist(); int sleep = 0; - int maxSleep = 30; + const int maxSleep = 30; while (!received && sleep < maxSleep) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -228,7 +229,7 @@ class TeleopTest : public ::testing::Test { auto plugins = win->findChildren(); EXPECT_EQ(plugins.size(), 1); - auto plugin = plugins[0]; + const auto plugin = plugins[0]; EXPECT_EQ(plugin->Title(), "Teleop!"); // Set desire topic. @@ -239,8 +240,8 @@ class TeleopTest : public ::testing::Test { EXPECT_EQ(plugin->AngularDirection(), 0); // Define velocity values. - double linearVel = 1.0; - double angularVel = 0.5; + const double linearVel = 1.0; + const double angularVel = 0.5; // Set velocity value and movement direction. plugin->OnLinearVelSelection(QString::number(linearVel)); @@ -274,7 +275,7 @@ class TeleopTest : public ::testing::Test { app.sendEvent(win->QuickWindow(), keypress_W); int sleep = 0; - int maxSleep = 30; + const int maxSleep = 30; while (!received && sleep < maxSleep) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -430,13 +431,11 @@ TEST_F(TeleopTest, Load) ///////////////////////////////////////////////// TEST_F(TeleopTest, ButtonCommand) { - TestButtons("/cmd_vel"); TestButtons("/model/vehicle_blue/cmd_vel"); } ///////////////////////////////////////////////// TEST_F(TeleopTest, KeyboardCommand) { - TestKeys("/cmd_vel"); TestKeys("/model/vehicle_blue/cmd_vel"); }