musikr: fix tests
Had to remove some, but they were outdated anyway.
This commit is contained in:
parent
2fd4fd751f
commit
d228793e9b
6 changed files with 135 additions and 170 deletions
|
@ -25,7 +25,7 @@ import dagger.hilt.InstallIn
|
|||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
import org.oxycblt.musikr.cache.SongCache
|
||||
import org.oxycblt.musikr.cache.MutableSongCache
|
||||
import org.oxycblt.musikr.cache.db.DBSongCache
|
||||
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
||||
|
||||
|
@ -34,7 +34,8 @@ import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
|||
class MusikrShimModule {
|
||||
@Singleton
|
||||
@Provides
|
||||
fun songCache(@ApplicationContext context: Context): SongCache = DBSongCache.from(context)
|
||||
fun songCache(@ApplicationContext context: Context): MutableSongCache =
|
||||
DBSongCache.from(context)
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
|
|
|
@ -153,6 +153,7 @@ private class MusikrImpl(
|
|||
.buffer(Channel.UNLIMITED)
|
||||
.onStart { onProgress(IndexingProgress.Songs(0, 0)) }
|
||||
.onEach { onProgress(IndexingProgress.Songs(extractedCount, ++exploredCount)) }
|
||||
|
||||
val typeDiversion =
|
||||
explored.divert {
|
||||
when (it) {
|
||||
|
@ -162,15 +163,18 @@ private class MusikrImpl(
|
|||
}
|
||||
val known = typeDiversion.right
|
||||
val new = typeDiversion.left
|
||||
|
||||
val extracted =
|
||||
extractStep
|
||||
.extract(new)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
.onEach { onProgress(IndexingProgress.Songs(++extractedCount, exploredCount)) }
|
||||
.onCompletion { onProgress(IndexingProgress.Indeterminate) }
|
||||
|
||||
val complete =
|
||||
merge(typeDiversion.manager, known, extracted.filterIsInstance<Extracted.Valid>())
|
||||
val library = evaluateStep.evaluate(complete)
|
||||
|
||||
LibraryResultImpl(storage, library)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,33 +57,11 @@ internal fun Metadata.disc() =
|
|||
(xiph["TOTALDISCS"] ?: xiph["DISCTOTAL"] ?: xiph["DISCC"])?.run { first() })
|
||||
?: (mp4["disk"] ?: id3v2["TPOS"])?.run { first().parseJoinedPosition() })
|
||||
|
||||
/**
|
||||
* Parse an ID3v2-style position + total [String] field. These fields consist of a number and an
|
||||
* (optional) total value delimited by a /.
|
||||
*
|
||||
* @return The position value extracted from the string field, or null if:
|
||||
* - The position could not be parsed
|
||||
* - The position was zeroed AND the total value was not present/zeroed
|
||||
*
|
||||
* @see transformPosition
|
||||
*/
|
||||
private fun String.parseJoinedPosition() =
|
||||
split('/', limit = 2).let {
|
||||
transformPosition(it[0].toIntOrNull(), it.getOrNull(1)?.toIntOrNull())
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a vorbis-style position + total field. These fields consist of two fields for the position
|
||||
* and total numbers.
|
||||
*
|
||||
* @param pos The position value, or null if not present.
|
||||
* @param total The total value, if not present.
|
||||
* @return The position value extracted from the field, or null if:
|
||||
* - The position could not be parsed
|
||||
* - The position was zeroed AND the total value was not present/zeroed
|
||||
*
|
||||
* @see transformPosition
|
||||
*/
|
||||
private fun parseSeparatedPosition(pos: String?, total: String?) =
|
||||
pos?.let { posStr ->
|
||||
posStr.toIntOrNull()?.let { transformPosition(it, total?.toIntOrNull()) }
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* ID3GenreTest.kt is part of Auxio.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.musikr.tag.interpret
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class ID3GenreTest {
|
||||
@Test
|
||||
fun parseId3v2Genre_multi() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_multiId3v1() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("176", "178", "Glitch").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_wackId3() {
|
||||
assertEquals(null, listOf("2941").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_singleId3v23() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Remix", "Cover", "Glitch"),
|
||||
listOf("(176)(178)(RX)(CR)Glitch").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_singleId3v1() {
|
||||
assertEquals(listOf("Post-Rock"), listOf("176").parseId3GenreNames())
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* TagUtilTest.kt is part of Auxio.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.musikr.tag.parse
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.oxycblt.musikr.tag.format.parseId3GenreNames
|
||||
import org.oxycblt.musikr.tag.format.parseSlashPositionField
|
||||
import org.oxycblt.musikr.tag.format.parseXiphPositionField
|
||||
import org.oxycblt.musikr.util.correctWhitespace
|
||||
import org.oxycblt.musikr.util.splitEscaped
|
||||
|
||||
class TagUtilTest {
|
||||
@Test
|
||||
fun splitEscaped_correct() {
|
||||
assertEquals(listOf("a", "b", "c"), "a,b,c".splitEscaped { it == ',' })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun splitEscaped_escaped() {
|
||||
assertEquals(listOf("a,b", "c"), "a\\,b,c".splitEscaped { it == ',' })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun splitEscaped_whitespace() {
|
||||
assertEquals(listOf("a ", " b", " c ", " "), "a , b, c , ".splitEscaped { it == ',' })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun splitEscaped_escapedWhitespace() {
|
||||
assertEquals(listOf("a , b", " c ", " "), ("a \\, b, c , ".splitEscaped { it == ',' }))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_stringCorrect() {
|
||||
assertEquals(
|
||||
"asymptotic self-improvement",
|
||||
" asymptotic self-improvement ".correctWhitespace(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_stringOopsAllWhitespace() {
|
||||
assertEquals(null, "".correctWhitespace())
|
||||
assertEquals(null, " ".correctWhitespace())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_listCorrect() {
|
||||
assertEquals(
|
||||
listOf("asymptotic self-improvement", "daemons never stop", "tcp phagocyte"),
|
||||
listOf(" asymptotic self-improvement ", " daemons never stop", "tcp phagocyte")
|
||||
.correctWhitespace(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_listOopsAllWhitespace() {
|
||||
assertEquals(
|
||||
listOf("tcp phagocyte"), listOf(" ", "", " tcp phagocyte").correctWhitespace())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2PositionField_correct() {
|
||||
assertEquals(16, "16/32".parseSlashPositionField())
|
||||
assertEquals(16, "16".parseSlashPositionField())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2PositionField_zeroed() {
|
||||
assertEquals(null, "0".parseSlashPositionField())
|
||||
assertEquals(0, "0/32".parseSlashPositionField())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2PositionField_wack() {
|
||||
assertEquals(16, "16/".parseSlashPositionField())
|
||||
assertEquals(null, "a".parseSlashPositionField())
|
||||
assertEquals(null, "a/b".parseSlashPositionField())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseVorbisPositionField_correct() {
|
||||
assertEquals(16, parseXiphPositionField("16", "32"))
|
||||
assertEquals(16, parseXiphPositionField("16", null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseVorbisPositionField_zeroed() {
|
||||
assertEquals(null, parseXiphPositionField("0", null))
|
||||
assertEquals(0, parseXiphPositionField("0", "32"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseVorbisPositionField_wack() {
|
||||
assertEquals(null, parseXiphPositionField("a", null))
|
||||
assertEquals(null, parseXiphPositionField("a", "b"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_multi() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_multiId3v1() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("176", "178", "Glitch").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_wackId3() {
|
||||
assertEquals(null, listOf("2941").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_singleId3v23() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Remix", "Cover", "Glitch"),
|
||||
listOf("(176)(178)(RX)(CR)Glitch").parseId3GenreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parsId3v2Genre_singleId3v1() {
|
||||
assertEquals(listOf("Post-Rock"), listOf("176").parseId3GenreNames())
|
||||
}
|
||||
}
|
73
musikr/src/test/java/org/oxycblt/musikr/util/TagFieldTest.kt
Normal file
73
musikr/src/test/java/org/oxycblt/musikr/util/TagFieldTest.kt
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* TagFieldTest.kt is part of Auxio.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.musikr.util
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class TagFieldTest {
|
||||
@Test
|
||||
fun splitEscaped_correct() {
|
||||
assertEquals(listOf("a", "b", "c"), "a,b,c".splitEscaped { it == ',' })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun splitEscaped_escaped() {
|
||||
assertEquals(listOf("a,b", "c"), "a\\,b,c".splitEscaped { it == ',' })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun splitEscaped_whitespace() {
|
||||
assertEquals(listOf("a ", " b", " c ", " "), "a , b, c , ".splitEscaped { it == ',' })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun splitEscaped_escapedWhitespace() {
|
||||
assertEquals(listOf("a , b", " c ", " "), ("a \\, b, c , ".splitEscaped { it == ',' }))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_stringCorrect() {
|
||||
assertEquals(
|
||||
"asymptotic self-improvement",
|
||||
" asymptotic self-improvement ".correctWhitespace(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_stringOopsAllWhitespace() {
|
||||
assertEquals(null, "".correctWhitespace())
|
||||
assertEquals(null, " ".correctWhitespace())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_listCorrect() {
|
||||
assertEquals(
|
||||
listOf("asymptotic self-improvement", "daemons never stop", "tcp phagocyte"),
|
||||
listOf(" asymptotic self-improvement ", " daemons never stop", "tcp phagocyte")
|
||||
.correctWhitespace(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun correctWhitespace_listOopsAllWhitespace() {
|
||||
assertEquals(
|
||||
listOf("tcp phagocyte"), listOf(" ", "", " tcp phagocyte").correctWhitespace())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue