Coverage Report

Created: 2017-11-12 13:27

/home/liu/buildslave/linux-x64-runtests/build/test/unit/io.tests.c
Line
Count
Source
1
#include "ccv.h"
2
#include "case.h"
3
#include "ccv_case.h"
4
5
TEST_CASE("read raw memory, rgb => gray")
6
1
{
7
1
  unsigned char rgb[] = {
8
1
    10, 20, 30, 40, 50, 60, 70,
9
1
    80, 90, 15, 25, 35, 45, 55,
10
1
  };
11
1
  ccv_dense_matrix_t* x = 0;
12
1
  ccv_read(rgb, &x, CCV_IO_RGB_RAW | CCV_IO_GRAY, 2, 2, 7);
13
1
  unsigned char hx1[] = {
14
1
    18, 48,
15
1
  };
16
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 2, "1st row when reading raw rgb ordered memory block into grayscale matrix doesn't match")
;1
17
1
  unsigned char hx2[] = {
18
1
    82, 33,
19
1
  };
20
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 2, "2nd row when reading raw rgb ordered memory block into grayscale matrix doesn't match")
;1
21
1
  ccv_matrix_free(x);
22
1
}
23
24
TEST_CASE("read raw memory, rgb => rgb")
25
1
{
26
1
  unsigned char rgb[] = {
27
1
    10, 20, 30, 40, 50, 60, 70,
28
1
    80, 90, 15, 25, 35, 45, 55,
29
1
  };
30
1
  ccv_dense_matrix_t* x = 0;
31
1
  ccv_read(rgb, &x, CCV_IO_RGB_RAW | CCV_IO_RGB_COLOR, 2, 2, 7);
32
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, rgb, x->data.u8, 6, "1st row when reading raw rgb ordered memory block into rgb matrix doesn't match")
;1
33
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, rgb + 7, x->data.u8 + x->step, 6, "2nd row when reading raw rgb ordered memory block into rgb matrix doesn't match")
;1
34
1
  ccv_matrix_free(x);
35
1
}
36
37
TEST_CASE("read raw memory, rgba => rgb")
38
1
{
39
1
  unsigned char rgba[] = {
40
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
41
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
42
1
  };
43
1
  ccv_dense_matrix_t* x = 0;
44
1
  ccv_read(rgba, &x, CCV_IO_RGBA_RAW | CCV_IO_RGB_COLOR, 2, 2, 9);
45
1
  unsigned char hx1[] = {
46
1
    10, 20, 30, 50, 60, 70,
47
1
  };
48
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 6, "1st row when reading raw rgba memory block into rgb matrix doesn't match")
;1
49
1
  unsigned char hx2[] = {
50
1
    15, 25, 35, 55, 65, 75,
51
1
  };
52
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 6, "2nd row when reading raw rgba memory block into rgb matrix doesn't match")
;1
53
1
  ccv_matrix_free(x);
54
1
}
55
56
TEST_CASE("read raw memory, rgba => gray")
57
1
{
58
1
  unsigned char rgba[] = {
59
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
60
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
61
1
  };
62
1
  ccv_dense_matrix_t* x = 0;
63
1
  ccv_read(rgba, &x, CCV_IO_RGBA_RAW | CCV_IO_GRAY, 2, 2, 9);
64
1
  unsigned char hx1[] = {
65
1
    18, 58,
66
1
  };
67
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 2, "1st row when reading raw rgba memory block into grayscale matrix doesn't match")
;1
68
1
  unsigned char hx2[] = {
69
1
    23, 63,
70
1
  };
71
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 2, "2nd row when reading raw rgba memory block into grayscale matrix doesn't match")
;1
72
1
  ccv_matrix_free(x);
73
1
}
74
75
TEST_CASE("read raw memory, rgba => rgba")
76
1
{
77
1
  unsigned char rgba[] = {
78
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
79
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
80
1
  };
81
1
  ccv_dense_matrix_t* x = 0;
82
1
  ccv_read(rgba, &x, CCV_IO_RGBA_RAW, 2, 2, 9);
83
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, rgba, x->data.u8, 8, "1st row when reading raw rgba memory block into rgba matrix doesn't match")
;1
84
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, rgba + 9, x->data.u8 + x->step, 8, "2nd row when reading raw rgba memory block into rgba matrix doesn't match")
;1
85
1
  ccv_matrix_free(x);
86
1
}
87
88
TEST_CASE("read raw memory, argb => rgb")
89
1
{
90
1
  unsigned char argb[] = {
91
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
92
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
93
1
  };
94
1
  ccv_dense_matrix_t* x = 0;
95
1
  ccv_read(argb, &x, CCV_IO_ARGB_RAW | CCV_IO_RGB_COLOR, 2, 2, 9);
96
1
  unsigned char hx1[] = {
97
1
    20, 30, 40, 60, 70, 80,
98
1
  };
99
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 6, "1st row when reading raw argb memory block into rgb matrix doesn't match")
;1
100
1
  unsigned char hx2[] = {
101
1
    25, 35, 45, 65, 75, 85,
102
1
  };
