aboutsummaryrefslogtreecommitdiff
path: root/test/test_apng.cpp
blob: 50965ad53ebc49249bf4801e3a3d68739b5e280b (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
#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][noci]") {
  // Required for QPixmap methods
  int argc = 1;
  char bin[] = "test";
  char *argv[] = { bin };
  QGuiApplication app(argc, argv);

  // Detect apng supports animation
  QImageReader a("snackoo.png", "apng");
  REQUIRE(a.supportsAnimation());
  REQUIRE(!QPixmap::fromImage(a.read()).isNull());

  // Detect png frame has no animation
  QImageReader p("snackoo-frame.png", "apng");
  REQUIRE(!p.supportsAnimation());
  p.setFormat("png");
  REQUIRE(!QPixmap::fromImage(p.read()).isNull());

  // Auto detect fails on apng
  QImageReader d;
  d.setDecideFormatFromContent(true);
  d.setFileName("snackoo.png");
  REQUIRE(!d.supportsAnimation());
  REQUIRE(!QPixmap::fromImage(d.read()).isNull());

  // Decide format fom content fails on apng
  QImageReader c;
  c.setDecideFormatFromContent(true);
  c.setFileName("snackoo.png");
  REQUIRE(!c.supportsAnimation());
  REQUIRE(!QPixmap::fromImage(c.read()).isNull());
}