Permalink
Browse files

Merge node display cleanup and new unit test framework support from D…

…aniel Katz
  • Loading branch information...
richard committed Mar 1, 2011
1 parent 8b0401a commit 00aeb565f4e6f548363541b68638f551920cff65
Showing with 3,725 additions and 11 deletions.
  1. +24 −5 Classes/DataModel/Node.m
  2. +76 −0 Classes/DataModel/NodeTest.m
  3. +2 −0 Classes/MobileOrgAppDelegate.h
  4. +1 −0 Classes/Parsing/ChecksumFileParser.m
  5. +1 −0 Classes/Parsing/EditsFileParser.m
  6. +1 −0 Classes/Parsing/OrgFileParser.m
  7. +1 −0 Classes/Settings/Settings.m
  8. +1 −0 Classes/Sync/SyncManager.m
  9. +82 −0 Classes/ThirdParty/GH-Unit/GHUnitIOSTestMain.m
  10. +6 −1 Classes/Utilities/GlobalUtils.h
  11. +1 −0 GHUnitIOS.framework/GHUnitIOS
  12. +1 −0 GHUnitIOS.framework/Headers
  13. +1 −0 GHUnitIOS.framework/Resources
  14. BIN GHUnitIOS.framework/Versions/A/GHUnitIOS
  15. +155 −0 GHUnitIOS.framework/Versions/A/Headers/GHAsyncTestCase.h
  16. +44 −0 GHUnitIOS.framework/Versions/A/Headers/GHTest+JUnitXML.h
  17. +184 −0 GHUnitIOS.framework/Versions/A/Headers/GHTest.h
  18. +146 −0 GHUnitIOS.framework/Versions/A/Headers/GHTestCase.h
  19. +42 −0 GHUnitIOS.framework/Versions/A/Headers/GHTestGroup+JUnitXML.h
  20. +176 −0 GHUnitIOS.framework/Versions/A/Headers/GHTestGroup.h
  21. +1,012 −0 GHUnitIOS.framework/Versions/A/Headers/GHTestMacros.h
  22. +46 −0 GHUnitIOS.framework/Versions/A/Headers/GHTestOperation.h
  23. +162 −0 GHUnitIOS.framework/Versions/A/Headers/GHTestRunner.h
  24. +118 −0 GHUnitIOS.framework/Versions/A/Headers/GHTestSuite.h
  25. +148 −0 GHUnitIOS.framework/Versions/A/Headers/GHTesting.h
  26. +590 −0 GHUnitIOS.framework/Versions/A/Headers/GHUnit.h
  27. +39 −0 GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneAppDelegate.h
  28. +40 −0 GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneTableViewDataSource.h
  29. +42 −0 GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneTestViewController.h
  30. +52 −0 GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneView.h
  31. +71 −0 GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneViewController.h
  32. +97 −0 GHUnitIOS.framework/Versions/A/Headers/NSException+GHTestFailureExceptions.h
  33. +71 −0 GHUnitIOS.framework/Versions/A/Headers/NSValue+GHValueFormatter.h
  34. +18 −0 GHUnitIOS.framework/Versions/A/Resources/Info.plist
  35. +1 −0 GHUnitIOS.framework/Versions/Current
  36. +253 −5 MobileOrg.xcodeproj/project.pbxproj
  37. +20 −0 UnitTests-Info.plist
