-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add androidx-startup, enable auto CouchbaseLite.init()
- Loading branch information
Showing
15 changed files
with
198 additions
and
66 deletions.
There are no files selected for viewing
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
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 @@ | ||
../../../couchbase-lite/src/androidMain/AndroidManifest.xml |
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
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<application> | ||
<provider android:name="androidx.startup.InitializationProvider" | ||
android:authorities="${applicationId}.androidx-startup" | ||
android:exported="false" | ||
tools:node="merge"> | ||
<meta-data android:name="com.couchbase.lite.kmp.internal.CouchbaseLiteInitializer" | ||
android:value="androidx.startup" /> | ||
</provider> | ||
</application> | ||
</manifest> |
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
18 changes: 18 additions & 0 deletions
18
...e-lite/src/androidMain/kotlin/com/couchbase/lite/kmp/internal/CouchbaseLiteInitializer.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,18 @@ | ||
package com.couchbase.lite.kmp.internal | ||
|
||
import android.content.Context | ||
import androidx.startup.Initializer | ||
import com.couchbase.lite.kmp.CouchbaseLite | ||
|
||
/** | ||
* Initializes CouchbaseLite library automatically on app startup | ||
* from androidx-startup Content Provider. | ||
*/ | ||
public class CouchbaseLiteInitializer : Initializer<Unit> { | ||
|
||
override fun create(context: Context) { | ||
CouchbaseLite.internalInit(context) | ||
} | ||
|
||
override fun dependencies(): List<Class<out Initializer<*>>> = emptyList() | ||
} |
51 changes: 0 additions & 51 deletions
51
couchbase-lite/src/commonTest/kotlin/com/couchbase/lite/kmp/PreInitTest.kt
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
couchbase-lite/src/jvmCommonMain/kotlin/com/couchbase/lite/kmp/CouchbaseLite.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,6 @@ | ||
package com.couchbase.lite.kmp | ||
|
||
public expect object CouchbaseLite { | ||
|
||
internal fun internalInit() | ||
} |
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
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
27 changes: 27 additions & 0 deletions
27
couchbase-lite/src/jvmCommonTest/kotlin/com/couchbase/lite/kmp/AutoInitTest.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,27 @@ | ||
package com.couchbase.lite.kmp | ||
|
||
import org.junit.Test | ||
|
||
class AutoInitTest { | ||
|
||
@Test | ||
fun testCreateDatabaseWithoutInit() { | ||
val db = Database("succeed", DatabaseConfiguration()) | ||
db.delete() | ||
} | ||
|
||
@Test | ||
fun testGetConsoleWithoutInit() { | ||
Database.log.console | ||
} | ||
|
||
@Test | ||
fun testGetFileWithoutInit() { | ||
Database.log.file | ||
} | ||
|
||
@Test | ||
fun testCreateDBConfigWithoutInit() { | ||
DatabaseConfiguration() | ||
} | ||
} |
43 changes: 41 additions & 2 deletions
43
couchbase-lite/src/jvmCommonTest/kotlin/com/couchbase/lite/kmp/PreInitTest.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,7 +1,46 @@ | ||
package com.couchbase.lite.kmp | ||
|
||
import com.couchbase.lite.internal.CouchbaseLiteInternal | ||
import kotlin.test.* | ||
|
||
internal actual fun couchbaseLiteReset(state: Boolean) { | ||
CouchbaseLiteInternal.reset(state) | ||
// native doesn't need initializing | ||
class PreInitTest : BaseTest() { | ||
|
||
@BeforeTest | ||
fun setUpPreInitTest() { | ||
CouchbaseLiteInternal.reset(false) | ||
} | ||
|
||
@AfterTest | ||
fun tearDownPreInitTest() { | ||
CouchbaseLiteInternal.reset(true) | ||
} | ||
|
||
@Test | ||
fun testCreateDatabaseBeforeInit() { | ||
assertFailsWith<IllegalStateException> { | ||
Database("fail", DatabaseConfiguration()) | ||
} | ||
} | ||
|
||
@Test | ||
fun testGetConsoleBeforeInit() { | ||
assertFailsWith<IllegalStateException> { | ||
Database.log.console | ||
} | ||
} | ||
|
||
@Test | ||
fun testGetFileBeforeInit() { | ||
assertFailsWith<IllegalStateException> { | ||
Database.log.file | ||
} | ||
} | ||
|
||
@Test | ||
fun testCreateDBConfigBeforeInit() { | ||
assertFailsWith<IllegalStateException> { | ||
DatabaseConfiguration() | ||
} | ||
} | ||
} |
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
5 changes: 0 additions & 5 deletions
5
couchbase-lite/src/nativeCommonTest/kotlin/com/couchbase/lite/kmp/PreInitTest.kt
This file was deleted.
Oops, something went wrong.
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