MCPcopy Create free account
hub / github.com/davisking/dlib / test_serialization

Function test_serialization

dlib/test/array2d.cpp:400–555  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398 }
399
400 void test_serialization()
401 {
402 // Do these tests because there are overloads of the serialize routines
403 // specifically for these types of pixel (except for unsigned short,
404 // we do that because you can never have too many tests).
405 {
406 array2d<rgb_alpha_pixel> img, img2;
407 img.set_size(3,2);
408 assign_all_pixels(img, 5);
409 img[1][1].red = 9;
410 img[1][1].green = 8;
411 img[1][1].blue = 7;
412 img[1][1].alpha = 3;
413 ostringstream sout;
414 serialize(img, sout);
415 istringstream sin(sout.str());
416 deserialize(img2, sin);
417
418 DLIB_TEST(img2.nr() == 3);
419 DLIB_TEST(img2.nc() == 2);
420
421 for (long r = 0; r < img.nr(); ++r)
422 {
423 for (long c = 0; c < img.nc(); ++c)
424 {
425 DLIB_TEST(img[r][c].red == img2[r][c].red);
426 DLIB_TEST(img[r][c].green == img2[r][c].green);
427 DLIB_TEST(img[r][c].blue == img2[r][c].blue);
428 DLIB_TEST(img[r][c].alpha == img2[r][c].alpha);
429 }
430 }
431 }
432 {
433 array2d<hsi_pixel> img, img2;
434 img.set_size(3,2);
435 assign_all_pixels(img, 5);
436 img[1][1].h = 9;
437 img[1][1].s = 2;
438 img[1][1].i = 3;
439 ostringstream sout;
440 serialize(img, sout);
441 istringstream sin(sout.str());
442 deserialize(img2, sin);
443
444 DLIB_TEST(img2.nr() == 3);
445 DLIB_TEST(img2.nc() == 2);
446
447 for (long r = 0; r < img.nr(); ++r)
448 {
449 for (long c = 0; c < img.nc(); ++c)
450 {
451 DLIB_TEST(img[r][c].h == img2[r][c].h);
452 DLIB_TEST(img[r][c].s == img2[r][c].s);
453 DLIB_TEST(img[r][c].i == img2[r][c].i);
454 }
455 }
456 }
457 {

Callers 1

perform_testMethod · 0.70

Calls 8

assign_all_pixelsFunction · 0.85
serializeFunction · 0.70
deserializeFunction · 0.70
set_sizeMethod · 0.45
strMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
width_stepMethod · 0.45

Tested by

no test coverage detected