OLD | NEW |
(Empty) | |
| 1 // This file is part of class-dump, a utility for examining the Objective-C seg
ment of Mach-O files. |
| 2 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard. |
| 3 |
| 4 #import "CDTypeParserUnitTest.h" |
| 5 |
| 6 #import <Foundation/Foundation.h> |
| 7 #import "NSError-CDExtensions.h" |
| 8 |
| 9 #import "CDType.h" |
| 10 #import "CDTypeLexer.h" |
| 11 #import "CDTypeParser.h" |
| 12 |
| 13 @implementation CDTypeParserUnitTest |
| 14 |
| 15 - (void)setUp; |
| 16 { |
| 17 } |
| 18 |
| 19 - (void)tearDown; |
| 20 { |
| 21 } |
| 22 |
| 23 - (void)testType:(NSString *)aType showLexing:(BOOL)shouldShowLexing; |
| 24 { |
| 25 CDTypeParser *aTypeParser; |
| 26 CDType *result; |
| 27 NSError *error; |
| 28 |
| 29 if (shouldShowLexing) { |
| 30 NSLog(@"----------------------------------------"); |
| 31 NSLog(@"str: %@", aType); |
| 32 } |
| 33 |
| 34 aTypeParser = [[CDTypeParser alloc] initWithType:aType]; |
| 35 [[aTypeParser lexer] setShouldShowLexing:shouldShowLexing]; |
| 36 result = [aTypeParser parseType:&error]; |
| 37 STAssertNotNil(result, @"-[CDTypeParser parseType:] error: %@", [error myExp
lanation]); |
| 38 [aTypeParser release]; |
| 39 } |
| 40 |
| 41 - (void)testMethodType:(NSString *)aMethodType showLexing:(BOOL)shouldShowLexing
; |
| 42 { |
| 43 CDTypeParser *aTypeParser; |
| 44 NSArray *result; |
| 45 NSError *error; |
| 46 |
| 47 aTypeParser = [[CDTypeParser alloc] initWithType:aMethodType]; |
| 48 [[aTypeParser lexer] setShouldShowLexing:shouldShowLexing]; |
| 49 result = [aTypeParser parseMethodType:&error]; |
| 50 STAssertNotNil(result, @"-[CDTypeParser parseMethodType:] error: %@", [error
myExplanation]); |
| 51 [aTypeParser release]; |
| 52 } |
| 53 |
| 54 - (void)testLoneConstType; |
| 55 { |
| 56 // On Panther, from WebCore, -[KWQPageState |
| 57 // initWithDocument:URL:windowProperties:locationProperties:interpreterBuilt
ins:] |
| 58 // has part of a method type as "r12". "r" is const, but it doesn't modify
anything. |
| 59 |
| 60 [self testMethodType:@"ri12i16" showLexing:NO]; // This works |
| 61 [self testMethodType:@"r12i16" showLexing:NO]; // This didn't work. |
| 62 } |
| 63 |
| 64 // Field names: |
| 65 // {?="field1"^@"NSObject"} -- end of struct, use quoted string |
| 66 // {?="field1"^@"NSObject""field2"@} -- followed by field, use quoted string |
| 67 // {?="field1"^@"field2"^@} -- quoted string is followed by type, don't use quot
ed string for object |
| 68 |
| 69 // No field names -- always use the quoted string |
| 70 // {?=^@"NSObject"} |
| 71 // {?=^@"NSObject"^@"NSObject"} |
| 72 |
| 73 - (void)testObjectQuotedStringTypes; |
| 74 { |
| 75 NSString *str; |
| 76 |
| 77 str = @"{?=\"field1\"^@\"NSObject\"}"; |
| 78 [self testType:str showLexing:NO]; |
| 79 |
| 80 str = @"{?=\"field1\"^@\"NSObject\"\"field2\"@}"; |
| 81 [self testType:str showLexing:NO]; |
| 82 |
| 83 str = @"{?=\"field1\"^@\"field2\"^@}"; |
| 84 [self testType:str showLexing:NO]; |
| 85 |
| 86 str = @"{?=^@\"NSObject\"}"; |
| 87 [self testType:str showLexing:NO]; |
| 88 |
| 89 str = @"{?=^@\"NSObject\"^@\"NSObject\"}"; |
| 90 [self testType:str showLexing:NO]; |
| 91 } |
| 92 |
| 93 - (void)testMissingFieldNames; |
| 94 { |
| 95 NSString *str; |
| 96 |
| 97 str = @"{?=b8b4b1b1b18\"_field1\"[8S]}"; |
| 98 [self testType:str showLexing:NO]; |
| 99 } |
| 100 |
| 101 - (void)testLowercaseClassName; |
| 102 { |
| 103 NSString *str; |
| 104 |
| 105 str = @"@\"iToolsAccount\""; |
| 106 [self testType:str showLexing:NO]; |
| 107 } |
| 108 |
| 109 - (void)testLowercaseClassName2; |
| 110 { |
| 111 NSString *str; |
| 112 |
| 113 str = @"{?=@\"iToolsAccount\"}"; |
| 114 [self testType:str showLexing:NO]; |
| 115 } |
| 116 |
| 117 - (void)testPages08; |
| 118 { |
| 119 // Pages '08 has this bit in it: {vector<<unnamed>::AnimationChunk,std::allo
cator<<unnamed>::AnimationChunk> >=II} |
| 120 |
| 121 [self testType:@"{unnamed=II}" showLexing:NO]; |
| 122 [self testType:@"{vector<unnamed>=II}" showLexing:NO]; |
| 123 [self testType:@"{vector<unnamed::blegga>=II}" showLexing:NO]; |
| 124 [self testType:@"{vector<<unnamed>::blegga>=II}" showLexing:NO]; |
| 125 [self testType:@"{vector<<unnamed>::AnimationChunk>=II}" showLexing:NO]; |
| 126 [self testType:@"{vector<<unnamed>::AnimationChunk>=II}" showLexing:NO]; |
| 127 [self testType:@"{vector<<unnamed>::AnimationChunk,std::allocator<<unnamed>:
:AnimationChunk> >=II}" showLexing:NO]; |
| 128 } |
| 129 |
| 130 @end |
OLD | NEW |