mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Unify async tests
This commit is contained in:
@@ -23,7 +23,6 @@ enum class TextAlign {
|
|||||||
LEFT, CENTER, RIGHT
|
LEFT, CENTER, RIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum class Font {
|
enum class Font {
|
||||||
REGULAR,
|
REGULAR,
|
||||||
BOLD,
|
BOLD,
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package org.isoron.platform.io
|
package org.isoron.platform.io
|
||||||
|
|
||||||
import org.isoron.uhabits.*
|
|
||||||
|
|
||||||
interface PreparedStatement {
|
interface PreparedStatement {
|
||||||
fun step(): StepResult
|
fun step(): StepResult
|
||||||
fun finalize()
|
fun finalize()
|
||||||
|
|||||||
@@ -35,5 +35,4 @@ class StandardLog : Log {
|
|||||||
override fun debug(tag: String, msg: String) {
|
override fun debug(tag: String, msg: String) {
|
||||||
println("D/$tag $msg")
|
println("D/$tag $msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -47,8 +47,8 @@ class Backend(private val databaseName: String,
|
|||||||
private val fileOpener: FileOpener,
|
private val fileOpener: FileOpener,
|
||||||
private val localeHelper: LocaleHelper,
|
private val localeHelper: LocaleHelper,
|
||||||
private val log: Log,
|
private val log: Log,
|
||||||
private val crCtx: CoroutineContext
|
private val scope: CoroutineContext
|
||||||
) : CoroutineScope by BackendScope(crCtx, log) {
|
) : CoroutineScope by BackendScope(scope, log) {
|
||||||
|
|
||||||
|
|
||||||
private lateinit var database: Database
|
private lateinit var database: Database
|
||||||
|
|||||||
26
core/src/commonTest/kotlin/org/isoron/AsyncTests.kt
Normal file
26
core/src/commonTest/kotlin/org/isoron/AsyncTests.kt
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround until Kotlin adds support for testing suspend functions
|
||||||
|
* https://youtrack.jetbrains.com/issue/KT-22228
|
||||||
|
*/
|
||||||
|
expect fun asyncTest(block: suspend () -> Unit)
|
||||||
34
core/src/commonTest/kotlin/org/isoron/DependencyResolver.kt
Normal file
34
core/src/commonTest/kotlin/org/isoron/DependencyResolver.kt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron
|
||||||
|
|
||||||
|
import org.isoron.platform.gui.*
|
||||||
|
import org.isoron.platform.io.*
|
||||||
|
|
||||||
|
interface CanvasHelper {
|
||||||
|
fun createCanvas(width: Int, height: Int): Canvas
|
||||||
|
fun exportCanvas(canvas: Canvas, filename: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect object DependencyResolver {
|
||||||
|
suspend fun getFileOpener(): FileOpener
|
||||||
|
suspend fun getDatabase(): Database
|
||||||
|
fun getCanvasHelper(): CanvasHelper
|
||||||
|
}
|
||||||
@@ -19,9 +19,14 @@
|
|||||||
|
|
||||||
package org.isoron.platform.gui
|
package org.isoron.platform.gui
|
||||||
|
|
||||||
class CanvasTest(val platform: Platform) {
|
import org.isoron.*
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
class CanvasTest {
|
||||||
|
@Test
|
||||||
fun run() {
|
fun run() {
|
||||||
val canvas = platform.createCanvas(500, 400)
|
val helper = DependencyResolver.getCanvasHelper()
|
||||||
|
val canvas = helper.createCanvas(500, 400)
|
||||||
|
|
||||||
canvas.setColor(Color(0x303030))
|
canvas.setColor(Color(0x303030))
|
||||||
canvas.fillRect(0.0, 0.0, 500.0, 400.0)
|
canvas.fillRect(0.0, 0.0, 500.0, 400.0)
|
||||||
@@ -61,11 +66,6 @@ class CanvasTest(val platform: Platform) {
|
|||||||
canvas.setFont(Font.FONT_AWESOME)
|
canvas.setFont(Font.FONT_AWESOME)
|
||||||
canvas.drawText(FontAwesome.CHECK, 250.0, 300.0)
|
canvas.drawText(FontAwesome.CHECK, 250.0, 300.0)
|
||||||
|
|
||||||
platform.exportCanvas(canvas, "CanvasTest.png")
|
helper.exportCanvas(canvas, "CanvasTest.png")
|
||||||
}
|
|
||||||
|
|
||||||
interface Platform {
|
|
||||||
fun createCanvas(width: Int, height: Int): Canvas
|
|
||||||
fun exportCanvas(canvas: Canvas, filename: String)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,10 +19,15 @@
|
|||||||
|
|
||||||
package org.isoron.platform.io
|
package org.isoron.platform.io
|
||||||
|
|
||||||
|
import org.isoron.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class DatabaseTest(val db: Database) {
|
class DatabaseTest {
|
||||||
fun testUsage() {
|
|
||||||
|
@Test
|
||||||
|
fun testUsage() = asyncTest{
|
||||||
|
val db = DependencyResolver.getDatabase()
|
||||||
|
|
||||||
db.setVersion(0)
|
db.setVersion(0)
|
||||||
assertEquals(0, db.getVersion())
|
assertEquals(0, db.getVersion())
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,11 @@ package org.isoron.platform.io
|
|||||||
import org.isoron.*
|
import org.isoron.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class FilesTest(val fileOpener: FileOpener) {
|
class FilesTest() {
|
||||||
suspend fun testLines() {
|
@Test
|
||||||
|
fun testLines() = asyncTest {
|
||||||
|
val fileOpener = DependencyResolver.getFileOpener()
|
||||||
|
|
||||||
assertFalse(fileOpener.openUserFile("non-existing-usr.txt").exists(),
|
assertFalse(fileOpener.openUserFile("non-existing-usr.txt").exists(),
|
||||||
"non-existing-usr.txt shouldn't exist")
|
"non-existing-usr.txt shouldn't exist")
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,11 @@ import org.isoron.platform.time.*
|
|||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
|
||||||
class CheckmarkRepositoryTest(val db: Database) {
|
class CheckmarkRepositoryTest() {
|
||||||
fun testCRUD() {
|
@Test
|
||||||
|
fun testCRUD() = asyncTest {
|
||||||
|
val db = DependencyResolver.getDatabase()
|
||||||
|
|
||||||
val habitA = 10
|
val habitA = 10
|
||||||
var checkmarksA = listOf(Checkmark(LocalDate(2019, 1, 15), 100),
|
var checkmarksA = listOf(Checkmark(LocalDate(2019, 1, 15), 100),
|
||||||
Checkmark(LocalDate(2019, 1, 7), 500),
|
Checkmark(LocalDate(2019, 1, 7), 500),
|
||||||
|
|||||||
@@ -21,11 +21,12 @@ package org.isoron.uhabits.models
|
|||||||
|
|
||||||
import org.isoron.*
|
import org.isoron.*
|
||||||
import org.isoron.platform.gui.*
|
import org.isoron.platform.gui.*
|
||||||
import org.isoron.platform.io.*
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class HabitRepositoryTest(val db: Database) {
|
class HabitRepositoryTest() {
|
||||||
fun testCRUD() {
|
@Test
|
||||||
|
fun testCRUD() = asyncTest{
|
||||||
|
val db = DependencyResolver.getDatabase()
|
||||||
val original0 = Habit(id = 0,
|
val original0 = Habit(id = 0,
|
||||||
name = "Wake up early",
|
name = "Wake up early",
|
||||||
description = "Did you wake up before 6am?",
|
description = "Did you wake up before 6am?",
|
||||||
|
|||||||
@@ -19,11 +19,14 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.models
|
package org.isoron.uhabits.models
|
||||||
|
|
||||||
|
import org.isoron.*
|
||||||
import org.isoron.platform.io.*
|
import org.isoron.platform.io.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class PreferencesRepositoryTest(val db: Database) {
|
class PreferencesRepositoryTest() {
|
||||||
fun testUsage() {
|
@Test
|
||||||
|
fun testUsage() = asyncTest{
|
||||||
|
val db = DependencyResolver.getDatabase()
|
||||||
val prefs = PreferencesRepository(db)
|
val prefs = PreferencesRepository(db)
|
||||||
assertEquals("default", prefs.getString("non_existing_key", "default"))
|
assertEquals("default", prefs.getString("non_existing_key", "default"))
|
||||||
prefs.putString("ringtone_path", "/tmp")
|
prefs.putString("ringtone_path", "/tmp")
|
||||||
|
|||||||
31
core/src/iosTest/kotlin/org/isoron/DependencyResolver.kt
Normal file
31
core/src/iosTest/kotlin/org/isoron/DependencyResolver.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron
|
||||||
|
|
||||||
|
import org.isoron.platform.io.*
|
||||||
|
|
||||||
|
actual object DependencyResolver {
|
||||||
|
actual suspend fun getFileOpener(): FileOpener = IosFileOpener()
|
||||||
|
|
||||||
|
// IosDatabase and IosCanvas are currently implemented in Swift, so we
|
||||||
|
// cannot test these classes here.
|
||||||
|
actual suspend fun getDatabase(): Database = TODO()
|
||||||
|
actual fun getCanvasHelper(): CanvasHelper = TODO()
|
||||||
|
}
|
||||||
@@ -20,12 +20,9 @@
|
|||||||
package org.isoron
|
package org.isoron
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import org.isoron.platform.io.*
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
class IosAsyncTests {
|
/**
|
||||||
@Test
|
* Workaround until Kotlin adds support for testing suspend functions
|
||||||
fun testFiles() = runBlocking {
|
* https://youtrack.jetbrains.com/issue/KT-22228
|
||||||
FilesTest(IosFileOpener()).testLines()
|
*/
|
||||||
}
|
actual fun asyncTest(block: suspend () -> Unit) = runBlocking { block() }
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,14 +17,40 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.isoron.platform
|
package org.isoron
|
||||||
|
|
||||||
import org.isoron.platform.gui.*
|
import org.isoron.platform.gui.*
|
||||||
|
import org.isoron.platform.io.*
|
||||||
|
import org.isoron.uhabits.*
|
||||||
import org.w3c.dom.*
|
import org.w3c.dom.*
|
||||||
import kotlin.browser.*
|
import kotlin.browser.*
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
class JsCanvasTest : CanvasTest.Platform {
|
actual object DependencyResolver {
|
||||||
|
|
||||||
|
var fileOpener: JsFileOpener? = null
|
||||||
|
|
||||||
|
actual suspend fun getFileOpener(): FileOpener {
|
||||||
|
if (fileOpener == null) {
|
||||||
|
val fs = JsFileStorage()
|
||||||
|
fs.init()
|
||||||
|
fileOpener = JsFileOpener(fs)
|
||||||
|
}
|
||||||
|
return fileOpener!!
|
||||||
|
}
|
||||||
|
|
||||||
|
actual suspend fun getDatabase(): Database {
|
||||||
|
val nativeDB = eval("new SQL.Database()")
|
||||||
|
val db = JsDatabase(nativeDB)
|
||||||
|
db.migrateTo(LOOP_DATABASE_VERSION, getFileOpener(), StandardLog())
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun getCanvasHelper(): CanvasHelper {
|
||||||
|
return JsCanvasHelper()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JsCanvasHelper : CanvasHelper {
|
||||||
override fun createCanvas(width: Int, height: Int): Canvas {
|
override fun createCanvas(width: Int, height: Int): Canvas {
|
||||||
val canvasElement = document.getElementById("canvas") as HTMLCanvasElement
|
val canvasElement = document.getElementById("canvas") as HTMLCanvasElement
|
||||||
canvasElement.style.width = "${width}px"
|
canvasElement.style.width = "${width}px"
|
||||||
@@ -35,7 +61,4 @@ class JsCanvasTest : CanvasTest.Platform {
|
|||||||
override fun exportCanvas(canvas: Canvas, filename: String) {
|
override fun exportCanvas(canvas: Canvas, filename: String) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDrawing() = CanvasTest(this).run()
|
|
||||||
}
|
}
|
||||||
28
core/src/jsTest/kotlin/org/isoron/JsAsyncTests.kt
Normal file
28
core/src/jsTest/kotlin/org/isoron/JsAsyncTests.kt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron
|
||||||
|
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround until Kotlin adds support for testing suspend functions
|
||||||
|
* https://youtrack.jetbrains.com/issue/KT-22228
|
||||||
|
*/
|
||||||
|
actual fun asyncTest(block: suspend () -> Unit): dynamic = GlobalScope.promise { block() }
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron
|
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import org.isoron.platform.io.*
|
|
||||||
import org.isoron.uhabits.*
|
|
||||||
import org.isoron.uhabits.models.*
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
class JsAsyncTests {
|
|
||||||
var fs: JsFileStorage? = null
|
|
||||||
|
|
||||||
suspend fun getFileOpener(): FileOpener {
|
|
||||||
if (fs == null) {
|
|
||||||
fs = JsFileStorage()
|
|
||||||
fs?.init()
|
|
||||||
}
|
|
||||||
return JsFileOpener(fs!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getDatabase(): Database {
|
|
||||||
val nativeDB = eval("new SQL.Database()")
|
|
||||||
val db = JsDatabase(nativeDB)
|
|
||||||
db.migrateTo(LOOP_DATABASE_VERSION, getFileOpener(), StandardLog())
|
|
||||||
return db
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testFiles() = GlobalScope.promise {
|
|
||||||
FilesTest(getFileOpener()).testLines()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDatabase() = GlobalScope.promise {
|
|
||||||
DatabaseTest(getDatabase()).testUsage()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testCheckmarkRepository() = GlobalScope.promise {
|
|
||||||
CheckmarkRepositoryTest(getDatabase()).testCRUD()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testHabitRepository() = GlobalScope.promise {
|
|
||||||
HabitRepositoryTest(getDatabase()).testCRUD()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testPreferencesRepository() = GlobalScope.promise {
|
|
||||||
PreferencesRepositoryTest(getDatabase()).testUsage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,15 +17,34 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.isoron.platform
|
package org.isoron
|
||||||
|
|
||||||
import org.isoron.platform.gui.*
|
import org.isoron.platform.gui.*
|
||||||
import org.junit.*
|
import org.isoron.platform.io.*
|
||||||
|
import org.isoron.uhabits.*
|
||||||
import java.awt.image.*
|
import java.awt.image.*
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import javax.imageio.*
|
import javax.imageio.*
|
||||||
|
|
||||||
class JavaCanvasTest : CanvasTest.Platform {
|
actual object DependencyResolver {
|
||||||
|
actual suspend fun getFileOpener(): FileOpener = JavaFileOpener()
|
||||||
|
actual fun getCanvasHelper(): CanvasHelper = JavaCanvasHelper()
|
||||||
|
|
||||||
|
actual suspend fun getDatabase(): Database {
|
||||||
|
val log = StandardLog()
|
||||||
|
val fileOpener = JavaFileOpener()
|
||||||
|
val databaseOpener = JavaDatabaseOpener(log)
|
||||||
|
|
||||||
|
val dbFile = fileOpener.openUserFile("test.sqlite3")
|
||||||
|
if (dbFile.exists()) dbFile.delete()
|
||||||
|
val db = databaseOpener.open(dbFile)
|
||||||
|
db.migrateTo(LOOP_DATABASE_VERSION, fileOpener, log)
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaCanvasHelper : CanvasHelper {
|
||||||
override fun createCanvas(width: Int, height: Int): Canvas {
|
override fun createCanvas(width: Int, height: Int): Canvas {
|
||||||
val image = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
|
val image = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
|
||||||
return JavaCanvas(image, pixelScale = 1.0)
|
return JavaCanvas(image, pixelScale = 1.0)
|
||||||
@@ -35,7 +54,4 @@ class JavaCanvasTest : CanvasTest.Platform {
|
|||||||
val javaCanvas = canvas as JavaCanvas
|
val javaCanvas = canvas as JavaCanvas
|
||||||
ImageIO.write(javaCanvas.image, "png", File("/tmp/$filename"))
|
ImageIO.write(javaCanvas.image, "png", File("/tmp/$filename"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDrawing() = CanvasTest(this).run()
|
|
||||||
}
|
}
|
||||||
@@ -20,47 +20,9 @@
|
|||||||
package org.isoron
|
package org.isoron
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import org.isoron.platform.io.*
|
|
||||||
import org.isoron.uhabits.*
|
|
||||||
import org.isoron.uhabits.models.*
|
|
||||||
import org.junit.*
|
|
||||||
|
|
||||||
class JavaAsyncTests {
|
/**
|
||||||
|
* Workaround until Kotlin adds support for testing suspend functions
|
||||||
val log = StandardLog()
|
* https://youtrack.jetbrains.com/issue/KT-22228
|
||||||
val fileOpener = JavaFileOpener()
|
*/
|
||||||
val databaseOpener = JavaDatabaseOpener(log)
|
actual fun asyncTest(block: suspend () -> Unit) = runBlocking { block() }
|
||||||
|
|
||||||
suspend fun getDatabase(): Database {
|
|
||||||
val dbFile = fileOpener.openUserFile("test.sqlite3")
|
|
||||||
if (dbFile.exists()) dbFile.delete()
|
|
||||||
val db = databaseOpener.open(dbFile)
|
|
||||||
db.migrateTo(LOOP_DATABASE_VERSION, fileOpener, log)
|
|
||||||
return db
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testFiles() = runBlocking {
|
|
||||||
FilesTest(fileOpener).testLines()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDatabase() = runBlocking {
|
|
||||||
DatabaseTest(getDatabase()).testUsage()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testCheckmarkRepository() = runBlocking {
|
|
||||||
CheckmarkRepositoryTest(getDatabase()).testCRUD()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testHabitRepository() = runBlocking {
|
|
||||||
HabitRepositoryTest(getDatabase()).testCRUD()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testPreferencesRepository() = runBlocking {
|
|
||||||
PreferencesRepositoryTest(getDatabase()).testUsage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import UIKit
|
|||||||
fileOpener: IosFileOpener(),
|
fileOpener: IosFileOpener(),
|
||||||
localeHelper: IosLocaleHelper(NSLocale.preferredLanguages),
|
localeHelper: IosLocaleHelper(NSLocale.preferredLanguages),
|
||||||
log: log,
|
log: log,
|
||||||
crCtx: UIDispatcher())
|
scope: UIDispatcher())
|
||||||
|
|
||||||
backend?.observable.addListener(listener: self)
|
backend?.observable.addListener(listener: self)
|
||||||
backend?.doInit()
|
backend?.doInit()
|
||||||
|
|||||||
Reference in New Issue
Block a user