aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrickyLeifa <date.epoch@gmail.com>2024-05-15 00:00:17 +0200
committerTrickyLeifa <date.epoch@gmail.com>2024-05-15 00:04:16 +0200
commitc9f52b7223685d2e7fca925594171f94dd8c6e3b (patch)
tree740bb32a40da98a4d52836432f59a16b31333900 /test
parent951766666621fa77e257e6b5616fe4ab1eb2a52f (diff)
Ported to CMake, ...
* Ported the project to CMake * Android and Mac support dropped for the time being. * Tests, BASS and Discord-RPC are now options * Restructured and reformated the project. * Merged `include` and `src` * Renamed `resource` to `data` * Renamed various files * External libraries headers are no longer included in `src` * Replaced header guards with #pragma once * Multiple refactors (keywords, headers) * Added Qt6 compatibility * Removed various unused functions and headers * Reworked AOPacket * When content is passed to AOPacket, it should be ensured that the content is already decoded. * Encoding/decoding are now static methods. * Fixed various memory leaks * Removed animation code for AOImage * AOImage is always using static images * Simplified ChatLogPiece
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt22
-rw-r--r--test/test_aopacket.cpp18
-rw-r--r--test/test_apng.cpp24
-rw-r--r--test/test_bass.cpp19
-rw-r--r--test/test_caseloading.cpp8
5 files changed, 59 insertions, 32 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 393a7537..c6b191e4 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,8 +1,20 @@
-find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
+find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets REQUIRED)
find_package(Catch2 REQUIRED)
-add_executable(test test_aopacket.cpp test_caseloading.cpp test_apng.cpp test_bass.cpp ../include/aopacket.h ../src/aopacket.cpp)
-target_include_directories(test PRIVATE ../include)
+target_include_directories(test PRIVATE ../src)
target_link_directories(test PRIVATE ../lib)
-target_link_libraries(test PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Catch2::Catch2 bass bassmidi bassopus discord-rpc)
-target_compile_definitions(Attorney_Online PRIVATE DISCORD)
+target_link_libraries(test PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets Catch2::Catch2)
+
+add_executable(test
+ test_aopacket.cpp
+ test_caseloading.cpp
+ test_apng.cpp
+ ../src/aopacket.h
+ ../src/aopacket.cpp
+)
+
+if(AO_ENABLE_BASS)
+ target_compile_definitions(Attorney_Online PRIVATE AO_ENABLE_BASS)
+ target_link_libraries(Attorney_Online PRIVATE bass bassmidi bassopus)
+ target_sources(test PRIVATE test_bass.cpp)
+endif()
diff --git a/test/test_aopacket.cpp b/test/test_aopacket.cpp
index 0b318213..42ff778e 100644
--- a/test/test_aopacket.cpp
+++ b/test/test_aopacket.cpp
@@ -3,27 +3,32 @@
#include "aopacket.h"
-TEST_CASE("AOPacket construct", "[aopacket]") {
+TEST_CASE("AOPacket construct", "[aopacket]")
+{
// Parameters
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/123/edit##%";
- SECTION("Packet string") {
+ SECTION("Packet string")
+ {
AOPacket p(packet_string);
REQUIRE(p.to_string() == packet_string);
}
- SECTION("Header and contents") {
+ SECTION("Header and contents")
+ {
QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/123/edit#"};
AOPacket p("CT", contents);
REQUIRE(p.to_string() == packet_string);
}
}
-TEST_CASE("AOPacket encode/decode", "[aopacket]") {
+TEST_CASE("AOPacket encode/decode", "[aopacket]")
+{
// Parameters
QString packet_string = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/%$&/edit##%";
QString good_encode = "CT#MY_OOC_NAME#/doc https://docs.google.com/document/d/<percent><dollar><and>/edit<num>#%";
- SECTION("Bad encode/decode because packet string constructor splits the '#' after 'edit'") {
+ SECTION("Bad encode/decode because packet string constructor splits the '#' after 'edit'")
+ {
AOPacket p(packet_string);
p.net_encode();
REQUIRE(p.to_string() != good_encode);
@@ -32,7 +37,8 @@ TEST_CASE("AOPacket encode/decode", "[aopacket]") {
REQUIRE(p.to_string() == packet_string);
}
- SECTION("Good encode/decode with header and contents constructor") {
+ SECTION("Good encode/decode with header and contents constructor")
+ {
QStringList contents = {"MY_OOC_NAME", "/doc https://docs.google.com/document/d/%$&/edit#"};
AOPacket p("CT", contents);
diff --git a/test/test_apng.cpp b/test/test_apng.cpp
index 20c7e927..c092191f 100644
--- a/test/test_apng.cpp
+++ b/test/test_apng.cpp
@@ -1,12 +1,13 @@
#include <catch2/catch.hpp>
-#include <QPluginLoader>
-#include <QImageReader>
#include <QCoreApplication>
#include <QGuiApplication>
+#include <QImageReader>
#include <QPixmap>
+#include <QPluginLoader>
-TEST_CASE("Support APNG Plugin", "[apng]") {
+TEST_CASE("Support APNG Plugin", "[apng]")
+{
// Check paths for libs
QCoreApplication::addLibraryPath(".");
QCoreApplication::addLibraryPath("lib");
@@ -19,38 +20,43 @@ TEST_CASE("Support APNG Plugin", "[apng]") {
REQUIRE(QImageReader::supportedImageFormats().contains("apng"));
}
-TEST_CASE("Detect png animation", "[apng]") {
+TEST_CASE("Detect png animation", "[apng]")
+{
// Required for QPixmap methods
int argc = 1;
char bin[] = "test";
- char *argv[] = { bin };
+ char *argv[] = {bin};
QGuiApplication app(argc, argv);
// Instantiate reader
QImageReader reader;
- SECTION("Decide format from content fails on apng") {
+ SECTION("Decide format from content fails on apng")
+ {
reader.setFileName("snackoo.png");
reader.setDecideFormatFromContent(true);
REQUIRE(!reader.supportsAnimation());
REQUIRE(!QPixmap::fromImage(reader.read()).isNull());
}
- SECTION("Auto detect fails on apng") {
+ SECTION("Auto detect fails on apng")
+ {
reader.setFileName("snackoo.png");
reader.setAutoDetectImageFormat(true);
REQUIRE(!reader.supportsAnimation());
REQUIRE(!QPixmap::fromImage(reader.read()).isNull());
}
- SECTION("Detect apng supports animation") {
+ SECTION("Detect apng supports animation")
+ {
reader.setFileName("snackoo.png");
reader.setFormat("apng");
REQUIRE(reader.supportsAnimation());
REQUIRE(!QPixmap::fromImage(reader.read()).isNull());
}
- SECTION("Detect png frame has no animation") {
+ SECTION("Detect png frame has no animation")
+ {
reader.setFileName("missle.png");
reader.setFormat("apng");
REQUIRE(!reader.supportsAnimation());
diff --git a/test/test_bass.cpp b/test/test_bass.cpp
index e48decd8..0e97b6a1 100644
--- a/test/test_bass.cpp
+++ b/test/test_bass.cpp
@@ -1,14 +1,15 @@
-#include <iostream>
#include <cstring>
+#include <iostream>
-#include <catch2/catch.hpp>
#include <QString>
+#include <catch2/catch.hpp>
#include "bass.h"
#include "bassmidi.h"
#include "bassopus.h"
-TEST_CASE("BASS URL streaming", "[bass][noci]") {
+TEST_CASE("BASS URL streaming", "[bass][noci]")
+{
// Sample
QString url = "https://raw.githubusercontent.com/skyedeving/aocharedit/master/Attorney%20Online%20Character%20Editor/Resources/about.mp3";
@@ -18,17 +19,21 @@ TEST_CASE("BASS URL streaming", "[bass][noci]") {
// create stream from url
HSTREAM stream;
unsigned int flags = BASS_STREAM_AUTOFREE | BASS_STREAM_STATUS;
- if (url.endsWith(".opus")) {
+ if (url.endsWith(".opus"))
+ {
stream = BASS_OPUS_StreamCreateURL(url.toStdString().c_str(), 0, flags, nullptr, 0);
}
- else {
+ else
+ {
stream = BASS_StreamCreateURL(url.toStdString().c_str(), 0, flags, nullptr, 0);
}
// Log http status
const char *tags = BASS_ChannelGetTags(stream, BASS_TAG_HTTP);
- if (tags) {
- while(*tags) {
+ if (tags)
+ {
+ while (*tags)
+ {
UNSCOPED_INFO(tags);
tags += strlen(tags) + 1;
}
diff --git a/test/test_caseloading.cpp b/test/test_caseloading.cpp
index 5df27823..dd82c7e5 100644
--- a/test/test_caseloading.cpp
+++ b/test/test_caseloading.cpp
@@ -2,16 +2,14 @@
#include <QStringList>
-TEST_CASE("Sort case evidence numerically", "[case]") {
+TEST_CASE("Sort case evidence numerically", "[case]")
+{
// Parameters
QStringList case_evidence = {"1", "10", "11", "2", "3", "4", "5", "6", "7", "8", "9"};
QStringList case_evidence_sorted = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"};
// Sort
- std::sort(case_evidence.begin(), case_evidence.end(),
- [] (const QString &a, const QString &b) {
- return a.toInt() < b.toInt();
- });
+ std::sort(case_evidence.begin(), case_evidence.end(), [](const QString &a, const QString &b) { return a.toInt() < b.toInt(); });
// Test
REQUIRE(case_evidence == case_evidence_sorted);