[sword-svn] r3369 - in trunk/bindings/objc: ObjCSword.xcodeproj src test

mdbergmann at crosswire.org mdbergmann at crosswire.org
Mon Apr 13 02:17:42 MST 2015


Author: mdbergmann
Date: 2015-04-13 02:17:42 -0700 (Mon, 13 Apr 2015)
New Revision: 3369

Added:
   trunk/bindings/objc/test/SwordInstallSourceManagerTest.m
Modified:
   trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj
   trunk/bindings/objc/src/SwordInstallSource.h
   trunk/bindings/objc/src/SwordInstallSource.mm
   trunk/bindings/objc/src/SwordInstallSourceManager.h
   trunk/bindings/objc/src/SwordInstallSourceManager.mm
Log:
Simplifications in SwordInstallSourceManager.
Added a couple unit tests for this class.
API changes are intended so that clients need to check their setup (this probably is only Eloquent).

Modified: trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj
===================================================================
--- trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj	2015-04-11 12:46:54 UTC (rev 3368)
+++ trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj	2015-04-13 09:17:42 UTC (rev 3369)
@@ -39,6 +39,7 @@
 /* Begin PBXBuildFile section */
 		8C92C31DC92DF0671FCEB5B3 /* SwordFilter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8C92CC111DC521DE0C054C60 /* SwordFilter.mm */; };
 		8C92CC7B68FDCDFFFB8B4A31 /* DefaultFilterProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8C92C0124F354F4CB4F294F9 /* DefaultFilterProvider.mm */; };
+		8C92CC9CEC8A341B902C53E2 /* SwordInstallSourceManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C92C0CA467F3114A1DC89DD /* SwordInstallSourceManagerTest.m */; };
 		8C92CE0B19FBB659FB8F8B71 /* FilterProviderFactory.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8C92C25F57CB01957B086256 /* FilterProviderFactory.mm */; };
 		8C92CE39E231FF9CAAB5308B /* SwordUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C92C291C40A77060C12A21B /* SwordUtil.m */; };
 		8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
@@ -1664,6 +1665,7 @@
 		32DBCF5E0370ADEE00C91783 /* ObjCSword_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCSword_Prefix.pch; sourceTree = "<group>"; };
 		8C92C0124F354F4CB4F294F9 /* DefaultFilterProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DefaultFilterProvider.mm; path = src/DefaultFilterProvider.mm; sourceTree = "<group>"; };
 		8C92C02A5C86E1C75ED1CEF4 /* SwordFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SwordFilter.h; path = src/SwordFilter.h; sourceTree = "<group>"; };
+		8C92C0CA467F3114A1DC89DD /* SwordInstallSourceManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SwordInstallSourceManagerTest.m; sourceTree = "<group>"; };
 		8C92C25F57CB01957B086256 /* FilterProviderFactory.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = FilterProviderFactory.mm; path = src/FilterProviderFactory.mm; sourceTree = "<group>"; };
 		8C92C291C40A77060C12A21B /* SwordUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SwordUtil.m; path = src/SwordUtil.m; sourceTree = "<group>"; };
 		8C92C72ADACB017A434CD268 /* FilterProviderFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FilterProviderFactory.h; path = src/FilterProviderFactory.h; sourceTree = "<group>"; };
@@ -5349,6 +5351,7 @@
 				A9BDFA771207F9F00067ED5B /* SwordListKeyTest.m */,
 				A968BE4C19DFF832002C9B78 /* SwordBibleTest.swift */,
 				A968BE4B19DFF831002C9B78 /* Tests-Bridging-Header.h */,
+				8C92C0CA467F3114A1DC89DD /* SwordInstallSourceManagerTest.m */,
 			);
 			name = Tests;
 			path = test;
