root/branches/CoreData/SapphireFrappliance/main_debug.m @ 833

Revision 833, 6.7 KB (checked in by gbooker, 17 months ago)

Tests to find issues with cascading delete

Line 
1/*
2 * main_debug.c
3 * Sapphire
4 *
5 * Created by Graham Booker on Aug. 2, 2008.
6 * Copyright 2007 Sapphire Development Team and/or www.nanopi.net
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation; either version 3 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program; if not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21#import "SapphireImportHelper.h"
22#import <CoreData/CoreData.h>
23
24#include "../SapphireCompatibilityClasses/Sapphire_Prefix.pch"
25
26//Debug Imports
27#import "SapphireCollectionDirectory.h"
28#import "SapphireDirectoryMetaData.h"
29#import "SapphireApplianceController.h"
30#import "SapphireMetaDataUpgrading.h"
31#import "SapphireMovie.h"
32#import "CoreDataSupportFunctions.h"
33#import "SapphireFileMetaData.h"
34#import "SapphireFileDataImporter.h"
35#import "SapphireXMLFileDataImporter.h"
36#import "SapphireTVShowImporter.h"
37#import "SapphireMovieImporter.h"
38#import "SapphireMetaDataSupport.h"
39#import "SapphireAllImporter.h"
40
41void overrideApplicationSupportdir(NSString *override);
42
43@interface TestFileScanning : NSObject <SapphireMetaDataScannerDelegate>
44{
45        int i;
46        NSArray *collections;
47        NSMutableSet *skip;
48}
49- (id)initWithCollections:(NSArray *)col;
50@end
51
52@implementation TestFileScanning
53
54- (id)initWithCollections:(NSArray *)col
55{
56        self = [super init];
57       
58        collections = [col retain];
59        skip = [[NSMutableSet alloc] init];
60        i=-1;
61       
62        return self;
63}
64
65- (void) dealloc
66{
67        [collections release];
68        [skip release];
69        [super dealloc];
70}
71
72- (void)gotSubFiles:(NSArray *)subs
73{
74        i++;
75        if(i==[collections count])
76                NSLog(@"DONE!!!");
77        else
78        {
79                [[(SapphireCollectionDirectory *)[collections objectAtIndex:i] directory] getSubFileMetasWithDelegate:self skipDirectories:skip];
80        }
81}
82
83- (void)scanningDir:(NSString *)dir
84{
85}
86
87- (BOOL)getSubFilesCanceled
88{
89        return NO;
90}
91
92@end
93
94@interface SapphireMetaDataUpgrading (debug)
95- (void)doUpgrade:(id)obj;
96@end
97
98
99
100int main(int argc, char *argv[])
101{
102        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
103       
104        {
105                NSString *path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:argv[0] length:strlen(argv[0])];
106               
107                path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Sapphire.frappliance"];
108               
109                NSBundle *bundle = [NSBundle bundleWithPath:path];
110                [bundle load];         
111        }
112       
113//      overrideApplicationSupportdir([NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Frontrow"]);
114#define TESTING_UPGRADE
115#ifdef TESTING_UPGRADE
116        {
117                SapphireMetaDataUpgrading *upgrade = [[SapphireMetaDataUpgrading alloc] init];
118                [upgrade doUpgrade:nil];
119                [upgrade release];
120        }
121#endif
122       
123        NSString *storeFile = [applicationSupportDir() stringByAppendingPathComponent:@"metaData.sapphireDataV2"];
124        BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:storeFile];
125        if(!exists)
126                return 0;
127       
128        NSManagedObjectContext *moc = [SapphireApplianceController newManagedObjectContextForFile:storeFile];
129        [SapphireMetaDataSupport setMainContext:moc];
130       
131        //Debug code goes here:
132//#define LISTING_MOVIES
133#ifdef LISTING_MOVIES
134        {
135                NSArray *allMovies = doFetchRequest(SapphireMovieName, moc, nil);
136                NSEnumerator *movieEnum = [allMovies objectEnumerator];
137                SapphireMovie *movie;
138                while((movie = [movieEnum nextObject]) != nil)
139                {
140                        NSLog(@"Looking at movie %@ with xml: %d", [movie title], [[movie xmlSet] count]);
141                        NSLog(@"Cast is %@", [movie valueForKeyPath:@"cast.name"]);
142                        NSLog(@"Directors is %@", [movie valueForKeyPath:@"directors.name"]);
143                        NSLog(@"Genres is %@", [movie valueForKeyPath:@"genres.name"]);
144                        NSLog(@"Plot is %@", [movie plot]);
145                }               
146        }
147#endif
148//#define TESTING_XML_IMPORT
149#ifdef TESTING_XML_IMPORT
150        {
151                NSString *path = @"/Users/gbooker/Movies/Little Einsteins.avi";
152                SapphireFileMetaData *meta = [SapphireFileMetaData fileWithPath:path inContext:moc];
153                [meta clearMetaData];
154                [SapphireMetaDataSupport save:moc];
155                SapphireXMLFileDataImporter *importer = [[SapphireXMLFileDataImporter alloc] init];
156                [importer importMetaData:meta path:[meta path]];
157                [importer release];             
158        }
159#endif
160//#define TESTING_FILE_SCANNING
161#ifdef TESTING_FILE_SCANNING
162        {
163                NSMutableArray *collections = [[SapphireCollectionDirectory allCollectionsInContext:moc] mutableCopy];
164                //remove / and ~/Movies
165                [collections removeObjectAtIndex:0];
166                [collections removeObjectAtIndex:0];
167                TestFileScanning *debug = [[TestFileScanning alloc] initWithCollections:collections];
168                [NSTimer scheduledTimerWithTimeInterval:0 target:debug selector:@selector(gotSubFiles:) userInfo:nil repeats:NO];
169                [debug release];
170               
171                NSRunLoop *currentRL = [NSRunLoop currentRunLoop];
172                while([currentRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
173                        ;               
174        }
175#endif
176//#define TESTING_UPDATED_VALUES
177#ifdef TESTING_UPDATED_VALUES
178        {
179                NSString *path = @"/Users/gbooker/Movies/Little Einsteins.avi";
180                SapphireFileMetaData *meta = [SapphireFileMetaData fileWithPath:path inContext:moc];
181                [meta clearMetaData];
182                SapphireXMLFileDataImporter *xmlImpr = [[SapphireXMLFileDataImporter alloc] init];
183                SapphireFileDataImporter *fileImp = [[SapphireFileDataImporter alloc] init];
184                SapphireTVShowImporter *tvImp = [[SapphireTVShowImporter alloc] initWithContext:moc];
185                SapphireMovieImporter *movImp = [[SapphireMovieImporter alloc] initWithContext:moc];
186                SapphireAllImporter *allImporter = [[SapphireAllImporter alloc] initWithImporters:[NSArray arrayWithObjects:xmlImpr,tvImp,movImp,fileImp,nil]];
187                [xmlImpr release];
188                [fileImp release];
189                [tvImp release];
190                [movImp release];
191               
192                [allImporter importMetaData:meta path:[meta path]];
193               
194                NSDictionary *changes = [SapphireMetaDataSupport changesDictionaryForContext:moc];
195                [moc reset];
196                [SapphireMetaDataSupport applyChanges:changes toContext:moc];
197                [allImporter release];
198        }
199#endif
200#define TESTING_DIRECTORY_RESCAN
201#ifdef TESTING_DIRECTORY_RESCAN
202        {
203                SapphireMovie *movie = [SapphireMovie movieWithTitle:@"Little Eistiens: Our Big Huge Adventure" inContext:moc];
204                SapphireFileMetaData *file = [SapphireFileMetaData fileWithPath:@"/Users/gbooker/Movies/Little Einsteins.avi" inContext:moc];
205                [moc deleteObject:file];
206                [moc processPendingChanges];
207                SapphireDirectoryMetaData *dir = [SapphireDirectoryMetaData directoryWithPath:@"/Users/gbooker/Movies" inContext:moc];
208                [dir reloadDirectoryContents];
209        }
210#endif
211       
212        [pool release];
213       
214        return 0;
215}
Note: See TracBrowser for help on using the browser.