-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoverStoryCoverageDataTest.m
230 lines (209 loc) · 8.82 KB
/
CoverStoryCoverageDataTest.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
//
// CoverStoryCoverageDataTest.m
// CoverStory
//
// Created by Thomas Van Lenten on 6/19/08.
// Copyright 2008 Google Inc. All rights reserved.
//
#import "GTMSenTestCase.h"
#import "CoverStoryCoverageData.h"
@interface CoverStoryCoverageDataTest : SenTestCase
@end
@implementation CoverStoryCoverageDataTest
#pragma mark CoverStoryCoverageLineData
- (void)test1LineDataBasics {
struct TestDataRecord {
NSString *line;
NSInteger hitCount;
} testData[] = {
{ nil, 0 },
{ nil, 1 },
{ @"line", 0 },
{ @"line2", 10 },
{ @"line3", kCoverStoryNotExecutedMarker },
{ @"line4", kCoverStoryNonFeasibleMarker },
};
for (size_t x = 0; x < sizeof(testData)/sizeof(struct TestDataRecord); ++x) {
CoverStoryCoverageLineData *data =
[CoverStoryCoverageLineData coverageLineDataWithLine:testData[x].line
hitCount:testData[x].hitCount
coverageFile:nil];
STAssertNotNil(data, nil);
STAssertEqualObjects([data line], testData[x].line, @"index %u", x);
STAssertEquals([data hitCount], testData[x].hitCount, @"index %u", x);
STAssertGreaterThan([[data description] length], (NSUInteger)5, @"index %u", x);
}
}
- (void)test2LineDataAddHits {
struct TestDataRecord {
NSInteger hitCount1;
NSInteger hitCount2;
NSInteger hitCountSum;
} testData[] = {
{ 0, 0, 0 },
{ 0, 1, 1 },
{ 1, 0, 1 },
{ 1, 1, 2 },
{ 0, kCoverStoryNotExecutedMarker, 0 },
{ kCoverStoryNotExecutedMarker, 0, 0 },
{ kCoverStoryNotExecutedMarker, kCoverStoryNotExecutedMarker, kCoverStoryNotExecutedMarker },
{ 1, kCoverStoryNotExecutedMarker, 1 },
{ kCoverStoryNotExecutedMarker, 1, 1 },
{ kCoverStoryNonFeasibleMarker, kCoverStoryNonFeasibleMarker, kCoverStoryNonFeasibleMarker },
};
for (size_t x = 0; x < sizeof(testData)/sizeof(struct TestDataRecord); ++x) {
CoverStoryCoverageLineData *data =
[CoverStoryCoverageLineData coverageLineDataWithLine:@"line"
hitCount:testData[x].hitCount1
coverageFile:nil];
STAssertNotNil(data, nil);
[data addHits:testData[x].hitCount2];
STAssertEquals([data hitCount], testData[x].hitCountSum, @"index %u", x);
}
}
#pragma mark CoverStoryCoverageFileData
- (void)test3FileDataBasics {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
STAssertNotNil(testBundle, nil);
struct TestDataRecord {
NSString *name;
NSString *sourcePath;
NSInteger numberTotalLines;
NSInteger numberCodeLines;
NSInteger numberHitCodeLines;
NSInteger numberNonFeasibleLines;
float coverage;
} testData[] = {
{ @"Foo1a", @"Foo.m", 11, 8, 6, 0, 75.0f },
{ @"Foo1b", @"Foo.m", 11, 8, 6, 0, 75.0f },
{ @"Foo2", @"Bar.m", 15, 4, 2, 5, 50.0f },
{ @"Foo3", @"mcctest.c", 64, 18, 0, 0, 0.0f },
{ @"NoEndingNewline", @"Baz.m", 11, 8, 6, 0, 75.0f },
};
for (size_t x = 0; x < sizeof(testData)/sizeof(struct TestDataRecord); ++x) {
NSString *path = [testBundle pathForResource:testData[x].name
ofType:@"gcov"];
STAssertNotNil(path, @"index %u", x);
CoverStoryCoverageFileData *data =
[CoverStoryCoverageFileData coverageFileDataFromPath:path
document:nil
messageReceiver:nil];
STAssertNotNil(data, @"index %u", x);
STAssertEquals([[data lines] count],
(NSUInteger)testData[x].numberTotalLines,
@"index %u", x);
STAssertEqualObjects([data sourcePath],
testData[x].sourcePath,
@"index %u", x);
NSInteger totalLines = 0;
NSInteger codeLines = 0;
NSInteger hitCodeLines = 0;
NSInteger nonFeasible = 0;
NSString *coverageString = nil;
float coverage = 0.0f;
[data coverageTotalLines:&totalLines
codeLines:&codeLines
hitCodeLines:&hitCodeLines
nonFeasibleLines:&nonFeasible
coverageString:&coverageString
coverage:&coverage];
STAssertEquals(totalLines, testData[x].numberTotalLines, @"index %u", x);
STAssertEquals(codeLines, testData[x].numberCodeLines, @"index %u", x);
STAssertEquals(hitCodeLines, testData[x].numberHitCodeLines, @"index %u", x);
STAssertEquals(nonFeasible, testData[x].numberNonFeasibleLines, @"index %u", x);
STAssertEqualsWithAccuracy(coverage, testData[x].coverage, 0x001f, @"index %u", x);
STAssertNotNil(coverageString, @"index %u", x);
STAssertGreaterThan([[data description] length], (NSUInteger)5, @"index %u", x);
}
}
- (void)test4FileDataLineEndings {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
STAssertNotNil(testBundle, nil);
struct TestDataRecord {
NSString *name;
NSString *sourcePath;
NSInteger numberTotalLines;
NSInteger numberCodeLines;
NSInteger numberHitCodeLines;
NSInteger numberNonFeasibleLines;
float coverage;
} testData[] = {
{ @"testCR", @"Foo.m", 11, 8, 6, 0, 75.0f },
{ @"testLF", @"Foo.m", 11, 8, 6, 0, 75.0f },
{ @"testCRLF", @"Foo.m", 11, 8, 6, 0, 75.0f },
};
NSMutableSet *fileContentsSet = [NSMutableSet set];
STAssertNotNil(fileContentsSet, nil);
CoverStoryCoverageFileData *prevData = nil;
for (size_t x = 0; x < sizeof(testData)/sizeof(struct TestDataRecord); ++x) {
NSString *path = [testBundle pathForResource:testData[x].name
ofType:@"gcov"];
// load the file blob and store in a set to ensure they each have different
// byte sequences (due to the end of line markers they are using)
STAssertNotNil(path, @"index %u", x);
NSData *fileContents = [NSData dataWithContentsOfFile:path];
STAssertNotNil(fileContents, @"index %u", x);
[fileContentsSet addObject:fileContents];
STAssertEquals([fileContentsSet count], (NSUInteger)(x + 1),
@"failed to get a uniq file contents at index %u", x);
// now process the file
CoverStoryCoverageFileData *data =
[CoverStoryCoverageFileData coverageFileDataFromPath:path
document:nil
messageReceiver:nil];
STAssertNotNil(data, @"index %u", x);
STAssertEquals([[data lines] count],
(NSUInteger)testData[x].numberTotalLines,
@"index %u", x);
STAssertEqualObjects([data sourcePath],
testData[x].sourcePath,
@"index %u", x);
NSInteger totalLines = 0;
NSInteger codeLines = 0;
NSInteger hitCodeLines = 0;
NSInteger nonFeasible = 0;
NSString *coverageString = nil;
float coverage = 0.0f;
[data coverageTotalLines:&totalLines
codeLines:&codeLines
hitCodeLines:&hitCodeLines
nonFeasibleLines:&nonFeasible
coverageString:&coverageString
coverage:&coverage];
STAssertEquals(totalLines, testData[x].numberTotalLines, @"index %u", x);
STAssertEquals(codeLines, testData[x].numberCodeLines, @"index %u", x);
STAssertEquals(hitCodeLines, testData[x].numberHitCodeLines, @"index %u", x);
STAssertEquals(nonFeasible, testData[x].numberNonFeasibleLines, @"index %u", x);
STAssertEqualsWithAccuracy(coverage, testData[x].coverage, 0x001f, @"index %u", x);
STAssertNotNil(coverageString, @"index %u", x);
// compare this to the previous to make sure we got the same thing (the
// file all match except for newlines).
if (prevData) {
NSArray *prevDataLines = [prevData lines];
NSArray *dataLines = [data lines];
STAssertNotNil(prevDataLines, @"index %u", x);
STAssertNotNil(dataLines, @"index %u", x);
STAssertEquals([prevDataLines count], [dataLines count], @"index %u", x);
for (unsigned int y = 0 ; y < [dataLines count] ; ++y) {
CoverStoryCoverageLineData *prevDataLine = [prevDataLines objectAtIndex:y];
CoverStoryCoverageLineData *dataLine = [prevDataLines objectAtIndex:y];
STAssertNotNil(prevDataLine, @"index %u - %u", y, x);
STAssertNotNil(dataLine, @"index %u - %u", y, x);
STAssertEqualObjects([prevDataLine line], [dataLine line],
@"line contents didn't match at index %u - %u", y, x);
STAssertEquals([prevDataLine hitCount], [dataLine hitCount],
@"line hits didn't match at index %u - %u", y, x);
}
}
prevData = data;
}
}
- (void)test5FileDataAddFileData {
// TODO: write this one
// test each of the fail paths
// test that the working sum does as expected w/ NF, and non executable lines
// (ifdefs)
}
#pragma mark CoverStoryCoverageSet
// TODO: write these tests
@end