Changeset 11798 for lang/objective-c

Show
Ignore:
Timestamp:
05/18/08 00:07:27 (6 months ago)
Author:
mootoh
Message:

small refactoring.

Location:
lang/objective-c/HatebuCoreData
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/objective-c/HatebuCoreData/BookmarkTest.m

    r11796 r11798  
    1515-(void) setUp { 
    1616  context_ = [NSManagedObjectContext inMemoryMOCForTesting]; 
    17  
    1817  STAssertNotNil(context_, @"context loaded"); 
    19 } 
    20  
    21 -(void) tearDown { 
    2218} 
    2319 
     
    3127} 
    3228 
    33 #if 0 
    3429-(void) testSetValue { 
    3530  NSEntityDescription *entity = [NSEntityDescription 
     
    6156#endif // 0 
    6257} 
    63 #endif // 0 
    6458 
    6559@end 
  • lang/objective-c/HatebuCoreData/UTManagedObjectContext.h

    r11796 r11798  
    99#import <Cocoa/Cocoa.h> 
    1010 
    11  
    1211@interface NSManagedObjectContext (UnitTest) 
    1312 
     
    1514 
    1615@end 
     16// vim:set ft=objc: 
  • lang/objective-c/HatebuCoreData/UTManagedObjectContext.m

    r11796 r11798  
    66//  Copyright 2008 deadbeaf.org. All rights reserved. 
    77// 
    8 // This code is posted by Bill Garrison to CocoaDev ML: 
    9 //   http://lists.apple.com/archives/Cocoa-dev/2008/Mar/msg00777.html 
     8//  This code is posted originally by Bill Garrison to CocoaDev ML: 
     9//    http://lists.apple.com/archives/Cocoa-dev/2008/Mar/msg00777.html 
    1010// 
    1111#import "UTManagedObjectContext.h" 
     
    1515 
    1616// 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 { 
    2418        // 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]]]; 
    2722        NSManagedObjectModel *model = [[NSManagedObjectModel alloc] 
    28     initWithContentsOfURL:[NSURL fileURLWithPath:modelStr]]; 
    29  
     23    initWithContentsOfURL:url]; 
    3024  NSAssert(model != nil, @"model should not be nil"); 
    3125  NSAssert([model entities] != nil, @"entities should not be nil"); 
    32   NSLog(@"NSManagedObjectModel(UnitTest).inMemoryMOCForTesting : %d", [[model entities] count]); 
    3326         
    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."); 
    3930         
    4031        // Add an in-memory persistent store to the coordinator. 
    41          
    4232        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: "); 
    4836         
    4937        // Now we can set up the managed object context and assign it to persistent store coordinator. 
    50          
    5138        NSManagedObjectContext *moc = [[[NSManagedObjectContext alloc] init] autorelease]; 
    5239        [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."); 
    5441         
    5542        return moc;