KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_reference_image_load.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <board.h>
25#include <kiid.h>
26#include <pcb_reference_image.h>
31
32namespace
33{
34
35struct REFERENCE_IMAGE_LOAD_TEST_FIXTURE
36{
37 REFERENCE_IMAGE_LOAD_TEST_FIXTURE() {}
38};
39
40
41struct REFERENCE_IMAGE_LOAD_TEST_CASE
42{
43 // Which one to look at in the file
44 KIID m_imageUuid;
45 // Expected values
46 bool m_expectedLocked;
47 VECTOR2I m_expectedPos;
48 double m_expectedScale;
49 // This should also check correct image decoding, as it won't work otherwise
50 VECTOR2I m_expectedPixelSize;
51};
52
53
54struct REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE
55{
56 // The board to load
57 wxString m_boardFileRelativePath;
58 // List of images to check
59 std::vector<REFERENCE_IMAGE_LOAD_TEST_CASE> m_imageCases;
60};
61
62} // namespace
63
64BOOST_FIXTURE_TEST_CASE( ReferenceImageLoading, REFERENCE_IMAGE_LOAD_TEST_FIXTURE )
65{
66 const std::vector<REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE> testCases{
67 {
68 "reference_images_load_save",
69 {
70 // From top to bottom in the board file
71 {
72 "7dde345e-020a-4fdd-af77-588b452be5e0",
73 false,
74 { 100, 46 },
75 1.0,
76 { 64, 64 },
77 },
78 {
79 "e4fd52dd-1d89-4c43-b621-aebfc9788d5c",
80 true,
81 { 100, 65 },
82 1.0,
83 { 64, 64 },
84 },
85 {
86 "d402397e-bce0-4cae-a398-b5aeef397e87",
87 false,
88 { 100, 90 },
89 2.0,
90 { 64, 64 }, // It's the same size, but scaled
91 },
92 },
93 },
94 };
95
96 for( const REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE& testCase : testCases )
97 {
98 const auto doBoardTest = [&]( const BOARD& aBoard )
99 {
100 for( const REFERENCE_IMAGE_LOAD_TEST_CASE& imageTestCase : testCase.m_imageCases )
101 {
102 BOOST_TEST_MESSAGE(
103 "Checking for image with UUID: " << imageTestCase.m_imageUuid.AsString() );
104
105 const auto& image =
107 aBoard, PCB_REFERENCE_IMAGE_T, imageTestCase.m_imageUuid ) );
108
109 BOOST_CHECK_EQUAL( image.IsLocked(), imageTestCase.m_expectedLocked );
110 BOOST_CHECK_EQUAL( image.GetPosition(), imageTestCase.m_expectedPos * 1000000 );
111 BOOST_CHECK_CLOSE( image.GetImageScale(), imageTestCase.m_expectedScale, 1e-6 );
112
113 const BITMAP_BASE* bitmap = image.GetImage();
114
115 BOOST_REQUIRE( bitmap );
116
117 BOOST_TEST_MESSAGE( "Got underlying image" );
118
119 BOOST_CHECK_EQUAL( bitmap->GetSizePixels(), imageTestCase.m_expectedPixelSize );
120 }
121 };
122
123 KI_TEST::LoadAndTestBoardFile( testCase.m_boardFileRelativePath, true, doBoardTest );
124 }
125}
General utilities for PCB file IO for QA programs.
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:48
VECTOR2I GetSizePixels() const
Definition: bitmap_base.h:106
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
Definition: kiid.h:49
Object to handle a bitmap image that can be inserted in a PCB.
void LoadAndTestBoardFile(const wxString aRelativePath, bool aRoundtrip, std::function< void(BOARD &)> aBoardTestFunction, std::optional< int > aExpectedBoardVersion)
Perform "some test" on a board file loaded from the path, then optionally save and reload and run the...
BOARD_ITEM & RequireBoardItemWithTypeAndId(const BOARD &aBoard, KICAD_T aItemType, const KIID &aID)
Get an item from the given board with a certain type and UUID.
BOOST_FIXTURE_TEST_CASE(ReferenceImageLoading, REFERENCE_IMAGE_LOAD_TEST_FIXTURE)
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition: typeinfo.h:89