103
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 6, "2nd row when reading raw argb memory block into rgb matrix doesn't match")
;1
104
1
  ccv_matrix_free(x);
105
1
}
106
107
TEST_CASE("read raw memory, argb => gray")
108
1
{
109
1
  unsigned char argb[] = {
110
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
111
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
112
1
  };
113
1
  ccv_dense_matrix_t* x = 0;
114
1
  ccv_read(argb, &x, CCV_IO_ARGB_RAW | CCV_IO_GRAY, 2, 2, 9);
115
1
  unsigned char hx1[] = {
116
1
    28, 68,
117
1
  };
118
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 2, "1st row when reading raw argb memory block into grayscale matrix doesn't match")
;1
119
1
  unsigned char hx2[] = {
120
1
    33, 73,
121
1
  };
122
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 2, "2nd row when reading raw argb memory block into grayscale matrix doesn't match")
;1
123
1
  ccv_matrix_free(x);
124
1
}
125
126
TEST_CASE("read raw memory, argb => argb")
127
1
{
128
1
  unsigned char argb[] = {
129
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
130
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
131
1
  };
132
1
  ccv_dense_matrix_t* x = 0;
133
1
  ccv_read(argb, &x, CCV_IO_ARGB_RAW, 2, 2, 9);
134
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, argb, x->data.u8, 8, "1st row when reading raw argb memory block into argb matrix doesn't match")
;1
135
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, argb + 9, x->data.u8 + x->step, 8, "2nd row when reading raw argb memory block into argb matrix doesn't match")
;1
136
1
  ccv_matrix_free(x);
137
1
}
138
139
TEST_CASE("read raw memory, bgr => gray")
140
1
{
141
1
  unsigned char bgr[] = {
142
1
    10, 20, 30, 40, 50, 60, 70,
143
1
    80, 90, 15, 25, 35, 45, 55,
144
1
  };
145
1
  ccv_dense_matrix_t* x = 0;
146
1
  ccv_read(bgr, &x, CCV_IO_BGR_RAW | CCV_IO_GRAY, 2, 2, 7);
147
1
  unsigned char hx1[] = {
148
1
    21, 51,
149
1
  };
150
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 2, "1st row when reading raw bgr ordered memory block into grayscale matrix doesn't match")
;1
151
1
  unsigned char hx2[] = {
152
1
    73, 36,
153
1
  };
154
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 2, "2nd row when reading raw bgr ordered memory block into grayscale matrix doesn't match")
;1
155
1
  ccv_matrix_free(x);
156
1
}
157
158
TEST_CASE("read raw memory, bgr => rgb")
159
1
{
160
1
  unsigned char bgr[] = {
161
1
    10, 20, 30, 40, 50, 60, 70,
162
1
    80, 90, 15, 25, 35, 45, 55,
163
1
  };
164
1
  ccv_dense_matrix_t* x = 0;
165
1
  ccv_read(bgr, &x, CCV_IO_BGR_RAW | CCV_IO_RGB_COLOR, 2, 2, 7);
166
1
  unsigned char hx1[] = {
167
1
    30, 20, 10, 60, 50, 40,
168
1
  };
169
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 6, "1st row when reading raw bgr ordered memory block into rgb matrix doesn't match")
;1
170
1
  unsigned char hx2[] = {
171
1
    15, 90, 80, 45, 35, 25,
172
1
  };
173
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 6, "2nd row when reading raw bgr ordered memory block into rgb matrix doesn't match")
;1
174
1
  ccv_matrix_free(x);
175
1
}
176
177
TEST_CASE("read raw memory, bgr => bgr")
178
1
{
179
1
  unsigned char bgr[] = {
180
1
    10, 20, 30, 40, 50, 60, 70,
181
1
    80, 90, 15, 25, 35, 45, 55,
182
1
  };
183
1
  ccv_dense_matrix_t* x = 0;
184
1
  ccv_read(bgr, &x, CCV_IO_BGR_RAW, 2, 2, 7);
185
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, bgr, x->data.u8, 6, "1st row when reading raw bgr ordered memory block into rgb matrix doesn't match")
;1
186
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, bgr + 7, x->data.u8 + x->step, 6, "2nd row when reading raw bgr ordered memory block into rgb matrix doesn't match")
;1
187
1
  ccv_matrix_free(x);
