Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit testing and clang-tidy #94

Merged
merged 13 commits into from
Jun 19, 2024
147 changes: 147 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Generated from CLion Inspection settings
---
Checks: '-*,
bugprone-argument-comment,
bugprone-assert-side-effect,
bugprone-bad-signal-to-kill-thread,
bugprone-branch-clone,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-no-escape,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-reserved-identifier,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-suspicious-memory-comparison,
bugprone-suspicious-realloc-usage,
bugprone-swapped-arguments,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
bugprone-virtual-near-miss,
cert-dcl21-cpp,
cert-dcl58-cpp,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
cert-str34-c,
cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-slicing,
google-default-arguments,
google-explicit-constructor,
google-runtime-operator,
hicpp-exception-baseclass,
hicpp-multiway-paths-covered,
misc-misplaced-const,
misc-new-delete-overloads,
misc-no-recursion,
misc-non-copyable-objects,
misc-throw-by-value-catch-by-reference,
misc-unconventional-assign-operator,
misc-uniqueptr-reset-release,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-raw-string-literal,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-disallow-copy-and-assign-macro,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-shrink-to-fit,
modernize-unary-static-assert,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
mpi-buffer-deref,
mpi-type-mismatch,
openmp-use-default-none,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-string-concatenation,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-no-automatic-move,
performance-noexcept-move-constructor,
performance-trivially-destructible,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param,
portability-simd-intrinsics,
readability-avoid-const-params-in-decls,
readability-const-return-type,
readability-container-size-empty,
readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-deleted-default,
readability-inconsistent-declaration-parameter-name,
readability-make-member-function-const,
readability-misleading-indentation,
readability-misplaced-array-index,
readability-non-const-parameter,
readability-redundant-control-flow,
readability-redundant-declaration,
readability-redundant-function-ptr-dereference,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-redundant-string-init,
readability-simplify-subscript-expr,
readability-static-accessed-through-instance,
readability-static-definition-in-anonymous-namespace,
readability-string-compare,
readability-uniqueptr-delete-release,
readability-use-anyofallof'
49 changes: 49 additions & 0 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Unit Tests"

on:
workflow_dispatch:
push:
branches: [ "senpai", "kouhai" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "senpai", "kouhai" ]

jobs:
testing:
name: Testing
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
checks: write

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Cache Qt dependencies
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/qt
key: qt-${{ runner.os }}-${{ hashFiles('**/qt/**') }}

- name: Install Qt
if: steps.cache.outputs.cache-hit != 'true'
uses: jurplel/[email protected]
with:
version: '6.6.2'
modules: 'qtwebsockets'
dir: ${{ github.workspace }}/qt

- name: Build
run: cd tests && mkdir build && cd build && cmake .. && make

- name: Run tests
run: cd tests/build && ctest --output-junit testResults.xml

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/tests/build/testResults.xml'
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ compile_commands.json

# Cmake builds
build*
bin*

# VSCode
.vscode

# Testing stuff
*.conf
*.json

#Visual Studio
.vscode
52 changes: 31 additions & 21 deletions src/about/about.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
#include "about.h"

void About::show()
{
void About::show() {
qDebug() << "[About] Displaying about...";
QMessageBox::about(nullptr,
"About Miraya",
createMessageBox()->show();
qDebug() << "[About] Closed";
}

"<h1>Miraya</h1>"
"<p>A Twitch chatbot with GosuMemory and osu! IRC support.</p>"
"<p>Version: " + QApplication::applicationVersion() + "</p>"
"<p>Copyright © "+ QString::number(QDate::currentDate().year()) + " Miraya Project</p>"
"<p>This program is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version.</p>"
"<p>This program is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
"GNU General Public License for more details.</p>"
"<p>You should have received a copy of the GNU General Public License "
"along with this program. If not, see <a href=\"https://www.gnu.org/licenses/\">"
"https://www.gnu.org/licenses/</a>.</p>" +
"<p>Icons provided by <a href=\"https://icons8.com\">Icons8</a></p>"
QMessageBox *About::createMessageBox(QWidget *parent) {
auto *msgBox = new QMessageBox(parent);
msgBox->setWindowTitle("About Miraya");
auto body = (
QString("<h1>Miraya</h1>"
"<p>A Twitch chatbot with GosuMemory and osu! IRC support.</p>"
"<p>Version: %1</p>"
"<p>Copyright © %2 Miraya Project</p>"
"<p>This program is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version.</p>"
"<p>This program is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
"GNU General Public License for more details.</p>"
"<p>You should have received a copy of the GNU General Public License "
"along with this program. If not, see <a href=\"https://www.gnu.org/licenses/\">"
"https://www.gnu.org/licenses/</a>.</p>"
"<p>Icons provided by <a href=\"https://icons8.com\">Icons8</a></p>").arg(
QApplication::applicationVersion(), QString::number(QDate::currentDate().year()))
);
qDebug() << "[About] Closed";
msgBox->setText(body);
msgBox->setIcon(QMessageBox::Information);
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setWindowFlags(msgBox->windowFlags() & ~Qt::WindowContextHelpButtonHint);

return msgBox;
}
9 changes: 5 additions & 4 deletions src/about/about.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
#include <QMessageBox>
#include <QObject>

class About : public QObject
{
class About : public QObject {
Q_OBJECT
public:
static void show();

public:
static QMessageBox* createMessageBox(QWidget *parent = nullptr);
static void show();
};

#endif // ABOUT_H
16 changes: 7 additions & 9 deletions src/backup/backup.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "backup.h"


void Backup::backup(QString filePath, bool includeSensitiveInfo)
{
void Backup::backup(QString filePath, bool includeSensitiveInfo) {
if (filePath.isEmpty()) {
return;
}

// adding .json if needed
if(!filePath.endsWith(".json")) {
if (!filePath.endsWith(".json")) {
filePath.append(".json");
}

Expand All @@ -26,13 +25,13 @@ void Backup::backup(QString filePath, bool includeSensitiveInfo)
QStringList keys = settings.allKeys();

// sensitive info must be excluded
if(!includeSensitiveInfo) {
keys.removeIf([](const QString& key){
if (!includeSensitiveInfo) {
keys.removeIf([](const QString &key) {
return key.startsWith("osuirc") || key.startsWith("twitch");
});
}

for(const QString& key: keys){
for (const QString &key: keys) {
QString value = settings.value(key).toString();
jsonObject.insert(key, QJsonValue(value));
}
Expand All @@ -45,8 +44,7 @@ void Backup::backup(QString filePath, bool includeSensitiveInfo)
qDebug() << "[Backup] Backup completed";
}

void Backup::restore(QString filePath)
{
void Backup::restore(const QString &filePath) {
if (filePath.isEmpty()) {
return;
}
Expand All @@ -65,7 +63,7 @@ void Backup::restore(QString filePath)

QSettings settings;
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8());
if (!jsonDoc.isNull()){
if (!jsonDoc.isNull()) {
QJsonObject jsonObject = jsonDoc.object();
for (auto it = jsonObject.begin(); it != jsonObject.end(); ++it) {
QString key = it.key();
Expand Down
7 changes: 4 additions & 3 deletions src/backup/backup.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#include <QObject>
#include <QSettings>

class Backup
{
// @formatter:off
class Backup {
public:
static void backup(QString filePath, bool includeSensitiveInfo);
static void restore(QString filePath);
static void restore(const QString &filePath);
};
// @formatter:on

#endif // BACKUP_H
Loading
Loading