Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build
build/
57 changes: 35 additions & 22 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
{
"configurations": [
{
"name": "MinGW",
"compilerPath": "C:/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64",

"includePath": [
"${workspaceFolder}/**",
"C:/Qt/6.9.0/mingw_64/include",
"C:/Qt/6.9.0/mingw_64/include/QtCore",
"C:/Qt/6.9.0/mingw_64/include/QtGui",
"C:/Qt/6.9.0/mingw_64/include/QtWidgets",
"C:/Qt/6.9.0/mingw_64/include/QtNetwork",
"C:/Qt/6.9.0/mingw_64/include/QtWebSockets",
"C:/Qt/6.9.0/mingw_64/include/QtSerialPort"
]
}
{
"name": "Linux",
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include/qt6",
"/usr/include/qt6/QtCore",
"/usr/include/qt6/QtGui",
"/usr/include/qt6/QtWidgets"
]
},
{
"name": "Windows",
"compilerPath": "C:/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"C:/Qt/6.9.0/mingw_64/include",
"C:/Qt/6.9.0/mingw_64/include/QtCore",
"C:/Qt/6.9.0/mingw_64/include/QtGui",
"C:/Qt/6.9.0/mingw_64/include/QtWidgets",
"C:/Qt/6.9.0/mingw_64/include/QtNetwork",
"C:/Qt/6.9.0/mingw_64/include/QtWebSockets",
"C:/Qt/6.9.0/mingw_64/include/QtSerialPort"
]
}
],
"version": 4,

}

"version": 4
}
21 changes: 20 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug engine",
"name": "Debug engine (Linux)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/engine",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Debug engine (Windows)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/engine.exe",
Expand Down
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"cmake.configureSettings": {
"CMAKE_PREFIX_PATH": "C:/Qt/6.9.0/mingw_64/lib/cmake"
"CMAKE_PREFIX_PATH": "C:/Qt/6.9.0/mingw_64/lib/cmake"
},

"files.associations": {
"qudpsocket": "cpp",
"qhostaddress": "cpp",
Expand Down Expand Up @@ -99,4 +98,4 @@
"text_encoding": "cpp",
"qtmath": "cpp"
}
}
}
43 changes: 21 additions & 22 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"label": "build (Linux)",
"type": "shell",
"command": "cmake",
"args": ["--build", "build", "--target", "engine"],
"group": "build",
"problemMatcher": []
},
{
"label": "build (Windows)",
"type": "shell",
"command": "cmake",
"args": ["--build", "build", "--target", "engine"],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
"shell": {
"executable": "C:\\Windows\\System32\\cmd.exe",
"args": ["/d", "/c"]
}
},
"detail": "Task generated by Debugger."
"group": "build",
"problemMatcher": []
}
],
"version": "2.0.0"
}
]
}
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# The CMakeRoot handles all the libraries necessary to run the code
cmake_minimum_required(VERSION 3.16)

project(engine VERSION 1.0.0 LANGUAGES CXX)
project(engine VERSION 1.0.0 LANGUAGES CXX C)
set(TARGET engine)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Setup Qt6
find_package(Qt6 REQUIRED COMPONENTS Core Network Gui Widgets WebSockets SerialPort)
find_package(Qt6 REQUIRED COMPONENTS Core Network Gui Widgets WebSockets SerialPort Test)
qt_standard_project_setup()

# Build protobuf
Expand Down Expand Up @@ -51,3 +51,6 @@ FetchContent_MakeAvailable(sol2)

add_subdirectory(src)

enable_testing()
add_subdirectory(tests)

2 changes: 1 addition & 1 deletion src/radio/grsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <QByteArray>
#include <QHostAddress>
#include <QtMath>
#include <Qdebug>
#include <QDebug>

Grsim::Grsim() {
sendSocket = new QUdpSocket();
Expand Down
14 changes: 14 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_executable(robotstate_test robotstate_test.cpp)
target_include_directories(robotstate_test PRIVATE
${CMAKE_SOURCE_DIR}/src/utilities
)
target_link_libraries(robotstate_test Qt6::Test utilities)
add_test(NAME robotstate_test COMMAND robotstate_test)

add_executable(world_test world_test.cpp)
target_include_directories(world_test PRIVATE
${CMAKE_SOURCE_DIR}/src/utilities
${CMAKE_SOURCE_DIR}/src/world
)
target_link_libraries(world_test Qt6::Test utilities world)
add_test(NAME world_test COMMAND world_test)
31 changes: 31 additions & 0 deletions tests/robotstate_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <QtTest/QtTest>
#include "robotstate.hpp"

class RobotStateTest : public QObject {
Q_OBJECT
private slots:
void defaultConstruction();
void updateFunctions();
};

void RobotStateTest::defaultConstruction() {
RobotState rs;
QCOMPARE(rs.getId(), 0);
QCOMPARE(rs.getTeam(), 0);
QCOMPARE(rs.getPosition(), QVector2D(0, 0));
QCOMPARE(rs.getOrientation(), 0.0f);
}

void RobotStateTest::updateFunctions() {
RobotState rs(1, 0);
rs.setPosition({1.0f, 2.0f});
rs.setOrientation(0.5f);
rs.setVelocity({0.3f, -0.2f});

QCOMPARE(rs.getPosition(), QVector2D(1.0f, 2.0f));
QCOMPARE(rs.getOrientation(), 0.5f);
QCOMPARE(rs.getVelocity(), QVector2D(0.3f, -0.2f));
}

QTEST_MAIN(RobotStateTest)
#include "robotstate_test.moc"
32 changes: 32 additions & 0 deletions tests/world_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <QtTest/QtTest>
#include "world.hpp"

class WorldTest : public QObject {
Q_OBJECT
private slots:
void robotUpdates();
void jsonSerialization();
};

void WorldTest::robotUpdates() {
World w(1,1);
QVector2D p(2.0f,3.0f);
w.updateRobot(0,0,p,1.0f);
RobotState r = w.getRobotState(0,0);
QCOMPARE(r.getPosition(), p);
QVERIFY(r.isActive());
}

void WorldTest::jsonSerialization() {
World w(1,0);
w.updateRobot(0,0,{1.0f,1.0f},0.0f);
QJsonObject obj = w.toJson();
QVERIFY(obj.contains("robots"));
QJsonArray arr = obj["robots"].toArray();
QCOMPARE(arr.size(), 1);
QJsonObject r = arr.at(0).toObject();
QCOMPARE(r["id"].toInt(), 0);
}

QTEST_MAIN(WorldTest)
#include "world_test.moc"