generated from vextorspace/KotlinMultiplatformTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AppFile create, check existence, delete, works for android
- Loading branch information
1 parent
0a778fd
commit 26cf217
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
composeApp/src/androidInstrumentedTest/kotlin/resources/CreatesAppFileTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
composeApp/src/androidMain/kotlin/resources/AppFile.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
File renamed without changes.