@@ -7193,6 +7196,7 @@
 				A9BFB0BC13EDF5C900032679 /* SwordManagerTest.m in Sources */,
 				A9BFB0BD13EDF5C900032679 /* SwordModuleTest.m in Sources */,
 				A9BFB0BE13EDF5C900032679 /* SwordListKeyTest.m in Sources */,
+				8C92CC9CEC8A341B902C53E2 /* SwordInstallSourceManagerTest.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/bindings/objc/src/SwordInstallSource.h
===================================================================
--- trunk/bindings/objc/src/SwordInstallSource.h	2015-04-11 12:46:54 UTC (rev 3368)
+++ trunk/bindings/objc/src/SwordInstallSource.h	2015-04-13 09:17:42 UTC (rev 3369)
@@ -25,10 +25,8 @@
     sword::InstallSource *swInstallSource;
 #endif
     
-    BOOL temporarySource;
-
     /** the sword manager for this source */
-    SwordManager *swordManager;    
+    SwordManager *swordManager;
 }
 
 // init

Modified: trunk/bindings/objc/src/SwordInstallSource.mm
===================================================================
--- trunk/bindings/objc/src/SwordInstallSource.mm	2015-04-11 12:46:54 UTC (rev 3368)
+++ trunk/bindings/objc/src/SwordInstallSource.mm	2015-04-13 09:17:42 UTC (rev 3369)
@@ -12,6 +12,8 @@
 
 @interface SwordInstallSource ()
 
+ at property (nonatomic) BOOL deleteSwInstallSource;
+
 @end
 
 @implementation SwordInstallSource
