forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTestFS.m
1228 lines (968 loc) · 33.6 KB
/
TestFS.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import "TestFS.h"
#import <Foundation/Foundation.h>
#import "FSArray.h"
#import "FSBlock.h"
#import "FSNSString.h"
#import "FSInterpreterResult.h"
#import <objc/objc-class.h>
#import "FSMiscTools.h"
#import <servers/bootstrap.h>
#import <mach/task_special_ports.h>
#import <mach/mach_init.h>
#import "PointerPrivate.h"
#include <stdbool.h>
#include <malloc/malloc.h>
#import "FSFlight.h"
#import "FSAirplane.h"
#import "FSPilot.h"
#import "FSConstantsInitialization.h"
#include <unistd.h>
#import <ExceptionHandling/NSExceptionHandler.h>
#include <stdbool.h>
#import "FScriptMenuItem.h"
#import "FSNumber.h"
#import "FScriptFunctions.h"
#import "FSPointer.h"
#import "FSGenericPointer.h"
#import "FSGenericPointerPrivate.h"
#import <CoreData/CoreData.h>
#import "KTestManager.h"
#include <ffi/ffi.h>
#include <sys/mman.h>
unsigned char foo(unsigned int, float);
static void foo_closure(ffi_cif*, void*, void**, void*);
int testFFI()
{
ffi_cif cif;
ffi_closure *closure;
ffi_type *arg_types[2];
ffi_arg result;
ffi_status status;
// Specify the data type of each argument. Available types are defined
// in <ffi/ffi.h>.
arg_types[0] = &ffi_type_uint;
arg_types[1] = &ffi_type_float;
// Allocate a page to hold the closure with read and write permissions.
if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0)) == (void*)-1)
{
// Check errno and handle the error.
}
// Prepare the ffi_cif structure.
if ((status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_uint8, arg_types)) != FFI_OK)
{
// Handle the ffi_status error.
}
// Prepare the ffi_closure structure.
if ((status = ffi_prep_closure(closure, &cif, foo_closure, NULL)) != FFI_OK)
{
// Handle the ffi_status error.
}
// Ensure that the closure will execute on all architectures.
if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1)
{
// Check errno and handle the error.
}
// The closure is now ready to be executed, and can be saved for later
// execution if desired.
// Invoke the closure.
result = ((unsigned char(*)(float, unsigned int))closure)(42, 5);
NSLog(@"result = %@", [NSNumber numberWithUnsignedChar:result]);
// Free the memory associated with the closure.
if (munmap(closure, sizeof(closure)) == -1)
{
// Check errno and handle the error.
}
return 0;
}
// Invoking the closure transfers control to this function.
static void foo_closure(ffi_cif* cif, void* result, void** args, void* userdata)
{
// Access the arguments to be sent to foo().
float arg1 = *(float*)args[0];
unsigned int arg2 = *(unsigned int*)args[1];
// Call foo() and save its return value.
unsigned char ret_val = foo(arg1, arg2);
// Copy the returned value into result. Because the return value of foo()
// is smaller than sizeof(long), typecast it to ffi_arg. Use ffi_sarg
// instead for signed types.
*(ffi_arg*)result = (ffi_arg)ret_val;
}
// The closed-over function.
unsigned char foo(unsigned int x, float y)
{
unsigned char result = x - y;
return result;
}
@interface NSMethodSignature(UndocumentedNSMethodSignature)
+ (NSMethodSignature*) signatureWithObjCTypes:(char *)types;
@end
@interface FSNumber(NumberExt)
+ numberWithDoubleNoCache:(double)val;
@end
extern FSNumber *numberWithDouble(double val);
@implementation TestFS : NSObject
@synthesize p1 = p_p1;
@synthesize toto = p_toto;
@synthesize tutu = p_tutu;
//@synthesize zozo = p_zozo;
//@dynamic dynamicProperty;
- dynamicProperty
{
return @"hello";
}
- testProperty
{
return self.dynamicProperty;
}
+ (void)testFFI
{
testFFI();
}
- (fsstruct) zozo { fsstruct r; r.a = 5; r.b = 88; return r;}
+ :(id)arg
{
return arg;
}
+ testColonSelector
{
return [self :self];
}
+ (SEL) nullSel {return (SEL)0;}
+ (NSInteger)query:(NSArray *)A :(NSArray *)F :(NSArray *)P
{
NSInteger result;
NSString *city;
FSFlight *flight;
NSCountedSet *countedSet = [NSCountedSet set];
NSEnumerator *enumerator = [F objectEnumerator];
while ((flight = [enumerator nextObject]))
{
[countedSet addObject:[flight arrivalLocation]];
}
enumerator = [countedSet objectEnumerator];
result = 0;
while ((city = [enumerator nextObject]))
{
if ([countedSet countForObject:city] < 50)
result++;
}
return result;
}
+ (NSArray *)query2:(NSArray *)A :(NSArray *)F :(NSArray *)P
{
FSAirplane *airplane;
FSPilot *pilot;
FSFlight *flight;
NSMutableArray *result = [NSMutableArray array];
NSEnumerator *pilotEnumerator = [P objectEnumerator];
while ((pilot = [pilotEnumerator nextObject]))
{
NSEnumerator *airplaneEnumerator = [A objectEnumerator];
while ((airplane = [airplaneEnumerator nextObject]))
{
NSEnumerator *flightEnumerator = [F objectEnumerator];
while ((flight = [flightEnumerator nextObject]))
{
if ([flight airplane] == airplane && [flight pilot] == pilot)
{
break;
}
}
if (!flight) break;
}
if (!airplane) [result addObject:pilot];
}
return result;
}
+ (NSUInteger) uintmax
{
return UINT_MAX;
}
+ (long long) llongmax
{
return LLONG_MAX;
}
+ (long long) llongmaxMinusOne
{
return LLONG_MAX-1;
}
+ (void)printIntegerTypeInfo
{
printIntegerTypeInfo();
}
+ (NSUInteger) booleanSize
{
return sizeof(_Bool);
}
+ (void) testClass:(Class)arg1 with:(NSInteger)arg2
{return;}
- (id) testStr
{
return @"str";
}
/*- (id) test:(Class) cls
{
Array *r = [Array array];
void *iterator = 0;
struct objc_method_list *mlist;
NSInteger i = 0;
while ( mlist = class_nextMethodList( cls, &iterator ) )
{
for (i = 0; i < mlist->method_count; i++)
{
[r add:[Block blockWithSelector:mlist->method_list[i].method_name]];
}
}
return r;
}*/
-(SEL) test2
{
return @selector(operator_plus:);
}
+ (void) testvoid { return;}
- (id) testvoid {return [FSNumber numberWithDouble:88];}
- (FSArray *) test3
{
/*void *iterator = 0;
struct objc_method_list *methods;
int i;
Class cls = [NSArray class];*/
FSArray *r = [FSArray array];
//while (cls)
//{
// while ( methods = class_nextMethodList( cls, &iterator ) )
// {
/* methods = class_nextMethodList( cls, &iterator );
for ( i = 0; i < methods->method_count; i++ )
{
struct objc_method method = methods->method_list[ i];
SEL selector = method.method_name;
[r addObject:[NSString stringWithCString:sel_getName( selector )]];
}*/
// }
// cls = [cls superclass];
//}
return r;
}
- (BOOL)testNSProxy
{
return isKindOfClassNSProxy([NSDistantObject class]);
}
+ (BOOL)testx
{
return [NSDistantObject isKindOfClass:[NSProxy class]];
}
+(Protocol*)proto
{
return @protocol(NSObject);
}
/*+ boot
{
NSMutableArray *r = [NSMutableArray array];
int i;
kern_return_t infoReturn;
mach_port_t bootstrap_port;
name_array_t service_names;
mach_msg_type_number_t service_namesCnt;
name_array_t server_names;
mach_msg_type_number_t server_namesCnt;
bool_array_t service_active;
mach_msg_type_number_t service_activeCnt;
task_get_bootstrap_port(mach_task_self(), &bootstrap_port);
infoReturn = bootstrap_info(bootstrap_port, &service_names, &service_namesCnt, &server_names, &server_namesCnt, &service_active, &service_activeCnt);
for (i = 0; i < service_namesCnt; i++)
{
[r addObject:[NSString stringWithCString:service_names[i] length:128]];
}
[r addObject:[NSString stringWithFormat:@"Number of services = %d", service_namesCnt]];
return r;
}*/
+ (BOOL) tt
{
return [NSEvent respondsToSelector:@selector(keyEventWithType:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifier:isARepeat:keyCode:)];
//return [NSEvent respondsToSelector:@selector(mouseEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:)];
}
+ (NSEvent *) tt2
{
// return [NSEvent keyEventWithType:4 location:NSMakePoint(40,40) modifierFlags:0 timestamp:40 windowNumber:1 context:nil characters:@"r" charactersIgnoringModifier:@"r" isARepeat:NO keyCode:67];
return nil;
}
static NSInteger p = 362;
+ (NSInteger *)pointer
{ NSLog(@"TestFS return %p", &p); return &p;}
+ (NSInteger *)pointerWith:object with:(NSInteger)i
{ NSLog(@"object received: %@, int received:%ld . TestFS return %p",object, (long)i, &p); return &p;}
+ (void) setPValue:(NSInteger)new
{ p = new; }
+ (NSInteger)pValue {return p;}
+ (void)setPointer:(NSInteger *)p
{
NSLog(@"setPointer: received pointer to %p", p);
NSLog(@"%ld", (long)*p);
}
+ (FSPointer *)fsPointer
{
return [[[FSGenericPointer alloc] initWithCPointer:&p freeWhenDone:NO type:@encode(typeof(p))] autorelease];
}
+ (NSInteger) sized
{
return sizeof(double);
}
/*+ bench:(Array)*a
{
}*/
- (void)forwardInvocation:(NSInvocation *)invocation
{
NSLog(@"In forwardInvocation:, invocation = %@", invocation);
[invocation setSelector:@selector(fff)];
[invocation invokeWithTarget:self];
}
- (id)fff
{
NSLog(@"In fff");
return self;
}
/*- (id)testForward
{
return [self edr];
}*/
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
if (aSelector == @selector(edr)) return [NSMethodSignature signatureWithObjCTypes:"@@:"];
else return [super methodSignatureForSelector:aSelector];
}
- (BOOL) respondsToSelector:(SEL)aSelector
{
if (aSelector == @selector(edr)) return YES;
else return [super respondsToSelector:aSelector];
}
- (NSDictionary *) constants
{
NSMutableDictionary *d = [NSMutableDictionary dictionary];
FSConstantsInitialization(d);
return d;
}
+(SEL)mySel
{
SEL selector;
NSInteger i;
selector = NSSelectorFromString(@"initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:");
i = 8;
return selector;
}
+(SEL)mySel2
{
SEL selector;
NSInteger i;
selector = NSSelectorFromString(@"initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:");
i = 8;
return selector;
}
/*+ (void) error
{
int *p = 0;
printf("handling = %d --- hanging = %d",[[NSExceptionHandler defaultExceptionHandler] exceptionHandlingMask],[[NSExceptionHandler defaultExceptionHandler] exceptionHangingMask]);
fflush(stdout);
int a = *p;
}*/
+(NSUInteger)mask
{
return [[NSExceptionHandler defaultExceptionHandler] exceptionHangingMask];
}
+(double)ld
{
long long ll1 = 2;
//unsigned long long ll2 = 1;
//double r = (long long)(ll2-ll1);
return sizeof(ll1);
}
+(void) passll:(long long)ll
{
NSLog(@"%@", [NSNumber numberWithLongLong:ll]);
}
+(void) passull:(unsigned long long)ull
{
NSLog(@"%@", [NSNumber numberWithUnsignedLongLong:ull]);
}
+(NSNumber *)ullong_max
{
return [NSNumber numberWithUnsignedLongLong:ULLONG_MAX];
}
+ (void) FSExecError
{
FSExecError(@"error test");
}
+(NSSize) size
{
return NSMakeSize(-3,-10);
}
+ (_Bool) bbbt
{return true;}
+ (_Bool) bbbf
{return false;}
+(_Bool)bbb:(_Bool)b
{ return b;}
+(_Bool)bbbn:(_Bool)b
{ return !b;}
+ (unsigned char)returnUnsignedChar
{
unsigned char r = 8;
return r;
}
+ ( char)returnChar
{
char r = 8;
return r;
}
+ (char *) BOOLe
{return @encode(BOOL);}
static NSPoint point;
+ (NSPoint *) pointPointer {point.x = 10; point.y = 20; return &point;}
+ (NSInteger) BOOLs
{return sizeof(BOOL);}
+ (void) findPathToFileInLibraryWithinUserDomain
/*" Retuns the path to the first occurrence of fileName in a Library
directory within the User domain. "*/
{
NSString *result = nil; // the returned path
NSString *candidate; // candidate paths
NSArray *pathArray; // array of standard locations
NSEnumerator *pathEnumerator; // used to enumerate pathArray
pathArray = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
pathEnumerator = [pathArray objectEnumerator];
while(nil == result && (nil != (candidate = [pathEnumerator nextObject])))
{
NSLog(@"%@", candidate);
}
}
+(void) testLock
{
NSLock *lock = [[NSLock alloc] init];
NSInteger i;
for (i = 0; i < 700000; i++)
{
[lock lock];
[lock unlock];
}
}
+(void) testLock2
{
NSInteger i;
for (i = 0; i < 700000; i++)
{
[FSNumber numberWithDouble:3.0];
}
}
+(void) testLock3
{
NSInteger i;
for (i = 0; i < 700000; i++)
{
numberWithDouble(3.0);
}
}
+(void) testLock4
{
NSInteger i;
for (i = 0; i < 700000; i++)
{
[FSNumber numberWithDoubleNoCache:3.0];
}
}
+(void) threadTest:(FSBlock *)block
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[block value];
[pool release];
}
+(void)addMenu
{
[[NSApp mainMenu] addItem: [[[FScriptMenuItem alloc] init] autorelease]];
}
/*
-(id)idRaise
{
[NSException raise:@"Exception Test" format:@"This is an exception for test purpose"];
}
-(double)doubleRaise
{
[NSException raise:@"Exception Test" format:@"This is an exception for test purpose"];
}
-(NSSize)sizeRaise
{
[NSException raise:@"Exception Test" format:@"This is an exception for test purpose"];
}
-(NSRect)rectRaise
{
[NSException raise:@"Exception Test" format:@"This is an exception for test purpose"];
}
*/
+ managed
{
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init];
NSManagedObjectModel *objectModel = [[NSManagedObjectModel alloc] init];
NSEntityDescription *employeeEntity = [[[NSEntityDescription alloc] init] autorelease];
[employeeEntity setName:@"employee"];
[employeeEntity setManagedObjectClassName:@"NSManagedObject"];
NSEntityDescription *departmentEntity = [[[NSEntityDescription alloc] init] autorelease];
[departmentEntity setName:@"department"];
[departmentEntity setManagedObjectClassName:@"Department"];
NSAttributeDescription *nameAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[nameAttribute setName:@"name"];
[nameAttribute setAttributeType:NSStringAttributeType];
NSAttributeDescription *budgetAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[budgetAttribute setName:@"budget"];
[budgetAttribute setAttributeType:NSInteger32AttributeType];
NSRelationshipDescription *employeesRelationship = [[[NSRelationshipDescription alloc] init] autorelease];
[employeesRelationship setName:@"employees"];
[employeesRelationship setDestinationEntity:employeeEntity];
[employeesRelationship setMinCount:0];
[employeesRelationship setMaxCount:999];
NSAttributeDescription *firstNameAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[firstNameAttribute setName:@"firstName"];
[firstNameAttribute setAttributeType:NSStringAttributeType];
[firstNameAttribute setDefaultValue:@""];
NSAttributeDescription *lastNameAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[lastNameAttribute setName:@"lastName"];
[lastNameAttribute setAttributeType:NSStringAttributeType];
[lastNameAttribute setDefaultValue:@""];
NSAttributeDescription *salaryAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[salaryAttribute setName:@"salary"];
[salaryAttribute setAttributeType:NSInteger32AttributeType];
NSAttributeDescription *blongaAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[blongaAttribute setName:@"Blonga"];
[blongaAttribute setAttributeType:NSInteger32AttributeType];
NSAttributeDescription *phoneAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[phoneAttribute setName:@"phone"];
[phoneAttribute setAttributeType:NSStringAttributeType];
NSAttributeDescription *emailAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[emailAttribute setName:@"email"];
[emailAttribute setAttributeType:NSStringAttributeType];
NSAttributeDescription *addressAttribute = [[[NSAttributeDescription alloc] init] autorelease];
[addressAttribute setName:@"address"];
[addressAttribute setAttributeType:NSStringAttributeType];
NSRelationshipDescription *managerRelationship = [[[NSRelationshipDescription alloc] init] autorelease];
[managerRelationship setName:@"manager"];
[managerRelationship setDestinationEntity:employeeEntity];
[managerRelationship setMinCount:0];
[managerRelationship setMaxCount:1];
NSRelationshipDescription *directReportsRelationship = [[[NSRelationshipDescription alloc] init] autorelease];
[directReportsRelationship setName:@"directReports"];
[directReportsRelationship setDestinationEntity:employeeEntity];
[directReportsRelationship setMinCount:0];
[directReportsRelationship setMaxCount:99];
NSRelationshipDescription *departmentRelationship = [[[NSRelationshipDescription alloc] init] autorelease];
[departmentRelationship setName:@"department"];
[departmentRelationship setDestinationEntity:departmentEntity];
[departmentRelationship setMinCount:0];
[departmentRelationship setMaxCount:1];
[managerRelationship setInverseRelationship:directReportsRelationship];
[directReportsRelationship setInverseRelationship:managerRelationship];
[departmentRelationship setInverseRelationship:employeesRelationship];
[employeesRelationship setInverseRelationship:departmentRelationship];
[employeeEntity setProperties:[NSArray arrayWithObjects:firstNameAttribute, lastNameAttribute, salaryAttribute, phoneAttribute, emailAttribute, addressAttribute, managerRelationship, directReportsRelationship, departmentRelationship, blongaAttribute,nil]];
[departmentEntity setProperties:[NSArray arrayWithObjects:nameAttribute, budgetAttribute, employeesRelationship, nil]];
NSArray *entities = [NSArray arrayWithObjects:departmentEntity, employeeEntity, nil];
[objectModel setEntities:entities];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:objectModel];
[context setPersistentStoreCoordinator:coordinator];
NSManagedObject *department1 = [[[NSManagedObject alloc] initWithEntity:departmentEntity insertIntoManagedObjectContext:context] autorelease];
[department1 setValue:@"R&D" forKey:@"name"];
[department1 setValue:[NSNumber numberWithInt:450000] forKey:@"budget"];
NSManagedObject *department2 = [[[NSManagedObject alloc] initWithEntity:departmentEntity insertIntoManagedObjectContext:context] autorelease];
[department2 setValue:@"Sales" forKey:@"name"];
[department2 setValue:[NSNumber numberWithInt:575000] forKey:@"budget"];
NSManagedObject *department3 = [[[NSManagedObject alloc] initWithEntity:departmentEntity insertIntoManagedObjectContext:context] autorelease];
[department3 setValue:@"Support" forKey:@"name"];
[department3 setValue:[NSNumber numberWithInt:10000] forKey:@"budget"];
NSManagedObject *department4 = [[[NSManagedObject alloc] initWithEntity:departmentEntity insertIntoManagedObjectContext:context] autorelease];
[department4 setValue:@"Marketing" forKey:@"name"];
[department4 setValue:[NSNumber numberWithInt:110000] forKey:@"budget"];
NSManagedObject *employee1 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee1 setValue:@"John" forKey:@"firstName"];
[employee1 setValue:@"Smith" forKey:@"lastName"];
[employee1 setValue:[NSNumber numberWithInt:3000] forKey:@"salary"];
[employee1 setValue:@"[email protected]" forKey:@"email"];
[employee1 setValue:@"08 65 424" forKey:@"phone"];
[employee1 setValue:@"9 Lupo Place, 74986 Coolville" forKey:@"address"];
NSManagedObject *employee2 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee2 setValue:@"Jean-Louis" forKey:@"firstName"];
[employee2 setValue:@"Langlois" forKey:@"lastName"];
[employee2 setValue:[NSNumber numberWithInt:3700] forKey:@"salary"];
[employee2 setValue:@"[email protected]" forKey:@"email"];
[employee2 setValue:@"04 56 896" forKey:@"phone"];
[employee2 setValue:@"7 Bleker Street, 74986 Coolville" forKey:@"address"];
NSManagedObject *employee3 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee3 setValue:@"Henri" forKey:@"firstName"];
[employee3 setValue:@"Carter" forKey:@"lastName"];
[employee3 setValue:[NSNumber numberWithInt:3800] forKey:@"salary"];
[employee3 setValue:@"[email protected]" forKey:@"email"];
[employee3 setValue:@"04 55 654" forKey:@"phone"];
[employee3 setValue:@"850 Bleker Street, 74986 Coolville" forKey:@"address"];
NSManagedObject *employee4 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee4 setValue:@"Fred" forKey:@"firstName"];
[employee4 setValue:@"Fonda" forKey:@"lastName"];
[employee4 setValue:[NSNumber numberWithInt:4300] forKey:@"salary"];
[employee4 setValue:@"[email protected]" forKey:@"email"];
[employee4 setValue:@"02 76 654" forKey:@"phone"];
[employee4 setValue:@"23 Roma Street, 40538 Fairyville" forKey:@"address"];
NSManagedObject *employee5 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee5 setValue:@"Phil" forKey:@"firstName"];
[employee5 setValue:@"Berry" forKey:@"lastName"];
[employee5 setValue:[NSNumber numberWithInt:2200] forKey:@"salary"];
[employee5 setValue:@"[email protected]" forKey:@"email"];
[employee5 setValue:@"04 98 652" forKey:@"phone"];
[employee5 setValue:@"6 Panda Street, 40538 Fairyville" forKey:@"address"];
NSManagedObject *employee6 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee6 setValue:@"Eric" forKey:@"firstName"];
[employee6 setValue:@"Bill" forKey:@"lastName"];
[employee6 setValue:[NSNumber numberWithInt:4000] forKey:@"salary"];
[employee6 setValue:@"[email protected]" forKey:@"email"];
[employee6 setValue:@"04 56 896" forKey:@"phone"];
[employee6 setValue:@"67 Cool Street, 74986 Coolville" forKey:@"address"];
NSManagedObject *employee7 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee7 setValue:@"Hannah" forKey:@"firstName"];
[employee7 setValue:@"Mig" forKey:@"lastName"];
[employee7 setValue:[NSNumber numberWithInt:3750] forKey:@"salary"];
[employee7 setValue:@"[email protected]" forKey:@"email"];
[employee7 setValue:@"02 76 109" forKey:@"phone"];
[employee7 setValue:@"34 Super Street, 40538 Fairyville" forKey:@"address"];
NSManagedObject *employee8 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee8 setValue:@"Suzan" forKey:@"firstName"];
[employee8 setValue:@"Mina" forKey:@"lastName"];
[employee8 setValue:[NSNumber numberWithInt:3550] forKey:@"salary"];
[employee8 setValue:@"[email protected]" forKey:@"email"];
[employee8 setValue:@"05 45 123" forKey:@"phone"];
[employee8 setValue:@"70 Quality Street, 74986 Coolville" forKey:@"address"];
NSManagedObject *employee9 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee9 setValue:@"Irene" forKey:@"firstName"];
[employee9 setValue:@"French" forKey:@"lastName"];
[employee9 setValue:[NSNumber numberWithInt:3200] forKey:@"salary"];
[employee9 setValue:@"[email protected]" forKey:@"email"];
[employee9 setValue:@"04 56 875" forKey:@"phone"];
[employee9 setValue:@"953 Long Street, 40538 Fairyville" forKey:@"address"];
NSManagedObject *employee10 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee10 setValue:@"Alan" forKey:@"firstName"];
[employee10 setValue:@"Peer" forKey:@"lastName"];
[employee10 setValue:[NSNumber numberWithInt:3000] forKey:@"salary"];
[employee10 setValue:@"[email protected]" forKey:@"email"];
[employee10 setValue:@"04 56 100" forKey:@"phone"];
[employee10 setValue:@"1 Short Street, 40538 Fairyville" forKey:@"address"];
NSManagedObject *employee11 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee11 setValue:@"Daniel" forKey:@"firstName"];
[employee11 setValue:@"Wylde" forKey:@"lastName"];
[employee11 setValue:[NSNumber numberWithInt:3900] forKey:@"salary"];
[employee11 setValue:@"[email protected]" forKey:@"email"];
[employee11 setValue:@"04 34 982" forKey:@"phone"];
[employee11 setValue:@"76 Cocoa Place, 74986 Coolville" forKey:@"address"];
NSManagedObject *employee12 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee12 setValue:@"Brett" forKey:@"firstName"];
[employee12 setValue:@"Sinclair" forKey:@"lastName"];
[employee12 setValue:[NSNumber numberWithInt:3000] forKey:@"salary"];
[employee12 setValue:@"[email protected]" forKey:@"email"];
[employee12 setValue:@"04 51 221" forKey:@"phone"];
[employee12 setValue:@"211 Salon Street, 40538 Fairyville" forKey:@"address"];
NSManagedObject *employee13 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee13 setValue:@"Britany" forKey:@"firstName"];
[employee13 setValue:@"Holder" forKey:@"lastName"];
[employee13 setValue:[NSNumber numberWithInt:3400] forKey:@"salary"];
[employee13 setValue:@"[email protected]" forKey:@"email"];
[employee13 setValue:@"01 23 432" forKey:@"phone"];
[employee13 setValue:@"21 Life Street, 03242 Aloa" forKey:@"address"];
NSManagedObject *employee14 = [[[NSManagedObject alloc] initWithEntity:employeeEntity insertIntoManagedObjectContext:context] autorelease];
[employee14 setValue:@"Angela" forKey:@"firstName"];
[employee14 setValue:@"Lucidi" forKey:@"lastName"];
[employee14 setValue:[NSNumber numberWithInt:3800] forKey:@"salary"];
[employee14 setValue:@"[email protected]" forKey:@"email"];
[employee14 setValue:@"04 87 336" forKey:@"phone"];
[employee14 setValue:@"9 Rich Street, 03242 Aloa" forKey:@"address"];
[employee1 setValue:employee2 forKey:@"manager"];
[employee1 setValue:department1 forKey:@"department"];
[employee2 setValue:department1 forKey:@"department"];
[employee3 setValue:employee2 forKey:@"manager"];
[employee3 setValue:department1 forKey:@"department"];
[employee4 setValue:employee2 forKey:@"manager"];
[employee4 setValue:department1 forKey:@"department"];
[employee5 setValue:employee2 forKey:@"manager"];
[employee5 setValue:department1 forKey:@"department"];
[employee6 setValue:department2 forKey:@"department"];
[employee7 setValue:employee6 forKey:@"manager"];
[employee7 setValue:department2 forKey:@"department"];
[employee8 setValue:employee6 forKey:@"manager"];
[employee8 setValue:department2 forKey:@"department"];
[employee9 setValue:employee6 forKey:@"manager"];
[employee9 setValue:department3 forKey:@"department"];
[employee10 setValue:department4 forKey:@"department"];
[employee11 setValue:employee10 forKey:@"manager"];
[employee11 setValue:department4 forKey:@"department"];
[employee12 setValue:employee11 forKey:@"manager"];
[employee12 setValue:department4 forKey:@"department"];
[employee13 setValue:employee2 forKey:@"manager"];
[employee13 setValue:department1 forKey:@"department"];
[employee14 setValue:employee11 forKey:@"manager"];
[employee14 setValue:department4 forKey:@"department"];
return employee1;
}
+(id)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
{
return nil;
}
+classFromString:(NSString *)string
{
return NSStringFromClass(NSClassFromString(string));
}
+stringFromClass:(Class)aClass
{
return @"haha";
}
+ (void) method1:(NSNumber **)p
{
// Replace the NSNumber referenced by p by a new NSNumber
// with a value that is the double of the original one.
*p = [NSNumber numberWithDouble:[*p doubleValue] * 2];
}
+ (id)november2005
{
return @"november 2005";
}
+ stringSelect:(NSArray *) strings
{
NSString *aString;
NSMutableArray *result = [NSMutableArray array];
NSEnumerator *stringEnumerator = [strings objectEnumerator];
while ((aString = [stringEnumerator nextObject]))
{
if ([aString length] < 10)
[result addObject:aString];
}
return result;
}
+ (id)testincr
{
NSInteger x,y;
x = 10;
y = 2 * (++x);
return [NSNumber numberWithInt:y];
}
+ (void) throwObject:(id)object
{
@throw object;
}
+ (void) throw
{
@throw @"ZZZZ";
}
+(NSInteger)throwNil
{
id object = @"yaa";
@try
{
NSLog(@"WillThrow");
@throw object;
NSLog(@"after throw !!!!");
}
@catch (id exception)
{
NSLog(@"Catch");
return 1;
}
NSLog(@"End");
return 22;
}
+(NSInteger)finally1
{
@try
{
@throw @"hello";
}
@finally
{
NSLog(@"finally");
}
return 88;
}
+(NSInteger)finally2
{
NSInteger i;
@try
{
i = 6+4;
}
@finally
{
NSLog(@"finally");
}
return 88;