|
16 | 16 |
|
17 | 17 | describe(@"Tesseract initialization", ^{ |
18 | 18 |
|
19 | | - let(fileManager, ^id{ |
20 | | - return [NSFileManager defaultManager]; |
21 | | - }); |
22 | | - |
23 | | - let(resourcePath, ^id{ |
24 | | - return [[NSBundle bundleForClass:G8Tesseract.class].resourcePath stringByAppendingString:@"/"]; |
25 | | - }); |
26 | | - |
27 | | - let(tessdataFolderName, ^id{ |
28 | | - return @"tessdata"; |
29 | | - }); |
30 | | - |
31 | | - let(tessdataFolderPathFromTheBundle, ^id{ |
32 | | - return [[resourcePath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingString:@"/"]; |
33 | | - }); |
34 | | - |
35 | | - let(debugConfigsFileName, ^id{ |
36 | | - return @"debugConfigs.txt"; |
37 | | - }); |
38 | | - |
39 | | - let(recognitionConfigsFileName, ^id{ |
40 | | - return @"recognitionConfis.txt"; |
41 | | - }); |
42 | | - |
43 | | - let(tessConfigsFolderName, ^id{ |
44 | | - return @"tessconfigs"; |
45 | | - }); |
| 19 | + NSFileManager *fileManager = [NSFileManager defaultManager]; |
| 20 | + NSString *resourcePath = [[NSBundle bundleForClass:G8Tesseract.class].resourcePath stringByAppendingString:@"/"]; |
| 21 | + NSString *tessdataFolderName = @"tessdata"; |
| 22 | + NSString *tessdataFolderPathFromTheBundle = [[resourcePath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingString:@"/"]; |
| 23 | + NSString *debugConfigsFileName = @"debugConfigs.txt"; |
| 24 | + NSString *recognitionConfigsFileName = @"recognitionConfis.txt"; |
| 25 | + NSString *tessConfigsFolderName = @"tessconfigs"; |
46 | 26 |
|
47 | 27 | void (^checkVariablesAreSetForTesseract)(G8Tesseract *tesseract) = ^(G8Tesseract *tesseract){ |
48 | 28 | [[[tesseract variableValueForKey:kG8ParamTessdataManagerDebugLevel] should] equal:@"1"]; |
|
52 | 32 | [[[tesseract variableValueForKey:kG8ParamUserPatternsSuffix] should] equal:@"user-patterns"]; |
53 | 33 | }; |
54 | 34 |
|
55 | | - context(@"nil dataPath", ^{ |
| 35 | + context(@"nil cachesRelatedDataPath", ^{ |
56 | 36 |
|
57 | | - it(@"simple", ^{ |
| 37 | + it(@"Should initialize simple", ^{ |
58 | 38 | [[fileManager shouldNot] receive:@selector(createSymbolicLinkAtPath:withDestinationPath:error:)]; |
59 | 39 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages]; |
60 | 40 | [[tesseract shouldNot] beNil]; |
61 | 41 |
|
62 | 42 | [[tesseract.absoluteDataPath should] equal:resourcePath]; |
63 | 43 | }); |
64 | 44 |
|
65 | | - let(debugConfigsFilePathFromTheBundle, ^id{ |
66 | | - return [[tessdataFolderPathFromTheBundle stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:debugConfigsFileName]; |
67 | | - }); |
| 45 | + NSString *debugConfigsFilePathFromTheBundle = [[tessdataFolderPathFromTheBundle stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:debugConfigsFileName]; |
| 46 | + NSString *recognitionConfigsFilePathFromTheBundle = [[tessdataFolderPathFromTheBundle stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:recognitionConfigsFileName]; |
68 | 47 |
|
69 | | - let(recognitionConfigsFilePathFromTheBundle, ^id{ |
70 | | - return [[tessdataFolderPathFromTheBundle stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:recognitionConfigsFileName]; |
71 | | - }); |
72 | | - |
73 | | - it(@"config file path", ^{ |
| 48 | + it(@"Should initialize with config file path", ^{ |
74 | 49 | [[theBlock(^{ |
75 | 50 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
76 | 51 | configDictionary:nil |
77 | | - configFileNames:debugConfigsFilePathFromTheBundle |
| 52 | + configFileNames:(NSArray*)debugConfigsFilePathFromTheBundle |
78 | 53 | cachesRelatedDataPath:nil |
79 | 54 | engineMode:G8OCREngineModeTesseractOnly]; |
80 | 55 | [tesseract recognize]; |
81 | 56 | }) should] raise]; |
82 | 57 |
|
83 | | - [[theValue([fileManager fileExistsAtPath:debugConfigsFilePathFromTheBundle]) should] equal:theValue(YES)]; |
84 | | - [[theValue([fileManager fileExistsAtPath:recognitionConfigsFilePathFromTheBundle]) should] equal:theValue(YES)]; |
| 58 | + [[theValue([fileManager fileExistsAtPath:debugConfigsFilePathFromTheBundle]) should] beYes]; |
| 59 | + [[theValue([fileManager fileExistsAtPath:recognitionConfigsFilePathFromTheBundle]) should] beYes]; |
85 | 60 |
|
86 | 61 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
87 | 62 | configDictionary:nil |
|
94 | 69 | checkVariablesAreSetForTesseract(tesseract); |
95 | 70 | }); |
96 | 71 |
|
97 | | - it(@"config dictionary", ^{ |
| 72 | + it(@"Should initialize with config dictionary", ^{ |
98 | 73 |
|
99 | 74 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
100 | 75 | configDictionary:@{ |
|
113 | 88 | checkVariablesAreSetForTesseract(tesseract); |
114 | 89 | }); |
115 | 90 |
|
116 | | - it(@"config dictionary and a file", ^{ |
| 91 | + it(@"Should initialize with config dictionary and a file", ^{ |
117 | 92 |
|
118 | 93 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
119 | 94 | configDictionary:@{ |
|
129 | 104 | }); |
130 | 105 | }); |
131 | 106 |
|
132 | | - let(cashesPath, ^id{ |
133 | | - NSArray *cachesPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); |
134 | | - NSString *cachesPath = cachesPaths.firstObject; |
135 | | - return cachesPath; |
136 | | - }); |
137 | | - |
138 | | - let(tessdataPath, ^id{ |
139 | | - return @"foo/bar"; |
140 | | - }); |
141 | | - |
142 | | - let(cachesTessDataPath, ^id{ |
143 | | - return [cashesPath stringByAppendingPathComponent:tessdataPath]; |
144 | | - }); |
| 107 | + NSArray *cachesPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); |
| 108 | + NSString *cachesPath = cachesPaths.firstObject; |
| 109 | + NSString *tessdataPath = @"foo/bar"; |
| 110 | + NSString *cachesTessDataPath = [cachesPath stringByAppendingPathComponent:tessdataPath]; |
145 | 111 |
|
146 | | - context(@"not nil dataPath", ^{ |
| 112 | + context(@"not nil cachesRelatedDataPath", ^{ |
147 | 113 |
|
148 | 114 | // helper |
149 | 115 | BOOL (^doFoldersContainTheSameElements)(void) = ^(void){ |
|
163 | 129 | return [contentsOfTheTessdataPathFolder isEqualToArray:contentsOfTessdataFromTheBundle]; |
164 | 130 | }; |
165 | 131 |
|
166 | | - let(tessdataFolderName, ^id{ |
167 | | - return @"tessdata"; |
168 | | - }); |
169 | | - |
170 | | - let(debugConfigsFilePathFromTheCaches, ^id{ |
171 | | - return [[[cachesTessDataPath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:debugConfigsFileName]; |
172 | | - }); |
173 | | - let(recognitionConfigsFilePathFromTheCaches, ^id{ |
174 | | - return [[[cachesTessDataPath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:recognitionConfigsFileName]; |
175 | | - }); |
176 | | - |
| 132 | + NSString *debugConfigsFilePathFromTheCaches = [[[cachesTessDataPath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:debugConfigsFileName]; |
| 133 | + NSString *recognitionConfigsFilePathFromTheCaches = [[[cachesTessDataPath stringByAppendingPathComponent:tessdataFolderName] stringByAppendingPathComponent:tessConfigsFolderName] stringByAppendingPathComponent:recognitionConfigsFileName]; |
| 134 | + |
177 | 135 | context(@"no tessdata folder in the Caches yet", ^{ |
178 | 136 |
|
179 | | - it(@"simple init", ^{ |
| 137 | + it(@"Should simple init", ^{ |
180 | 138 | // proof Caches folder is empty |
181 | 139 | BOOL folderExists = [fileManager fileExistsAtPath:cachesTessDataPath]; |
182 | | - [[theValue(folderExists) should] equal:theValue(NO)]; |
| 140 | + [[theValue(folderExists) should] beNo]; |
183 | 141 |
|
184 | 142 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
185 | 143 | configDictionary:nil |
|
190 | 148 |
|
191 | 149 | [[tesseract.absoluteDataPath should] equal:cachesTessDataPath]; |
192 | 150 |
|
193 | | - [[theValue(doFoldersContainTheSameElements()) should] equal:theValue(YES)]; |
| 151 | + [[theValue(doFoldersContainTheSameElements()) should] beYes]; |
194 | 152 | }); |
195 | 153 |
|
196 | | - it(@"config dictionary", ^{ |
| 154 | + it(@"Should initialize with config dictionary", ^{ |
197 | 155 |
|
198 | 156 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
199 | 157 | configDictionary:@{ |
|
212 | 170 | checkVariablesAreSetForTesseract(tesseract); |
213 | 171 | }); |
214 | 172 |
|
215 | | - it(@"config dictionary and a file", ^{ |
| 173 | + it(@"Should initialize config dictionary and a file", ^{ |
216 | 174 |
|
217 | 175 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
218 | 176 | configDictionary:@{ |
|
228 | 186 | }); |
229 | 187 | }); |
230 | 188 |
|
231 | | - it(@"config file path, while there is no tessdata folder yet", ^{ |
| 189 | + it(@"Should initialize with config file path, while there is no tessdata folder yet", ^{ |
232 | 190 |
|
233 | 191 | NSLog(@"debugConfigsFilePathFromTheCaches: %@", debugConfigsFilePathFromTheCaches); |
234 | 192 | NSLog(@"recognitionConfigsFilePathFromTheCaches: %@", recognitionConfigsFilePathFromTheCaches); |
|
255 | 213 |
|
256 | 214 | // Useful paths |
257 | 215 | NSString *tessdataSourcePath = [resourcePath stringByAppendingPathComponent:tessdataFolderName]; |
258 | | - NSString *destinationPath = [[cashesPath stringByAppendingPathComponent:dataPath] stringByAppendingPathComponent:tessdataFolderName]; |
| 216 | + NSString *destinationPath = [[cachesPath stringByAppendingPathComponent:dataPath] stringByAppendingPathComponent:tessdataFolderName]; |
259 | 217 |
|
260 | 218 | if ([fileManager fileExistsAtPath:destinationPath] == NO) { |
261 | 219 | NSError *error = nil; |
|
301 | 259 | beforeEach(^{ |
302 | 260 | // copy files to the Caches dir first |
303 | 261 | BOOL res = moveTessdataToCachesDirectoryIfNecessary(tessdataPath); |
304 | | - [[theValue(res) should] equal:theValue(YES)]; |
| 262 | + NSAssert(res == YES, @"Error copying tessadata from the bundle to the Caches folder"); |
305 | 263 |
|
306 | | - [[theValue(doFoldersContainTheSameElements()) should] equal:theValue(YES)]; |
| 264 | + [[theValue(doFoldersContainTheSameElements()) should] beYes]; |
307 | 265 | }); |
308 | 266 |
|
309 | | - it(@"no configs", ^{ |
| 267 | + it(@"Should initialize with no configs", ^{ |
310 | 268 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
311 | 269 | configDictionary:nil |
312 | 270 | configFileNames:nil |
|
317 | 275 | }); |
318 | 276 |
|
319 | 277 |
|
320 | | - it(@"config file path", ^{ |
| 278 | + it(@"Should initialize with config file path", ^{ |
321 | 279 |
|
322 | 280 | NSError *error = nil; |
323 | 281 | [[[fileManager attributesOfItemAtPath:debugConfigsFilePathFromTheCaches error:&error] shouldNot] beNil]; |
|
340 | 298 | checkVariablesAreSetForTesseract(tesseract); |
341 | 299 | }); |
342 | 300 |
|
343 | | - it(@"config dictionary", ^{ |
| 301 | + it(@"Should initialize with config dictionary", ^{ |
344 | 302 |
|
345 | 303 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
346 | 304 | configDictionary:@{ |
|
359 | 317 | checkVariablesAreSetForTesseract(tesseract); |
360 | 318 | }); |
361 | 319 |
|
362 | | - it(@"config dictionary and a file", ^{ |
| 320 | + it(@"Should initialize with config dictionary and a file", ^{ |
363 | 321 |
|
364 | 322 | G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:kG8Languages |
365 | 323 | configDictionary:@{ |
|
379 | 337 | //NSLog(@"Removing previous tessdata folder from Caches folder"); |
380 | 338 | NSError *error = nil; |
381 | 339 | BOOL fileIsRemoved = [fileManager removeItemAtPath:cachesTessDataPath error:&error]; |
382 | | - [[theValue(fileIsRemoved) should] equal:theValue(YES)]; |
383 | 340 | if (error != nil) { |
384 | 341 | NSLog(@"Error deleting tessdata folder from the Caches folder: %@", error); |
385 | 342 | } |
| 343 | + NSAssert(fileIsRemoved == YES, @"Error cleaning tessdata from the Caches folder"); |
386 | 344 |
|
387 | 345 | // check tessdata folder was deleted |
388 | | - NSArray *cachesContent = [fileManager contentsOfDirectoryAtPath:cashesPath error:&error]; |
389 | | - [[cachesContent shouldNot] contain:tessdataPath]; |
| 346 | + NSArray *cachesContent = [fileManager contentsOfDirectoryAtPath:cachesPath error:&error]; |
390 | 347 | if (error != nil) { |
391 | 348 | NSLog(@"Error getting the contents of the Caches folder: %@", error); |
392 | 349 | } |
| 350 | + NSAssert([cachesContent containsObject:tessdataPath] == NO, @"Assert! Tessdata path was not removed from the Caches folder"); |
393 | 351 | }); |
394 | 352 | }); |
395 | 353 | }); |
|
0 commit comments