You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.3 KiB

  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. #include <qa_utils/wx_utils/unit_test_utils.h>
  24. #include <boost/test/data/test_case.hpp>
  25. #include <board.h>
  26. #include <kiid.h>
  27. #include <pcb_reference_image.h>
  28. #include <pcbnew_utils/board_file_utils.h>
  29. #include <pcbnew_utils/board_test_utils.h>
  30. #include <settings/settings_manager.h>
  31. namespace
  32. {
  33. struct REFERENCE_IMAGE_LOAD_TEST_FIXTURE
  34. {
  35. REFERENCE_IMAGE_LOAD_TEST_FIXTURE() {}
  36. };
  37. struct REFERENCE_IMAGE_LOAD_TEST_CASE
  38. {
  39. // Which one to look at in the file
  40. KIID m_imageUuid;
  41. // Expected values
  42. bool m_expectedLocked;
  43. VECTOR2I m_expectedPos;
  44. double m_expectedScale;
  45. // This should also check correct image decoding, as it won't work otherwise
  46. VECTOR2I m_expectedPixelSize;
  47. };
  48. struct REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE: public KI_TEST::BOARD_LOAD_TEST_CASE
  49. {
  50. // List of images to check
  51. std::vector<REFERENCE_IMAGE_LOAD_TEST_CASE> m_imageCases;
  52. };
  53. const std::vector<REFERENCE_IMAGE_LOAD_BOARD_TEST_CASE> ReferenceImageLoading_testCases{
  54. {
  55. "reference_images_load_save",
  56. std::nullopt,
  57. {
  58. // From top to bottom in the board file
  59. {
  60. "7dde345e-020a-4fdd-af77-588b452be5e0",
  61. false,
  62. { 100, 46 },
  63. 1.0,
  64. { 64, 64 },
  65. },
  66. {
  67. "e4fd52dd-1d89-4c43-b621-aebfc9788d5c",
  68. true,
  69. { 100, 65 },
  70. 1.0,
  71. { 64, 64 },
  72. },
  73. {
  74. "d402397e-bce0-4cae-a398-b5aeef397e87",
  75. false,
  76. { 100, 90 },
  77. 2.0,
  78. { 64, 64 }, // It's the same size, but scaled
  79. },
  80. },
  81. },
  82. };
  83. } // namespace
  84. BOOST_DATA_TEST_CASE_F( REFERENCE_IMAGE_LOAD_TEST_FIXTURE, ReferenceImageLoading,
  85. boost::unit_test::data::make( ReferenceImageLoading_testCases ), testCase )
  86. {
  87. const auto doBoardTest = [&]( const BOARD& aBoard )
  88. {
  89. for( const REFERENCE_IMAGE_LOAD_TEST_CASE& imageTestCase : testCase.m_imageCases )
  90. {
  91. BOOST_TEST_MESSAGE(
  92. "Checking for image with UUID: " << imageTestCase.m_imageUuid.AsString() );
  93. const auto& image =
  94. static_cast<PCB_REFERENCE_IMAGE&>( KI_TEST::RequireBoardItemWithTypeAndId(
  95. aBoard, PCB_REFERENCE_IMAGE_T, imageTestCase.m_imageUuid ) );
  96. const REFERENCE_IMAGE& refImage = image.GetReferenceImage();
  97. BOOST_CHECK_EQUAL( image.IsLocked(), imageTestCase.m_expectedLocked );
  98. BOOST_CHECK_EQUAL( image.GetPosition(), imageTestCase.m_expectedPos * 1000000 );
  99. BOOST_CHECK_CLOSE( refImage.GetImageScale(), imageTestCase.m_expectedScale, 1e-6 );
  100. const BITMAP_BASE& bitmap = refImage.GetImage();
  101. BOOST_CHECK_EQUAL( bitmap.GetSizePixels(), imageTestCase.m_expectedPixelSize );
  102. }
  103. };
  104. KI_TEST::LoadAndTestBoardFile( testCase.m_BoardFileRelativePath, true, doBoardTest,
  105. testCase.m_ExpectedBoardVersion );
  106. }