|
5 | 5 |
|
6 | 6 | package app.morphe.patcher.patch |
7 | 7 |
|
| 8 | +import org.junit.jupiter.api.assertDoesNotThrow |
8 | 9 | import org.junit.jupiter.api.assertThrows |
9 | 10 | import kotlin.test.Test |
10 | 11 | import kotlin.test.assertEquals |
@@ -338,4 +339,115 @@ internal object CompatibilityTest { |
338 | 339 | sorted |
339 | 340 | ) |
340 | 341 | } |
| 342 | + |
| 343 | + @Test |
| 344 | + fun `compatibility color string`() { |
| 345 | + val colorString = Compatibility( |
| 346 | + name = "Example app", |
| 347 | + packageName = "compatible.package", |
| 348 | + targets = listOf( |
| 349 | + AppTarget(version = "1.1.0", isExperimental = true), |
| 350 | + AppTarget(version = "1.0.0", isExperimental = true) |
| 351 | + ), |
| 352 | + appIconColor = "#FF0000" |
| 353 | + ) |
| 354 | + |
| 355 | + val colorInt = Compatibility( |
| 356 | + name = "Example app", |
| 357 | + packageName = "compatible.package", |
| 358 | + targets = listOf( |
| 359 | + AppTarget(version = "1.1.0", isExperimental = true), |
| 360 | + AppTarget(version = "1.0.0", isExperimental = true) |
| 361 | + ), |
| 362 | + appIconColor = 0xFF0000 |
| 363 | + ) |
| 364 | + |
| 365 | + assertEquals(colorString.appIconColor, colorInt.appIconColor) |
| 366 | + |
| 367 | + assertThrows<Exception> { |
| 368 | + Compatibility( |
| 369 | + name = "Example app", |
| 370 | + packageName = "compatible.package", |
| 371 | + targets = listOf( |
| 372 | + AppTarget(version = "1.1.0", isExperimental = true), |
| 373 | + AppTarget(version = "1.0.0", isExperimental = true) |
| 374 | + ), |
| 375 | + appIconColor = "#00FF0000" |
| 376 | + ) |
| 377 | + } |
| 378 | + |
| 379 | + assertThrows<Exception> { |
| 380 | + Compatibility( |
| 381 | + name = "Example app", |
| 382 | + packageName = "compatible.package", |
| 383 | + targets = listOf( |
| 384 | + AppTarget(version = "1.1.0", isExperimental = true), |
| 385 | + AppTarget(version = "1.0.0", isExperimental = true) |
| 386 | + ), |
| 387 | + appIconColor = "#0000" |
| 388 | + ) |
| 389 | + } |
| 390 | + } |
| 391 | + |
| 392 | + @Test |
| 393 | + fun `app version code`() { |
| 394 | + var compatibility = Compatibility( |
| 395 | + name = "Example app", |
| 396 | + packageName = "compatible.package", |
| 397 | + apkFileType = ApkFileType.APKM, |
| 398 | + targets = listOf( |
| 399 | + AppTarget( |
| 400 | + version = "1.0.0", versionCodes = mapOf( |
| 401 | + SupportedAbi.X86_64 to 100, |
| 402 | + SupportedAbi.ARMEABI_V7A to 300, |
| 403 | + SupportedAbi.ARM64_V8A to 400 |
| 404 | + ) |
| 405 | + ) |
| 406 | + ) |
| 407 | + ) |
| 408 | + |
| 409 | + var versionCodes = compatibility.targets.first().versionCodes!! |
| 410 | + |
| 411 | + assertEquals(3, versionCodes.count()) |
| 412 | + assertEquals(100, versionCodes[SupportedAbi.X86_64]) |
| 413 | + assertEquals(null, versionCodes[SupportedAbi.X86]) |
| 414 | + assertEquals(300, versionCodes[SupportedAbi.ARMEABI_V7A]) |
| 415 | + assertEquals(400, versionCodes[SupportedAbi.ARM64_V8A]) |
| 416 | + |
| 417 | + // Universal APK |
| 418 | + compatibility = Compatibility( |
| 419 | + name = "Example app", |
| 420 | + packageName = "compatible.package", |
| 421 | + apkFileType = ApkFileType.APK, |
| 422 | + targets = listOf( |
| 423 | + AppTarget(version = "1.0.0", versionCode = 500) |
| 424 | + ) |
| 425 | + ) |
| 426 | + versionCodes = compatibility.targets.first().versionCodes!! |
| 427 | + |
| 428 | + assertEquals(4, versionCodes.count()) |
| 429 | + assertTrue(versionCodes.all { it.value == 500 }) |
| 430 | + |
| 431 | + |
| 432 | + // No version codes |
| 433 | + compatibility = Compatibility( |
| 434 | + name = "Example app", |
| 435 | + packageName = "compatible.package", |
| 436 | + apkFileType = ApkFileType.APK, |
| 437 | + targets = listOf( |
| 438 | + AppTarget(version = "1.0.0") |
| 439 | + ) |
| 440 | + ) |
| 441 | + |
| 442 | + assertEquals(null, compatibility.targets.first().versionCodes) |
| 443 | + |
| 444 | + |
| 445 | + assertThrows<IllegalArgumentException> { |
| 446 | + AppTarget(version = null, versionCodes = mapOf(SupportedAbi.ARM64_V8A to 123)) |
| 447 | + } |
| 448 | + |
| 449 | + assertDoesNotThrow { |
| 450 | + AppTarget(version = null, versionCodes = mapOf()) |
| 451 | + } |
| 452 | + } |
341 | 453 | } |
0 commit comments