From 3a7fa499d1fc8fb78ed4d6cae88dd6332bbc3ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Thu, 20 Jan 2022 18:19:30 +0100 Subject: [PATCH] Add two tests for image compression, one failing deliberately atm --- .../attachment/media/ImageCompressorTest.kt | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/test/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorTest.kt diff --git a/src/test/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorTest.kt b/src/test/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorTest.kt new file mode 100644 index 0000000000..62647bc9c2 --- /dev/null +++ b/src/test/kotlin/org/briarproject/briar/desktop/attachment/media/ImageCompressorTest.kt @@ -0,0 +1,68 @@ +/* + * Briar Desktop + * Copyright (C) 2021-2022 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop.attachment.media + +import java.net.URL +import javax.imageio.ImageIO +import kotlin.test.Test + +class ImageCompressorTest { + + private val compressor = ImageCompressorImpl() + + @Test + fun `can compress voronoi image`() { + // load image + val input = Thread.currentThread().contextClassLoader.getResourceAsStream("images/voronoi1.png") + val image = input.use { + ImageIO.read(input) + } + println("image size: ${image.width}x${image.height}") + + // compress image + val compressed = compressor.compressImage(image) + + // reload compressed image + val reloaded = compressed.use { + ImageIO.read(compressed) + } + println("image size: ${reloaded.width}x${reloaded.height}") + } + + @Test + fun `can compress quasar`() { + // load image + val url = "https://upload.wikimedia.org/wikipedia/commons/3/38/Artist%27s_rendering_ULAS_J1120%2B0641.jpg" + val input = URL(url).openStream() + val image = input.use { + ImageIO.read(input) + } + println("image size: ${image.width}x${image.height}") + + // compress image + val compressed = compressor.compressImage(image) + + // reload compressed image + val reloaded = compressed.use { + ImageIO.read(compressed) + } + println("image size: ${reloaded.width}x${reloaded.height}") + } + +} -- GitLab