Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: class-dump/src/UnitTests/CDStructHandlingUnitTest.m

Issue 7793008: Add the 3.3.3 sources for class-dump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 "CDStructHandlingUnitTest.h"
5
6 #import <Foundation/Foundation.h>
7 #import "NSError-CDExtensions.h"
8
9 #import "CDClassDump.h"
10 #import "CDType.h"
11 #import "CDTypeFormatter.h"
12 #import "CDTypeParser.h"
13
14 @implementation CDStructHandlingUnitTest
15
16 - (void)dealloc;
17 {
18 [classDump release];
19
20 [super dealloc];
21 }
22
23 - (void)setUp;
24 {
25 classDump = [[CDClassDump alloc] init];
26 }
27
28 - (void)tearDown;
29 {
30 [classDump release];
31 classDump = nil;
32 }
33
34 - (void)testVariableName:(NSString *)aVariableName type:(NSString *)aType expect edResult:(NSString *)expectedResult;
35 {
36 NSString *result;
37
38 result = [[classDump ivarTypeFormatter] formatVariable:aVariableName type:aT ype symbolReferences:nil];
39 STAssertEqualObjects(expectedResult, result, @"");
40 }
41
42 - (void)registerStructsFromType:(NSString *)aTypeString phase:(int)phase;
43 {
44 CDTypeParser *parser;
45 CDType *type;
46 NSError *error;
47
48 parser = [[CDTypeParser alloc] initWithType:aTypeString];
49 type = [parser parseType:&error];
50 STAssertNotNil(type, @"-[CDTypeParser parseType:] error: %@", [error myExpla nation]);
51
52 [type phase:phase registerStructuresWithObject:classDump usedInMethod:NO];
53 [parser release];
54 }
55
56 // TODO (2004-01-05): Move this somewhere that we can share it with the main app .
57 - (void)testFilename:(NSString *)testFilename;
58 {
59 NSString *inputFilename, *outputFilename;
60 NSMutableString *resultString;
61 NSString *inputContents, *expectedOutputContents;
62 NSArray *inputLines, *inputFields;
63 int phase;
64 int count, index;
65 NSBundle *bundle;
66
67 //NSLog(@"***** %@", testFilename);
68
69 resultString = [NSMutableString string];
70
71 bundle = [NSBundle bundleForClass:[self class]];
72 inputFilename = [bundle pathForResource:[testFilename stringByAppendingStrin g:@"-in"] ofType:@"txt"];
73 outputFilename = [bundle pathForResource:[testFilename stringByAppendingStri ng:@"-out"] ofType:@"txt"];
74
75 inputContents = [NSString stringWithContentsOfFile:inputFilename];
76 expectedOutputContents = [NSString stringWithContentsOfFile:outputFilename];
77
78 inputLines = [inputContents componentsSeparatedByString:@"\n"];
79 count = [inputLines count];
80
81 // First register structs/unions
82 for (phase = 1; phase <= 2; phase++) {
83 //NSLog(@"Phase %d ========================================", phase);
84
85 for (index = 0; index < count; index++) {
86 NSString *line;
87
88 line = [inputLines objectAtIndex:index];
89 if ([line length] > 0 && [line hasPrefix:@"//"] == NO) {
90 inputFields = [line componentsSeparatedByString:@"\t"];
91 [self registerStructsFromType:[inputFields objectAtIndex:0] phas e:phase];
92 }
93 }
94
95 [classDump endPhase:phase];
96 }
97
98 // Then generate output
99 [classDump appendStructuresToString:resultString symbolReferences:nil];
100
101 for (index = 0; index < count; index++) {
102 NSString *line;
103 NSString *type, *variableName;
104
105 line = [inputLines objectAtIndex:index];
106 if ([line length] > 0 && [line hasPrefix:@"//"] == NO) {
107 int fieldCount, level;
108 NSString *formattedString;
109
110 inputFields = [line componentsSeparatedByString:@"\t"];
111 fieldCount = [inputFields count];
112 type = [inputFields objectAtIndex:0];
113 if (fieldCount > 1)
114 variableName = [inputFields objectAtIndex:1];
115 else
116 variableName = @"var";
117
118 if (fieldCount > 2)
119 level = [[inputFields objectAtIndex:2] intValue];
120 else
121 level = 0;
122
123 formattedString = [[classDump ivarTypeFormatter] formatVariable:vari ableName type:type symbolReferences:nil];
124 if (formattedString != nil) {
125 [resultString appendString:formattedString];
126 [resultString appendString:@";\n"];
127 } else {
128 [resultString appendString:@"Parse failed.\n"];
129 }
130 }
131 }
132
133 STAssertEqualObjects(expectedOutputContents, resultString, @"test file: %@", testFilename);
134 }
135
136 #if 1
137 - (void)test01;
138 {
139 NSString *first = @"{_NSRange=II}";
140 int phase;
141
142 STAssertNotNil(classDump, @"classDump");
143 STAssertNotNil([classDump ivarTypeFormatter], @"[classDump ivarTypeFormatter ]");
144
145 for (phase = 1; phase <= 2; phase++)
146 [self registerStructsFromType:first phase:phase];
147 [self testVariableName:@"foo" type:first expectedResult:@" struct _NSRang e foo"];
148
149 // Register {_NSRange=II}
150 // Test {_NSRange=II}
151 }
152
153 - (void)test02;
154 {
155 NSString *first = @"{_NSRange=II}";
156 NSString *second = @"{_NSRange=\"location\"I\"length\"I}";
157 int phase;
158
159 for (phase = 1; phase <= 2; phase++) {
160 [self registerStructsFromType:first phase:phase];
161 [self registerStructsFromType:second phase:phase];
162 }
163
164 [self testVariableName:@"foo" type:first expectedResult:@" struct _NSRang e foo"];
165 [self testVariableName:@"bar" type:second expectedResult:@" struct _NSRan ge bar"];
166
167 // Register {_NSRange=II}
168 // Register {_NSRange="location"I"length"I}
169 // Test {_NSRange=II}
170 // Test {_NSRange="location"I"length"I}
171 }
172
173 - (void)test03;
174 {
175 NSString *first = @"{_NSRange=\"location\"I\"length\"I}";
176 NSString *second = @"{_NSRange=II}";
177 int phase;
178
179 for (phase = 1; phase <= 2; phase++) {
180 [self registerStructsFromType:first phase:phase];
181 [self registerStructsFromType:second phase:phase];
182 }
183
184 [self testVariableName:@"foo" type:first expectedResult:@" struct _NSRang e foo"];
185 [self testVariableName:@"bar" type:second expectedResult:@" struct _NSRan ge bar"];
186
187 // Register {_NSRange="location"I"length"I}
188 // Register {_NSRange=II}
189 // Test {_NSRange="location"I"length"I}
190 // Test {_NSRange=II}
191 }
192
193 - (void)test04;
194 {
195 // I'm guessing that "shud" could stand for Struct Handling Unittest Data.
196 [self testFilename:@"shud01"];
197 }
198
199 - (void)test05;
200 {
201 [self testFilename:@"shud02"];
202 }
203
204 - (void)test06;
205 {
206 //[self testFilename:@"shud03"];
207 }
208
209 - (void)test07;
210 {
211 [self testFilename:@"shud04"];
212 }
213
214 - (void)test08;
215 {
216 [self testFilename:@"shud05"];
217 }
218
219 - (void)test09;
220 {
221 [self testFilename:@"shud06"];
222 }
223
224 - (void)test10;
225 {
226 [self testFilename:@"shud07"];
227 }
228
229 - (void)test11;
230 {
231 [self testFilename:@"shud08"];
232 }
233
234 - (void)test12;
235 {
236 [self testFilename:@"shud09"];
237 }
238
239 - (void)test13;
240 {
241 [self testFilename:@"shud10"];
242 }
243
244 - (void)test14;
245 {
246 [self testFilename:@"shud11"];
247 }
248 #endif
249
250 - (void)test15;
251 {
252 [self testFilename:@"shud13"];
253 }
254
255 - (void)test16;
256 {
257 //[self testFilename:@"shud14"];
258 }
259
260 // This tests the new code for dealing with named objects and field names in str uctures.
261 - (void)test17;
262 {
263 [self testFilename:@"shud15"];
264 }
265
266 - (void)test18;
267 {
268 [self testFilename:@"shud16"];
269 }
270
271 @end
OLDNEW
« no previous file with comments | « class-dump/src/UnitTests/CDStructHandlingUnitTest.h ('k') | class-dump/src/UnitTests/CDTypeFormatterUnitTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698