KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_bitmap_base.cpp File Reference

Test suite for BITMAP_BASE. More...

#include <qa_utils/wx_utils/unit_test_utils.h>
#include <bitmap_base.h>
#include "wximage_test_utils.h"
#include <wx/mstream.h>

Go to the source code of this file.

Classes

class  TEST_BITMAP_BASE_FIXTURE
 
struct  TEST_PIXEL_CASE
 

Functions

 BOOST_AUTO_TEST_CASE (Empty)
 Declare the test suite.
 
 BOOST_AUTO_TEST_CASE (EmptyCopy)
 Check we can validly copy an empty bitmap.
 
 BOOST_AUTO_TEST_CASE (BasicProps)
 Check basic properties of the populated images.
 
 BOOST_AUTO_TEST_CASE (PPIFromNonIntegerPixelsPerCm)
 Verify PPI is computed without integer truncation when pixels/cm is non-integer.
 
 BOOST_AUTO_TEST_CASE (BasicImage)
 Check the image is right.
 
 BOOST_AUTO_TEST_CASE (RotateImageCCW)
 Check the image is right after rotating CCW.
 
 BOOST_AUTO_TEST_CASE (RotateImageCW)
 Check the image is right after rotating CW.
 
 BOOST_AUTO_TEST_CASE (MirrorImage)
 Check the image is right after mirroring.
 
 BOOST_AUTO_TEST_CASE (SetImageOutputsData)
 Check setting image data by SetImage produces saveable data via SaveImageData.
 

Variables

static const std::vector< unsigned char > png_data_4tile
 4tile is an 8x8 image
 
static const VECTOR2I size_4tile { 8, 8 }
 
static const KIGFX::COLOR4D col_red { 1.0, 0.0, 0.0, 1.0 }
 
static const KIGFX::COLOR4D col_green { 0.0, 1.0, 0.0, 1.0 }
 
static const KIGFX::COLOR4D col_blue { 0.0, 0.0, 1.0, 1.0 }
 
static const KIGFX::COLOR4D col_black { 0.0, 0.0, 0.0, 1.0 }
 

Detailed Description

Test suite for BITMAP_BASE.

Definition in file test_bitmap_base.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/9]

BOOST_AUTO_TEST_CASE ( BasicImage )

Check the image is right.

Definition at line 206 of file test_bitmap_base.cpp.

References BOOST_CHECK_PREDICATE(), col_black, col_blue, col_green, col_red, and KI_TEST::IsImagePixelOfColor().

◆ BOOST_AUTO_TEST_CASE() [2/9]

◆ BOOST_AUTO_TEST_CASE() [3/9]

BOOST_AUTO_TEST_CASE ( Empty )

Declare the test suite.

Check basic properties of a populated image

Definition at line 103 of file test_bitmap_base.cpp.

References BOOST_AUTO_TEST_CASE(), BOOST_CHECK_EQUAL(), empty(), BITMAP_BASE::GetImageData(), BITMAP_BASE::GetPixelSizeIu(), BITMAP_BASE::GetPPI(), BITMAP_BASE::GetScale(), and TOP_BOTTOM.

◆ BOOST_AUTO_TEST_CASE() [4/9]

BOOST_AUTO_TEST_CASE ( EmptyCopy )

Check we can validly copy an empty bitmap.

Definition at line 124 of file test_bitmap_base.cpp.

References BOOST_CHECK_EQUAL(), copied, and empty().

◆ BOOST_AUTO_TEST_CASE() [5/9]

BOOST_AUTO_TEST_CASE ( MirrorImage )

Check the image is right after mirroring.

Definition at line 284 of file test_bitmap_base.cpp.

References BOOST_CHECK_PREDICATE(), col_black, col_blue, col_green, col_red, KI_TEST::IsImagePixelOfColor(), and TOP_BOTTOM.

◆ BOOST_AUTO_TEST_CASE() [6/9]

BOOST_AUTO_TEST_CASE ( PPIFromNonIntegerPixelsPerCm )

Verify PPI is computed without integer truncation when pixels/cm is non-integer.

PNG stores resolution as pixels-per-meter (e.g. 3780 PPM for ~96 DPI). wxWidgets converts to pixels-per-cm as a string ("37.8"). The old code used GetOptionInt() which truncated "37.8" to 37 before multiplying by 2.54, giving 94 instead of the correct 96. This tests that the full precision path is used.

Definition at line 178 of file test_bitmap_base.cpp.

