Skip to content

Commit 2a45ff3

Browse files
author
Kirill Makankov
committed
1. Added tests to verify config files and config dictionaries.
2. Added empty .user-patterns and .user-words files to avoid error messages from tesseract.
1 parent 49d0d90 commit 2a45ff3

File tree

4 files changed

+129
-20
lines changed

4 files changed

+129
-20
lines changed

Tesseract-OCR-iOS.xcworkspace/xcshareddata/xcschemes/TestsProject.xcscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
BlueprintName = "TestsProjectTests"
6666
ReferencedContainer = "container:TestsProject/TestsProject.xcodeproj">
6767
</BuildableReference>
68+
<SkippedTests>
69+
<Test
70+
Identifier = "RecognitionTests">
71+
</Test>
72+
</SkippedTests>
6873
</TestableReference>
6974
</Testables>
7075
<MacroExpansion>

TestsProject/TestsProjectTests/InitializationTests.m

Lines changed: 124 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@
9393

9494
checkVariablesAreSetForTesseract(tesseract);
9595
});
96+
97+
it(@"config dictionary", ^{
98+
99+
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
100+
configDictionary:@{
101+
kG8ParamTessdataManagerDebugLevel : @"1",
102+
kG8ParamLoadSystemDawg : @"F",
103+
kG8ParamLoadFreqDawg : @"F",
104+
kG8ParamUserWordsSuffix : @"user-words",
105+
kG8ParamUserPatternsSuffix : @"user-patterns",
106+
}
107+
configFileNames:nil
108+
cachesRelatedDataPath:nil
109+
engineMode:G8OCREngineModeTesseractOnly];
110+
[[tesseract shouldNot] beNil];
111+
[[tesseract.absoluteDataPath should] equal:resourcePath];
112+
113+
checkVariablesAreSetForTesseract(tesseract);
114+
});
115+
116+
it(@"config dictionary and a file", ^{
117+
118+
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
119+
configDictionary:@{
120+
kG8ParamTessdataManagerDebugLevel : @"1",
121+
}
122+
configFileNames:@[recognitionConfigsFilePathFromTheBundle]
123+
cachesRelatedDataPath:nil
124+
engineMode:G8OCREngineModeTesseractOnly];
125+
[[tesseract shouldNot] beNil];
126+
[[tesseract.absoluteDataPath should] equal:resourcePath];
127+
128+
checkVariablesAreSetForTesseract(tesseract);
129+
});
96130
});
97131

98132
let(cashesPath, ^id{
@@ -133,31 +167,67 @@
133167
return @"tessdata";
134168
});
135169

