Skip to content

Commit

Permalink
Remove resources lib due to lack of WASM support (#46)
Browse files Browse the repository at this point in the history
Removed `com.goncalossilva:resources` due to the lack of WASM support,
because `kotlinx-io` can fully replace it.
  • Loading branch information
StefanOltmann authored Dec 15, 2023
1 parent 8f50c31 commit 49a94e8
Show file tree
Hide file tree
Showing 12 changed files with 3,802 additions and 32 deletions.
19 changes: 16 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ kotlin {

/* Kotlin Test */
implementation(kotlin("test"))

/* Multiplatform test resources */
implementation("com.goncalossilva:resources:$testRessourcesVersion")
}
}

Expand Down Expand Up @@ -256,6 +253,22 @@ kotlin {
macosArm64Main.dependsOn(this)
}

val iosArm64Test by sourceSets.getting
val iosSimulatorArm64Test by sourceSets.getting
val macosX64Test by sourceSets.getting
val macosArm64Test by sourceSets.getting

@Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive
val appleTest by sourceSets.creating {

dependsOn(commonTest)

iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
macosX64Test.dependsOn(this)
macosArm64Test.dependsOn(this)
}

val wasmJsMain by sourceSets.getting
// val wasmWasiMain by sourceSets.getting

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2023 Ashampoo GmbH & Co. KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ashampoo.kim

actual fun getPathForResource(path: String): String = path
28 changes: 28 additions & 0 deletions src/appleTest/kotlin/com/ashampoo/kim/ResourcePath.apple.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023 Ashampoo GmbH & Co. KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ashampoo.kim

import platform.Foundation.NSBundle

actual fun getPathForResource(path: String): String {

val pathForResource = NSBundle.mainBundle.pathForResource(
path.substringBeforeLast("."),
path.substringAfterLast(".")
).toString()

return pathForResource
}
18 changes: 18 additions & 0 deletions src/commonTest/kotlin/com/ashampoo/kim/ResourcePath.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2023 Ashampoo GmbH & Co. KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ashampoo.kim

expect fun getPathForResource(path: String): String
24 changes: 24 additions & 0 deletions src/commonTest/kotlin/com/ashampoo/kim/common/ZLibTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.ashampoo.kim.common

import com.ashampoo.kim.getPathForResource
import kotlinx.io.files.Path
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
Expand Down Expand Up @@ -130,4 +132,26 @@ class ZLibTest {
for (entry in zlibTestData)
assertEquals(entry.key, decompress(entry.value))
}

@Test
fun testRoundtripWithLongText() {

val testString = Path(getPathForResource(RESOURCE_PATH)).readBytes().decodeToString()

val compressed = compress(testString)

val decompressed = decompress(compressed)

assertEquals(
expected = testString,
actual = decompressed,
message = "Test string differs."
)
}

