[sword-svn] r3389 - in trunk/bindings/objc: ObjCSword.xcodeproj src test
mdbergmann at crosswire.org
mdbergmann at crosswire.org
Tue Sep 8 05:38:03 MST 2015
Author: mdbergmann
Date: 2015-09-08 05:38:02 -0700 (Tue, 08 Sep 2015)
New Revision: 3389
Modified:
trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj
trunk/bindings/objc/src/SwordBible.mm
trunk/bindings/objc/src/SwordBook.mm
trunk/bindings/objc/src/SwordDictionary.mm
trunk/bindings/objc/src/SwordInstallSource.mm
trunk/bindings/objc/src/SwordInstallSourceManager.h
trunk/bindings/objc/src/SwordInstallSourceManager.mm
trunk/bindings/objc/src/SwordKey.mm
trunk/bindings/objc/src/SwordManager.h
trunk/bindings/objc/src/SwordManager.mm
trunk/bindings/objc/src/SwordModule.h
trunk/bindings/objc/src/SwordModule.mm
trunk/bindings/objc/src/SwordVerseKey.h
trunk/bindings/objc/src/SwordVerseKey.mm
trunk/bindings/objc/test/SwordInstallSourceManagerTest.m
trunk/bindings/objc/test/SwordModuleTest.m
Log:
Test improvements.
More minor cleanups.
Modified: trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj
===================================================================
--- trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/ObjCSword.xcodeproj/project.pbxproj 2015-09-08 12:38:02 UTC (rev 3389)
@@ -6312,6 +6312,9 @@
LastTestingUpgradeCheck = 0610;
LastUpgradeCheck = 0610;
TargetAttributes = {
+ 8DC2EF4F0486A6940098B216 = {
+ DevelopmentTeam = 27XS5W9C3J;
+ };
A9EE8A8A19E286E500CFFE6A = {
CreatedOnToolsVersion = 6.1;
};
@@ -7535,7 +7538,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
- CODE_SIGN_IDENTITY = "Developer ID Application: Manfred Bergmann";
+ CODE_SIGN_IDENTITY = "Developer ID Application";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -7580,7 +7583,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
- CODE_SIGN_IDENTITY = "Developer ID Application: Manfred Bergmann";
+ CODE_SIGN_IDENTITY = "Developer ID Application";
COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_COMPATIBILITY_VERSION = 1;
Modified: trunk/bindings/objc/src/SwordBible.mm
===================================================================
--- trunk/bindings/objc/src/SwordBible.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordBible.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -168,7 +168,7 @@
}
- (BOOL)hasReference:(NSString *)ref {
- [moduleLock lock];
+ [self.moduleLock lock];
sword::VerseKey *key = (sword::VerseKey *)(swModule->createKey());
(*key) = [ref UTF8String];
@@ -185,7 +185,7 @@
}
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
return NO;
}
@@ -257,7 +257,7 @@
- (NSString *)moduleIntroduction {
NSString *ret;
- [moduleLock lock];
+ [self.moduleLock lock];
// save key
SwordVerseKey *save = (SwordVerseKey *)[self getKeyCopy];
@@ -271,7 +271,7 @@
// restore old key
[self setSwordKey:save];
- [moduleLock unlock];
+ [self.moduleLock unlock];
return ret;
}
@@ -279,7 +279,7 @@
- (NSString *)bookIntroductionFor:(SwordBibleBook *)aBook {
NSString *ret;
- [moduleLock lock];
+ [self.moduleLock lock];
// save key
SwordVerseKey *save = (SwordVerseKey *)[self getKeyCopy];
@@ -294,7 +294,7 @@
// restore old key
[self setSwordKey:save];
- [moduleLock unlock];
+ [self.moduleLock unlock];
return ret;
}
@@ -302,7 +302,7 @@
- (NSString *)chapterIntroductionIn:(SwordBibleBook *)aBook forChapter:(int)chapter {
NSString *ret;
- [moduleLock lock];
+ [self.moduleLock lock];
// save key
SwordVerseKey *save = (SwordVerseKey *)[self getKeyCopy];
@@ -318,7 +318,7 @@
// restore old key
[self setSwordKey:save];
- [moduleLock unlock];
+ [self.moduleLock unlock];
return ret;
}
@@ -327,7 +327,7 @@
SwordBibleTextEntry *ret = nil;
if(aKey) {
- [moduleLock lock];
+ [self.moduleLock lock];
[self setSwordKey:aKey];
if(![self error]) {
NSString *txt;
@@ -343,32 +343,32 @@
ALog(@"nil key");
}
- if([swManager globalOption:SW_OPTION_HEADINGS] && [self hasFeature:SWMOD_FEATURE_HEADINGS]) {
+ if([self.swManager globalOption:SW_OPTION_HEADINGS] && [self hasFeature:SWMOD_FEATURE_HEADINGS]) {
NSString *preverseHeading = [self entryAttributeValuePreverse];
if(preverseHeading && [preverseHeading length] > 0) {
[ret setPreVerseHeading:preverseHeading];
}
}
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
}
return ret;
}
- (NSString *)versification {
- NSString *versification = configEntries[SWMOD_CONFENTRY_VERSIFICATION];
+ NSString *versification = self.configEntries[SWMOD_CONFENTRY_VERSIFICATION];
if(versification == nil) {
versification = [self configFileEntryForConfigKey:SWMOD_CONFENTRY_VERSIFICATION];
if(versification != nil) {
- configEntries[SWMOD_CONFENTRY_VERSIFICATION] = versification;
+ self.configEntries[SWMOD_CONFENTRY_VERSIFICATION] = versification;
}
}
// if still nil, use KJV versification
if(versification == nil) {
versification = @"KJV";
- configEntries[SWMOD_CONFENTRY_VERSIFICATION] = versification;
+ self.configEntries[SWMOD_CONFENTRY_VERSIFICATION] = versification;
}
return versification;
@@ -456,16 +456,16 @@
- (void)writeEntry:(SwordModuleTextEntry *)anEntry {
const char *data = [[anEntry text] UTF8String];
- int dLen = strlen(data);
+ size_t dLen = strlen(data);
- [moduleLock lock];
+ [self.moduleLock lock];
[self setKeyString:[anEntry key]];
if(![self error]) {
swModule->setEntry(data, dLen); // save text to module at current position
} else {
ALog(@"error at positioning module!");
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
}
@end
Modified: trunk/bindings/objc/src/SwordBook.mm
===================================================================
--- trunk/bindings/objc/src/SwordBook.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordBook.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -47,17 +47,17 @@
- (SwordModuleTreeEntry *)treeEntryForKey:(NSString *)treeKey {
SwordModuleTreeEntry * ret;
- [moduleLock lock];
+ [self.moduleLock lock];
if(treeKey == nil) {
- ret = [contents objectForKey:@"root"];
+ ret = contents[@"root"];
if(ret == nil) {
sword::TreeKeyIdx *tk = dynamic_cast<sword::TreeKeyIdx*>((sword::SWKey *)*(swModule));
ret = [self _treeEntryForKey:tk];
// add to content
- [contents setObject:ret forKey:@"root"];
+ contents[@"root"] = ret;
}
} else {
- ret = [contents objectForKey:treeKey];
+ ret = contents[treeKey];
if(ret == nil) {
const char *keyStr = [treeKey UTF8String];
if(![self isUnicode]) {
@@ -69,10 +69,10 @@
sword::TreeKeyIdx *key = dynamic_cast<sword::TreeKeyIdx*>((sword::SWKey *)*(swModule));
ret = [self _treeEntryForKey:key];
// add to content
- [contents setObject:ret forKey:treeKey];
+ contents[treeKey] = ret;
}
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
return ret;
}
Modified: trunk/bindings/objc/src/SwordDictionary.mm
===================================================================
--- trunk/bindings/objc/src/SwordDictionary.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordDictionary.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -40,7 +40,7 @@
if([keys count] == 0) {
NSMutableArray *arr = [NSMutableArray array];
- [moduleLock lock];
+ [self.moduleLock lock];
swModule->setSkipConsecutiveLinks(true);
*swModule = sword::TOP;
@@ -66,7 +66,7 @@
(*swModule)++;
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
self.keys = arr;
[self writeToCache];
@@ -133,14 +133,14 @@
- (NSString *)entryForKey:(NSString *)aKey {
NSString *ret = nil;
- [moduleLock lock];
+ [self.moduleLock lock];
[self setKeyString:aKey];
if([self error]) {
ALog(@"Error on setting key!");
} else {
ret = [self strippedText];
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
return ret;
}
@@ -152,13 +152,13 @@
- (id)attributeValueForParsedLinkData:(NSDictionary *)data withTextRenderType:(TextPullType)textType {
id ret = nil;
- NSString *attrType = [data objectForKey:ATTRTYPE_TYPE];
+ NSString *attrType = data[ATTRTYPE_TYPE];
if([attrType isEqualToString:@"scriptRef"] ||
[attrType isEqualToString:@"scripRef"] ||
[attrType isEqualToString:@"Greek"] ||
[attrType isEqualToString:@"Hebrew"] ||
[attrType hasPrefix:@"strongMorph"] || [attrType hasPrefix:@"robinson"]) {
- NSString *key = [data objectForKey:ATTRTYPE_VALUE];
+ NSString *key = data[ATTRTYPE_VALUE];
ret = [self strippedTextEntriesForRef:key];
}
Modified: trunk/bindings/objc/src/SwordInstallSource.mm
===================================================================
--- trunk/bindings/objc/src/SwordInstallSource.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordInstallSource.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -50,8 +50,9 @@
}
- (void)dealloc {
+ ALog(@"");
if(swInstallSource != NULL && self.deleteSwInstallSource) {
- ALog(@"Deleting swInstallSource");
+ ALog(@"Deleting InstallSource");
delete swInstallSource;
}
}
Modified: trunk/bindings/objc/src/SwordInstallSourceManager.h
===================================================================
--- trunk/bindings/objc/src/SwordInstallSourceManager.h 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordInstallSourceManager.h 2015-09-08 12:38:02 UTC (rev 3389)
@@ -40,7 +40,6 @@
// ------------------- properties -------------------
/** Dictionary of InstallSources. Key: Caption */
@property (strong, readonly) NSDictionary *installSources;
- at property (strong, readonly) NSArray *installSourceList;
@property (strong, nonatomic) NSString *ftpUser;
@property (strong, nonatomic) NSString *ftpPassword;
@property (strong, readwrite) NSString *configPath;
Modified: trunk/bindings/objc/src/SwordInstallSourceManager.mm
===================================================================
--- trunk/bindings/objc/src/SwordInstallSourceManager.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordInstallSourceManager.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -23,7 +23,6 @@
@interface SwordInstallSourceManager ()
@property (strong, readwrite) NSDictionary *installSources;
- at property (strong, readwrite) NSArray *installSourceList;
@end
@@ -50,7 +49,6 @@
[self setCreateConfigPath:NO];
[self setConfigPath:nil];
[self setInstallSources:[NSDictionary dictionary]];
- [self setInstallSourceList:[NSArray array]];
[self setFtpUser:@"ftp"];
[self setFtpPassword:@"ObjCSword at crosswire.org"];
}
@@ -76,7 +74,9 @@
}
- (void)dealloc {
+ DLog(@"");
if(swInstallMgr != nil) {
+ DLog(@"deleting InstallMgr");
delete swInstallMgr;
}
}
@@ -92,7 +92,7 @@
}
if(swInstallMgr == NULL) {
- ALog(@"Initializing swInstallMgr");
+ DLog(@"Initializing swInstallMgr");
swInstallMgr = [self newDefaultInstallMgr];
if(swInstallMgr == nil) {
ALog(@"Could not initialize InstallMgr!");
@@ -181,18 +181,15 @@
- (void)setupInstallSources {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- NSMutableArray *arr = [NSMutableArray array];
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]);
dict[[is caption]] = is;
- [arr addObject:is];
}
[self setInstallSources:dict];
- [self setInstallSourceList:arr];
}
- (NSString *)createInstallMgrConfPath {
@@ -203,10 +200,8 @@
ALog(@"Adding install source: %@", [is caption]);
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[self installSources]];
- NSMutableArray *arr = [NSMutableArray arrayWithArray:[self installSourceList]];
dict[[is caption]] = is;
- [arr addObject:is];
// modify conf file
sword::SWConfig config([[self createInstallMgrConfPath] UTF8String]);
@@ -218,16 +213,13 @@
config.Save();
[self setInstallSources:dict];
- [self setInstallSourceList:arr];
[self readInstallMgrConf];
}
- (void)removeInstallSource:(SwordInstallSource *)is {
ALog(@"Removing install source: %@", [is caption]);
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[self installSources]];
- NSMutableArray *arr = [NSMutableArray arrayWithArray:[self installSourceList]];
[dict removeObjectForKey:[is caption]];
- [arr removeObject:is];
// modify conf file
sword::SWConfig config([[self createInstallMgrConfPath] UTF8String]);
@@ -235,7 +227,7 @@
config["Sources"].erase(INSTALLSOURCE_SECTION_TYPE_FTP);
// build up new
- for(SwordInstallSource *sis in self.installSourceList) {
+ for(SwordInstallSource *sis in [self.installSources allValues]) {
if([[sis type] isEqualToString:INSTALLSOURCE_TYPE_FTP]) {
config["Sources"].insert(ConfigEntMap::value_type(INSTALLSOURCE_SECTION_TYPE_FTP, [[sis configEntry] UTF8String]));
} else {
@@ -245,11 +237,11 @@
config.Save();
[self setInstallSources:dict];
- [self setInstallSourceList:arr];
[self readInstallMgrConf];
}
- (void)updateInstallSource:(SwordInstallSource *)is {
+ ALog(@"Updating install source [remove|add]: %@", [is caption]);
// hold a ref to the is
SwordInstallSource *save = is;
// first remove, then add again
@@ -258,8 +250,8 @@
save = nil;
}
-// installation/unInstallation
- (int)installModule:(SwordModule *)aModule fromSource:(SwordInstallSource *)is withManager:(SwordManager *)manager {
+ ALog(@"Installing module: %@, from source: %@", [aModule name], [is caption]);
int stat;
if([is isLocalSource]) {
stat = swInstallMgr->installModule([manager swManager], [[is directory] UTF8String], [[aModule name] UTF8String]);
@@ -269,7 +261,13 @@
return stat;
}
+- (int)uninstallModule:(SwordModule *)aModule fromManager:(SwordManager *)swManager {
+ ALog(@"Removing module: %@", [aModule name]);
+ return swInstallMgr->removeModule([swManager swManager], [[aModule name] UTF8String]);
+}
+
- (int)refreshMasterRemoteInstallSourceList {
+ ALog(@"Refreshing remote install sources from master repo.");
int stat = swInstallMgr->refreshRemoteSourceConfiguration();
if(stat) {
ALog(@"Unable to refresh with master install source!");
@@ -280,15 +278,6 @@
return stat;
}
-/**
- uninstalls a module from a SwordManager
- */
-- (int)uninstallModule:(SwordModule *)aModule fromManager:(SwordManager *)swManager {
- int stat = swInstallMgr->removeModule([swManager swManager], [[aModule name] UTF8String]);
-
- return stat;
-}
-
// list modules in sources
- (NSArray *)listModulesForSource:(SwordInstallSource *)is {
return [is listModules];
@@ -298,8 +287,8 @@
refreshing the install source is necessary before installation of
*/
- (int)refreshInstallSource:(SwordInstallSource *)is {
+ ALog(@"Refreshing install source:%@", [is caption]);
int ret = 1;
-
if(is == nil) {
ALog(@"Install source is nil");
} else {
@@ -315,6 +304,7 @@
returns an array of Modules with status set
*/
- (NSArray *)moduleStatusInInstallSource:(SwordInstallSource *)is baseManager:(SwordManager *)baseMgr {
+ ALog(@"Retrieving module status for install source:%@", [is caption]);
// get modules map
NSMutableArray *ar = [NSMutableArray array];
std::map<sword::SWModule *, int> modStats = swInstallMgr->getModuleStatus(*[baseMgr swManager], *[[is swordManager] swManager]);
Modified: trunk/bindings/objc/src/SwordKey.mm
===================================================================
--- trunk/bindings/objc/src/SwordKey.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordKey.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -69,7 +69,6 @@
if(created) {
delete sk;
}
-
}
- (SwordKey *)clone {
Modified: trunk/bindings/objc/src/SwordManager.h
===================================================================
--- trunk/bindings/objc/src/SwordManager.h 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordManager.h 2015-09-08 12:38:02 UTC (rev 3389)
@@ -115,7 +115,6 @@
@property (strong, readonly) NSDictionary *modules;
@property (strong, readwrite) NSString *modulesPath;
@property (strong, readwrite) NSLock *managerLock;
- at property (readwrite) BOOL temporaryManager;
// --------------------- methods -----------------------
Modified: trunk/bindings/objc/src/SwordManager.mm
===================================================================
--- trunk/bindings/objc/src/SwordManager.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordManager.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -22,6 +22,7 @@
@interface SwordManager ()
@property (strong, readwrite) NSDictionary *modules;
+ at property (readwrite) BOOL deleteSWMgr;
- (void)refreshModules;
- (void)addFiltersToModule:(SwordModule *)mod;
@@ -53,13 +54,10 @@
}
- (id)initWithPath:(NSString *)path {
-
if((self = [super init])) {
- // this is our main swManager
- self.temporaryManager = NO;
-
+ ALog(@"Init with path:%@", path);
+ self.deleteSWMgr = YES;
self.modulesPath = path;
-
self.modules = [NSDictionary dictionary];
self.managerLock = (id) [[NSRecursiveLock alloc] init];
@@ -78,10 +76,9 @@
- (id)initWithSWMgr:(sword::SWMgr *)aSWMgr {
self = [super init];
if(self) {
+ ALog(@"Init with temporary SWMgr");
swManager = aSWMgr;
- // this is a temporary swManager
- self.temporaryManager = YES;
-
+ self.deleteSWMgr = NO;
self.modules = [NSDictionary dictionary];
self.managerLock = (id) [[NSRecursiveLock alloc] init];
@@ -93,13 +90,15 @@
- (void)dealloc {
- if(!self.temporaryManager) {
+ DLog(@"");
+ if(!self.deleteSWMgr) {
ALog(@"Deleting SWMgr!");
delete swManager;
}
}
- (void)reInit {
+ DLog(@"");
[self.managerLock lock];
if(self.modulesPath && [self.modulesPath length] > 0) {
@@ -139,10 +138,7 @@
}
}
- // clear some data
[self refreshModules];
-
- SendNotifyModulesChanged(NULL);
}
}
[self.managerLock unlock];
@@ -165,14 +161,12 @@
[self refreshModules];
[self.managerLock unlock];
-
- SendNotifyModulesChanged(NULL);
}
- (void)refreshModules {
+ DLog(@"");
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- // loop over modules
sword::SWModule *mod;
for(sword::ModMap::iterator it = swManager->Modules.begin(); it != swManager->Modules.end(); it++) {
mod = it->second;
@@ -190,7 +184,7 @@
}
}
- // set modules
+ SendNotifyModulesChanged(NULL);
self.modules = dict;
}
@@ -343,7 +337,6 @@
}
}
- // sort
NSArray *sortDescriptors = @[[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]];
[ret sortUsingDescriptors:sortDescriptors];
Modified: trunk/bindings/objc/src/SwordModule.h
===================================================================
--- trunk/bindings/objc/src/SwordModule.h 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordModule.h 2015-09-08 12:38:02 UTC (rev 3389)
@@ -30,8 +30,7 @@
#define SWPOS_TOP 1
- at class SwordManager, SwordModuleTextEntry, SwordKey;
- at class SwordFilter;
+ at class SwordManager, SwordModuleTextEntry, SwordKey, SwordFilter;
typedef enum {
TextTypeStripped = 1,
@@ -65,21 +64,8 @@
@interface SwordModule : NSObject {
- NSMutableDictionary *configEntries;
- ModuleType type;
ModuleCategory category;
- int status;
- SwordManager *swManager;
- NSRecursiveLock *moduleLock;
- NSLock *indexLock;
-
- /** we store the name separately */
- NSString *typeString;
- NSString *name;
- NSString *descr;
- NSString *lang;
-
/** yes, we have a delegate to report any action to */
id delegate;
@@ -91,16 +77,11 @@
// ------------- properties ---------------
@property (readwrite) ModuleType type;
@property (readwrite) int status;
- at property (strong, readwrite) NSRecursiveLock *moduleLock;
- at property (strong, readwrite) NSLock *indexLock;
@property (strong, readwrite) SwordManager *swManager;
+ at property (strong, readwrite) NSLock *indexLock;
+ at property (strong, readwrite) NSRecursiveLock *moduleLock;
+ at property (strong, readwrite) NSMutableDictionary *configEntries;
-// swmodule properties
- at property (strong, readonly) NSString *name;
- at property (strong, readonly) NSString *typeString;
- at property (strong, readonly) NSString *descr;
- at property (strong, readonly) NSString *lang;
-
#ifdef __cplusplus
/**
@@ -166,8 +147,16 @@
*/
- (NSInteger)error;
-// --------------- Conf entries --------------
+/** module name */
+- (NSString *)name;
+/** module description */
+- (NSString *)descr;
+/** module language */
+- (NSString *)lang;
+/** module type string */
+- (NSString *)typeString;
+// --------------- Conf entries --------------
/**
Module category as string
*/
Modified: trunk/bindings/objc/src/SwordModule.mm
===================================================================
--- trunk/bindings/objc/src/SwordModule.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordModule.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -21,30 +21,10 @@
@interface SwordModule ()
- at property (strong, readwrite) NSString *name;
- at property (strong, readwrite) NSString *typeString;
- at property (strong, readwrite) NSString *descr;
- at property (strong, readwrite) NSString *lang;
- at property(readwrite, strong) NSMutableDictionary *configEntries;
-
-- (void)mainInit;
-
@end
@implementation SwordModule
- at synthesize configEntries;
- at synthesize type;
- at synthesize status;
- at synthesize moduleLock;
- at synthesize indexLock;
- at synthesize swManager;
- at synthesize name;
- at synthesize typeString;
- at synthesize descr;
- at synthesize lang;
-
-
+ (id)moduleForSWModule:(sword::SWModule *)aModule {
return [[SwordModule alloc] initWithSWModule:aModule];
}
@@ -120,12 +100,8 @@
- (void)mainInit {
category = Unset;
- self.name = [self retrieveName];
- self.typeString = [self retrieveType];
- self.descr = [self retrieveDescr];
- self.lang = [self retrieveLang];
- self.type = [SwordModule moduleTypeForModuleTypeString:self.typeString];
+ self.type = [SwordModule moduleTypeForModuleTypeString:[self typeString]];
self.moduleLock = [[NSRecursiveLock alloc] init];
self.indexLock = [[NSLock alloc] init];
self.configEntries = [NSMutableDictionary dictionary];
@@ -159,8 +135,10 @@
return self;
}
+- (void)dealloc {
+// ALog(@"");
+}
-
#pragma mark - Filters
- (void)addRenderFilter:(SwordFilter *)aFilter {
@@ -174,24 +152,14 @@
#pragma mark - Module access semaphores
- (void)lockModuleAccess {
- [moduleLock lock];
+ [self.moduleLock lock];
}
- (void)unlockModuleAccess {
- [moduleLock unlock];
+ [self.moduleLock unlock];
}
-#pragma mark - Conf entries
-
-- (NSAttributedString *)fullAboutText {
- return [[NSAttributedString alloc] initWithString:@""];
-}
-
-- (NSInteger)error {
- return swModule->popError();
-}
-
-- (NSString *)retrieveName {
+- (NSString *)name {
NSString *str = [NSString stringWithCString:swModule->getName() encoding:NSUTF8StringEncoding];
if(!str) {
str = [NSString stringWithCString:swModule->getName() encoding:NSISOLatin1StringEncoding];
@@ -199,7 +167,7 @@
return str;
}
-- (NSString *)retrieveDescr {
+- (NSString *)descr {
NSString *str = [NSString stringWithCString:swModule->getDescription() encoding:NSUTF8StringEncoding];
if(!str) {
str = [NSString stringWithCString:swModule->getDescription() encoding:NSISOLatin1StringEncoding];
@@ -207,7 +175,7 @@
return str;
}
-- (NSString *)retrieveLang {
+- (NSString *)lang {
NSString *str = [NSString stringWithCString:swModule->getLanguage() encoding:NSUTF8StringEncoding];
if(!str) {
str = [NSString stringWithCString:swModule->getLanguage() encoding:NSISOLatin1StringEncoding];
@@ -215,7 +183,7 @@
return str;
}
-- (NSString *)retrieveType {
+- (NSString *)typeString {
NSString *str = [NSString stringWithCString:swModule->getType() encoding:NSUTF8StringEncoding];
if(!str) {
str = [NSString stringWithCString:swModule->getType() encoding:NSISOLatin1StringEncoding];
@@ -223,12 +191,22 @@
return str;
}
+- (NSAttributedString *)fullAboutText {
+ return [[NSAttributedString alloc] initWithString:@""];
+}
+
+- (NSInteger)error {
+ return swModule->popError();
+}
+
+#pragma mark - Conf entries
+
- (NSString *)categoryString {
- NSString *cat = configEntries[SWMOD_CONFENTRY_CATEGORY];
+ NSString *cat = self.configEntries[SWMOD_CONFENTRY_CATEGORY];
if(cat == nil) {
cat = [self configFileEntryForConfigKey:SWMOD_CONFENTRY_CATEGORY];
if(cat != nil) {
- configEntries[SWMOD_CONFENTRY_CATEGORY] = cat;
+ self.configEntries[SWMOD_CONFENTRY_CATEGORY] = cat;
}
}
@@ -243,11 +221,11 @@
}
- (NSString *)cipherKey {
- NSString *cipherKey = configEntries[SWMOD_CONFENTRY_CIPHERKEY];
+ NSString *cipherKey = self.configEntries[SWMOD_CONFENTRY_CIPHERKEY];
if(cipherKey == nil) {
cipherKey = [self configFileEntryForConfigKey:SWMOD_CONFENTRY_CIPHERKEY];
if(cipherKey != nil) {
- configEntries[SWMOD_CONFENTRY_CIPHERKEY] = cipherKey;
+ self.configEntries[SWMOD_CONFENTRY_CIPHERKEY] = cipherKey;
}
}
@@ -255,11 +233,11 @@
}
- (NSString *)version {
- NSString *version = configEntries[SWMOD_CONFENTRY_VERSION];
+ NSString *version = self.configEntries[SWMOD_CONFENTRY_VERSION];
if(version == nil) {
version = [self configFileEntryForConfigKey:SWMOD_CONFENTRY_VERSION];
if(version != nil) {
- configEntries[SWMOD_CONFENTRY_VERSION] = version;
+ self.configEntries[SWMOD_CONFENTRY_VERSION] = version;
}
}
@@ -267,11 +245,11 @@
}
- (NSString *)minVersion {
- NSString *minVersion = configEntries[SWMOD_CONFENTRY_MINVERSION];
+ NSString *minVersion = self.configEntries[SWMOD_CONFENTRY_MINVERSION];
if(minVersion == nil) {
minVersion = [self configFileEntryForConfigKey:SWMOD_CONFENTRY_MINVERSION];
if(minVersion != nil) {
- configEntries[SWMOD_CONFENTRY_MINVERSION] = minVersion;
+ self.configEntries[SWMOD_CONFENTRY_MINVERSION] = minVersion;
}
}
@@ -280,7 +258,7 @@
/** this might be RTF string but the return value will be converted to UTF8 */
- (NSString *)aboutText {
- NSMutableString *aboutText = configEntries[SWMOD_CONFENTRY_ABOUT];
+ NSMutableString *aboutText = self.configEntries[SWMOD_CONFENTRY_ABOUT];
if(aboutText == nil) {
aboutText = [NSMutableString stringWithString:[self configFileEntryForConfigKey:SWMOD_CONFENTRY_ABOUT]];
if(aboutText != nil) {
@@ -336,7 +314,7 @@
} else {
aboutText = [NSMutableString string];
}
- configEntries[SWMOD_CONFENTRY_ABOUT] = aboutText;
+ self.configEntries[SWMOD_CONFENTRY_ABOUT] = aboutText;
}
return aboutText;
@@ -349,11 +327,11 @@
- (BOOL)isEditable {
BOOL ret = NO;
- NSString *editable = configEntries[SWMOD_CONFENTRY_EDITABLE];
+ NSString *editable = self.configEntries[SWMOD_CONFENTRY_EDITABLE];
if(editable == nil) {
editable = [self configFileEntryForConfigKey:SWMOD_CONFENTRY_EDITABLE];
if(editable != nil) {
- configEntries[SWMOD_CONFENTRY_EDITABLE] = editable;
+ self.configEntries[SWMOD_CONFENTRY_EDITABLE] = editable;
}
}
@@ -368,11 +346,11 @@
- (BOOL)isRTL {
BOOL ret = NO;
- NSString *direction = configEntries[SWMOD_CONFENTRY_DIRECTION];
+ NSString *direction = self.configEntries[SWMOD_CONFENTRY_DIRECTION];
if(direction == nil) {
direction = [self configFileEntryForConfigKey:SWMOD_CONFENTRY_DIRECTION];
if(direction != nil) {
- configEntries[SWMOD_CONFENTRY_DIRECTION] = direction;
+ self.configEntries[SWMOD_CONFENTRY_DIRECTION] = direction;
}
}
@@ -437,7 +415,7 @@
- (NSString *)configFileEntryForConfigKey:(NSString *)entryKey {
NSString *result = nil;
- [moduleLock lock];
+ [self.moduleLock lock];
const char *entryStr = swModule->getConfigEntry([entryKey UTF8String]);
if(entryStr) {
result = [NSString stringWithUTF8String:entryStr];
@@ -445,7 +423,7 @@
result = [NSString stringWithCString:entryStr encoding:NSISOLatin1StringEncoding];
}
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
return result;
}
@@ -463,7 +441,7 @@
cipherKeys[[self name]] = unlockKey;
[[NSUserDefaults standardUserDefaults] setObject:cipherKeys forKey:DefaultsModuleCipherKeysKey];
- [swManager setCipherKey:unlockKey forModuleNamed:[self name]];
+ [self.swManager setCipherKey:unlockKey forModuleNamed:[self name]];
return YES;
}
@@ -595,20 +573,20 @@
}
- (NSString *)entryAttributeValuePreverseForKey:(SwordKey *)aKey {
- [moduleLock lock];
+ [self.moduleLock lock];
[self setSwordKey:aKey];
swModule->renderText(); // force processing of key
NSString *value = [self entryAttributeValuePreverse];
- [moduleLock unlock];
+ [self.moduleLock unlock];
return value;
}
- (NSString *)entryAttributeValueFootnoteOfType:(NSString *)fnType indexValue:(NSString *)index forKey:(SwordKey *)aKey {
- [moduleLock lock];
+ [self.moduleLock lock];
[self setSwordKey:aKey];
swModule->renderText(); // force processing of key
NSString *value = [self entryAttributeValueFootnoteOfType:fnType indexValue:index];
- [moduleLock unlock];
+ [self.moduleLock unlock];
return value;
}
@@ -667,7 +645,7 @@
SwordModuleTextEntry *ret = nil;
if(aKey) {
- [moduleLock lock];
+ [self.moduleLock lock];
[self setSwordKey:aKey];
if(![self error]) {
NSString *txt = @"";
@@ -683,7 +661,7 @@
ALog(@"Nil key");
}
}
- [moduleLock unlock];
+ [self.moduleLock unlock];
}
return ret;
Modified: trunk/bindings/objc/src/SwordVerseKey.h
===================================================================
--- trunk/bindings/objc/src/SwordVerseKey.h 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordVerseKey.h 2015-09-08 12:38:02 UTC (rev 3389)
@@ -33,7 +33,7 @@
- (SwordVerseKey *)initWithRef:(NSString *)aRef;
- (SwordVerseKey *)initWithRef:(NSString *)aRef v11n:(NSString *)scheme;
-- (int)index;
+- (long)index;
- (int)testament;
- (void)setTestament:(char)val;
- (int)book;
Modified: trunk/bindings/objc/src/SwordVerseKey.mm
===================================================================
--- trunk/bindings/objc/src/SwordVerseKey.mm 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/src/SwordVerseKey.mm 2015-09-08 12:38:02 UTC (rev 3389)
@@ -67,7 +67,7 @@
if(scheme) {
[self setVersification:scheme];
}
-
+
if(aRef) {
[self setKeyText:aRef];
}
@@ -82,7 +82,7 @@
return [SwordVerseKey verseKeyWithSWVerseKey:(sword::VerseKey *)sk];
}
-- (int)index {
+- (long)index {
return ((sword::VerseKey *)sk)->getIndex();
}
Modified: trunk/bindings/objc/test/SwordInstallSourceManagerTest.m
===================================================================
--- trunk/bindings/objc/test/SwordInstallSourceManagerTest.m 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/test/SwordInstallSourceManagerTest.m 2015-09-08 12:38:02 UTC (rev 3389)
@@ -138,15 +138,34 @@
[mgr initManager];
XCTAssertTrue([[mgr installSources] count] == 1, @"");
- XCTAssertTrue([[mgr installSourceList] count] == 1, @"");
+ XCTAssertTrue([[[[[mgr installSources] allValues] firstObject] caption] isEqualToString:@"CrossWire"], @"");
+ XCTAssertTrue([[[[[mgr installSources] allValues] firstObject] source] isEqualToString:@"ftp.crosswire.org"], @"");
+ XCTAssertTrue([[[[[mgr installSources] allValues] firstObject] directory] isEqualToString:@"/pub/sword/raw"], @"");
+}
- XCTAssertEqual([[mgr installSourceList] firstObject], [mgr installSources][@"CrossWire"]);
+- (void)testDisclaimerNotApproved {
+ SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
+ [mgr initManager];
- 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"], @"");
+ XCTAssertTrue([[mgr installSources] count] == 1, @"");
+
+ NSInteger stat = [mgr refreshInstallSource:[[mgr installSources] allValues][0]];
+ NSLog(@"stat: %li", stat);
+ XCTAssertTrue(stat == -1);
}
+- (void)testRefreshInstallSource {
+ SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
+ [mgr initManager];
+
+ XCTAssertTrue([[mgr installSources] count] == 1, @"");
+
+ [mgr setUserDisclaimerConfirmed:YES];
+ NSInteger stat = [mgr refreshInstallSource:[[mgr installSources] allValues][0]];
+ NSLog(@"stat: %li", stat);
+ XCTAssertTrue(stat == 0);
+}
+
- (void)testAddInstallSource {
SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
[mgr initManager];
@@ -159,7 +178,6 @@
[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"], @"");
@@ -179,7 +197,6 @@
[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"], @"");
@@ -189,9 +206,35 @@
[mgr removeInstallSource:is];
XCTAssertTrue([[mgr installSources] count] == 1, @"");
- XCTAssertTrue([[mgr installSourceList] count] == 1, @"");
}
+- (void)testUpdateInstallSource {
+ 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 installSources][@"test"] caption] isEqualToString:@"test"], @"");
+ XCTAssertTrue([[[mgr installSources][@"test"] source] isEqualToString:@"foo.bar.local"], @"");
+ XCTAssertTrue([[[mgr installSources][@"test"] directory] isEqualToString:@"/foobar"], @"");
+
+ SwordInstallSource *update = [mgr installSources][@"test"];
+ [update setSource:@"local.bar.foo"];
+
+ [mgr updateInstallSource:update];
+
+ XCTAssertTrue([[mgr installSources] count] == 2, @"");
+ XCTAssertTrue([[[mgr installSources][@"test"] caption] isEqualToString:@"test"], @"");
+ XCTAssertTrue([[[mgr installSources][@"test"] source] isEqualToString:@"local.bar.foo"], @"");
+ XCTAssertTrue([[[mgr installSources][@"test"] directory] isEqualToString:@"/foobar"], @"");
+}
+
- (void)testUseAsDefaultManager {
SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES];
[mgr useAsDefaultManager];
Modified: trunk/bindings/objc/test/SwordModuleTest.m
===================================================================
--- trunk/bindings/objc/test/SwordModuleTest.m 2015-09-03 16:13:36 UTC (rev 3388)
+++ trunk/bindings/objc/test/SwordModuleTest.m 2015-09-08 12:38:02 UTC (rev 3389)
@@ -30,7 +30,7 @@
}
- (void)testModuleIntroduction {
- SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"];
+ SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"];
NSString *modIntro = [bible moduleIntroduction];
NSLog(@"mod intro: %@", modIntro);
@@ -38,6 +38,7 @@
XCTAssertEqual(@"Im Anfang schuf Gott Himmel und Erde.", modIntro);
}
+/*
- (void)testFirstBookATIntro {
SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"];
@@ -47,6 +48,7 @@
XCTAssertNotNil(intro);
XCTAssertTrue([intro hasPrefix:@" <!P><br />Das erste Buch der Bibel wird auch Genesis"]);
}
+*/
- (void)testFirstBookATIntroGer {
SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"];
@@ -58,6 +60,7 @@
XCTAssertTrue([intro hasPrefix:@" <!P><br />Das erste Buch der Bibel wird auch Genesis"]);
}
+/*
- (void)testFirstBookNTIntro {
SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"];
@@ -67,6 +70,7 @@
XCTAssertNotNil(intro);
XCTAssertTrue([intro hasPrefix:@" <!P><br />Um die Zeit der Apostelversammlung herum"]);
}
+*/
- (void)testFirstBookNTIntroGer {
SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"];
@@ -96,7 +100,7 @@
SwordBibleTextEntry *text = (SwordBibleTextEntry *) [bible textEntryForKeyString:@"Numbers 4:21" textType:TextTypeRendered];
NSLog(@"Preverse text: %@", [text preVerseHeading]);
XCTAssertTrue([[text preVerseHeading] length] > 0);
- XCTAssertTrue([[text preVerseHeading] isEqualToString:@"<title>Die Sonderstellung der Leviten</title>"]);
+ XCTAssertTrue([[text preVerseHeading] isEqualToString:@"<title>Die Gerschoniten</title>"]);
[mgr setGlobalOption:SW_OPTION_HEADINGS value:SW_OFF];
}
@@ -223,7 +227,7 @@
}
}
-- (void)testStrippedTextForRef {
+- (void)testVersePositioning {
SwordVerseKey *vk = [SwordVerseKey verseKeyWithRef:@"1Mo 1:2"];
NSLog(@"start position: %@", [vk keyText]);
[vk decrement];
More information about the sword-cvs
mailing list