File: ImageTest.cpp

package info (click to toggle)
xournalpp 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,036 kB
  • sloc: cpp: 64,137; xml: 939; sh: 752; ansic: 362; python: 338; php: 74; makefile: 15
file content (54 lines) | stat: -rw-r--r-- 1,815 bytes parent folder | download | duplicates (2)
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
/*
 * Xournal++
 *
 * This file is part of the Xournal UnitTests
 *
 * @author Xournal++ Team
 * https://github.com/xournalpp/xournalpp
 *
 * @license GNU GPLv2 or later
 */

#include <fstream>

#include <config-test.h>
#include <gtest/gtest.h>

#include "model/Image.h"

#include "filesystem.h"


TEST(Image, testGetImageApplyOrientation) {
    auto image = Image();

    // Image width is 500px and height 130px - but has exif data saying image should be
    // rotated 90 deg CW to have correct orientation.
    std::ifstream imageFile{fs::path(GET_TESTFILE(u8"images/r90.jpg")), std::ios::binary};
    auto imageData = std::string(std::istreambuf_iterator<char>(imageFile), {});

    GdkPixbufLoader* loader = gdk_pixbuf_loader_new();
    gdk_pixbuf_loader_write(loader, reinterpret_cast<const guchar*>(imageData.c_str()), imageData.length(), nullptr);
    gdk_pixbuf_loader_close(loader, nullptr);

    GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);

    // Image size before  orientation
    auto origImageSize = std::make_pair(gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
    auto rotatedImageSize = std::make_pair(origImageSize.second, origImageSize.first);
    g_object_unref(loader);

    image.setImage(imageData);

    // Test Image object has no size before the image has be rendered
    EXPECT_EQ(image.getImageSize(), Image::NOSIZE);

    // getImage render the image in a cairo surface
    auto surface = image.getImage();

    // Test image now have the correct size - which is the image has been rotated.
    EXPECT_EQ(image.getImageSize(), rotatedImageSize);
    EXPECT_EQ(image.getImageSize(), std::make_pair(130, 500));
    EXPECT_EQ(std::make_pair(cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface)),
              rotatedImageSize);
}