188
1
}
189
190
TEST_CASE("read raw memory, bgra => rgb")
191
1
{
192
1
  unsigned char bgra[] = {
193
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
194
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
195
1
  };
196
1
  ccv_dense_matrix_t* x = 0;
197
1
  ccv_read(bgra, &x, CCV_IO_BGRA_RAW | CCV_IO_RGB_COLOR, 2, 2, 9);
198
1
  unsigned char hx1[] = {
199
1
    30, 20, 10, 70, 60, 50,
200
1
  };
201
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 6, "1st row when reading raw bgra memory block into rgb matrix doesn't match")
;1
202
1
  unsigned char hx2[] = {
203
1
    35, 25, 15, 75, 65, 55,
204
1
  };
205
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 6, "2nd row when reading raw bgra memory block into rgb matrix doesn't match")
;1
206
1
  ccv_matrix_free(x);
207
1
}
208
209
TEST_CASE("read raw memory, bgra => gray")
210
1
{
211
1
  unsigned char bgra[] = {
212
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
213
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
214
1
  };
215
1
  ccv_dense_matrix_t* x = 0;
216
1
  ccv_read(bgra, &x, CCV_IO_BGRA_RAW | CCV_IO_GRAY, 2, 2, 9);
217
1
  unsigned char hx1[] = {
218
1
    21, 61,
219
1
  };
220
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 2, "1st row when reading raw bgra memory block into grayscale matrix doesn't match")
;1
221
1
  unsigned char hx2[] = {
222
1
    26, 66,
223
1
  };
224
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 2, "2nd row when reading raw bgra memory block into grayscale matrix doesn't match")
;1
225
1
  ccv_matrix_free(x);
226
1
}
227
228
TEST_CASE("read raw memory, bgra => bgra")
229
1
{
230
1
  unsigned char bgra[] = {
231
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
232
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
233
1
  };
234
1
  ccv_dense_matrix_t* x = 0;
235
1
  ccv_read(bgra, &x, CCV_IO_BGRA_RAW, 2, 2, 9);
236
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, bgra, x->data.u8, 8, "1st row when reading raw bgra memory block into bgra matrix doesn't match")
;1
237
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, bgra + 9, x->data.u8 + x->step, 8, "2nd row when reading raw bgra memory block into bgra matrix doesn't match")
;1
238
1
  ccv_matrix_free(x);
239
1
}
240
241
TEST_CASE("read raw memory, abgr => rgb")
242
1
{
243
1
  unsigned char abgr[] = {
244
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
245
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
246
1
  };
247
1
  ccv_dense_matrix_t* x = 0;
248
1
  ccv_read(abgr, &x, CCV_IO_ABGR_RAW | CCV_IO_RGB_COLOR, 2, 2, 9);
249
1
  unsigned char hx1[] = {
250
1
    40, 30, 20, 80, 70, 60,
251
1
  };
252
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 6, "1st row when reading raw abgr memory block into rgb matrix doesn't match")
;1
253
1
  unsigned char hx2[] = {
254
1
    45, 35, 25, 85, 75, 65,
255
1
  };
256
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 6, "2nd row when reading raw abgr memory block into rgb matrix doesn't match")
;1
257
1
  ccv_matrix_free(x);
258
1
}
259
260
TEST_CASE("read raw memory, abgr => gray")
261
1
{
262
1
  unsigned char abgr[] = {
263
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
264
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
265
1
  };
266
1
  ccv_dense_matrix_t* x = 0;
267
1
  ccv_read(abgr, &x, CCV_IO_ABGR_RAW | CCV_IO_GRAY, 2, 2, 9);
268
1
  unsigned char hx1[] = {
269
1
    31, 71,
270
1
  };
271
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 2, "1st row when reading raw abgr memory block into grayscale matrix doesn't match")
;1
272
1
  unsigned char hx2[] = {
273
1
    36, 76,
274
1
  };
275
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 2, "2nd row when reading raw abgr memory block into grayscale matrix doesn't match")
;1
276
1
  ccv_matrix_free(x);
277
1
}
278
279
TEST_CASE("read raw memory, abgr => abgr")
280
1
{
281
1
  unsigned char abgr[] = {
282
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
283
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
284
1
  };
285
1
  ccv_dense_matrix_t* x = 0;
286
1
  ccv_read(abgr, &x, CCV_IO_ABGR_RAW, 2, 2, 9);
287
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, abgr, x->data.u8, 8, "1st row when reading raw abgr memory block into abgr matrix doesn't match")
;1
288
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, abgr + 9, x->data.u8 + x->step, 8, "2nd row when reading raw abgr memory block into abgr matrix doesn't match")
;1
289
1
  ccv_matrix_free(x);
