Skip to content

Commit

Permalink
AppFile create, check existence, delete, works for android
Browse files Browse the repository at this point in the history
  • Loading branch information
vextorspace committed Jul 10, 2024
1 parent 0a778fd commit 26cf217
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package resources

import androidx.test.platform.app.InstrumentationRegistry
import io.kotest.matchers.booleans.shouldBeFalse
import io.kotest.matchers.booleans.shouldBeTrue
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test

class CreatesAppFileTest {
val saveFile = AppFile("saveFile.json")

@BeforeTest
fun setup() {
AppFile.context = InstrumentationRegistry.getInstrumentation().targetContext
if(saveFile.exists()) {
saveFile.delete()
}
}

@AfterTest
fun teardown() {
if(saveFile.exists()) {
saveFile.delete()
}
}

@Test
fun createAppFile() {
saveFile.exists().shouldBeFalse()
saveFile.create().shouldBeTrue()
saveFile.exists().shouldBeTrue()
}
}
15 changes: 11 additions & 4 deletions composeApp/src/androidMain/kotlin/resources/AppFile.android.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package resources

@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
actual class AppFile actual constructor(fileName: String) {
actual class AppFile actual constructor(val fileName: String) {
actual fun exists(): Boolean {
TODO("Not yet implemented")
return context?.getFileStreamPath(fileName)?.exists() ?: false
}

actual fun create(): Boolean {
TODO("Not yet implemented")
return context?.openFileOutput(fileName, android.content.Context.MODE_PRIVATE)?.use {
it.write(byteArrayOf())
true
} ?: false
}

actual fun delete(): Boolean {
TODO("Not yet implemented")
return context?.deleteFile(fileName) ?: false
}

companion object {
var context: android.content.Context? = null
}
}

0 comments on commit 26cf217

Please sign in to comment.