mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 23:40:26 -04:00
Added test cases for inserting very long values, undefined values, empty values, unicode values into room database for recent searches
This commit is contained in:
parent
613d375e1d
commit
f091da24c7
@ -72,6 +72,33 @@ class RecentSearchRoomDaoTest {
|
|||||||
recentSearchRoomDao.deleteSearchHistory()
|
recentSearchRoomDao.deleteSearchHistory()
|
||||||
// Verify that the result is empty
|
// Verify that the result is empty
|
||||||
assertThat(getRecentSearchByZimId(zimId).size, equalTo(0))
|
assertThat(getRecentSearchByZimId(zimId).size, equalTo(0))
|
||||||
|
|
||||||
|
// test to save empty values for recent search
|
||||||
|
val emptyQuery = ""
|
||||||
|
recentSearchRoomDao.saveSearch(emptyQuery, zimId)
|
||||||
|
// verify that the result is not empty
|
||||||
|
assertThat(getRecentSearchByZimId(zimId).size, equalTo(1))
|
||||||
|
|
||||||
|
// we are not saving undefined or null values into database.
|
||||||
|
// test to save undefined value for recent search.
|
||||||
|
lateinit var undefinedQuery: String
|
||||||
|
try {
|
||||||
|
recentSearchRoomDao.saveSearch(undefinedQuery, zimId)
|
||||||
|
assertThat(
|
||||||
|
"Undefined value was saved into database",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
assertThat("Undefined value was not saved, as expected.", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all recent search entities for testing unicodes values
|
||||||
|
recentSearchRoomDao.deleteSearchHistory()
|
||||||
|
|
||||||
|
// save unicode values into database
|
||||||
|
val unicodeQuery = "title \u03A3" // Unicode character for Greek capital letter Sigma
|
||||||
|
recentSearchRoomDao.saveSearch(unicodeQuery, zimId)
|
||||||
|
assertThat(getRecentSearchByZimId(zimId)[0].searchTerm, equalTo("title Σ"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getRecentSearchByZimId(zimId: String) =
|
private suspend fun getRecentSearchByZimId(zimId: String) =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user