View
@@ -25,6 +25,7 @@
#import "DataUtils.h"
#import "Settings.h"
#import "GlobalUtils.h"
+#import "RegexKitLite.h"
@implementation Node
@@ -127,17 +128,35 @@ - (NSString*)afterText {
return nil;
}
+
- (NSString*)bodyForDisplay {
NSString *summary = [self body];
+ summary = [summary stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ // Will this cause us problems if stuff comes from Windows with CRLF line endings?
+ NSArray* lines = [summary componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
+
+ NSMutableArray* goodLines = [[NSMutableArray alloc] init];
+ BOOL inDrawer = NO;
+ for (NSString* line in lines) {
+ if (!inDrawer && [line isMatchedByRegex:@"^\\s*:.+:\\s*$"] &&
+ ![line isMatchedByRegex:@"^\\s*:END:\\s*$"]) {
+ inDrawer = YES;
+ continue;
+ }
+ else if ([line isMatchedByRegex:@"^\\s*:END:\\s*$"]) {
+ inDrawer = NO;
+ continue; // We don't want the :END: line either.
+ }
- NSRange break_range = [[self heading] rangeOfString:@"<break>"];
- if (break_range.location != NSNotFound) {
- summary = [[self heading] substringFromIndex:break_range.location+break_range.length];
+ if (! inDrawer) {
+ [goodLines addObject:line];
+ }
}
- summary = [summary stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ NSString *result = [goodLines componentsJoinedByString:@"\n"];
+ [goodLines release];
- return summary;
+ return result;
}
- (NSString*)completeTags {
@@ -0,0 +1,76 @@
+#import <GHUnitIOS/GHUnit.h>
+#import "Node.h"
+
+@interface NodeTest : GHTestCase {
+ NSManagedObjectModel* model_;
+ NSPersistentStoreCoordinator* coordinator_;
+ NSManagedObjectContext* context_;
+}
+
+@property (nonatomic, retain) NSManagedObjectModel* model_;
+@property (nonatomic, retain) NSPersistentStoreCoordinator* coordinator_;
+@property (nonatomic, retain) NSManagedObjectContext* context_;
+
+@end
+
+@implementation NodeTest
+
+@synthesize model_;
+@synthesize coordinator_;
+@synthesize context_;
+
+- (BOOL)shouldRunOnMainThread {
+ // By default NO, but if you have a UI test or test dependent on running on the main thread return YES
+ return NO;
+}
+
+- (void)setUpClass {
+ // Run at start of all tests in the class
+ self.model_ = [NSManagedObjectModel mergedModelFromBundles:nil];
+ self.coordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model_];
+ self.context_ = [[NSManagedObjectContext alloc] init];
+ [context_ setPersistentStoreCoordinator:coordinator_];
+}
+
+- (void)tearDownClass {
+ // Run at end of all tests in the class
+ [context_ release];
+ [coordinator_ release];
+}
+
+- (void)setUp {
+ // Run before each test method
+}
+
+- (void)tearDown {
+ // Run after each test method
+}
+
+- (void)testDrawerGetsHiddenInDisplayedBody {
+ Node *node = (Node *)[NSEntityDescription insertNewObjectForEntityForName:@"Node"
+ inManagedObjectContext:context_];
+ node.body = @" :DRAWER: \n foo \n :END: \n bar\n";
+
+ GHAssertEqualObjects(@" bar", [node bodyForDisplay],
+ @"The text outside the drawer should not change.", nil);
+}
+
+- (void)testMultipleDrawersGetHiddenInDisplayedBody {
+ Node *node = (Node *)[NSEntityDescription insertNewObjectForEntityForName:@"Node"
+ inManagedObjectContext:context_];
+ node.body = @" :DRAWER: \n foo \n :END: \n :DRAWER2: \n bar \n :END: \n baz\n";
+
+ GHAssertEqualObjects(@" baz", [node bodyForDisplay],
+ @"The text outside the drawer should not change.", nil);
+}
+
+- (void)testDrawersRemovedFromMiddleOfBodyInDisplayedBody {
+ Node *node = (Node *)[NSEntityDescription insertNewObjectForEntityForName:@"Node"
+ inManagedObjectContext:context_];
+ node.body = @"foo \n :DRAWER: \n bar \n :END: \n baz \n";
+
+ GHAssertEqualObjects(@"foo \n baz", [node bodyForDisplay],
+ @"The text outside the drawer should be concatenated.", nil);
+}
+
+@end
@@ -20,6 +20,8 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
+#import <CoreData/CoreData.h>
+
@class OutlineViewController;
@class NoteListController;
@class SearchController;
@@ -21,6 +21,7 @@
//
#import "ChecksumFileParser.h"
+#import "RegexKitLite.h"
@implementation ChecksumFileParser
@@ -24,6 +24,7 @@
#import "EditEntity.h"
#import "DataUtils.h"
#import "GlobalUtils.h"
+#import "RegexKitLite.h"
@implementation EditsFileParser
@@ -25,6 +25,7 @@
#import "GlobalUtils.h"
#import "DataUtils.h"
#import "Settings.h"
+#import "RegexKitLite.h"
@implementation OrgFileParser
@@ -29,6 +29,7 @@
#import "Settings.h"
#import "GlobalUtils.h"
#import "DropboxTransferManager.h"
+#import "RegexKitLite.h"
// Singleton instance
static Settings *gInstance = NULL;
@@ -36,6 +36,7 @@
#import "LocalEditAction.h"
#import "StatusViewController.h"
#import "MobileOrgAppDelegate.h"
+#import "RegexKitLite.h"
@interface SyncManager(private)
- (TransferManager*)transferManager;
@@ -0,0 +1,82 @@
+ //
+ // GHUnitIOSTestMain.m
+ // GHUnitIPhone
+ //
+ // Created by Gabriel Handford on 1/25/09.
+ // Copyright 2009. All rights reserved.
+ //
+ // Permission is hereby granted, free of charge, to any person
+ // obtaining a copy of this software and associated documentation
+ // files (the "Software"), to deal in the Software without
+ // restriction, including without limitation the rights to use,
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
+ // copies of the Software, and to permit persons to whom the
+ // Software is furnished to do so, subject to the following
+ // conditions:
+ //
+ // The above copyright notice and this permission notice shall be
+ // included in all copies or substantial portions of the Software.
+ //
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ // OTHER DEALINGS IN THE SOFTWARE.
+ //
+
+#import <UIKit/UIKit.h>
+
+ // If you are using the framework
+#import <GHUnitIOS/GHUnit.h>
+ // If you are using the static library and importing header files manually
+ //#import "GHUnit.h"
+
+ // Default exception handler
+void exceptionHandler(NSException *exception) {
+ NSLog(@"%@\n%@", [exception reason], GHUStackTraceFromException(exception));
+}
+
+int main(int argc, char *argv[]) {
+
+ /*!
+ For debugging:
+ Go into the "Get Info" contextual menu of your (test) executable (inside the "Executables" group in the left panel of XCode).
+ Then go in the "Arguments" tab. You can add the following environment variables:
+
+ Default: Set to:
+ NSDebugEnabled NO "YES"
+ NSZombieEnabled NO "YES"
+ NSDeallocateZombies NO "YES"
+ NSHangOnUncaughtException NO "YES"
+
+ NSEnableAutoreleasePool YES "NO"
+ NSAutoreleaseFreedObjectCheckEnabled NO "YES"
+ NSAutoreleaseHighWaterMark 0 non-negative integer
+ NSAutoreleaseHighWaterResolution 0 non-negative integer
+
+ For info on these varaiables see NSDebug.h; http://theshadow.uw.hu/iPhoneSDKdoc/Foundation.framework/NSDebug.h.html
+
+ For malloc debugging see: http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html
+ */
+
+ NSSetUncaughtExceptionHandler(&exceptionHandler);
+
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ // Register any special test case classes
+ //[[GHTesting sharedInstance] registerClassName:@"GHSpecialTestCase"];
+
+ int retVal = 0;
+ // If GHUNIT_CLI is set we are using the command line interface and run the tests
+ // Otherwise load the GUI app
+ if (getenv("GHUNIT_CLI")) {
+ retVal = [GHTestRunner run];
+ } else {
+ retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate");
+ }
+ [pool release];
+ return retVal;
+}
@@ -42,4 +42,9 @@ void UpdateAppBadge();
BOOL IsIpad();
-NSString *ReadPossiblyEncryptedFile(NSString *filename, NSString **error);
+NSString *ReadPossiblyEncryptedFile(NSString *filename, NSString **error);
+
+@interface NSData (AES256)
+- (NSData *)AES256EncryptWithKey:(NSString *)passphrase;
+- (NSData *)AES256DecryptWithKey:(NSString *)passphrase;
+@end
Binary file not shown.
Oops, something went wrong.

0 comments on commit 00aeb56

Please sign in to comment.