Skip to content

Commit

Permalink
Fix some connected tests failing when legacy_schema=false
Browse files Browse the repository at this point in the history
Some were irrelevant; the ones in ContentProviderTest need investigating.
  • Loading branch information
dae committed Jul 24, 2022
1 parent cf7e236 commit db67460
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
import com.ichi2.libanki.StdModels;
import com.ichi2.libanki.Utils;

import com.ichi2.utils.BlocksSchemaUpgrade;
import com.ichi2.utils.JSONArray;
import com.ichi2.utils.JSONObject;

import net.ankiweb.rsdroid.BackendFactory;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -135,7 +139,9 @@ public static java.util.Collection<Object[]> initParameters() {
* Initially create one note for each model.
*/
@Before
@BlocksSchemaUpgrade("some of these tests are failing; need to investigate why")
public void setUp() throws Exception {
assumeThat(BackendFactory.getDefaultLegacySchema(), is(true));
Timber.i("setUp()");
mCreatedNotes = new ArrayList<>();
final Collection col = getCol();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package com.ichi2.anki.tests

import com.ichi2.libanki.Storage
import net.ankiweb.rsdroid.BackendException
import net.ankiweb.rsdroid.BackendFactory
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers.equalTo
import org.junit.Assume.assumeThat
import org.junit.Rule
import org.junit.Test
import org.junit.rules.Timeout
Expand All @@ -35,6 +37,7 @@ class RustTest : InstrumentedTest() {
@Test
@Throws(BackendException::class, IOException::class)
fun collectionIsVersion11AfterOpen() {
assumeThat(BackendFactory.defaultLegacySchema, equalTo(true))
// This test will be decommissioned, but before we get an upgrade strategy, we need to ensure we're not upgrading the database.
val path = Shared.getTestFilePath(testContext, "initial_version_2_12_1.anki2")
val collection = Storage.collection(testContext, path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.ichi2.utils.JSONException;
import com.ichi2.utils.JSONObject;

import net.ankiweb.rsdroid.BackendFactory;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
Expand All @@ -57,8 +59,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeThat;

@RunWith(AndroidJUnit4.class)
public class ImportTest extends InstrumentedTest {
Expand Down Expand Up @@ -86,6 +90,8 @@ public class ImportTest extends InstrumentedTest {
@Before
public void setUp() throws IOException {
mTestCol = getEmptyCol();
// the backend provides its own importing methods
assumeThat(BackendFactory.getDefaultLegacySchema(), is(true));
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.ichi2.libanki.Note;
import com.ichi2.libanki.exception.EmptyMediaException;

import net.ankiweb.rsdroid.BackendFactory;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -47,6 +49,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;


/**
Expand Down Expand Up @@ -221,6 +224,8 @@ private List<String> removed(Collection d) {

@Test
public void testChanges() throws IOException, EmptyMediaException {
// legacy code, not used by backend
assumeThat(BackendFactory.getDefaultLegacySchema(), is(true));
assertNotNull(mTestCol.getMedia()._changed());
assertEquals(0, added(mTestCol).size());
assertEquals(0, removed(mTestCol).size());
Expand Down
3 changes: 3 additions & 0 deletions AnkiDroid/src/androidTest/java/com/ichi2/libanki/DBTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package com.ichi2.libanki

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.tests.InstrumentedTest
import net.ankiweb.rsdroid.BackendFactory
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.junit.Assume.assumeThat
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*
Expand All @@ -28,6 +30,7 @@ class DBTest : InstrumentedTest() {
/** mDatabase.disableWriteAheadLogging(); is called in DB init */
@Test
fun writeAheadLoggingIsDisabled() {
assumeThat(BackendFactory.defaultLegacySchema, equalTo(true))
// An old comment noted that explicitly disabling the WAL was no longer necessary after API 16:
// https://github.com/ankidroid/Anki-Android/commit/6e34663ba9d09dc8b023230811c3185b72ee7eec#diff-4fdbf41d84a547a45edad66ae1f543128d1118b0e831a12916b4fac11b483688

Expand Down

0 comments on commit db67460

Please sign in to comment.