aboutsummaryrefslogtreecommitdiff
path: root/test/test_apng.cpp
blob: 20c7e92775dc0cb6be983ee86fc6dacc502be248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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());
  }
}