@@ -20,16 +22,11 @@
 - (id)init {
     self = [super init];
     if(self) {
-        temporarySource = NO;
-
         // at first we have no sword manager
         [self setSwordManager:nil];
-        
-        // init InstallMgr
+
         swInstallSource = new sword::InstallSource("", "");
-        if(swInstallSource == nil) {
-            ALog(@"Could not init sword install source!");
-        }
+        self.deleteSwInstallSource = YES;
     }
     
     return self;
@@ -38,8 +35,7 @@
 - (id)initWithType:(NSString *)aType {
     self = [self init];
     if(self) {
-        // set type
-        swInstallSource->type = [aType cStringUsingEncoding:NSUTF8StringEncoding];
+        swInstallSource->type = [aType UTF8String];
     }
     
     return self;
@@ -49,31 +45,33 @@
 - (id)initWithSource:(sword::InstallSource *)is {
     self = [super init];
     if(self) {
-        temporarySource = YES;
-        
         // at first we have no sword manager
         [self setSwordManager:nil];
-        
         swInstallSource = is;
+        self.deleteSwInstallSource = NO;
     }
     
     return self;
 }
 
+- (void)dealloc {
+    if(swInstallSource != NULL && self.deleteSwInstallSource) {
+        ALog(@"Deleting swInstallSource");
+        delete swInstallSource;
+    }
+}
 
-
 - (void)setSwordManager:(SwordManager *)swManager {
     swordManager = swManager;
 }
 
-// accessors
 - (NSString *)caption {
     const char *str = swInstallSource->caption;
     return [[NSString alloc] initWithCString:str encoding:NSUTF8StringEncoding];
 }
 
 - (void)setCaption:(NSString *)aCaption {
-    swInstallSource->caption = [aCaption cStringUsingEncoding:NSUTF8StringEncoding];
+    swInstallSource->caption = [aCaption UTF8String];
 }
 
 - (NSString *)type {
@@ -82,7 +80,7 @@
 }
 
 - (void)setType:(NSString *)aType {
-    swInstallSource->type = [aType cStringUsingEncoding:NSUTF8StringEncoding];
+    swInstallSource->type = [aType UTF8String];
 }
 
 - (NSString *)source {
@@ -91,7 +89,7 @@
 }
 
 - (void)setSource:(NSString *)aSource {
-    swInstallSource->source = [aSource cStringUsingEncoding:NSUTF8StringEncoding];
+    swInstallSource->source = [aSource UTF8String];
 }
 
 - (NSString *)directory {
@@ -100,7 +98,7 @@
 }
 
 - (void)setDirectory:(NSString *)aDir {
-    swInstallSource->directory = [aDir cStringUsingEncoding:NSUTF8StringEncoding];
+    swInstallSource->directory = [aDir UTF8String];
 }
 
 - (BOOL)isLocalSource {
@@ -162,7 +160,7 @@
             mgr = new sword::SWMgr([[self directory] UTF8String], true, NULL, false, false);
         } else {
             // create SwordManager from the SWMgr of this source
-            mgr = swInstallSource->getMgr();    
+            mgr = swInstallSource->getMgr();
         }
         
         if(mgr == nil) {

Modified: trunk/bindings/objc/src/SwordInstallSourceManager.h
===================================================================
--- trunk/bindings/objc/src/SwordInstallSourceManager.h	2015-04-11 12:46:54 UTC (rev 3368)
+++ trunk/bindings/objc/src/SwordInstallSourceManager.h	2015-04-13 09:17:42 UTC (rev 3369)
@@ -35,15 +35,9 @@
 #ifdef __cplusplus
     sword::InstallMgr *swInstallMgr;
 #endif
-
-    BOOL createPath;
-    
-    NSString *configPath;
 }
 
-// ------------------- getter / setter -------------------
- at property (strong, readwrite) NSString *configPath;
- at property (strong, readwrite) NSString *configFilePath;
+// ------------------- properties -------------------
 @property (strong, readwrite) NSMutableArray *installSourceList;
 /** Dictionary of InstallSources. Key: Caption */
 @property (strong, readwrite) NSMutableDictionary *installSources;
@@ -51,29 +45,26 @@
 // -------------------- methods --------------------
 
 // initialization
-+ (SwordInstallSourceManager *)defaultController;
-+ (SwordInstallSourceManager *)defaultControllerWithPath:(NSString *)aPath;
-+ (SwordInstallSourceManager *)controllerWithPath:(NSString *)aPath;
++ (SwordInstallSourceManager *)defaultManager;
 
 /**
-base path of the module installation
+    base path of the module installation
  */
-- (id)init;
 - (id)initWithPath:(NSString *)aPath createPath:(BOOL)create;
-- (id)initWithFtpUser:(NSString *)aFtpUser ftpPassword:(NSString *)aFtpPassword;
 
-/** re-init after adding or removing new modules */
-- (void)reinitialize;
+/** marks this manager as the default one / singleton */
+- (void)useAsDefaultManager;
 
+/** init after adding or removing new modules */
+- (void)initManager;
+
 // installation/unInstallation
 - (int)installModule:(SwordModule *)aModule fromSource:(SwordInstallSource *)is withManager:(SwordManager *)manager;
 - (int)uninstallModule:(SwordModule *)aModule fromManager:(SwordManager *)swManager;
 
 // add/remove install sources
 - (void)addInstallSource:(SwordInstallSource *)is;
-- (void)addInstallSource:(SwordInstallSource *)is withReinitialize:(BOOL)reinit;
 - (void)removeInstallSource:(SwordInstallSource *)is;
-- (void)removeInstallSource:(SwordInstallSource *)is withReinitialize:(BOOL)reinit;
 - (void)updateInstallSource:(SwordInstallSource *)is;
 - (int)refreshMasterRemoteInstallSourceList;
 

Modified: trunk/bindings/objc/src/SwordInstallSourceManager.mm
===================================================================
--- trunk/bindings/objc/src/SwordInstallSourceManager.mm	2015-04-11 12:46:54 UTC (rev 3368)
+++ trunk/bindings/objc/src/SwordInstallSourceManager.mm	2015-04-13 09:17:42 UTC (rev 3369)
@@ -24,75 +24,18 @@
 
 @property (strong, nonatomic) NSString *ftpUser;
 @property (strong, nonatomic) NSString *ftpPassword;
+ at property (strong, readwrite) NSString *configPath;
+ at property (readwrite) BOOL createConfigPath;
 
 @end
 
 @implementation SwordInstallSourceManager
 
- at dynamic configPath;
-
-// ------------------- getter / setter -------------------
-- (NSString *)configPath {
-    return configPath;
-}
-
-- (void)setConfigPath:(NSString *)value {
-    DLog(@"");
-    
-    if(configPath != value) {
-        configPath = [value copy];
-        
-        if(value == nil) {
-            return;
-        }
-        
-        
-        // check for existence
-        NSFileManager *fm = [NSFileManager defaultManager];
-        BOOL isDir;
-        if(![fm fileExistsAtPath:configPath] && createPath) {
-            // create path
-            [fm createDirectoryAtPath:configPath withIntermediateDirectories:NO attributes:nil error:NULL];
-        }
-        
-        if([fm fileExistsAtPath:configPath isDirectory:&isDir] && (isDir)) {
-            // set configFilePath
-            [self setConfigFilePath:[configPath stringByAppendingPathComponent:@"InstallMgr.conf"]];
-            
-            // check config
-            if(![fm fileExistsAtPath:self.configFilePath]) {
-                // create config entry
-                sword::SWConfig config([self.configFilePath cStringUsingEncoding:NSUTF8StringEncoding]);
-                config["General"]["PassiveFTP"] = "true";
-                config.Save();
-
-                // create default Install source
-                SwordInstallSource *is = [[SwordInstallSource alloc] initWithType:INSTALLSOURCE_TYPE_FTP];
-                [is setCaption:@"CrossWire"];
-                [is setSource:@"ftp.crosswire.org"];
-                [is setDirectory:@"/pub/sword/raw"];
-                                    
-                // addInstallSource will reinitialize
-                [self addInstallSource:is withReinitialize:NO];
-                
-            }
-            // init installMgr
-            [self reinitialize];                
-
-            // sync with master install source list
-            //[self refreshMasterRemoteInstallSourceList];
-
-        } else {
-            ALog(@"Config path does not exist: %@", configPath);
-        }
-    }
-}
-
 // -------------------- methods --------------------
 
+static SwordInstallSourceManager *singleton = nil;
 // initialization
-+ (SwordInstallSourceManager *)defaultController {
-    static SwordInstallSourceManager *singleton = nil;
++ (SwordInstallSourceManager *)defaultManager {
     if(singleton == nil) {
         singleton = [[SwordInstallSourceManager alloc] init];
     }
@@ -100,25 +43,14 @@
     return singleton;
 }
 
-+ (SwordInstallSourceManager *)defaultControllerWithPath:(NSString *)aPath {
-    SwordInstallSourceManager *m = [SwordInstallSourceManager defaultController];
-    [m setConfigPath:aPath];
-    return m;
-}
-
-+ (SwordInstallSourceManager *)controllerWithPath:(NSString *)aPath {
-    return [[SwordInstallSourceManager alloc] initWithPath:aPath createPath:YES];
-}
-
 /**
 base path of the module installation
  */
 - (id)init {
     self = [super init];
     if(self) {
-        createPath = NO;
+        [self setCreateConfigPath:NO];
         [self setConfigPath:nil];
-        [self setConfigFilePath:nil];
         [self setInstallSources:[NSMutableDictionary dictionary]];
         [self setInstallSourceList:[NSMutableArray array]];
         [self setFtpUser:@"ftp"];
@@ -134,99 +66,170 @@
 - (id)initWithPath:(NSString *)aPath createPath:(BOOL)create {
     self = [self init];
     if(self) {
-        createPath = create;
+        [self setCreateConfigPath:create];
         [self setConfigPath:aPath];
     }
     
     return self;
 }
 
-- (id)initWithFtpUser:(NSString *)aFtpUser ftpPassword:(NSString *)aFtpPassword {
-    self = [self init];
-    if(self) {
-        [self setFtpUser:aFtpUser];
-        [self setFtpPassword:aFtpPassword];
+- (void)useAsDefaultManager {
+    singleton = self;
+}
+
+- (void)dealloc {
+    if(swInstallMgr != nil) {
+        delete swInstallMgr;
     }
-    return self;
 }
 
-/** re-init after adding or removing new modules */
-- (void)reinitialize {
-    sword::SWConfig config([self.configFilePath UTF8String]);
-    config.Load();
+/** init after adding or removing new modules */
+- (void)initManager {
+    [self setupConfig];
 
-    // init installMgr
+    // safe disclaimer flag
     BOOL disclaimerConfirmed = NO;
-    if(swInstallMgr != nil) {
+    if(swInstallMgr != NULL) {
         disclaimerConfirmed = [self userDisclaimerConfirmed];
     }
-    ALog(@"Creating InstallMgr with: %@, %i, %@, %@", configPath, 0, [self ftpUser], [self ftpPassword]);
-    swInstallMgr = new sword::InstallMgr([configPath UTF8String], 0, sword::SWBuf([[self ftpUser] UTF8String]), sword::SWBuf([[self ftpPassword] UTF8String]));
-    if(swInstallMgr == nil) {
-        ALog(@"Could not initialize InstallMgr!");
+
+    if(swInstallMgr == NULL) {
+        ALog(@"Initializing swInstallMgr");
+        swInstallMgr = [self newDefaultInstallMgr];
+        if(swInstallMgr == nil) {
+            ALog(@"Could not initialize InstallMgr!");
+
+        } else {
+            [self setUserDisclaimerConfirmed:disclaimerConfirmed];
+
+            if(![self existsDefaultInstallSource]) {
+                [self addDefaultInstallSource];
+            }
+
+            [self setupInstallSources];
+        }
+
     } else {
-        [self setUserDisclaimerConfirmed:disclaimerConfirmed];
-        
-        // empty all lists
-        [self.installSources removeAllObjects];
-        [self.installSourceList removeAllObjects];
-        
-        // init install sources
-        for(InstallSourceMap::iterator it = swInstallMgr->sources.begin(); it != swInstallMgr->sources.end(); it++) {
-            sword::InstallSource *sis = it->second;
-            SwordInstallSource *is = [[SwordInstallSource alloc] initWithSource:sis];
-            
-            self.installSources[[is caption]] = is;
-            // also add to list
-            [self.installSourceList addObject:is];
+        ALog(@"Re-initializing swInstallMgr");
+        [self reInitialize];
+    }
+}
+
+- (void)reInitialize {
+    [self readInstallMgrConf];
+    [self setupInstallSources];
+}
+
+- (sword::InstallMgr *)newDefaultInstallMgr {
+    ALog(@"Creating InstallMgr with: %@, %i, %@, %@", [self configPath], 0, [self ftpUser], [self ftpPassword]);
+    return new sword::InstallMgr(
+            [[self configPath] UTF8String],
+            0,
+            sword::SWBuf([[self ftpUser] UTF8String]),
+            sword::SWBuf([[self ftpPassword] UTF8String]));
+}
+
+- (BOOL)existsDefaultInstallSource {
+    sword::InstallMgr mgr = sword::InstallMgr([[self configPath] UTF8String]);
+
+    for(InstallSourceMap::iterator it = mgr.sources.begin(); it != mgr.sources.end(); it++) {
+        sword::InstallSource *sis = it->second;
+
+        if([[NSString stringWithCString:sis->caption.c_str() encoding:NSUTF8StringEncoding] isEqualToString:@"CrossWire"]) {
+            return YES;
         }
     }
+    return NO;
 }
 
+- (void)addDefaultInstallSource {
+    SwordInstallSource *is = [[SwordInstallSource alloc] initWithType:INSTALLSOURCE_TYPE_FTP];
+    [is setCaption:@"CrossWire"];
+    [is setSource:@"ftp.crosswire.org"];
+    [is setDirectory:@"/pub/sword/raw"];
 
-- (void)dealloc {
-    if(swInstallMgr != nil) {
-        delete swInstallMgr;
+    [self addInstallSource:is];
+}
+
+- (void)setupConfig {
+    if([self configPath] == nil) {
+        ALog(@"No config path configured!");
+        return;
     }
+
+    // check for existence
+    NSFileManager *fm = [NSFileManager defaultManager];
+    BOOL isDir;
+    ALog(@"Checking for config path at: %@", [self configPath]);
+    if(![fm fileExistsAtPath:[self configPath]] && [self createConfigPath]) {
+        ALog(@"Config dir doesn't exist, creating it...");
+        [fm createDirectoryAtPath:[self configPath] withIntermediateDirectories:NO attributes:nil error:NULL];
+        ALog(@"Config dir doesn't exist, creating it...done");
+    }
+
+    if([fm fileExistsAtPath:[self configPath] isDirectory:&isDir] && (isDir)) {
+        // check config
+        if(![fm fileExistsAtPath:[self createInstallMgrConfPath]]) {
+            // create config entry
+            sword::SWConfig config([[self createInstallMgrConfPath] UTF8String]);
+            config["General"]["PassiveFTP"] = "true";
+            config.Save();
+        }
+
+    } else {
+        ALog(@"Config path does not exist: %@", [self configPath]);
+    }
 }
 
-- (void)addInstallSource:(SwordInstallSource *)is {
-    [self addInstallSource:is withReinitialize:YES];
+- (void)setupInstallSources {
+    ALog(@"Cleaning all install sources...");
+    [[self installSources] removeAllObjects];
+    [[self installSourceList] removeAllObjects];
+    ALog(@"Cleaning all install sources...done");
+
+    for(InstallSourceMap::iterator it = swInstallMgr->sources.begin(); it != swInstallMgr->sources.end(); it++) {
+        sword::InstallSource *sis = it->second;
+        SwordInstallSource *is = [[SwordInstallSource alloc] initWithSource:sis];
+
+        ALog(@"Adding install source: %@", [is caption]);
+        [self installSources][[is caption]] = is;
+        [[self installSourceList] addObject:is];
+    }
 }
 
-// add/remove install sources
-- (void)addInstallSource:(SwordInstallSource *)is withReinitialize:(BOOL)reinit {
-    
-    // save at once
-    sword::SWConfig config([self.configFilePath cStringUsingEncoding:NSUTF8StringEncoding]);
+- (NSString *)createInstallMgrConfPath {
+    return [[self configPath] stringByAppendingPathComponent:@"InstallMgr.conf"];
+}
+
+- (void)addInstallSource:(SwordInstallSource *)is {
+    ALog(@"Adding install source: %@", [is caption]);
+    [self installSources][[is caption]] = is;
+    [[self installSourceList] addObject:is];
+
+    // modify conf file
+    sword::SWConfig config([[self createInstallMgrConfPath] UTF8String]);
 	if([[is type] isEqualToString:INSTALLSOURCE_TYPE_FTP]) {
 		config["Sources"].insert(ConfigEntMap::value_type(INSTALLSOURCE_SECTION_TYPE_FTP, [[is configEntry] UTF8String]));
 	} else {
 		config["Sources"].insert(ConfigEntMap::value_type(INSTALLSOURCE_SECTION_TYPE_HTTP, [[is configEntry] UTF8String]));
 	}
     config.Save();
-    
-	if(reinit)
-		[self reinitialize];
+
+    [self readInstallMgrConf];
 }
 
 - (void)removeInstallSource:(SwordInstallSource *)is {
-    [self removeInstallSource:is withReinitialize:NO];
-}
-
-- (void)removeInstallSource:(SwordInstallSource *)is withReinitialize:(BOOL)reinit {
-    
-    // remove source
+    ALog(@"Removing install source: %@", [is caption]);
     [self.installSources removeObjectForKey:[is caption]];
     [self.installSourceList removeObject:is];
-    
-    // save at once
-    sword::SWConfig config([self.configFilePath cStringUsingEncoding:NSUTF8StringEncoding]);
+
+    // modify conf file
+    sword::SWConfig config([[self createInstallMgrConfPath] UTF8String]);
     config["Sources"].erase(INSTALLSOURCE_SECTION_TYPE_HTTP);
     config["Sources"].erase(INSTALLSOURCE_SECTION_TYPE_FTP);
-    
+
     // build up new
-    for(SwordInstallSource *sis in self.installSources) {
+    for(SwordInstallSource *sis in self.installSourceList) {
 		if([[sis type] isEqualToString:INSTALLSOURCE_TYPE_FTP]) {
 			config["Sources"].insert(ConfigEntMap::value_type(INSTALLSOURCE_SECTION_TYPE_FTP, [[sis configEntry] UTF8String]));
 		} else {
@@ -234,27 +237,24 @@
 		}
     }
     config.Save();
-    
-	if(reinit)
-		[self reinitialize];
+
+    [self readInstallMgrConf];
 }
 
 - (void)updateInstallSource:(SwordInstallSource *)is {
     // first remove, then add again
-    [self removeInstallSource:is withReinitialize:NO];
+    [self removeInstallSource:is];
     [self addInstallSource:is];
 }
 
 // installation/unInstallation
 - (int)installModule:(SwordModule *)aModule fromSource:(SwordInstallSource *)is withManager:(SwordManager *)manager {
-    
     int stat;
     if([[is source] isEqualToString:@"localhost"]) {
         stat = swInstallMgr->installModule([manager swManager], [[is directory] UTF8String], [[aModule name] UTF8String]);
     } else {
         stat = swInstallMgr->installModule([manager swManager], 0, [[aModule name] UTF8String], [is installSource]);
     }
-    
     return stat;
 }
 
@@ -334,6 +334,10 @@
     swInstallMgr->setUserDisclaimerConfirmed(flag);
 }
 
+- (void)readInstallMgrConf {
+    swInstallMgr->readInstallConf();
+}
+
 /** low level access */
 - (sword::InstallMgr *)installMgr {
     return swInstallMgr;

Added: trunk/bindings/objc/test/SwordInstallSourceManagerTest.m
===================================================================
--- trunk/bindings/objc/test/SwordInstallSourceManagerTest.m	                        (rev 0)
+++ trunk/bindings/objc/test/SwordInstallSourceManagerTest.m	2015-04-13 09:17:42 UTC (rev 3369)
@@ -0,0 +1,127 @@
+//
+//  SwordInstallSourceManagerTest.m
+//  ObjCSword
+//
+//  Created by Manfred Bergmann on 12.04.15.
+//
+//
+
+#import <XCTest/XCTest.h>
+#import "SwordInstallSourceManager.h"
+#import "SwordInstallSource.h"
+
+ at interface SwordInstallSourceManagerTest : XCTestCase
+
+ at end
+
+ at implementation SwordInstallSourceManagerTest
+
+NSString *testConfigPath = @"/tmp/testmodinst";
+
+- (void)setUp {
+    NSFileManager *fm = [NSFileManager defaultManager];
+    [fm removeItemAtPath:testConfigPath error:NULL];
+
+    [super setUp];
+}
+
+- (void)tearDown {
+    [super tearDown];
+}
+
+- (void)testObjectCreate {
+    SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:@"" createPath:YES];
+    XCTAssertTrue(mgr != nil, @"");
+}
+
+- (void)testInitManagerCheckConfigPath {
+    // make sure this folder doesn't exist at start
+    NSFileManager *fm = [NSFileManager defaultManager];
+    BOOL isDir;
+    BOOL existsFolder = [fm fileExistsAtPath:testConfigPath isDirectory:&isDir];
+    XCTAssertFalse(existsFolder, @"");
+
+    SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
+    [mgr initManager];
+
+    // make sure the folder was created
+    existsFolder = [fm fileExistsAtPath:testConfigPath isDirectory:&isDir];
+    BOOL existsInstallMgrConf = [fm fileExistsAtPath:[testConfigPath stringByAppendingPathComponent:@"InstallMgr.conf"]];
+    
+    XCTAssertTrue(isDir, @"");
+    XCTAssertTrue(existsFolder, @"");
+    XCTAssertTrue(existsInstallMgrConf, @"");
+}
+
+- (void)testHasOneInitialInstallSource {
+    SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
+    [mgr initManager];
+
+    XCTAssertTrue([[mgr installSources] count] == 1, @"");
+    XCTAssertTrue([[mgr installSourceList] count] == 1, @"");
+
+    XCTAssertEqual([[mgr installSourceList] firstObject], [mgr installSources][@"CrossWire"]);
+
+    XCTAssertTrue([[[[mgr installSourceList] firstObject] caption] isEqualToString:@"CrossWire"], @"");
+    XCTAssertTrue([[[[mgr installSourceList] firstObject] source] isEqualToString:@"ftp.crosswire.org"], @"");
+    XCTAssertTrue([[[[mgr installSourceList] firstObject] directory] isEqualToString:@"/pub/sword/raw"], @"");
+}
+
+- (void)testAddInstallSource {
+    SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
+    [mgr initManager];
+
+    SwordInstallSource *is = [[SwordInstallSource alloc] initWithType:INSTALLSOURCE_TYPE_FTP];
+    [is setCaption:@"test"];
+    [is setSource:@"foo.bar.local"];
+    [is setDirectory:@"/foobar"];
+
+    [mgr addInstallSource:is];
+
+    XCTAssertTrue([[mgr installSources] count] == 2, @"");
+    XCTAssertTrue([[mgr installSourceList] count] == 2, @"");
+
+    XCTAssertTrue([[[mgr installSources][@"test"] caption] isEqualToString:@"test"], @"");
+    XCTAssertTrue([[[mgr installSources][@"test"] source] isEqualToString:@"foo.bar.local"], @"");
+    XCTAssertTrue([[[mgr installSources][@"test"] directory] isEqualToString:@"/foobar"], @"");
+}
+
+- (void)testRemoveInstallSource {
+    SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
+    [mgr initManager];
+
+    // first add
+    SwordInstallSource *is = [[SwordInstallSource alloc] initWithType:INSTALLSOURCE_TYPE_FTP];
+    [is setCaption:@"test"];
+    [is setSource:@"foo.bar.local"];
+    [is setDirectory:@"/foobar"];
+
+    [mgr addInstallSource:is];
+
+    XCTAssertTrue([[mgr installSources] count] == 2, @"");
+    XCTAssertTrue([[mgr installSourceList] count] == 2, @"");
+
+    XCTAssertTrue([[[mgr installSources][@"test"] caption] isEqualToString:@"test"], @"");
+    XCTAssertTrue([[[mgr installSources][@"test"] source] isEqualToString:@"foo.bar.local"], @"");
+    XCTAssertTrue([[[mgr installSources][@"test"] directory] isEqualToString:@"/foobar"], @"");
+
+    // then remove
+    [mgr removeInstallSource:is];
+
+    XCTAssertTrue([[mgr installSources] count] == 1, @"");
+    XCTAssertTrue([[mgr installSourceList] count] == 1, @"");
+}
+
+- (void)testUseAsDefaultManager {
+    SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
+    [mgr useAsDefaultManager];
+
+    SwordInstallSourceManager *mgr2 = [SwordInstallSourceManager defaultManager];
+    XCTAssertEqual(mgr, mgr2);
+}
+
+- (void)testExample {
+    XCTAssert(YES, @"Pass");
+}
+
+ at end




More information about the sword-cvs mailing list