290
1
}
291
292
TEST_CASE("read raw memory, gray => rgb")
293
1
{
294
1
  unsigned char g[] = {
295
1
    10, 20, 30, 40, 50,
296
1
    15, 25, 35, 45, 55,
297
1
  };
298
1
  ccv_dense_matrix_t* x = 0;
299
1
  ccv_read(g, &x, CCV_IO_GRAY_RAW | CCV_IO_RGB_COLOR, 2, 2, 5);
300
1
  unsigned char hx1[] = {
301
1
    10, 10, 10, 20, 20, 20,
302
1
  };
303
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx1, x->data.u8, 6, "1st row when reading raw grayscale memory block into rgb matrix doesn't match")
;1
304
1
  unsigned char hx2[] = {
305
1
    15, 15, 15, 25, 25, 25,
306
1
  };
307
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, hx2, x->data.u8 + x->step, 6, "2nd row when reading raw grayscale memory block into rgb matrix doesn't match")
;1
308
1
  ccv_matrix_free(x);
309
1
}
310
311
TEST_CASE("read raw memory, gray => gray")
312
1
{
313
1
  unsigned char g[] = {
314
1
    10, 20, 30, 40, 50,
315
1
    15, 25, 35, 45, 55,
316
1
  };
317
1
  ccv_dense_matrix_t* x = 0;
318
1
  ccv_read(g, &x, CCV_IO_GRAY_RAW | CCV_IO_GRAY, 2, 2, 5);
319
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, g, x->data.u8, 2, "1st row when reading raw grayscale memory block into grayscale matrix doesn't match")
;1
320
1
  
REQUIRE_ARRAY_EQ1
(unsigned char, g + 5, x->data.u8 + x->step, 2, "2nd row when reading raw grayscale memory block into grayscale matrix doesn't match")
;1
321
1
  ccv_matrix_free(x);
322
1
}
323
324
TEST_CASE("read raw memory with no copy mode")
325
1
{
326
1
  unsigned char rgb[] = {
327
1
    10, 20, 30, 40, 50, 60, 70, 80, 90,
328
1
    15, 25, 35, 45, 55, 65, 75, 85, 95,
329
1
  };
330
1
  ccv_dense_matrix_t* x = 0;
331
1
  ccv_read(rgb, &x, CCV_IO_ANY_RAW | CCV_IO_NO_COPY, 2, 2, 9);
332
1
  
REQUIRE_EQ1
(9, x->step, "its step value should be equal to the passing scanline value in no copy mode")
;1
333
1
  
REQUIRE1
(rgb == x->data.u8, "its data section should point to the same memory region")
;1
334
1
  ccv_matrix_free(x);
335
1
}
336
337
TEST_CASE("read JPEG from memory")
338
1
{
339
1
  ccv_dense_matrix_t* x = 0;
340
1
  ccv_read("../../samples/cmyk-jpeg-format.jpg", &x, CCV_IO_ANY_FILE);
341
1
  ccv_dense_matrix_t* y = 0;
342
1
  FILE* rb = fopen("../../samples/cmyk-jpeg-format.jpg", "rb");
343
1
  fseek(rb, 0, SEEK_END);
344
1
  long size = ftell(rb);
345
1
  char* data = (char*)ccmalloc(size);
346
1
  fseek(rb, 0, SEEK_SET);
347
1
  fread(data, 1, size, rb);
348
1
  fclose(rb);
349
1
  ccv_read(data, &y, CCV_IO_ANY_STREAM, size);
350
1
  ccfree(data);
351
1
  
REQUIRE_MATRIX_EQ1
(x, y, "read cmyk-jpeg-format.jpg from file system and memory should be the same")
;1
352
1
  ccv_matrix_free(y);
353
1
  ccv_matrix_free(x);
354
1
}
355
356
TEST_CASE("read PNG from memory")
357
1
{
358
1
  ccv_dense_matrix_t* x = 0;
359
1
  ccv_read("../../samples/nature.png", &x, CCV_IO_ANY_FILE);
360
1
  ccv_dense_matrix_t* y = 0;
361
1
  FILE* rb = fopen("../../samples/nature.png", "rb");
362
1
  fseek(rb, 0, SEEK_END);
363
1
  long size = ftell(rb);
364
1
  char* data = (char*)ccmalloc(size);
365
1
  fseek(rb, 0, SEEK_SET);
366
1
  fread(data, 1, size, rb);
367
1
  fclose(rb);
368
1
  ccv_read(data, &y, CCV_IO_ANY_STREAM, size);
369
1
  ccfree(data);
370
1
  
REQUIRE_MATRIX_EQ1
(x, y, "read nature.png from file system and memory should be the same")
;1
371
1
  ccv_matrix_free(y);
372
1
  ccv_matrix_free(x);
373
1
}
374
375
#include "case_main.h"