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 The 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
25#include <boost/test/data/test_case.hpp>
26
27#include <board.h>
28#include <kiid.h>
29#include <pcb_reference_image.h>
33
34namespace
35{
36
37struct REFERENCE_IMAGE_LOAD_TEST_FIXTURE
38{
39 REFERENCE_IMAGE_LOAD_TEST_FIXTURE() {}
40};
41
42
43struct REFERENCE_IMAGE_LOAD_TEST_CASE
44{
45 // Which one to look at in the file
46 KIID m_imageUuid;
47 // Expected values
48 bool m_expectedLocked;
49 VECTOR2I m_expectedPos;
50 double m_expectedScale;
51 // This should also check correct image decoding, as it won't work otherwise
52 VECTOR2I m_expectedPixelSize;
53};
54
55
56struct REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE: public KI_TEST::BOARD_LOAD_TEST_CASE
57{
58 // List of images to check
59 std::vector<REFERENCE_IMAGE_LOAD_TEST_CASE> m_imageCases;
60};
61
62const std::vector<REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE> ReferenceImageLoading_testCases{
63 {
64 "reference_images_load_save",
65 std::nullopt,
66 {
67 // From top to bottom in the board file
68 {
69 "7dde345e-020a-4fdd-af77-588b452be5e0",
70 false,
71 { 100, 46 },
72 1.0,
73 { 64, 64 },
74 },
75 {
76 "e4fd52dd-1d89-4c43-b621-aebfc9788d5c",
77 true,
78 { 100, 65 },
79 1.0,
80 { 64, 64 },
81 },
82 {
83 "d402397e-bce0-4cae-a398-b5aeef397e87",
84 false,
85 { 100, 90 },
86 2.0,
87 { 64, 64 }, // It's the same size, but scaled
88 },
89 },
90 },
91};
92
93} // namespace
94
95
96BOOST_DATA_TEST_CASE_F( REFERENCE_IMAGE_LOAD_TEST_FIXTURE, ReferenceImageLoading,
97 boost::unit_test::data::make( ReferenceImageLoading_testCases ), testCase )
98{
99 const auto doBoardTest = [&]( const BOARD& aBoard )
100 {
101 for( const REFERENCE_IMAGE_LOAD_TEST_CASE& imageTestCase : testCase.m_imageCases )
102 {
104 "Checking for image with UUID: " << imageTestCase.m_imageUuid.AsString() );
105
106 const auto& image =
108 aBoard, PCB_REFERENCE_IMAGE_T, imageTestCase.m_imageUuid ) );
109 const REFERENCE_IMAGE& refImage = image.GetReferenceImage();
110
111 BOOST_CHECK_EQUAL( image.IsLocked(), imageTestCase.m_expectedLocked );
112 BOOST_CHECK_EQUAL( image.GetPosition(), imageTestCase.m_expectedPos * 1000000 );
113 BOOST_CHECK_CLOSE( refImage.GetImageScale(), imageTestCase.m_expectedScale, 1e-6 );
114
115 const BITMAP_BASE& bitmap = refImage.GetImage();
116
117 BOOST_CHECK_EQUAL( bitmap.GetSizePixels(), imageTestCase.m_expectedPixelSize );
118 }
119 };
120
121 KI_TEST::LoadAndTestBoardFile( testCase.m_BoardFileRelativePath, true, doBoardTest,
122 testCase.m_ExpectedBoardVersion );
123}
General utilities for PCB file IO for QA programs.
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:49
VECTOR2I GetSizePixels() const
Definition: bitmap_base.h:107
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:296
Definition: kiid.h:49
Object to handle a bitmap image that can be inserted in a PCB.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
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_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_DATA_TEST_CASE_F(REFERENCE_IMAGE_LOAD_TEST_FIXTURE, ReferenceImageLoading, boost::unit_test::data::make(ReferenceImageLoading_testCases), testCase)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition: typeinfo.h:89