Search in sources :

Example 1 with NextCard

use of com.ichi2.anki.servicelayer.SchedulerService.NextCard in project AnkiChinaAndroid by ankichinateam.

the class ContentProviderTest method testQueryCardFromCertainDeck.

/**
 * Test that query for the next card in the schedule returns a valid result WITH a deck selector
 */
@Test
public void testQueryCardFromCertainDeck() {
    long deckToTest = mTestDeckIds.get(0);
    String deckSelector = "deckID=?";
    String[] deckArguments = { Long.toString(deckToTest) };
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    long selectedDeckBeforeTest = col.getDecks().selected();
    // select Default deck
    col.getDecks().select(1);
    Cursor reviewInfoCursor = InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver().query(FlashCardsContract.ReviewInfo.CONTENT_URI, null, deckSelector, deckArguments, null);
    assertNotNull(reviewInfoCursor);
    assertEquals("Check that we actually received one card", 1, reviewInfoCursor.getCount());
    try {
        reviewInfoCursor.moveToFirst();
        int cardOrd = reviewInfoCursor.getInt(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.CARD_ORD));
        long noteID = reviewInfoCursor.getLong(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID));
        assertEquals("Check that the selected deck has not changed", 1, col.getDecks().selected());
        col.getDecks().select(deckToTest);
        Card nextCard = null;
        for (int i = 0; i < 10; i++) {
            // minimizing fails, when sched.reset() randomly chooses between multiple cards
            col.reset();
            nextCard = sched.getCard();
            if (nextCard.note().getId() == noteID && nextCard.getOrd() == cardOrd)
                break;
        }
        assertNotNull("Check that there actually is a next scheduled card", nextCard);
        assertEquals("Check that received card and actual card have same note id", nextCard.note().getId(), noteID);
        assertEquals("Check that received card and actual card have same card ord", nextCard.getOrd(), cardOrd);
    } finally {
        reviewInfoCursor.close();
    }
    col.getDecks().select(selectedDeckBeforeTest);
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) Cursor(android.database.Cursor) Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Example 2 with NextCard

use of com.ichi2.anki.servicelayer.SchedulerService.NextCard in project Anki-Android by ankidroid.

the class ContentProviderTest method testQueryCardFromCertainDeck.

/**
 * Test that query for the next card in the schedule returns a valid result WITH a deck selector
 */
@Test
public synchronized void testQueryCardFromCertainDeck() {
    long deckToTest = mTestDeckIds.get(0);
    String deckSelector = "deckID=?";
    String[] deckArguments = { Long.toString(deckToTest) };
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    long selectedDeckBeforeTest = col.getDecks().selected();
    // select Default deck
    col.getDecks().select(1);
    Cursor reviewInfoCursor = getContentResolver().query(FlashCardsContract.ReviewInfo.CONTENT_URI, null, deckSelector, deckArguments, null);
    assertNotNull(reviewInfoCursor);
    assertEquals("Check that we actually received one card", 1, reviewInfoCursor.getCount());
    try {
        reviewInfoCursor.moveToFirst();
        int cardOrd = reviewInfoCursor.getInt(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.CARD_ORD));
        long noteID = reviewInfoCursor.getLong(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID));
        assertEquals("Check that the selected deck has not changed", 1, col.getDecks().selected());
        col.getDecks().select(deckToTest);
        Card nextCard = null;
        for (int i = 0; i < 10; i++) {
            // minimizing fails, when sched.reset() randomly chooses between multiple cards
            col.reset();
            nextCard = sched.getCard();
            if (nextCard != null && nextCard.note().getId() == noteID && nextCard.getOrd() == cardOrd)
                break;
            // Reset counts is executed in background.
            try {
                Thread.sleep(500);
            } catch (Exception e) {
                Timber.e(e);
            }
        }
        assertNotNull("Check that there actually is a next scheduled card", nextCard);
        assertEquals("Check that received card and actual card have same note id", nextCard.note().getId(), noteID);
        assertEquals("Check that received card and actual card have same card ord", nextCard.getOrd(), cardOrd);
    } finally {
        reviewInfoCursor.close();
    }
    col.getDecks().select(selectedDeckBeforeTest);
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) Cursor(android.database.Cursor) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Example 3 with NextCard

use of com.ichi2.anki.servicelayer.SchedulerService.NextCard in project Anki-Android by ankidroid.

the class ContentProviderTest method testQueryNextCard.

/**
 * Test that query for the next card in the schedule returns a valid result without any deck selector
 */
@Test
public void testQueryNextCard() {
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    Cursor reviewInfoCursor = getContentResolver().query(FlashCardsContract.ReviewInfo.CONTENT_URI, null, null, null, null);
    assertNotNull(reviewInfoCursor);
    assertEquals("Check that we actually received one card", 1, reviewInfoCursor.getCount());
    reviewInfoCursor.moveToFirst();
    int cardOrd = reviewInfoCursor.getInt(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.CARD_ORD));
    long noteID = reviewInfoCursor.getLong(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID));
    Card nextCard = null;
    for (int i = 0; i < 10; i++) {
        // minimizing fails, when sched.reset() randomly chooses between multiple cards
        col.reset();
        nextCard = sched.getCard();
        TaskManager.waitToFinish();
        if (nextCard != null && nextCard.note().getId() == noteID && nextCard.getOrd() == cardOrd)
            break;
        TaskManager.waitToFinish();
    }
    assertNotNull("Check that there actually is a next scheduled card", nextCard);
    assertEquals("Check that received card and actual card have same note id", nextCard.note().getId(), noteID);
    assertEquals("Check that received card and actual card have same card ord", nextCard.getOrd(), cardOrd);
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) Cursor(android.database.Cursor) Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Example 4 with NextCard

use of com.ichi2.anki.servicelayer.SchedulerService.NextCard in project AnkiChinaAndroid by ankichinateam.

the class ContentProviderTest method testQueryNextCard.

/**
 * Test that query for the next card in the schedule returns a valid result without any deck selector
 */
@Test
public void testQueryNextCard() {
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    Cursor reviewInfoCursor = InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver().query(FlashCardsContract.ReviewInfo.CONTENT_URI, null, null, null, null);
    assertNotNull(reviewInfoCursor);
    assertEquals("Check that we actually received one card", 1, reviewInfoCursor.getCount());
    reviewInfoCursor.moveToFirst();
    int cardOrd = reviewInfoCursor.getInt(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.CARD_ORD));
    long noteID = reviewInfoCursor.getLong(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID));
    Card nextCard = null;
    for (int i = 0; i < 10; i++) {
        // minimizing fails, when sched.reset() randomly chooses between multiple cards
        col.reset();
        nextCard = sched.getCard();
        if (nextCard.note().getId() == noteID && nextCard.getOrd() == cardOrd)
            break;
    }
    assertNotNull("Check that there actually is a next scheduled card", nextCard);
    assertEquals("Check that received card and actual card have same note id", nextCard.note().getId(), noteID);
    assertEquals("Check that received card and actual card have same card ord", nextCard.getOrd(), cardOrd);
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) Cursor(android.database.Cursor) Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Aggregations

Cursor (android.database.Cursor)4 Card (com.ichi2.libanki.Card)4 Collection (com.ichi2.libanki.Collection)4 AbstractSched (com.ichi2.libanki.sched.AbstractSched)4 Test (org.junit.Test)4 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)1