Commits

Nathan Koenig  committed 5a51c98 Merge

Merged in qt_test (pull request #265)

Added in ability to make QT tests.

  • Participants
  • Parent commits 9c4a095, 39f1988

Comments (0)

Files changed (8)

File cmake/GazeboUtils.cmake

   endforeach()
 
 endmacro()
+
+#################################################
+macro (gz_build_qt_tests)
+
+  # Build all the tests
+  foreach(QTEST_SOURCE_file ${ARGN})
+    string(REGEX REPLACE ".cc" "" BINARY_NAME ${QTEST_SOURCE_file})
+    string(REGEX REPLACE ".cc" ".hh" QTEST_HEADER_file ${QTEST_SOURCE_file})
+    QT4_WRAP_CPP(test_MOC ${QTEST_HEADER_file} QTestFixture.hh)
+
+    add_executable(${BINARY_NAME}
+      ${test_MOC} ${QTEST_SOURCE_file} QTestFixture.cc)
+
+    add_dependencies(${BINARY_NAME}
+      gazebo_gui
+      gazebo_sdf_interface
+      gazebo_common
+      gazebo_math
+      gazebo_physics
+      gazebo_sensors
+      gazebo_rendering
+      gazebo_msgs
+      gazebo_transport)
+  
+    target_link_libraries(${BINARY_NAME}
+      gazebo_gui
+      gazebo_sdf_interface
+      gazebo_common
+      gazebo_math
+      gazebo_physics
+      gazebo_sensors
+      gazebo_rendering
+      gazebo_msgs
+      gazebo_transport
+      libgazebo
+      pthread
+      ${QT_QTTEST_LIBRARY}
+      ${QT_LIBRARIES}
+      )
+  
+    add_test(${BINARY_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME} -xml)
+  
+    set_tests_properties(${BINARY_NAME} PROPERTIES TIMEOUT 240)
+  
+    # Check that the test produced a result and create a failure if it didn't.
+    # Guards against crashed and timed out tests.
+    add_test(check_${BINARY_NAME} ${PROJECT_SOURCE_DIR}/tools/check_test_ran.py
+             ${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml)
+  endforeach()
+
+endmacro()

File gazebo/gui/CMakeLists.txt

   viewers/ViewFactory.hh
 )
 
+set (tests 
+  TimePanel_TEST.cc
+  )
+
+gz_build_qt_tests(${tests})
+
 set (resources resources.qrc)
 
+
 QT4_WRAP_CPP(headers_MOC ${qt_headers})
 QT4_ADD_RESOURCES(resources_RCC ${resources})
 

File gazebo/gui/QTestFixture.cc

+/*
+ * Copyright 2011 Nate Koenig
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+#include "gazebo/common/Time.hh"
+#include "gazebo/common/Console.hh"
+#include "gazebo/gazebo.hh"
+#include "gazebo/gui/QTestFixture.hh"
+
+/////////////////////////////////////////////////
+void QTestFixture::initTestCase()
+{
+  // Initialize the informational logger. This will log warnings, and
+  // errors.
+  gazebo::common::Console::Instance()->Init("test.log");
+
+  // Initialize the data logger. This will log state information.
+  gazebo::common::LogRecord::Instance()->Init("test");
+
+  // Add local search paths
+  gazebo::common::SystemPaths::Instance()->AddGazeboPaths(PROJECT_SOURCE_PATH);
+
+  std::string path = PROJECT_SOURCE_PATH;
+  path += "/sdf/worlds";
+  gazebo::common::SystemPaths::Instance()->AddGazeboPaths(path);
+
+  // Create, load, and run the server in its own thread
+  this->serverThread = new boost::thread(
+      boost::bind(&QTestFixture::RunServer, this));
+
+  // Wait for the server to come up
+  // Use a 30 second timeout.
+  int waitCount = 0, maxWaitCount = 3000;
+  while ((!this->server || !this->server->GetInitialized()) &&
+      ++waitCount < maxWaitCount)
+    gazebo::common::Time::MSleep(10);
+}
+
+/////////////////////////////////////////////////
+void QTestFixture::RunServer()
+{
+  this->server = new gazebo::Server();
+  this->server->LoadFile("empty.world");
+  this->server->Init();
+
+  gazebo::rendering::create_scene(
+      gazebo::physics::get_world()->GetName(), false);
+
+  // this->SetPause(false);
+
+  this->server->Run();
+
+  gazebo::rendering::remove_scene(gazebo::physics::get_world()->GetName());
+
+  this->server->Fini();
+  delete this->server;
+  this->server = NULL;
+}
+
+/////////////////////////////////////////////////
+void QTestFixture::cleanupTestCase()
+{
+  if (this->server)
+  {
+    this->server->Stop();
+
+    if (this->serverThread)
+    {
+      this->serverThread->join();
+    }
+  }
+
+  delete this->serverThread;
+  this->serverThread = NULL;
+}

File gazebo/gui/QTestFixture.hh

+/*
+ * Copyright 2011 Nate Koenig
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+#ifndef _QTESTFIXTURE_HH_
+#define _QTESTFIXTURE_HH_
+
+#include <boost/thread.hpp>
+
+#include "gazebo/physics/physics.hh"
+#include "gazebo/rendering/rendering.hh"
+#include "gazebo/Server.hh"
+#include "gazebo/gui/qt.h"
+
+#include "gazebo_config.h"
+#include "test_config.h"
+
+/// \brief Base class for all Gazebo GUI unit tests.
+class QTestFixture : public QObject
+{
+  Q_OBJECT
+
+  /// \brief QT slot that is called automatically when a test begins
+  private slots: void initTestCase();
+
+  /// \brief QT slot that is called automatically when a test ends
+  private slots: void cleanupTestCase();
+
+  /// \brief Run the Gazebo server in a thread.
+  private: void RunServer();
+
+  /// \brief The Gazebo server, which is run in a thread.
+  protected: gazebo::Server *server;
+
+  /// \brief Thread to run the Gazebo server.
+  protected: boost::thread *serverThread;
+};
+
+#endif

File gazebo/gui/TimePanel.cc

   QHBoxLayout *frameLayout = new QHBoxLayout;
 
   this->percentRealTimeEdit = new QLineEdit;
+  this->percentRealTimeEdit->setObjectName("timePanelPercentRealTime");
   this->percentRealTimeEdit->setReadOnly(true);
   this->percentRealTimeEdit->setFixedWidth(90);
 
   this->simTimeEdit = new QLineEdit;
+  this->simTimeEdit->setObjectName("timePanelSimTime");
   this->simTimeEdit->setReadOnly(true);
   this->simTimeEdit->setFixedWidth(110);
 
   this->realTimeEdit = new QLineEdit;
+  this->realTimeEdit->setObjectName("timePanelRealTime");
   this->realTimeEdit->setReadOnly(true);
   this->realTimeEdit->setFixedWidth(110);
 
   this->simTime = msgs::Convert(_msg->sim_time());
   this->realTime = msgs::Convert(_msg->real_time());
 
-  if (_msg->paused() && !g_pauseAct->isChecked())
+  if (_msg->paused() && (g_pauseAct && !g_pauseAct->isChecked()))
   {
     g_pauseAct->setChecked(true);
     g_playAct->setChecked(false);
   }
-  else if (!_msg->paused() && !g_playAct->isChecked())
+  else if (!_msg->paused() && (g_playAct && !g_playAct->isChecked()))
   {
     g_pauseAct->setChecked(false);
     g_playAct->setChecked(true);

File gazebo/gui/TimePanel_TEST.cc

+/*
+ * Copyright 2011 Nate Koenig
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+#include "gazebo/gui/TimePanel.hh"
+#include "gazebo/gui/TimePanel_TEST.hh"
+
+/////////////////////////////////////////////////
+void TimePanel_TEST::ValidTimes()
+{
+  // Create a new data logger widget
+  gazebo::gui::TimePanel *timePanel = new gazebo::gui::TimePanel;
+
+  // Get the percent real time line
+  QLineEdit *percentEdit = timePanel->findChild<QLineEdit*>(
+      "timePanelPercentRealTime");
+
+  // Get the sim time line
+  QLineEdit *simTimeEdit = timePanel->findChild<QLineEdit*>(
+      "timePanelSimTime");
+
+  // Get the real time line
+  QLineEdit *realTimeEdit = timePanel->findChild<QLineEdit*>(
+      "timePanelRealTime");
+
+  QVERIFY(percentEdit != NULL);
+  QVERIFY(simTimeEdit != NULL);
+  QVERIFY(realTimeEdit != NULL);
+
+  // Wait a little bit so that time increases.
+  for (unsigned int i = 0; i < 10; ++i)
+  {
+    gazebo::common::Time::MSleep(100);
+    QCoreApplication::processEvents();
+  }
+
+  std::string txt;
+  double value;
+
+  // Make sure realt time is greater than zero
+  txt = realTimeEdit->text().toStdString();
+  value = boost::lexical_cast<double>(txt.substr(0, txt.find(" ")));
+  QVERIFY(value > 0.0);
+
+  // Make sure sim time is greater than zero
+  txt = simTimeEdit->text().toStdString();
+  value = boost::lexical_cast<double>(txt.substr(0, txt.find(" ")));
+  QVERIFY(value > 0.0);
+
+  // Make sure the percent real time is greater than zero
+  txt = percentEdit->text().toStdString();
+  value = boost::lexical_cast<double>(txt.substr(0, txt.find(" ")));
+  QVERIFY(value > 0.0);
+}
+
+// Generate a main function for the test
+QTEST_MAIN(TimePanel_TEST)

File gazebo/gui/TimePanel_TEST.hh

+/*
+ * Copyright 2011 Nate Koenig
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+#ifndef _TIMEPANEL_TEST_HH_
+#define _TIMEPANEL_TEST_HH_
+
+#include "gazebo/gui/QTestFixture.hh"
+
+/// \brief A test class for the DataLogger widget.
+class TimePanel_TEST : public QTestFixture
+{
+  Q_OBJECT
+
+  /// \brief Test that the TimePanel gets valid times from the server.
+  private slots: void ValidTimes();
+};
+
+#endif

File gazebo/gui/qt.h

 #include <QApplication>
 #include <qmainwindow.h>
 #include <QAction>
+#include <QtTest/QtTest>
 
 #endif