companion object {

private const val RESOURCE_PATH: String =
"src/commonTest/resources/com/ashampoo/kim/testdata/alice_in_wonderland.txt"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
package com.ashampoo.kim.format.jpeg

import com.ashampoo.kim.Kim
import com.ashampoo.kim.common.exists
import com.ashampoo.kim.common.readBytes
import com.ashampoo.kim.common.writeBytes
import com.ashampoo.kim.getPathForResource
import com.ashampoo.kim.model.GpsCoordinates
import com.ashampoo.kim.model.MetadataUpdate
import com.ashampoo.kim.model.PhotoRating
import com.ashampoo.kim.model.TiffOrientation
import com.goncalossilva.resources.Resource
import kotlinx.io.files.Path
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -40,12 +42,17 @@ class JpegUpdaterTest {

private val resourcePath: String = "src/commonTest/resources/com/ashampoo/kim/updates_jpg"

private val originalBytes = Resource("$resourcePath/original.jpg").readBytes()
private val originalBytes = Path(
getPathForResource("$resourcePath/original.jpg")
).readBytes()

private val noMetadataBytes = Resource("$resourcePath/no_metadata.jpg").readBytes()
private val noMetadataBytes = Path(
getPathForResource("$resourcePath/no_metadata.jpg")
).readBytes()

private val thumbnailBytes =
Resource("$resourcePath/../testdata/test_thumb.jpg").readBytes()
private val thumbnailBytes = Path(
getPathForResource("$resourcePath/../testdata/test_thumb.jpg")
).readBytes()

@BeforeTest
fun setUp() {
Expand Down Expand Up @@ -223,17 +230,17 @@ class JpegUpdaterTest {
@OptIn(ExperimentalStdlibApi::class)
private fun compare(fileName: String, actualBytes: ByteArray) {

val resource = Resource("$resourcePath/$fileName")
val path = Path(getPathForResource("$resourcePath/$fileName"))

if (!resource.exists()) {
if (!path.exists()) {

Path("build/$fileName")
.writeBytes(actualBytes)

fail("Reference image $fileName does not exist.")
}

val expectedBytes = resource.readBytes()
val expectedBytes = path.readBytes()

val equals = expectedBytes.contentEquals(actualBytes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
package com.ashampoo.kim.format.png

import com.ashampoo.kim.Kim
import com.ashampoo.kim.common.exists
import com.ashampoo.kim.common.readBytes
import com.ashampoo.kim.common.writeBytes
import com.ashampoo.kim.getPathForResource
import com.ashampoo.kim.model.GpsCoordinates
import com.ashampoo.kim.model.MetadataUpdate
import com.ashampoo.kim.model.PhotoRating
import com.ashampoo.kim.model.TiffOrientation
import com.goncalossilva.resources.Resource
import kotlinx.io.files.Path
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -40,10 +42,13 @@ class PngUpdaterTest {

private val resourcePath: String = "src/commonTest/resources/com/ashampoo/kim/updates_png"

private val originalBytes = Resource("$resourcePath/original.png").readBytes()
private val originalBytes = Path(
getPathForResource("$resourcePath/original.png")
).readBytes()

private val thumbnailBytes =
Resource("$resourcePath/../testdata/test_thumb.jpg").readBytes()
private val thumbnailBytes = Path(
getPathForResource("$resourcePath/../testdata/test_thumb.jpg")
).readBytes()

@BeforeTest
fun setUp() {
Expand Down Expand Up @@ -137,17 +142,17 @@ class PngUpdaterTest {
@OptIn(ExperimentalStdlibApi::class)
private fun compare(fileName: String, actualBytes: ByteArray) {

val resource = Resource("$resourcePath/$fileName")
val path = Path(getPathForResource("$resourcePath/$fileName"))

if (!resource.exists()) {
if (!path.exists()) {

Path("build/$fileName")
.writeBytes(actualBytes)

fail("Reference image $fileName does not exist.")
}

val expectedBytes = resource.readBytes()
val expectedBytes = path.readBytes()

val equals = expectedBytes.contentEquals(actualBytes)

Expand Down
31 changes: 17 additions & 14 deletions src/commonTest/kotlin/com/ashampoo/kim/testdata/KimTestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.ashampoo.kim.testdata

import com.goncalossilva.resources.Resource
import com.ashampoo.kim.common.readBytes
import com.ashampoo.kim.getPathForResource
import kotlinx.io.files.Path

/**
* This object extracts the bundled test
Expand Down Expand Up @@ -108,44 +110,45 @@ object KimTestData {
fun getFileName(index: Int): String = "photo_$index.${getExtension(index)}"

fun getFullImageDiskPath(index: Int): String =
"$RESOURCE_PATH/full/${getFileName(index)}"
getPathForResource("$RESOURCE_PATH/full/${getFileName(index)}")

fun getBytesOf(index: Int): ByteArray =
getBytesOf(getFileName(index))

fun getBytesOf(fileName: String): ByteArray =
Resource("$RESOURCE_PATH/full/$fileName").readBytes()
Path(getPathForResource("$RESOURCE_PATH/full/$fileName")).readBytes()

fun getHeaderBytesOf(index: Int): ByteArray =
Resource("$RESOURCE_PATH/headers/photo_${index}_header.${getExtension(index)}").readBytes()
Path(getPathForResource("$RESOURCE_PATH/headers/photo_${index}_header.${getExtension(index)}")).readBytes()

fun getModifiedBytesOf(index: Int): ByteArray =
Resource("$RESOURCE_PATH/modified/photo_${index}_modified.${getExtension(index)}").readBytes()
Path(getPathForResource("$RESOURCE_PATH/modified/photo_${index}_modified.${getExtension(index)}")).readBytes()

fun getExifThumbnailBytesOf(index: Int): ByteArray =
Resource("$RESOURCE_PATH/exifthumbs/photo_${index}_exifthumb.jpg").readBytes()
Path(getPathForResource("$RESOURCE_PATH/exifthumbs/photo_${index}_exifthumb.jpg")).readBytes()

fun getPreviewBytesOf(index: Int): ByteArray =
Resource("$RESOURCE_PATH/previews/photo_${index}_preview.jpg").readBytes()
Path(getPathForResource("$RESOURCE_PATH/previews/photo_${index}_preview.jpg")).readBytes()

fun getHeaderExifBytesOf(index: Int): ByteArray =
Resource("$RESOURCE_PATH/headers/photo_${index}_header_exif.tif").readBytes()
Path(getPathForResource("$RESOURCE_PATH/headers/photo_${index}_header_exif.tif")).readBytes()

fun getHeaderTextFile(index: Int, identifier: String): String =
Resource("$RESOURCE_PATH/headers/photo_${index}_header_$identifier.txt").readText()
Path(getPathForResource("$RESOURCE_PATH/headers/photo_${index}_header_$identifier.txt")).readBytes()
.decodeToString()

fun getToStringText(index: Int): ByteArray =
Resource("$RESOURCE_PATH/txt/photo_$index.txt").readBytes()
Path(getPathForResource("$RESOURCE_PATH/txt/photo_$index.txt")).readBytes()

fun getXmp(fileName: String): String =
Resource("$RESOURCE_PATH/xmp/$fileName").readText()
Path(getPathForResource("$RESOURCE_PATH/xmp/$fileName")).readBytes().decodeToString()

fun getOriginalXmp(index: Int): ByteArray =
Resource("$RESOURCE_PATH/xmp/photo_$index.xmp").readBytes()
Path(getPathForResource("$RESOURCE_PATH/xmp/photo_$index.xmp")).readBytes()

fun getFormattedXmp(index: Int): String =
Resource("$RESOURCE_PATH/xmp/photo_${index}_formatted.xmp").readText()
Path(getPathForResource("$RESOURCE_PATH/xmp/photo_${index}_formatted.xmp")).readBytes().decodeToString()

fun getMetadataCsvString(): String =
Resource("$RESOURCE_PATH/metadata.csv").readText()
Path(getPathForResource("$RESOURCE_PATH/metadata.csv")).readBytes().decodeToString()
}
Loading

0 comments on commit 49a94e8

Please sign in to comment.