Skip to content

Commit

Permalink
improve test coverage (#64)
Browse files Browse the repository at this point in the history
* improve test coverage

* test if passes on GHactions

* didn't work on GHActions

* aded tests for SkeletonDebug class

* fix code climate issues
  • Loading branch information
fernandotonon committed Apr 11, 2024
1 parent d4fa74a commit 8915809
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cmake_minimum_required(VERSION 3.24.0)
cmake_policy(SET CMP0005 NEW)
cmake_policy(SET CMP0048 NEW) # manages project version

project(QtMeshEditor VERSION 1.8.7 LANGUAGES CXX)
project(QtMeshEditor VERSION 1.8.8 LANGUAGES CXX)
message(STATUS "Building QtMeshEditor version ${PROJECT_VERSION}")

set(QTMESHEDITOR_VERSION_STRING "\"${PROJECT_VERSION}\"")
Expand Down
26 changes: 0 additions & 26 deletions src/SkeletonDebug.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/*/////////////////////////////////////////////////////////////////////////////////
/// A QtMeshEditor file
///
/// Copyright (c) HogPog Team (www.hogpog.com.br)
///
/// The MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////*/

#include "SkeletonDebug.h"

#include <QTimer>
Expand Down
26 changes: 0 additions & 26 deletions src/SkeletonDebug.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
/*/////////////////////////////////////////////////////////////////////////////////
/// A QtMeshEditor file
///
/// Copyright (c) HogPog Team (www.hogpog.com.br)
///
/// The MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////*/

#ifndef SKELETONDEBUG_H_INCLUDED
#define SKELETONDEBUG_H_INCLUDED

Expand Down
71 changes: 71 additions & 0 deletions src/SkeletonDebug_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <gtest/gtest.h>
#include "Manager.h"
#include "mainwindow.h"
#include "SkeletonDebug.h"

class SkeletonDebugTests : public ::testing::Test {
protected:
std::unique_ptr<SkeletonDebug> skeletonDebug;

void SetUp() override {
QStringList validUri{"./media/models/robot.mesh"};
Manager::getSingleton()->getMainWindow()->importMeshs(validUri);
Ogre::Entity* entity = Manager::getSingleton()->getEntities().last();
Ogre::SceneManager* sceneManager = Manager::getSingleton()->getSceneMgr();
skeletonDebug = std::make_unique<SkeletonDebug>(entity,sceneManager);
}

};

TEST_F(SkeletonDebugTests, ShowAxesTest)
{
// Initially, axes should not be shown
EXPECT_FALSE(skeletonDebug->axesShown());

// Show axes
skeletonDebug->showAxes(true);
EXPECT_TRUE(skeletonDebug->axesShown());

// Hide axes
skeletonDebug->showAxes(false);
EXPECT_FALSE(skeletonDebug->axesShown());
}

TEST_F(SkeletonDebugTests, ShowNamesTest)
{
// Initially, names should not be shown
EXPECT_FALSE(skeletonDebug->namesShown());

// Show names
skeletonDebug->showNames(true);
EXPECT_TRUE(skeletonDebug->namesShown());

// Hide names
skeletonDebug->showNames(false);
EXPECT_FALSE(skeletonDebug->namesShown());
}

TEST_F(SkeletonDebugTests, ShowBonesTest)
{
// Initially, bones should not be shown
EXPECT_FALSE(skeletonDebug->bonesShown());

// Show bones
skeletonDebug->showBones(true);
EXPECT_TRUE(skeletonDebug->bonesShown());

// Hide bones
skeletonDebug->showBones(false);
EXPECT_FALSE(skeletonDebug->bonesShown());
}

TEST_F(SkeletonDebugTests, SetAndGetAxesScaleTest)
{
// Set axes scale
skeletonDebug->setAxesScale(0.5f);
EXPECT_FLOAT_EQ(skeletonDebug->getAxesScale(), 0.5f);

// Set axes scale to a different value
skeletonDebug->setAxesScale(1.0f);
EXPECT_FLOAT_EQ(skeletonDebug->getAxesScale(), 1.0f);
}
10 changes: 5 additions & 5 deletions src/TransformOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

////////////////////////////////////////
// Static variable initialisation
TransformOperator* TransformOperator:: m_pSingleton = 0;
TransformOperator* TransformOperator:: m_pSingleton = nullptr;
const QPoint TransformOperator::invalidPosition(-1,-1);

////////////////////////////////////////
/// Static Member to build & destroy

TransformOperator* TransformOperator::getSingleton()
{
if (m_pSingleton == 0)
if (m_pSingleton == nullptr)
{
m_pSingleton = new TransformOperator();
}
Expand All @@ -38,10 +38,10 @@ TransformOperator* TransformOperator::getSingleton()

void TransformOperator::kill()
{
if (m_pSingleton != 0)
if (m_pSingleton != nullptr)
{
delete m_pSingleton;
m_pSingleton = 0;
m_pSingleton = nullptr;
}
}

Expand Down Expand Up @@ -332,7 +332,7 @@ Ogre::MovableObject* TransformOperator::performRaySelection(const QPoint& pos, b
return (queryResultIterator->movable);
}

return 0;
return nullptr;
}


Expand Down
4 changes: 3 additions & 1 deletion src/TransformOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ class TransformOperator : public QObject, public QtMouseListener
};

