Skip to content

Commit

Permalink
Convert remaining Java files to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Sep 20, 2023
1 parent 98f154b commit 79186d2
Show file tree
Hide file tree
Showing 49 changed files with 2,463 additions and 2,825 deletions.
5 changes: 5 additions & 0 deletions rsdroid-instrumented/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

apply plugin: 'com.android.application'
apply plugin: "kotlin-android"

android {
namespace 'net.ankiweb.rsdroid.instrumented'
Expand All @@ -40,6 +41,10 @@ android {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '11'
}
}


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2020 David Allison <[email protected]>
*
* This program 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.
*
* This program 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 net.ankiweb.rsdroid

import androidx.test.ext.junit.runners.AndroidJUnit4
import net.ankiweb.rsdroid.ankiutil.DatabaseUtil.queryScalar
import net.ankiweb.rsdroid.ankiutil.InstrumentedTest
import net.ankiweb.rsdroid.database.AnkiSupportSQLiteDatabase.Companion.withRustBackend
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import timber.log.Timber
import java.io.IOException

@RunWith(AndroidJUnit4::class)
class BackendDisposalTests : InstrumentedTest() {
/** This test should be run under the profiler */
@Test
@Ignore("Run under profiler")
@Throws(IOException::class)
fun testDisposalDoesNotLeak() {
for (i in 0..9999) {
Timber.d("Iteration %d", i)
super.getBackend("initial_version_2_12_1.anki2").use { backend ->
val db = withRustBackend(backend)
queryScalar(db, "select count(*) from revlog")
}
}
}

@Test
@Ignore
fun getAssetFilePathFileLeak() {
// testDisposalDoesNotLeak had a failure: open failed: EMFILE (Too many open files)
// This determines if it is our file handling, or rust implementation which has the issue.
for (i in 0..9999) {
getAssetFilePath("initial_version_2_12_1.anki2")
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2021 David Allison <[email protected]>
*
* This program 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.
*
* This program 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 net.ankiweb.rsdroid

import androidx.annotation.VisibleForTesting

class BackendForTesting(langs: Iterable<String>) : Backend(langs) {
// Debug methods
/**
* Throws a given error, generated from the Rust
* @param error The error to throw
*/
@VisibleForTesting
fun debugProduceError(error: ErrorType) {
super.debugProduceError(error.toString())
throw IllegalStateException("An exception should have been thrown")
}

enum class ErrorType {
InvalidInput, TemplateError, DbErrorFileTooNew, DbErrorFileTooOld, DbErrorMissingEntity, DbErrorCorrupt, DbErrorLocked, DbErrorOther, NetworkError, SyncErrorAuthFailed, SyncErrorOther, JSONError, ProtoError, Interrupted, CollectionNotOpen, CollectionAlreadyOpen, NotFound, Existing, FilteredDeckError, SearchError, FatalError
}

companion object {
fun create(): BackendForTesting {
System.loadLibrary("rsdroid")
return BackendForTesting(mutableListOf("en"))
}
}
}

This file was deleted.

Loading

0 comments on commit 79186d2

Please sign in to comment.