From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- vcl/qa/cppunit/GraphicNativeMetadataTest.cxx | 105 +++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 vcl/qa/cppunit/GraphicNativeMetadataTest.cxx (limited to 'vcl/qa/cppunit/GraphicNativeMetadataTest.cxx') diff --git a/vcl/qa/cppunit/GraphicNativeMetadataTest.cxx b/vcl/qa/cppunit/GraphicNativeMetadataTest.cxx new file mode 100644 index 000000000..49bf55fa9 --- /dev/null +++ b/vcl/qa/cppunit/GraphicNativeMetadataTest.cxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +#include +#include +#include + +#include +#include +#include + +using namespace css; + +namespace +{ +class GraphicNativeMetadataTest : public test::BootstrapFixtureBase +{ + OUString getFullUrl(std::u16string_view sFileName) + { + return m_directories.getURLFromSrc(u"/vcl/qa/cppunit/data/") + sFileName; + } + + void testReadFromGraphic(); + void testExifRotationJpeg(); + + CPPUNIT_TEST_SUITE(GraphicNativeMetadataTest); + CPPUNIT_TEST(testReadFromGraphic); + CPPUNIT_TEST(testExifRotationJpeg); + CPPUNIT_TEST_SUITE_END(); +}; + +void GraphicNativeMetadataTest::testReadFromGraphic() +{ + SvFileStream aFileStream(getFullUrl(u"Exif1_180.jpg"), StreamMode::READ); + GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); + + // don't load the graphic, but try to get the metadata + Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aFileStream); + + { + GraphicNativeMetadata aMetadata; + aMetadata.read(aFileStream); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1800), aMetadata.getRotation().get()); + // just the metadata shouldn't make the graphic available + CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); + } + + // now load, and it should still work the same + { + aGraphic.makeAvailable(); + CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable()); + + GraphicNativeMetadata aMetadata; + aMetadata.read(aFileStream); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1800), aMetadata.getRotation().get()); + } +} + +void GraphicNativeMetadataTest::testExifRotationJpeg() +{ + { + // No rotation in metadata + SvFileStream aFileStream(getFullUrl(u"Exif1.jpg"), StreamMode::READ); + GraphicNativeMetadata aMetadata; + aMetadata.read(aFileStream); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aMetadata.getRotation().get()); + } + { + // Rotation 90 degree clock-wise = 270 degree counter-clock-wise + SvFileStream aFileStream(getFullUrl(u"Exif1_090CW.jpg"), StreamMode::READ); + GraphicNativeMetadata aMetadata; + aMetadata.read(aFileStream); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2700), aMetadata.getRotation().get()); + } + { + // Rotation 180 degree + SvFileStream aFileStream(getFullUrl(u"Exif1_180.jpg"), StreamMode::READ); + GraphicNativeMetadata aMetadata; + aMetadata.read(aFileStream); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1800), aMetadata.getRotation().get()); + } + { + // Rotation 270 degree clock-wise = 90 degree counter-clock-wise + SvFileStream aFileStream(getFullUrl(u"Exif1_270CW.jpg"), StreamMode::READ); + GraphicNativeMetadata aMetadata; + aMetadata.read(aFileStream); + CPPUNIT_ASSERT_EQUAL(sal_Int16(900), aMetadata.getRotation().get()); + } +} + +} // anonymous namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(GraphicNativeMetadataTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3