diff options
| author | oldmud0 <oldmud0@users.noreply.github.com> | 2021-01-29 12:17:54 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-29 12:17:54 -0600 |
| commit | 097220f11afa9cb0a045ac21fdedad6e0df69f57 (patch) | |
| tree | cd9ea0054cf3ec4e584ff650bce7e0a3967ce9e8 /test | |
| parent | 5cafb011f5b3cc2aef780f767e0bf054d18efc0f (diff) | |
| parent | 9242c3dd0d6429ae79679c1f7a2846c228f6d3e8 (diff) | |
Merge pull request #368 from skyedeving/add-tests
Add a CMakeLists, tests, and pipeline to automatically test with Github actions
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | test/missle.png | bin | 0 -> 55423 bytes | |||
| -rw-r--r-- | test/snackoo.png | bin | 0 -> 92034 bytes | |||
| -rw-r--r-- | test/test_aopacket.cpp | 45 | ||||
| -rw-r--r-- | test/test_apng.cpp | 61 | ||||
| -rw-r--r-- | test/test_bass.cpp | 40 | ||||
| -rw-r--r-- | test/test_caseloading.cpp | 18 |
7 files changed, 172 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..e43b5517 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +find_package(Qt5 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_link_directories(test PRIVATE ../lib) +target_link_libraries(test PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Catch2::Catch2 bass bassopus discord-rpc) +target_compile_definitions(Attorney_Online PRIVATE DISCORD) diff --git a/test/missle.png b/test/missle.png Binary files differnew file mode 100644 index 00000000..6f373b45 --- /dev/null +++ b/test/missle.png diff --git a/test/snackoo.png b/test/snackoo.png Binary files differnew file mode 100644 index 00000000..31577a31 --- /dev/null +++ b/test/snackoo.png diff --git a/test/test_aopacket.cpp b/test/test_aopacket.cpp new file mode 100644 index 00000000..0b318213 --- /dev/null +++ b/test/test_aopacket.cpp @@ -0,0 +1,45 @@ +#define CATCH_CONFIG_MAIN +#include <catch2/catch.hpp> + +#include "aopacket.h" + +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") { + AOPacket p(packet_string); + REQUIRE(p.to_string() == packet_string); + } + 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]") { + // 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'") { + AOPacket p(packet_string); + p.net_encode(); + REQUIRE(p.to_string() != good_encode); + + p.net_decode(); + REQUIRE(p.to_string() == packet_string); + } + + 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); + + p.net_encode(); + REQUIRE(p.to_string() == good_encode); + + p.net_decode(); + REQUIRE(p.to_string() == packet_string); + } +} diff --git a/test/test_apng.cpp b/test/test_apng.cpp new file mode 100644 index 00000000..20c7e927 --- /dev/null +++ b/test/test_apng.cpp @@ -0,0 +1,61 @@ +#include <catch2/catch.hpp> + +#include <QPluginLoader> +#include <QImageReader> +#include <QCoreApplication> +#include <QGuiApplication> +#include <QPixmap> + +TEST_CASE("Support APNG Plugin", "[apng]") { + // Check paths for libs + QCoreApplication::addLibraryPath("."); + QCoreApplication::addLibraryPath("lib"); + + // Either it's loaded from system or we load local + QPluginLoader apngPlugin("qapng"); + apngPlugin.load(); + + INFO(QImageReader::supportedImageFormats().join(' ').toStdString()); + REQUIRE(QImageReader::supportedImageFormats().contains("apng")); +} + +TEST_CASE("Detect png animation", "[apng]") { + // Required for QPixmap methods + int argc = 1; + char bin[] = "test"; + char *argv[] = { bin }; + QGuiApplication app(argc, argv); + + // Instantiate reader + QImageReader reader; + + 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") { + reader.setFileName("snackoo.png"); + reader.setAutoDetectImageFormat(true); + REQUIRE(!reader.supportsAnimation()); + REQUIRE(!QPixmap::fromImage(reader.read()).isNull()); + } + + 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") { + reader.setFileName("missle.png"); + reader.setFormat("apng"); + REQUIRE(!reader.supportsAnimation()); + reader.setFormat("png"); + REQUIRE(!reader.supportsAnimation()); + REQUIRE(!QPixmap::fromImage(reader.read()).isNull()); + } +} diff --git a/test/test_bass.cpp b/test/test_bass.cpp new file mode 100644 index 00000000..f5f9198d --- /dev/null +++ b/test/test_bass.cpp @@ -0,0 +1,40 @@ +#include <iostream> +#include <cstring> + +#include <catch2/catch.hpp> +#include <QString> + +#include "bass.h" +#include "bassopus.h" + +TEST_CASE("BASS URL streaming", "[bass][noci]") { + // Sample + QString url = "https://raw.githubusercontent.com/skyedeving/aocharedit/master/Attorney%20Online%20Character%20Editor/Resources/about.mp3"; + + // initialize + BASS_Init(-1, 44100, 0, 0, nullptr); + + // create stream from url + HSTREAM stream; + unsigned int flags = BASS_STREAM_AUTOFREE | BASS_STREAM_STATUS; + if (url.endsWith(".opus")) { + stream = BASS_OPUS_StreamCreateURL(url.toStdString().c_str(), 0, flags, nullptr, 0); + } + 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) { + UNSCOPED_INFO(tags); + tags += strlen(tags) + 1; + } + } + + // Test + REQUIRE(stream != 0); + REQUIRE(BASS_ChannelPlay(stream, TRUE) == TRUE); + // while (BASS_ChannelIsActive(stream) != BASS_ACTIVE_STOPPED); // block test to listen +} diff --git a/test/test_caseloading.cpp b/test/test_caseloading.cpp new file mode 100644 index 00000000..5df27823 --- /dev/null +++ b/test/test_caseloading.cpp @@ -0,0 +1,18 @@ +#include <catch2/catch.hpp> + +#include <QStringList> + +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(); + }); + + // Test + REQUIRE(case_evidence == case_evidence_sorted); +} |