References BOOST_CHECK_EQUAL(), BOOST_REQUIRE(), BITMAP_BASE::GetPPI(), and BITMAP_BASE::ReadImageFile().

◆ BOOST_AUTO_TEST_CASE() [7/9]

BOOST_AUTO_TEST_CASE ( RotateImageCCW )

Check the image is right after rotating CCW.

Definition at line 230 of file test_bitmap_base.cpp.

References BOOST_CHECK_PREDICATE(), col_black, col_blue, col_green, col_red, and KI_TEST::IsImagePixelOfColor().

◆ BOOST_AUTO_TEST_CASE() [8/9]

BOOST_AUTO_TEST_CASE ( RotateImageCW )

Check the image is right after rotating CW.

Definition at line 257 of file test_bitmap_base.cpp.

References BOOST_CHECK_PREDICATE(), col_black, col_blue, col_green, col_red, and KI_TEST::IsImagePixelOfColor().

◆ BOOST_AUTO_TEST_CASE() [9/9]

BOOST_AUTO_TEST_CASE ( SetImageOutputsData )

Check setting image data by SetImage produces saveable data via SaveImageData.

Regression test for: https://gitlab.com/kicad/code/kicad/-/issues/19772

Definition at line 313 of file test_bitmap_base.cpp.

References BOOST_CHECK_PREDICATE(), BOOST_REQUIRE(), KI_TEST::ImagesHaveSamePixels(), BITMAP_BASE::SaveImageData(), and BITMAP_BASE::SetImage().

Variable Documentation

◆ col_black

const KIGFX::COLOR4D col_black { 0.0, 0.0, 0.0, 1.0 }
static

◆ col_blue

const KIGFX::COLOR4D col_blue { 0.0, 0.0, 1.0, 1.0 }
static

◆ col_green

const KIGFX::COLOR4D col_green { 0.0, 1.0, 0.0, 1.0 }
static

◆ col_red

const KIGFX::COLOR4D col_red { 1.0, 0.0, 0.0, 1.0 }
static

◆ png_data_4tile

const std::vector<unsigned char> png_data_4tile
static
Initial value:
= {
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x08, 0x06, 0x00, 0x00, 0x00, 0xC4, 0x0F, 0xBE,
0x8B, 0x00, 0x00, 0x00, 0x04, 0x73, 0x42, 0x49, 0x54, 0x08, 0x08, 0x08, 0x08, 0x7C, 0x08, 0x64,
0x88, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0E, 0xC4, 0x00, 0x00, 0x0E,
0xC4, 0x01, 0x95, 0x2B, 0x0E, 0x1B, 0x00, 0x00, 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x53, 0x6F,
0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x00, 0x77, 0x77, 0x77, 0x2E, 0x69, 0x6E, 0x6B, 0x73, 0x63,
0x61, 0x70, 0x65, 0x2E, 0x6F, 0x72, 0x67, 0x9B, 0xEE, 0x3C, 0x1A, 0x00, 0x00, 0x00, 0x40, 0x49,
0x44, 0x41, 0x54, 0x18, 0x95, 0xA5, 0xCD, 0x4B, 0x0A, 0xC0, 0x20, 0x14, 0x43, 0xD1, 0x63, 0x77,
0xA7, 0xDD, 0xFF, 0x06, 0xD4, 0x7D, 0x3C, 0x07, 0x95, 0x42, 0x3F, 0xE0, 0xC0, 0x84, 0x0C, 0x02,
0xE1, 0x86, 0x78, 0x99, 0x13, 0x1D, 0x0D, 0xC5, 0xCF, 0xA0, 0x21, 0x66, 0xEA, 0x61, 0xA9, 0x2F,
0xA1, 0x4C, 0x4A, 0x45, 0x4E, 0x71, 0xA1, 0x6E, 0xA5, 0x67, 0xB5, 0xBC, 0xD8, 0x1F, 0x0C, 0xA7,
0xFD, 0x23, 0x67, 0x70, 0xDA, 0x89, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE,
0x42, 0x60, 0x82
}

4tile is an 8x8 image

Definition at line 44 of file test_bitmap_base.cpp.

Referenced by TEST_BITMAP_BASE_FIXTURE::TEST_BITMAP_BASE_FIXTURE().

◆ size_4tile

const VECTOR2I size_4tile { 8, 8 }
static

Definition at line 61 of file test_bitmap_base.cpp.

Referenced by BOOST_AUTO_TEST_CASE().