diff options
Diffstat (limited to 'bindings/objc/test')
-rw-r--r-- | bindings/objc/test/SwordBibleTest.swift | 28 | ||||
-rw-r--r-- | bindings/objc/test/SwordInstallSourceManagerTest.m | 253 | ||||
-rw-r--r-- | bindings/objc/test/SwordListKeyTest.h | 4 | ||||
-rw-r--r-- | bindings/objc/test/SwordListKeyTest.m | 24 | ||||
-rw-r--r-- | bindings/objc/test/SwordLocaleManagerTest.swift | 30 | ||||
-rw-r--r-- | bindings/objc/test/SwordManagerTest.h | 16 | ||||
-rw-r--r-- | bindings/objc/test/SwordManagerTest.m | 84 | ||||
-rw-r--r-- | bindings/objc/test/SwordManagerTest.swift | 67 | ||||
-rw-r--r-- | bindings/objc/test/SwordModuleLongRunTest.h | 4 | ||||
-rw-r--r-- | bindings/objc/test/SwordModuleLongRunTest.mm | 29 | ||||
-rw-r--r-- | bindings/objc/test/SwordModuleTest.h | 11 | ||||
-rw-r--r-- | bindings/objc/test/SwordModuleTest.m | 200 | ||||
-rw-r--r-- | bindings/objc/test/TestGlobals.h | 12 | ||||
-rw-r--r-- | bindings/objc/test/Tests-Bridging-Header.h | 6 | ||||
-rw-r--r-- | bindings/objc/test/Tests-Info.plist | 2 |
15 files changed, 670 insertions, 100 deletions
diff --git a/bindings/objc/test/SwordBibleTest.swift b/bindings/objc/test/SwordBibleTest.swift new file mode 100644 index 0000000..e5af36b --- /dev/null +++ b/bindings/objc/test/SwordBibleTest.swift @@ -0,0 +1,28 @@ +// +// SwordBibleTest.swift +// ObjCSword +// +// Created by Manfred Bergmann on 04.10.14. +// +// + +import Foundation +import XCTest + +class SwordBibleTest: XCTestCase { + + var mgr: SwordManager? + + override func setUp() { + super.setUp() + + Configuration.config(withImpl: OSXConfiguration()) + FilterProviderFactory().initWithImpl(DefaultFilterProvider()) + mgr = SwordManager(path:Configuration.config().defaultModulePath()) + } + + func testGetBible() { + let bibleMod = mgr?.module(withName: "GerNeUe") + XCTAssertNotNil(bibleMod); + } +} diff --git a/bindings/objc/test/SwordInstallSourceManagerTest.m b/bindings/objc/test/SwordInstallSourceManagerTest.m new file mode 100644 index 0000000..81f0fb2 --- /dev/null +++ b/bindings/objc/test/SwordInstallSourceManagerTest.m @@ -0,0 +1,253 @@ +// +// SwordInstallSourceManagerTest.m +// ObjCSword +// +// Created by Manfred Bergmann on 12.04.15. +// +// + +#import <XCTest/XCTest.h> +#import "SwordInstallSourceManager.h" +#import "SwordInstallSource.h" +#import "SwordManager.h" +#import "TestGlobals.h" + +@interface SwordInstallSourceManagerTest : XCTestCase + +@end + +@implementation SwordInstallSourceManagerTest + +NSString *testConfigPath = @"/tmp/testmodinst"; +NSString *testModuleManagerPath = @"/tmp/testmodmgr"; +NSString *localInstallSourcePath = @"/Users/mbergmann/Development/MySources/crosswire/Eloquent_MacOS/trunk/sword_src/sword-trunk/bindings/objc/LocalTestInstallSource"; + +- (void)setUp { + NSFileManager *fm = [NSFileManager defaultManager]; + [fm removeItemAtPath:testConfigPath error:NULL]; + [fm removeItemAtPath:testModuleManagerPath error:NULL]; + + [super setUp]; +} + +- (void)tearDown { + [super tearDown]; +} + +- (void)testObjectCreate { + SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:@"" createPath:YES]; + XCTAssertTrue(mgr != nil, @""); +} + +- (void)testLocalInstallSource { + SwordInstallSource *is = [[SwordInstallSource alloc] init]; + [is setSource:@"localhost"]; + [is setDirectory:localInstallSourcePath]; + [is setCaption:@"LocalTest"]; + + SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES]; + [mgr initManager]; + [mgr addInstallSource:is reload:YES]; + + NSDictionary *mods = [mgr listModulesForSource:is]; + XCTAssertTrue([mods count] == 1); + XCTAssertTrue([[((SwordModule *) [mods allValues][0]) name] isEqualToString:@"KJV"]); +} + +- (void)testLocalInstallSourceStatusNew { + SwordInstallSource *is = [[SwordInstallSource alloc] init]; + [is setSource:@"localhost"]; + [is setDirectory:localInstallSourcePath]; + [is setCaption:@"LocalTest"]; + + SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES]; + [mgr initManager]; + [mgr addInstallSource:is reload:YES]; + + SwordManager *swMgr = [SwordManager managerWithPath:testModuleManagerPath]; + NSArray *stats = [mgr moduleStatusInInstallSource:is baseManager:swMgr]; + for(SwordModule *mod in stats) { + NSLog(@"mod.name=%@", [mod name]); + NSLog(@"mod.stat=%i", [mod status]); + } + + XCTAssertTrue([((SwordModule *) stats[0]).name isEqualToString:@"KJV"]); + XCTAssertTrue(((SwordModule *) stats[0]).status == ModStatNew); +} + +- (void)testLocalInstallSourceStatusSame { + SwordInstallSource *is = [[SwordInstallSource alloc] init]; + [is setSource:@"localhost"]; + [is setDirectory:localInstallSourcePath]; + [is setCaption:@"LocalTest"]; + + SwordManager *swMgr = [SwordManager managerWithPath:testModuleManagerPath]; + SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES]; + [mgr initManager]; + [mgr addInstallSource:is reload:YES]; + + [mgr installModule:[[mgr listModulesForSource:is] allValues][0] fromSource:is withManager:swMgr]; + + [swMgr reloadManager]; + NSArray *stats = [mgr moduleStatusInInstallSource:is baseManager:swMgr]; + for(SwordModule *mod in stats) { + NSLog(@"mod.name=%@", [mod name]); + NSLog(@"mod.stat=%i", [mod status]); + } + + XCTAssertTrue([((SwordModule *) stats[0]).name isEqualToString:@"KJV"]); + XCTAssertTrue(((SwordModule *) stats[0]).status == ModStatSameVersion); +} + +- (void)testInstallModuleFromLocalSource { + SwordInstallSource *is = [[SwordInstallSource alloc] init]; + [is setSource:@"localhost"]; + [is setDirectory:localInstallSourcePath]; + [is setCaption:@"LocalTest"]; + + SwordManager *swMgr = [SwordManager managerWithPath:testModuleManagerPath]; + SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES]; + [mgr initManager]; + [mgr addInstallSource:is reload:YES]; + + int stat = [mgr installModule:[[mgr listModulesForSource:is] allValues][0] fromSource:is withManager:swMgr]; + XCTAssertTrue(stat == 0); +} + +- (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 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"], @""); +} + +- (void)testDisclaimerNotApproved { + SwordInstallSourceManager *mgr = [[SwordInstallSourceManager alloc] initWithPath:testConfigPath createPath:YES]; + [mgr initManager]; + + 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]; + + SwordInstallSource *is = [[SwordInstallSource alloc] initWithType:INSTALLSOURCE_TYPE_FTP]; + [is setCaption:@"test"]; + [is setSource:@"foo.bar.local"]; + [is setDirectory:@"/foobar"]; + + [mgr addInstallSource:is reload:YES]; + + 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"], @""); +} + +- (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 reload:YES]; + + 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"], @""); + + // then remove + [mgr removeInstallSource:is reload:YES]; + + XCTAssertTrue([[mgr installSources] count] == 1, @""); + is = [[[mgr installSources] allValues] firstObject]; + NSLog(@"IS caption: %@", [is caption]); + XCTAssertTrue([[is caption] isEqualToString:@"CrossWire"], @""); +} + +- (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 reload:YES]; + + 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]; + + SwordInstallSourceManager *mgr2 = [SwordInstallSourceManager defaultManager]; + XCTAssertEqual(mgr, mgr2); +} + +- (void)testExample { + XCTAssert(YES, @"Pass"); +} + +@end diff --git a/bindings/objc/test/SwordListKeyTest.h b/bindings/objc/test/SwordListKeyTest.h index 4d4ff43..fea4ab6 100644 --- a/bindings/objc/test/SwordListKeyTest.h +++ b/bindings/objc/test/SwordListKeyTest.h @@ -6,9 +6,9 @@ // Copyright 2009 __MyCompanyName__. All rights reserved. // -#import <SenTestingKit/SenTestingKit.h> +#import <XCTest/XCTest.h> -@interface SwordListKeyTest : SenTestCase { +@interface SwordListKeyTest : XCTestCase { } @end diff --git a/bindings/objc/test/SwordListKeyTest.m b/bindings/objc/test/SwordListKeyTest.m index 73d47dc..7b3181c 100644 --- a/bindings/objc/test/SwordListKeyTest.m +++ b/bindings/objc/test/SwordListKeyTest.m @@ -12,32 +12,32 @@ @implementation SwordListKeyTest - (void)testContainsKey { - SwordListKey *lk = [SwordListKey listKeyWithRef:@"Gen 1:1-5"]; + SwordListKey *lk = [SwordListKey listKeyWithRef:@"Gen 1:1-5" v11n:@"KJV"]; SwordVerseKey *vk = [SwordVerseKey verseKeyWithRef:@"Gen 1:3"]; - STAssertTrue([lk containsKey:vk], @""); + XCTAssertTrue([lk containsKey:vk], @""); } /* - (void)testNumberOfVerses { - SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:2-20"]; - STAssertNotNil(lk, @""); - STAssertTrue(([lk numberOfVerses] == 19), @""); + SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:2-20" v11n:@"KJV"]; + XCTAssertNotNil(lk, @""); + XCTAssertTrue(([lk numberOfVerses] == 19), @""); } */ - (void)testVerseEnumeratorAllObjects { - SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:2-20"]; - STAssertNotNil(lk, @""); + SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:2-20" v11n:@"KJV"]; + XCTAssertNotNil(lk, @""); VerseEnumerator *ve = [lk verseEnumerator]; NSArray *verseRefs = [ve allObjects]; - STAssertNotNil(verseRefs, @""); - STAssertTrue(([verseRefs count] == 19), @""); + XCTAssertNotNil(verseRefs, @""); + XCTAssertTrue(([verseRefs count] == 19), @""); } - (void)testVerseEnumeratorNextObject { - SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:2-20"]; - STAssertNotNil(lk, @""); + SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:2-20" v11n:@"KJV"]; + XCTAssertNotNil(lk, @""); VerseEnumerator *ve = [lk verseEnumerator]; int count = 0; @@ -45,7 +45,7 @@ while((ref = [ve nextObject])) { count++; } - STAssertTrue((count == 19), @""); + XCTAssertTrue((count == 19), @""); } @end diff --git a/bindings/objc/test/SwordLocaleManagerTest.swift b/bindings/objc/test/SwordLocaleManagerTest.swift new file mode 100644 index 0000000..7360af3 --- /dev/null +++ b/bindings/objc/test/SwordLocaleManagerTest.swift @@ -0,0 +1,30 @@ +// +// SwordLocaleManagerTest.swift +// ObjCSword +// +// Created by Manfred Bergmann on 02.10.16. +// +// + +import XCTest + +class SwordLocaleManagerTest: XCTestCase { + + override func setUp() { + super.setUp() + } + + override func tearDown() { + super.tearDown() + } + + func testDefaultLocalSetup() { + let locMgr = SwordLocaleManager.default() + locMgr?.initLocale() + + let defaultLocName = locMgr?.getDefaultLocaleName() + print(defaultLocName) + XCTAssert(defaultLocName != nil) + XCTAssert(defaultLocName == "de") + } +} diff --git a/bindings/objc/test/SwordManagerTest.h b/bindings/objc/test/SwordManagerTest.h deleted file mode 100644 index 167d335..0000000 --- a/bindings/objc/test/SwordManagerTest.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// SwordManagerTest.h -// ObjCSword -// -// Created by Manfred Bergmann on 14.06.10. -// Copyright 2010 Software by MABE. All rights reserved. -// - -#import <SenTestingKit/SenTestingKit.h> - - -@interface SwordManagerTest : SenTestCase { - -} - -@end diff --git a/bindings/objc/test/SwordManagerTest.m b/bindings/objc/test/SwordManagerTest.m index d2c93dd..5b48c3e 100644 --- a/bindings/objc/test/SwordManagerTest.m +++ b/bindings/objc/test/SwordManagerTest.m @@ -2,25 +2,89 @@ // SwordManagerTest.m // ObjCSword // -// Created by Manfred Bergmann on 14.06.10. -// Copyright 2010 Software by MABE. All rights reserved. +// Created by Manfred Bergmann on 02.03.16. +// // +#import <XCTest/XCTest.h> #import <ObjCSword/ObjCSword.h> -#import "SwordManagerTest.h" -@implementation SwordManagerTest +@interface SwordManagerTest : XCTestCase + +@end + +@implementation SwordManagerTest { + SwordManager *mgr; +} - (void)setUp { - [Configuration configWithImpl:[[[OSXConfiguration alloc] init] autorelease]]; + [super setUp]; + + [Configuration configWithImpl:[[OSXConfiguration alloc] init]]; + [[FilterProviderFactory providerFactory] initWithImpl:[[DefaultFilterProvider alloc] init]]; + + NSString *modulePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"TestModules"]; + + mgr = [SwordManager managerWithPath:modulePath]; +} + +- (void)testAvailableModules { + XCTAssert(mgr != nil); + + NSInteger count = [[mgr allModules] count]; + XCTAssert(count > 0); + NSLog(@"Modules: %lu", count); } -- (void)testSwordManagerInit { - NSString *modPath = [[Configuration config] defaultModulePath]; - NSLog(@"%@", modPath); +- (void)testGetModule { + SwordModule *mod = [mgr moduleWithName:@"KJV"]; + XCTAssert(mod != nil); + XCTAssert([[mod name] isEqualToString:@"KJV"]); +} + +- (void)testReloadWithRenderedKey_String { + SwordModule *mod = [mgr moduleWithName:@"KJV"]; + + [mod setKeyString:@"Gen 1:1"]; + NSString *text = [mod renderedText]; + XCTAssert(text != nil); + XCTAssert(text.length > 0); + NSLog(@"text: %@", text); + + [mgr reloadManager]; + mod = [mgr moduleWithName:@"KJV"]; + XCTAssert(mod != nil); + XCTAssert([[mod name] isEqualToString:@"KJV"]); +} + +- (void)testReloadWithRenderedKey_SwordKey { + SwordModule *mod = [mgr moduleWithName:@"KJV"]; + + SwordKey *key = [SwordKey swordKeyWithRef:@"Gen 1"]; + [mod setSwordKey:key]; + NSString *text = [mod renderedText]; + XCTAssert(text != nil); + XCTAssert(text.length > 0); + NSLog(@"text: %@", text); + + [mgr reloadManager]; + mod = [mgr moduleWithName:@"KJV"]; + XCTAssert(mod != nil); + XCTAssert([[mod name] isEqualToString:@"KJV"]); +} + +- (void)testReloadWithRenderedKey_CustomRender { + SwordModule *mod = [mgr moduleWithName:@"KJV"]; + + NSArray *textEntries = [(SwordBible *)mod renderedTextEntriesForRef:@"Gen 1" context:0]; + XCTAssert(textEntries != nil); + NSLog(@"Entries: %lu", [textEntries count]); + XCTAssert([textEntries count] == 31); - SwordManager *sm = [SwordManager managerWithPath:modPath]; - STAssertTrue([[sm modules] count] > 0, @""); + [mgr reloadManager]; + mod = [mgr moduleWithName:@"KJV"]; + XCTAssert(mod != nil); + XCTAssert([[mod name] isEqualToString:@"KJV"]); } @end diff --git a/bindings/objc/test/SwordManagerTest.swift b/bindings/objc/test/SwordManagerTest.swift new file mode 100644 index 0000000..8500eae --- /dev/null +++ b/bindings/objc/test/SwordManagerTest.swift @@ -0,0 +1,67 @@ +// +// SwordManagerTest.swift +// ObjCSword +// +// Created by Manfred Bergmann on 02.03.16. +// +// + +import XCTest + +class SwordManagerTest: XCTestCase { + + var mgr: SwordManager? + + override func setUp() { + super.setUp() + + let modulesDir = NSBundle(forClass:self.dynamicType).resourcePath!.stringByAppendingString("/TestModules") + NSLog("modulesDir: \(modulesDir)") + + Configuration.configWithImpl(OSXConfiguration()) + FilterProviderFactory().initWithImpl(DefaultFilterProvider()) + mgr = SwordManager(path:modulesDir) + } + + func testAvailableModules() { + XCTAssert(mgr != nil) + XCTAssert(mgr?.modules.count > 0) + NSLog("modules: \(mgr?.modules.count)") + } + + func testGetModule() { + let mod = mgr?.moduleWithName("kjv") + XCTAssert(mod != nil) + XCTAssert(mod?.name() == "KJV") + } + + func testReload() { + var mod = mgr?.moduleWithName("kjv") + + mgr?.reloadManager() + mod = mgr?.moduleWithName("kjv") + + XCTAssert(mod != nil) + XCTAssert(mod?.name() == "KJV") + } + + func testReloadWithKeyString() { + var mod = mgr?.moduleWithName("kjv") + + let te = mod?.renderedTextEntriesForRef("Gen 1") + XCTAssert(te?.count > 0) + NSLog(te![0] as! String) + +// mod?.setKeyString("Gen 1") +// let text = mod?.renderedText() +// XCTAssert(text != nil) +// XCTAssert(text?.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) +// NSLog(text!) + + mgr?.reloadManager() + mod = mgr?.moduleWithName("kjv") + + XCTAssert(mod != nil) + XCTAssert(mod?.name() == "KJV") + } +} diff --git a/bindings/objc/test/SwordModuleLongRunTest.h b/bindings/objc/test/SwordModuleLongRunTest.h index d415885..5eda8da 100644 --- a/bindings/objc/test/SwordModuleLongRunTest.h +++ b/bindings/objc/test/SwordModuleLongRunTest.h @@ -6,11 +6,11 @@ // Copyright 2008 __MyCompanyName__. All rights reserved. // -#import <SenTestingKit/SenTestingKit.h> +#import <XCTest/XCTest.h> @class SwordModule; -@interface SwordModuleTest : SenTestCase { +@interface SwordModuleLongRunTest : XCTestCase { SwordModule *mod; } diff --git a/bindings/objc/test/SwordModuleLongRunTest.mm b/bindings/objc/test/SwordModuleLongRunTest.mm index 699a18c..d63d4f5 100644 --- a/bindings/objc/test/SwordModuleLongRunTest.mm +++ b/bindings/objc/test/SwordModuleLongRunTest.mm @@ -6,33 +6,20 @@ // Copyright 2008 __MyCompanyName__. All rights reserved. // -#import "SwordModuleTest.h" -#ifdef TARGET_IPHONE_SIMULATOR -#import "SwordManager.h" -#import "Configuration.h" -#import "iOSConfiguration.h" -#import "SwordModule.h" -#import "SwordBibleTextEntry.h" -#import "VerseEnumerator.h" -#import "SwordListKey.h" -#else #import "ObjCSword/ObjCSword.h" -#endif +#import "SwordModuleLongRunTest.h" +#import "SwordModule+Index.h" -@implementation SwordModuleTest +@implementation SwordModuleLongRunTest - (void)setUp { -#ifdef TARGET_IPHONE_SIMULATOR - [[Configuration config] setClass:[iOSConfiguration class]]; -#else - [[Configuration config] setClass:[OSXConfiguration class]]; -#endif - mod = [[SwordManager defaultManager] moduleWithName:@"GerNeUe"]; + [Configuration configWithImpl:[[OSXConfiguration alloc] init]]; + mod = [[SwordManager defaultManager] moduleWithName:@"GerNeUe"]; } - (void)testCreateSearchIndex { SwordModule *sm = [[SwordManager defaultManager] moduleWithName:@"GerSch"]; - STAssertNotNil(sm, @"Module is nil"); + XCTAssertNotNil(sm, @"Module is nil"); NSLog(@"creating clucene search index..."); [sm createSearchIndex]; @@ -77,7 +64,7 @@ [com incKeyPosition]; count++; } - STAssertTrue((count == 1), @""); + XCTAssertTrue((count == 1), @""); } - (void)testCommentarySkipLinksNoPersist { @@ -97,7 +84,7 @@ [lk increment]; count++; } - STAssertTrue((count == 1), @""); + XCTAssertTrue((count == 1), @""); } @end diff --git a/bindings/objc/test/SwordModuleTest.h b/bindings/objc/test/SwordModuleTest.h index 95135fc..0eda60b 100644 --- a/bindings/objc/test/SwordModuleTest.h +++ b/bindings/objc/test/SwordModuleTest.h @@ -6,13 +6,4 @@ // Copyright 2010 Software by MABE. All rights reserved. // -#import <SenTestingKit/SenTestingKit.h> - -@class SwordModule, SwordManager; - -@interface SwordModuleTest : SenTestCase { - SwordManager *mgr; - SwordModule *mod; -} - -@end +#import <XCTest/XCTest.h> diff --git a/bindings/objc/test/SwordModuleTest.m b/bindings/objc/test/SwordModuleTest.m index a308513..2f1a489 100644 --- a/bindings/objc/test/SwordModuleTest.m +++ b/bindings/objc/test/SwordModuleTest.m @@ -6,43 +6,184 @@ // Copyright 2010 Software by MABE. All rights reserved. // -#import <ObjCSword/ObjCSword.h> #import "SwordModuleTest.h" +#import <ObjCSword/ObjCSword.h> + +@class SwordModule, SwordManager; + +@interface SwordModuleTest : XCTestCase { + SwordManager *mgr; + SwordModule *mod; +} + +@end @implementation SwordModuleTest - (void)setUp { - [Configuration configWithImpl:[[[OSXConfiguration alloc] init] autorelease]]; - mgr = [SwordManager managerWithPath:[[Configuration config] defaultModulePath]]; - mod = [mgr moduleWithName:@"GerNeUe"]; + [Configuration configWithImpl:[[OSXConfiguration alloc] init]]; + + [[FilterProviderFactory providerFactory] initWithImpl:[[DefaultFilterProvider alloc] init]]; + + mgr = [SwordManager managerWithPath:[[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"TestModules"]]; + mod = [mgr moduleWithName:@"KJV"]; } -- (void)testLoopRenderedVerses { - SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerSch"]; - STAssertNotNil(bible, @"Module is nil"); +- (void)testModuleIntroductionGer { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"]; - NSArray *verses = [bible renderedTextEntriesForRef:@"Gen"]; - STAssertNotNil(verses, @""); - STAssertTrue([bible numberOfVerseKeysForReference:@"Gen"] == [verses count], @""); + NSString *modIntro = [bible moduleIntroduction]; + NSLog(@"mod intro: %@", modIntro); + XCTAssertNotNil(modIntro); + XCTAssertTrue([@"Im Anfang schuf Gott Himmel und Erde." isEqualToString:modIntro]); } -- (void)testRenderedVerseText { - SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerSch"]; - STAssertNotNil(bible, @"Module is nil"); +/* +- (void)testFirstBookATIntro { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; - SwordModuleTextEntry *text = [bible textEntryForKeyString:@"gen1.1" textType:TextTypeRendered]; - STAssertNotNil(text, @""); - STAssertTrue([[text text] length] > 0, @""); + SwordBibleBook *book = [bible bookList][0]; + NSString *intro = [bible bookIntroductionFor:book]; + NSLog(@"testament: '%i', book '%@' intro: %@", [book testament], [book name], intro); + XCTAssertNotNil(intro); + XCTAssertTrue([intro hasPrefix:@" <!P><br />Das erste Buch der Bibel wird auch Genesis"]); } +*/ -- (void)testCloneModule { - SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerSch"]; - STAssertNotNil(bible, @"Module is nil"); +- (void)testFirstBookATIntroGer { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"]; - /* - SwordBible *cloned = (SwordBible *)[bible clone]; - STAssertNotNil(cloned, @"Module is nil"); - */ + SwordBibleBook *book = [bible bookList][0]; + NSString *intro = [bible bookIntroductionFor:book]; + NSLog(@"testament: '%i', book '%@' intro: %@", [book testament], [book name], intro); + XCTAssertNotNil(intro); + XCTAssertTrue([intro hasPrefix:@" <!P><br />Das erste Buch der Bibel wird auch Genesis"]); +} + +/* +- (void)testFirstBookNTIntro { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + + SwordBibleBook *book = [bible bookWithNamePrefix:@"Mat"]; + NSString *intro = [bible bookIntroductionFor:book]; + NSLog(@"testament: '%i', book '%@' intro: %@", [book testament], [book name], intro); + XCTAssertNotNil(intro); + XCTAssertTrue([intro hasPrefix:@" <!P><br />Um die Zeit der Apostelversammlung herum"]); +} +*/ + +- (void)testJesusWordsInRed { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + XCTAssertNotNil(bible, @"Module is nil"); + + [mgr setGlobalOption:SW_OPTION_REDLETTERWORDS value:SW_ON]; + SwordBibleTextEntry *text = (SwordBibleTextEntry *) [bible renderedTextEntryForRef:@"Mat 4:4"]; + XCTAssertTrue(text != nil); + NSLog(@"Mat 4:4: %@", [text text]); + XCTAssertTrue([[text text] containsString:@"But he answered and said, <font color=\"red\"> It is written, Man shall not live by bread alone, but by every word that proceedeth out of the mouth of God.</font>"]); +} + +- (void)testStrongsNumberHebrewRetrieval { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + XCTAssertNotNil(bible, @"Module is nil"); + + [bible setKeyString:@"Gen 1:1"]; + NSArray *strongsNumbers = [bible entryAttributeValuesLemma]; + XCTAssertTrue(strongsNumbers != nil); + XCTAssertTrue([strongsNumbers count] > 0); + NSString *combinedString = [strongsNumbers componentsJoinedByString:@","]; + NSLog(@"%@", combinedString); + XCTAssertTrue([@"H07225,H0430,H0853 H01254,H08064,H0853,H0776" isEqualToString:combinedString]); +} + +- (void)testStrongsNumberHebrewNormalizedRetrieval { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + XCTAssertNotNil(bible, @"Module is nil"); + + [bible setKeyString:@"Gen 1:1"]; + NSArray *strongsNumbers = [bible entryAttributeValuesLemmaNormalized]; + XCTAssertTrue(strongsNumbers != nil); + XCTAssertTrue([strongsNumbers count] > 0); + NSString *combinedString = [strongsNumbers componentsJoinedByString:@","]; + NSLog(@"%@", combinedString); + XCTAssertTrue([@"H07225,H00430,H00853,H01254,H08064,H00853,H00776" isEqualToString:combinedString]); +} + +- (void)testStrongsNumberGreekRetrieval { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + XCTAssertNotNil(bible, @"Module is nil"); + + [bible setKeyString:@"Mat 1:1"]; + NSArray *strongsNumbers = [bible entryAttributeValuesLemma]; + XCTAssertTrue(strongsNumbers != nil); + XCTAssertTrue([strongsNumbers count] > 0); + NSString *combinedString = [strongsNumbers componentsJoinedByString:@","]; + NSLog(@"%@", combinedString); + XCTAssertTrue([@"G976,G1078,G2424,G5547,G5207,G1138,G5207,G11" isEqualToString:combinedString]); +} + +- (void)testStrongsNumberGreekNormalizedRetrieval { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + XCTAssertNotNil(bible, @"Module is nil"); + + [bible setKeyString:@"Mat 1:1"]; + NSArray *strongsNumbers = [bible entryAttributeValuesLemmaNormalized]; + XCTAssertTrue(strongsNumbers != nil); + XCTAssertTrue([strongsNumbers count] > 0); + NSString *combinedString = [strongsNumbers componentsJoinedByString:@","]; + NSLog(@"%@", combinedString); + XCTAssertTrue([@"G00976,G01078,G02424,G05547,G05207,G01138,G05207,G00011" isEqualToString:combinedString]); +} + +- (void)testFirstBookNTIntroGer { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"]; + + SwordBibleBook *book = [bible bookWithNamePrefix:@"Mat"]; + NSString *intro = [bible bookIntroductionFor:book]; + NSLog(@"testament: '%i', book '%@' intro: %@", [book testament], [book name], intro); + XCTAssertNotNil(intro); + XCTAssertTrue([intro hasPrefix:@" <!P><br />Um die Zeit der Apostelversammlung herum"]); +} + +- (void)testPreverseHeading { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + + [mgr setGlobalOption:SW_OPTION_HEADINGS value:SW_ON]; + SwordBibleTextEntry *text = (SwordBibleTextEntry *) [bible renderedTextEntryForRef:@"Numbers 1:47"]; + NSLog(@"Preverse text: %@", [text preVerseHeading]); + XCTAssertTrue([[text preVerseHeading] length] > 0); + XCTAssertTrue([[text preVerseHeading] isEqualToString:@"<title>Die Sonderstellung der Leviten</title>"]); + [mgr setGlobalOption:SW_OPTION_HEADINGS value:SW_OFF]; +} + +- (void)testPreverseHeading2 { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"]; + + [mgr setGlobalOption:SW_OPTION_HEADINGS value:SW_ON]; + SwordBibleTextEntry *text = (SwordBibleTextEntry *) [bible renderedTextEntryForRef:@"Numbers 4:21"]; + NSLog(@"Preverse text: %@", [text preVerseHeading]); + XCTAssertTrue([[text preVerseHeading] length] > 0); + XCTAssertTrue([[text preVerseHeading] isEqualToString:@"<title>Die Gerschoniten</title>"]); + [mgr setGlobalOption:SW_OPTION_HEADINGS value:SW_OFF]; +} + +- (void)testLoopRenderedVerses { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + XCTAssertNotNil(bible, @"Module is nil"); + + NSArray *verses = [bible renderedTextEntriesForRef:@"Gen"]; + XCTAssertNotNil(verses, @""); + XCTAssertTrue([bible numberOfVerseKeysForReference:@"Gen"] == [verses count], @""); +} + +- (void)testRenderedVerseText { + SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"]; + XCTAssertNotNil(bible, @"Module is nil"); + + SwordModuleTextEntry *text = [bible renderedTextEntryForRef:@"gen1.1"]; + XCTAssertNotNil(text, @""); + NSLog(@"text: %@", [text text]); + XCTAssertTrue([[text text] length] > 0, @""); } - (void)testLoopWithModulePos { @@ -129,7 +270,7 @@ [vk setKeyText:[lk keyText]]; long lowVerse = [vk verse] - context; long highVerse = lowVerse + (context * 2); - [vk setVerse:lowVerse]; + [vk setVerse:(int)lowVerse]; [mod setSwordKey:vk]; for(;lowVerse <= highVerse;lowVerse++) { ref = [vk keyText]; @@ -149,13 +290,20 @@ } } -- (void)testStrippedTextForRef { - SwordVerseKey *vk = [SwordVerseKey verseKeyWithRef:@"1Mo 1:2"]; +- (void)testVersePositioning { + SwordVerseKey *vk = [SwordVerseKey verseKeyWithRef:@"gen 1:2"]; NSLog(@"start position: %@", [vk keyText]); [vk decrement]; NSLog(@"decrement position: %@", [vk keyText]); + XCTAssertTrue([vk chapter] == 1); + XCTAssertTrue([vk book] == 1); + XCTAssertTrue([vk verse] == 1); + [vk setVerse:[vk verse] + 3]; NSLog(@"verse + 3: %@", [vk keyText]); + XCTAssertTrue([vk chapter] == 1); + XCTAssertTrue([vk book] == 1); + XCTAssertTrue([vk verse] == 4); } @end diff --git a/bindings/objc/test/TestGlobals.h b/bindings/objc/test/TestGlobals.h new file mode 100644 index 0000000..f344c5b --- /dev/null +++ b/bindings/objc/test/TestGlobals.h @@ -0,0 +1,12 @@ +// +// TestGlobals.h +// ObjCSword +// +// Created by Manfred Bergmann on 02.03.16. +// +// + +#ifndef TestGlobals_h +#define TestGlobals_h + +#endif /* TestGlobals_h */ diff --git a/bindings/objc/test/Tests-Bridging-Header.h b/bindings/objc/test/Tests-Bridging-Header.h new file mode 100644 index 0000000..d4dd0a5 --- /dev/null +++ b/bindings/objc/test/Tests-Bridging-Header.h @@ -0,0 +1,6 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import <ObjCSword/ObjCSword.h> +#import "TestGlobals.h" diff --git a/bindings/objc/test/Tests-Info.plist b/bindings/objc/test/Tests-Info.plist index c285a47..66a5a8a 100644 --- a/bindings/objc/test/Tests-Info.plist +++ b/bindings/objc/test/Tests-Info.plist @@ -7,7 +7,7 @@ <key>CFBundleExecutable</key> <string>${EXECUTABLE_NAME}</string> <key>CFBundleIdentifier</key> - <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string> + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> |