Skip to content

Commit d709799

Browse files
committed
Merge pull request #117 from BamX/fix-tests-speed
Reduced time it takes for tests to complete and added some other minor docs/fixes.
2 parents 5482c04 + 149575a commit d709799

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

Products/TesseractOCR.framework/Versions/A/Headers/G8Tesseract.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
*/
2525
+ (NSString *)version;
2626

27+
/**
28+
* Clear any library-level memory caches.
29+
* There are a variety of expensive-to-load constant data structures (mostly
30+
* language dictionaries) that are cached globally. This function allows the
31+
* clearing of these caches.
32+
*/
2733
+ (void)clearCache;
2834

2935
/**

TesseractOCR/G8Tesseract.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
*/
2525
+ (NSString *)version;
2626

27+
/**
28+
* Clear any library-level memory caches.
29+
* There are a variety of expensive-to-load constant data structures (mostly
30+
* language dictionaries) that are cached globally. This function allows the
31+
* clearing of these caches.
32+
*/
2733
+ (void)clearCache;
2834

2935
/**

TestsProject/TestsProjectTests/RecognitionTests.m

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,7 @@
8484
tesseract.sourceResolution = sourceResolution;
8585
}
8686

87-
__block BOOL isDone = NO;
88-
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
89-
[tesseract recognize];
90-
isDone = YES;
91-
});
92-
93-
wait(maxExpectedRecognitionTime, ^{
94-
return (BOOL)(isDone == NO);
95-
});
96-
97-
if (isDone == NO) {
98-
[NSException raise:@"Tesseract stopped" format:@"Tesseract worked too long"];
99-
}
87+
[tesseract recognize];
10088
};
10189

10290
void (^recognizeImageUsingOperation)() = ^{
@@ -147,13 +135,17 @@
147135
it(@"Should recognize sync", ^{
148136
[[theBlock(recognizeImage) shouldNot] raise];
149137

138+
[[theValue(tesseract.progress) should] equal:theValue(100)];
139+
150140
NSString *recognizedText = tesseract.recognizedText;
151141
[[recognizedText should] containString:@"1234567890"];
152142
});
153143

154144
it(@"Should recognize by queue", ^{
155145
[[theBlock(recognizeImageUsingOperation) shouldNot] raise];
156146

147+
[[theValue(tesseract.progress) should] equal:theValue(100)];
148+
157149
NSString *recognizedText = tesseract.recognizedText;
158150
[[recognizedText should] containString:@"1234567890"];
159151
});
@@ -231,7 +223,7 @@
231223
});
232224

233225
it(@"Should draw blocks on image", ^{
234-
[[theBlock(recognizeImageUsingOperation) shouldNot] raise];
226+
[[theBlock(recognizeImage) shouldNot] raise];
235227

236228
NSArray *blocks = [tesseract confidencesByIteratorLevel:G8PageIteratorLevelSymbol];
237229
UIImage *blocksImage = [tesseract imageWithBlocks:blocks drawText:YES thresholded:NO];
@@ -289,6 +281,9 @@
289281

290282
describe(@"Well scaned page", ^{
291283

284+
static NSString *const kG8WellScanedFirstTitle = @"Foreword";
285+
static NSString *const kG8WellScanedFinalLongString = @"recommendations sometimes get acted on";
286+
292287
beforeEach(^{
293288
image = [UIImage imageNamed:@"well_scaned_page"];
294289
rect = (CGRect){CGPointZero, image.size};
@@ -297,8 +292,12 @@
297292
it(@"Should recognize", ^{
298293
[[theBlock(recognizeImage) shouldNot] raise];
299294

295+
[[theValue(tesseract.progress) should] equal:theValue(100)];
296+
300297
NSString *recognizedText = tesseract.recognizedText;
301-
[[recognizedText should] containString:@"Foreword"];
298+
[[recognizedText should] containString:kG8WellScanedFirstTitle];
299+
[[recognizedText should] containString:kG8WellScanedFinalLongString];
300+
302301
[[recognizedText should] containString:@"Division"];
303302
[[recognizedText should] containString:@"remove"];
304303
[[recognizedText should] containString:@"1954"];
@@ -314,7 +313,7 @@
314313
it(@"Should analyze layout", ^{
315314
pageSegmentationMode = G8PageSegmentationModeAutoOSD;
316315

317-
[[theBlock(recognizeImageUsingOperation) shouldNot] raise];
316+
[[theBlock(recognizeImage) shouldNot] raise];
318317

319318
CGFloat deskewAngle = tesseract.deskewAngle;
320319
[[theValue(ABS(deskewAngle)) should] beGreaterThan:theValue(FLT_EPSILON)];
@@ -325,14 +324,16 @@
325324
});
326325

327326
it(@"Should break by deadline", ^{
328-
waitDeadline = 2.0;
327+
waitDeadline = 1.0;
329328

330329
[[theBlock(recognizeImageUsingOperation) shouldNot] raise];
331330

332331
[[tesseract shouldNot] beNil];
332+
[[theValue(tesseract.progress) should] beLessThan:theValue(100)];
333+
333334
NSString *recognizedText = tesseract.recognizedText;
334-
[[recognizedText should] containString:@"Foreword"];
335-
[[recognizedText shouldNot] containString:@"Mathematcs"];
335+
[[recognizedText should] containString:kG8WellScanedFirstTitle];
336+
[[recognizedText shouldNot] containString:kG8WellScanedFinalLongString];
336337
[[[[tesseract confidencesByIteratorLevel:G8PageIteratorLevelWord] should] haveAtLeast:10] items];
337338
});
338339

0 commit comments

Comments
 (0)