136-
it(@"no tessdata folder in the Caches yet", ^{
137-
138-
// proof Caches folder is empty
139-
BOOL folderExists = [fileManager fileExistsAtPath:cachesTessDataPath];
140-
[[theValue(folderExists) should] equal:theValue(NO)];
141-
142-
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
143-
configDictionary:nil
144-
configFileNames:nil
145-
cachesRelatedDataPath:tessdataPath
146-
engineMode:G8OCREngineModeTesseractOnly];
147-
[[tesseract shouldNot] beNil];
148-
149-
[[tesseract.absoluteDataPath should] equal:cachesTessDataPath];
150-
151-
[[theValue(doFoldersContainTheSameElements()) should] equal:theValue(YES)];
152-
});
153-
154170
let(debugConfigsFilePathFromTheCaches, ^id{
155171
return [[[cachesTessDataPath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:debugConfigsFileName];
156172
});
157173
let(recognitionConfigsFilePathFromTheCaches, ^id{
158174
return [[[cachesTessDataPath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:recognitionConfigsFileName];
159175
});
160-
176+
177+
context(@"no tessdata folder in the Caches yet", ^{
178+
179+
it(@"simple init", ^{
180+
// proof Caches folder is empty
181+
BOOL folderExists = [fileManager fileExistsAtPath:cachesTessDataPath];
182+
[[theValue(folderExists) should] equal:theValue(NO)];
183+
184+
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
185+
configDictionary:nil
186+
configFileNames:nil
187+
cachesRelatedDataPath:tessdataPath
188+
engineMode:G8OCREngineModeTesseractOnly];
189+
[[tesseract shouldNot] beNil];
190+
191+
[[tesseract.absoluteDataPath should] equal:cachesTessDataPath];
192+
193+
[[theValue(doFoldersContainTheSameElements()) should] equal:theValue(YES)];
194+
});
195+
196+
it(@"config dictionary", ^{
197+
198+
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
199+
configDictionary:@{
200+
kG8ParamTessdataManagerDebugLevel : @"1",
201+
kG8ParamLoadSystemDawg : @"F",
202+
kG8ParamLoadFreqDawg : @"F",
203+
kG8ParamUserWordsSuffix : @"user-words",
204+
kG8ParamUserPatternsSuffix : @"user-patterns",
205+
}
206+
configFileNames:nil
207+
cachesRelatedDataPath:tessdataPath
208+
engineMode:G8OCREngineModeTesseractOnly];
209+
[[tesseract shouldNot] beNil];
210+
[[tesseract.absoluteDataPath should] equal:cachesTessDataPath];
211+
212+
checkVariablesAreSetForTesseract(tesseract);
213+
});
214+
215+
it(@"config dictionary and a file", ^{
216+
217+
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
218+
configDictionary:@{
219+
kG8ParamTessdataManagerDebugLevel : @"1",
220+
}
221+
configFileNames:@[recognitionConfigsFilePathFromTheCaches]
222+
cachesRelatedDataPath:tessdataPath
223+
engineMode:G8OCREngineModeTesseractOnly];
224+
[[tesseract shouldNot] beNil];
225+
[[tesseract.absoluteDataPath should] equal:cachesTessDataPath];
226+
227+
checkVariablesAreSetForTesseract(tesseract);
228+
});
229+
});
230+
161231
it(@"config file path, while there is no tessdata folder yet", ^{
162232

163233
NSLog(@"debugConfigsFilePathFromTheCaches: %@", debugConfigsFilePathFromTheCaches);
@@ -269,10 +339,44 @@
269339

270340
checkVariablesAreSetForTesseract(tesseract);
271341
});
342+
343+
it(@"config dictionary", ^{
344+
345+
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
346+
configDictionary:@{
347+
kG8ParamTessdataManagerDebugLevel : @"1",
348+
kG8ParamLoadSystemDawg : @"F",
349+
kG8ParamLoadFreqDawg : @"F",
350+
kG8ParamUserWordsSuffix : @"user-words",
351+
kG8ParamUserPatternsSuffix : @"user-patterns",
352+
}
353+
configFileNames:nil
354+
cachesRelatedDataPath:tessdataPath
355+
engineMode:G8OCREngineModeTesseractOnly];
356+
[[tesseract shouldNot] beNil];
357+
[[tesseract.absoluteDataPath should] equal:cachesTessDataPath];
358+
359+
checkVariablesAreSetForTesseract(tesseract);
360+
});
361+
362+
it(@"config dictionary and a file", ^{
363+
364+
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages
365+
configDictionary:@{
366+
kG8ParamTessdataManagerDebugLevel : @"1",
367+
}
368+
configFileNames:@[recognitionConfigsFilePathFromTheCaches]
369+
cachesRelatedDataPath:tessdataPath
370+
engineMode:G8OCREngineModeTesseractOnly];
371+
[[tesseract shouldNot] beNil];
372+
[[tesseract.absoluteDataPath should] equal:cachesTessDataPath];
373+
374+
checkVariablesAreSetForTesseract(tesseract);
375+
});
272376
});
273377

274378
afterEach(^{
275-
NSLog(@"Removing previous tessdata folder from Caches folder");
379+
//NSLog(@"Removing previous tessdata folder from Caches folder");
276380
NSError *error = nil;
277381
BOOL fileIsRemoved = [fileManager removeItemAtPath:cachesTessDataPath error:&error];
278382
[[theValue(fileIsRemoved) should] equal:theValue(YES)];

TestsProject/TestsProjectTests/tessdata/eng.user-patterns

Whitespace-only changes.

TestsProject/TestsProjectTests/tessdata/eng.user-words

Whitespace-only changes.

0 commit comments

Comments
 (0)