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.

95 lines
3.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2021 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 <pcbnew_utils/board_test_utils.h>
  25. #include <board.h>
  26. #include <board_design_settings.h>
  27. #include <pcb_marker.h>
  28. #include <drc/drc_item.h>
  29. #include <settings/settings_manager.h>
  30. struct DRC_REGRESSION_TEST_FIXTURE
  31. {
  32. DRC_REGRESSION_TEST_FIXTURE() :
  33. m_settingsManager( true /* headless */ )
  34. { }
  35. SETTINGS_MANAGER m_settingsManager;
  36. std::unique_ptr<BOARD> m_board;
  37. };
  38. BOOST_FIXTURE_TEST_CASE( DRCCustomRuleSeverityTest, DRC_REGRESSION_TEST_FIXTURE )
  39. {
  40. // This board has two edge-connectors. There is a custom DRC rule which conditionally
  41. // applies to one of them and sets the edge-clearance severity to "ignore". It should
  42. // therefore only generate edge-clearance violations for the other edge connector.
  43. KI_TEST::LoadBoard( m_settingsManager, "severities", m_board );
  44. KI_TEST::FillZones( m_board.get() );
  45. std::vector<DRC_ITEM> violations;
  46. BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
  47. // Disable DRC tests not handled in this testcase
  48. // These DRC tests are not useful and do not work because they need a footprint library
  49. // associated to the board
  50. bds.m_DRCSeverities[ DRCE_LIB_FOOTPRINT_ISSUES ] = SEVERITY::RPT_SEVERITY_IGNORE;
  51. bds.m_DRCSeverities[ DRCE_LIB_FOOTPRINT_MISMATCH ] = SEVERITY::RPT_SEVERITY_IGNORE;
  52. // Also disable a couple of footprint checks which throw up errors on this board
  53. bds.m_DRCSeverities[ DRCE_FOOTPRINT_TYPE_MISMATCH ] = SEVERITY::RPT_SEVERITY_IGNORE;
  54. bds.m_DRCEngine->SetViolationHandler(
  55. [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
  56. {
  57. PCB_MARKER temp( aItem, aPos );
  58. if( bds.m_DrcExclusions.find( temp.SerializeToString() ) == bds.m_DrcExclusions.end() )
  59. violations.push_back( *aItem );
  60. } );
  61. bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
  62. if( violations.size() == 8 )
  63. {
  64. BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
  65. BOOST_TEST_MESSAGE( "Custom rule severity test passed" );
  66. }
  67. else
  68. {
  69. BOOST_CHECK_EQUAL( violations.size(), 8 );
  70. UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCHES );
  71. std::map<KIID, EDA_ITEM*> itemMap;
  72. m_board->FillItemMap( itemMap );
  73. for( const DRC_ITEM& item : violations )
  74. BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
  75. BOOST_ERROR( "Custom rule severity test failed" );
  76. }
  77. }