const Ogre::ColourValue& getSelectionBoxColour() const;

// Made public for testing
static void swap(int& x, int& y);
Ogre::Ray rayFromScreenPoint(const QPoint& pos);

private:
TransformOperator ();
~TransformOperator ();

Ogre::Ray rayFromScreenPoint(const QPoint& pos);
Ogre::MovableObject* performRaySelection(const QPoint& pos, bool findGizmo = false);
void performBoxSelection(const QPoint& first, const QPoint& second, SelectionMode mode = NEW_SELECT);
void updateGizmo();
Expand Down
7 changes: 7 additions & 0 deletions src/TransformOperator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ TEST(TransformOperatorTest, Swap) {
EXPECT_EQ(x, 2);
EXPECT_EQ(y, 1);
}

TEST(TransformOperatorTest, RayFromScreenPoint) {
TransformOperator* instance = TransformOperator::getSingleton();
Ogre::Ray ray = instance->rayFromScreenPoint(QPoint(0, 0));
EXPECT_EQ(ray.getOrigin(), Ogre::Vector3::ZERO);
EXPECT_EQ(ray.getDirection(), Ogre::Vector3::UNIT_Z);
}
2 changes: 0 additions & 2 deletions src/TranslationGizmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ TranslationGizmo::TranslationGizmo(Ogre::SceneNode* linkNode, const Ogre::String
m_pYaxis = pSceneMgr->createManualObject(name + "Y");
m_pZaxis = pSceneMgr->createManualObject(name + "Z");


//Default Color
Ogre::Real solid=1.0f;
mXaxisColor = Ogre::ColourValue(solid, 0, 0, solid);
Expand All @@ -48,7 +47,6 @@ TranslationGizmo::~TranslationGizmo()
pSceneMgr->destroyManualObject(m_pXaxis);
pSceneMgr->destroyManualObject(m_pYaxis);
pSceneMgr->destroyManualObject(m_pZaxis);

}

void TranslationGizmo::createXaxis(const Ogre::ColourValue& colour)
Expand Down
4 changes: 3 additions & 1 deletion src/about_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ TEST_F(AboutTest, VersionTextIsCorrect) {
QApplication app(argc, argv);

About aboutDialog;
About aboutDialog2(&aboutDialog); // Also test with a parent widget.
QString expectedVersionText = QString("Version: ") + QTMESHEDITOR_VERSION;
EXPECT_EQ(aboutDialog.getVersionText(), expectedVersionText);
}
EXPECT_EQ(aboutDialog2.getVersionText(), expectedVersionText);
}

0 comments on commit 8915809

Please sign in to comment.