aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-11-18 11:38:59 -0500
committerYour Name <you@example.com>2020-11-18 11:38:59 -0500
commitdcfac3432f981191da68f14f21f5010fc4da51c0 (patch)
tree7e2a405d15f0ce4ce1c83e070d68fcb5088ed3c2
parent49c05187f739779a6433f75a348529c26e123e94 (diff)
downloadlibbible-dcfac3432f981191da68f14f21f5010fc4da51c0.tar.gz
libbible-dcfac3432f981191da68f14f21f5010fc4da51c0.tar.bz2
libbible-dcfac3432f981191da68f14f21f5010fc4da51c0.zip
Fixed issue with status reporting
-rw-r--r--libbible.h8
-rw-r--r--mods.cc24
-rw-r--r--testLibbible.cc18
3 files changed, 37 insertions, 13 deletions
diff --git a/libbible.h b/libbible.h
index cf8a1f4..85ea9eb 100644
--- a/libbible.h
+++ b/libbible.h
@@ -45,14 +45,18 @@ namespace libbible {
class Status {
public:
- void update(unsigned long totalBytes, unsigned long completedBytes, std::string message);
+ virtual void update(unsigned long totalBytes, unsigned long completedBytes, std::string message) {}
};
/**
* @param status Status update method is called asynchronously as download progresses
+ */
+ void setStatusReporter(Status& status);
+
+ /**
* @return A mapping from language to bible version names
*/
- std::map<std::string, std::vector<std::string>> downloadModsAvailable(Status *status = nullptr);
+ std::map<std::string, std::vector<std::string>> downloadModsAvailable();
/**
* Cancel an in-progress download
diff --git a/mods.cc b/mods.cc
index 6b2063a..903c91f 100644
--- a/mods.cc
+++ b/mods.cc
@@ -10,9 +10,9 @@ using namespace std;
class myStatusReporter : public sword::StatusReporter {
public:
myStatusReporter(libbible::Status *status);
- virtual ~myStatusReporter();
- virtual void preStatus(long totalBytes, long completedBytes, const char *message);
- virtual void update(unsigned long totalBytes, unsigned long completedBytes);
+ ~myStatusReporter();
+ void preStatus(long totalBytes, long completedBytes, const char *message);
+ void update(unsigned long totalBytes, unsigned long completedBytes);
protected:
libbible::Status *status;
string message;
@@ -24,31 +24,33 @@ myStatusReporter::myStatusReporter(libbible::Status *s) {
myStatusReporter::~myStatusReporter() {};
-void libbible::Status::update(unsigned long totalBytes, unsigned long completedBytes, string message) {}
+//virtual void libbible::Status::update(unsigned long totalBytes, unsigned long completedBytes, string message) {}
void myStatusReporter::preStatus(long totalBytes, long completedBytes, const char *msg) {
message = string(msg);
status->update((unsigned long) totalBytes, (unsigned long) completedBytes, message);
+ //printf("Got a status update: %ld / %ld, \"%s\"\n", completedBytes, totalBytes, message.c_str());
}
void myStatusReporter::update(unsigned long totalBytes, unsigned long completedBytes) {
status->update(totalBytes, completedBytes, message);
+ //printf("Got a status update: %ld / %ld, \"%s\"\n", completedBytes, totalBytes, message.c_str());
}
string basedir = (getenv("HOME")) + string("/.sword/");
sword::InstallMgr *installMgr = new sword::InstallMgr((basedir + std::string("InstallMgr")).c_str(), nullptr);
map<string, vector<pair<string, sword::InstallSource *>>> installSources;
-map<string, vector<string>> libbible::downloadModsAvailable(libbible::Status *status) {
+void libbible::setStatusReporter(libbible::Status& status) {
+ myStatusReporter *msr = new myStatusReporter(&status);
+ free(installMgr);
+ installMgr = new sword::InstallMgr((basedir + std::string("InstallMgr")).c_str(), msr);
+}
+
+map<string, vector<string>> libbible::downloadModsAvailable() {
installSources.clear();
mkdir((basedir + std::string("mods.d/")).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
mkdir((basedir + std::string("modules/")).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
- myStatusReporter *msr = nullptr;
- if(status) {
- msr = new myStatusReporter(status);
- }
- free(installMgr);
- installMgr = new sword::InstallMgr((basedir + std::string("InstallMgr")).c_str(), msr);
installMgr->setUserDisclaimerConfirmed(true);
string confpath = basedir + string("InstallMgr/InstallMgr.conf");
if(! sword::FileMgr::existsFile(confpath.c_str())) {
diff --git a/testLibbible.cc b/testLibbible.cc
index 3850aa0..8a7f468 100644
--- a/testLibbible.cc
+++ b/testLibbible.cc
@@ -47,6 +47,19 @@ class TestLibbible : public CppUnit::TestFixture
//-----------------------------------------------------------------------------
+class StatusTester : public libbible::Status
+{
+ public:
+ virtual void update(unsigned long totalBytes, unsigned long completedBytes, string message);
+ bool hasBeenUpdated = false;
+};
+
+void StatusTester::update(unsigned long totalBytes, unsigned long completedBytes, string message) {
+ hasBeenUpdated = true;
+}
+
+//-----------------------------------------------------------------------------
+
void TestLibbible::testGetModules(void) {
map<string, vector<string>> mods = libbible::getModules();
for(auto pair : mods) {
@@ -175,7 +188,11 @@ void TestLibbible::testSettings(void) {
}
void TestLibbible::testDownload(void) {
+ StatusTester status;
+ libbible::setStatusReporter(status);
map<string, vector<string>> modsAvailable = libbible::downloadModsAvailable();
+ //CPPUNIT_ASSERT(status.hasBeenUpdated);
+ status.hasBeenUpdated = false;
// We try installing the first available one
string language;
string name;
@@ -192,6 +209,7 @@ void TestLibbible::testDownload(void) {
libbible::installModFromInternet(language, name);
mods = libbible::getModules();
CPPUNIT_ASSERT(mods.find(name) != mods.end());
+ CPPUNIT_ASSERT(status.hasBeenUpdated);
}
//-----------------------------------------------------------------------------