Changeset 11798 for lang/objective-c
- Timestamp:
- 05/18/08 00:07:27 (6 months ago)
- Location:
- lang/objective-c/HatebuCoreData
- Files:
-
- 3 modified
-
BookmarkTest.m (modified) (3 diffs)
-
UTManagedObjectContext.h (modified) (2 diffs)
-
UTManagedObjectContext.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/objective-c/HatebuCoreData/BookmarkTest.m
r11796 r11798 15 15 -(void) setUp { 16 16 context_ = [NSManagedObjectContext inMemoryMOCForTesting]; 17 18 17 STAssertNotNil(context_, @"context loaded"); 19 }20 21 -(void) tearDown {22 18 } 23 19 … … 31 27 } 32 28 33 #if 034 29 -(void) testSetValue { 35 30 NSEntityDescription *entity = [NSEntityDescription … … 61 56 #endif // 0 62 57 } 63 #endif // 064 58 65 59 @end -
lang/objective-c/HatebuCoreData/UTManagedObjectContext.h
r11796 r11798 9 9 #import <Cocoa/Cocoa.h> 10 10 11 12 11 @interface NSManagedObjectContext (UnitTest) 13 12 … … 15 14 16 15 @end 16 // vim:set ft=objc: -
lang/objective-c/HatebuCoreData/UTManagedObjectContext.m
r11796 r11798 6 6 // Copyright 2008 deadbeaf.org. All rights reserved. 7 7 // 8 // This code is postedby Bill Garrison to CocoaDev ML:9 // http://lists.apple.com/archives/Cocoa-dev/2008/Mar/msg00777.html8 // This code is posted originally by Bill Garrison to CocoaDev ML: 9 // http://lists.apple.com/archives/Cocoa-dev/2008/Mar/msg00777.html 10 10 // 11 11 #import "UTManagedObjectContext.h" … … 15 15 16 16 // Configure a MOC backed by an in-memory store based on all bundled model files. 17 18 + (NSManagedObjectContext *) inMemoryMOCForTesting { 19 NSString *modelStr = [NSBundle 20 pathForResource:@"HatebuCoreData_DataModel" 21 ofType:@"mom" 22 inDirectory:[[NSBundle bundleForClass:[BookmarkTest class]] bundlePath]]; 23 17 + (NSManagedObjectContext *) inMemoryMOCForTesting { 24 18 // Set up a persistent store coordinator with an in-memory store. 25 26 //NSManagedObjectModel* model = [NSManagedObjectModel mergedModelFromBundles:nil]; 19 NSURL *url = [NSURL fileURLWithPath: 20 [NSBundle pathForResource:@"HatebuCoreData_DataModel" ofType:@"mom" 21 inDirectory:[[NSBundle bundleForClass:[BookmarkTest class]] bundlePath]]]; 27 22 NSManagedObjectModel *model = [[NSManagedObjectModel alloc] 28 initWithContentsOfURL:[NSURL fileURLWithPath:modelStr]]; 29 23 initWithContentsOfURL:url]; 30 24 NSAssert(model != nil, @"model should not be nil"); 31 25 NSAssert([model entities] != nil, @"entities should not be nil"); 32 NSLog(@"NSManagedObjectModel(UnitTest).inMemoryMOCForTesting : %d", [[model entities] count]);33 26 34 NSPersistentStoreCoordinator *coordinator = [[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model] autorelease]; 35 if (coordinator == nil) { 36 NSLog(@"Can't get instance of an NSPersistentStoreCoordinator."); 37 return nil; 38 } 27 NSPersistentStoreCoordinator *coordinator = [[[NSPersistentStoreCoordinator alloc] 28 initWithManagedObjectModel:model] autorelease]; 29 NSAssert(coordinator != nil, @"Can't get instance of an NSPersistentStoreCoordinator."); 39 30 40 31 // Add an in-memory persistent store to the coordinator. 41 42 32 NSError *addStoreError = nil; 43 [coordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:&addStoreError]; 44 if (addStoreError) { 45 NSLog(@"Error setting up in-memory store unit test: ", addStoreError); 46 return nil; 47 } 33 [coordinator addPersistentStoreWithType:NSInMemoryStoreType 34 configuration:nil URL:nil options:nil error:&addStoreError]; 35 NSAssert(nil == addStoreError, @"Error setting up in-memory store unit test: "); 48 36 49 37 // Now we can set up the managed object context and assign it to persistent store coordinator. 50 51 38 NSManagedObjectContext *moc = [[[NSManagedObjectContext alloc] init] autorelease]; 52 39 [moc setPersistentStoreCoordinator: coordinator]; 53 NSAssert( moc != nil, @"Can't set up managed object context for unit test.");40 NSAssert(moc != nil, @"Can't set up managed object context for unit test."); 54 41 55 42 return moc;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)