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);
}
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);
}
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);
}
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);
}
Aggregations