From 51734065a38cf6db48fe9fb4b16461ce424cad90 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 21 Nov 2020 14:33:33 -0500 Subject: Updated API to be more explicit with references --- testLibbible.cc | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'testLibbible.cc') diff --git a/testLibbible.cc b/testLibbible.cc index 8a7f468..b8f93b3 100644 --- a/testLibbible.cc +++ b/testLibbible.cc @@ -60,6 +60,18 @@ void StatusTester::update(unsigned long totalBytes, unsigned long completedBytes //----------------------------------------------------------------------------- +class CancelTester : public libbible::Status +{ + public: + virtual void update(unsigned long totalBytes, unsigned long completedBytes, string message); +}; + +void CancelTester::update(unsigned long totalBytes, unsigned long completedBytes, string message) { + libbible::terminateDownload(); +} + +//----------------------------------------------------------------------------- + void TestLibbible::testGetModules(void) { map> mods = libbible::getModules(); for(auto pair : mods) { @@ -141,7 +153,7 @@ void TestLibbible::testGetText(void) { //printf("Text is: `%s`\n", allText.c_str()); CPPUNIT_ASSERT(allText == "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. "); - text = libbible::getText(libbible::passage{.modName = "KJV", .reference="John 3:3"}); + text = libbible::getText(libbible::getPassage("KJV", "John 3:3")); allText.clear(); for(auto tex : text) { allText += tex.text; @@ -149,17 +161,17 @@ void TestLibbible::testGetText(void) { //printf("Text is: `%s`\n", allText.c_str()); CPPUNIT_ASSERT(allText == "Jesus answered and said unto him, Verily, verily, I say unto thee, Except a man be born again, he cannot see the kingdom of God. "); - text = libbible::getText(libbible::passage{.modName = "KJV", .reference="Gal 5:22-23"}); + text = libbible::getText(libbible::getPassage("KJV", "Gal 5:22-23")); chapVerses = getChapVerses(text); shouldContain = vector>({pair(5, 22), pair(5, 23)}); CPPUNIT_ASSERT(chapVerses == shouldContain); - text = libbible::getText(libbible::passage{.modName = "KJV", .reference="1 cor 1:31-2:1"}); + text = libbible::getText(libbible::getPassage("KJV", "1 cor 1:31-2:1")); chapVerses = getChapVerses(text); shouldContain = vector>({pair(1, 31), pair(2, 1)}); CPPUNIT_ASSERT(chapVerses == shouldContain); - text = libbible::getText(libbible::passage{.modName = "KJV", .reference="ps 14-15"}); + text = libbible::getText(libbible::getPassage("KJV", "ps 14-15")); chapVerses = getChapVerses(text); shouldContain = vector>({pair(14, 1), pair(14, 2), @@ -188,11 +200,7 @@ void TestLibbible::testSettings(void) { } void TestLibbible::testDownload(void) { - StatusTester status; - libbible::setStatusReporter(status); map> modsAvailable = libbible::downloadModsAvailable(); - //CPPUNIT_ASSERT(status.hasBeenUpdated); - status.hasBeenUpdated = false; // We try installing the first available one string language; string name; @@ -204,8 +212,15 @@ void TestLibbible::testDownload(void) { CPPUNIT_ASSERT(!language.empty() && !name.empty()); // Try uninstalling it (shouldn't crash or have nasty side effects!) libbible::uninstallMod(name); + // Try installing it with cancel. Shoudn't work because it gets cancelled! + CancelTester cancel; + libbible::setStatusReporter(cancel); + libbible::installModFromInternet(language, name); auto mods = libbible::getModules(); CPPUNIT_ASSERT(mods.find(name) == mods.end()); + // Now we try with normal status + StatusTester status; + libbible::setStatusReporter(status); libbible::installModFromInternet(language, name); mods = libbible::getModules(); CPPUNIT_ASSERT(mods.find(name) != mods.end()); -- cgit v1.2.3