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.

193 lines
5.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <qa_utils/wx_utils/unit_test_utils.h>
  20. #include "eeschema_test_utils.h"
  21. class TEST_NETLIST_EXPORTER_KICAD_FIXTURE : public TEST_NETLIST_EXPORTER_FIXTURE<NETLIST_EXPORTER_KICAD>
  22. {
  23. public:
  24. void CompareNetlists() override
  25. {
  26. NETLIST golden;
  27. NETLIST test;
  28. {
  29. std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
  30. &golden, getNetlistFileName(), wxEmptyString ) );
  31. BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
  32. }
  33. {
  34. std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
  35. &test, getNetlistFileName( true ), wxEmptyString ) );
  36. BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
  37. }
  38. // Number of components should match
  39. BOOST_REQUIRE_EQUAL( golden.GetCount(), test.GetCount() );
  40. for( unsigned i = 0; i < golden.GetCount(); i++ )
  41. {
  42. COMPONENT* goldenComp = golden.GetComponent( i );
  43. COMPONENT* refComp = test.GetComponentByReference( goldenComp->GetReference() );
  44. // Retrieval by reference
  45. BOOST_REQUIRE_NE( refComp, nullptr );
  46. // Retrieval by KIID
  47. KIID_PATH path = goldenComp->GetPath();
  48. BOOST_REQUIRE( !goldenComp->GetKIIDs().empty() );
  49. path.push_back( goldenComp->GetKIIDs().front() );
  50. COMPONENT* pathComp = test.GetComponentByPath( path );
  51. BOOST_REQUIRE_NE( pathComp, nullptr );
  52. // We should have found the same component
  53. BOOST_REQUIRE_EQUAL( refComp->GetReference(), pathComp->GetReference() );
  54. // And that component should have the same number of attached nets
  55. BOOST_REQUIRE_EQUAL( goldenComp->GetNetCount(), refComp->GetNetCount() );
  56. for( unsigned net = 0; net < goldenComp->GetNetCount(); net++ )
  57. {
  58. const COMPONENT_NET& goldenNet = goldenComp->GetNet( net );
  59. const COMPONENT_NET& testNet = refComp->GetNet( net );
  60. // The video test has a bunch of unconnected RESERVED pins which cause duplicate
  61. // auto-generated netnames. The connectivity algo disambiguates these with "_n"
  62. // suffixes, but since the algorithm is multi-threaded, which ones get which suffix
  63. // is not deterministic. So skip these.
  64. if( testNet.GetPinFunction().Contains( "RESERVED" ) )
  65. continue;
  66. // The two nets at the same index should be identical
  67. BOOST_REQUIRE_EQUAL( goldenNet.GetNetName(), testNet.GetNetName() );
  68. BOOST_REQUIRE_EQUAL( goldenNet.GetPinName(), testNet.GetPinName() );
  69. }
  70. }
  71. }
  72. };
  73. BOOST_FIXTURE_TEST_SUITE( Netlists, TEST_NETLIST_EXPORTER_KICAD_FIXTURE )
  74. BOOST_AUTO_TEST_CASE( FindPlugin )
  75. {
  76. BOOST_CHECK_NE( m_pi, nullptr );
  77. }
  78. BOOST_AUTO_TEST_CASE( GlobalPromotion )
  79. {
  80. doNetlistTest( "test_global_promotion" );
  81. }
  82. BOOST_AUTO_TEST_CASE( GlobalPromotion2 )
  83. {
  84. doNetlistTest( "test_global_promotion_2" );
  85. }
  86. BOOST_AUTO_TEST_CASE( Video )
  87. {
  88. doNetlistTest( "video" );
  89. }
  90. BOOST_AUTO_TEST_CASE( ComplexHierarchy )
  91. {
  92. doNetlistTest( "complex_hierarchy" );
  93. }
  94. BOOST_AUTO_TEST_CASE( WeakVectorBusDisambiguation )
  95. {
  96. doNetlistTest( "weak_vector_bus_disambiguation" );
  97. }
  98. BOOST_AUTO_TEST_CASE( BusJunctions )
  99. {
  100. doNetlistTest( "bus_junctions" );
  101. }
  102. BOOST_AUTO_TEST_CASE( HierRenaming )
  103. {
  104. doNetlistTest( "test_hier_renaming" );
  105. }
  106. BOOST_AUTO_TEST_CASE( NoConnects )
  107. {
  108. doNetlistTest( "noconnects" );
  109. }
  110. BOOST_AUTO_TEST_CASE( PrefixBusAlias )
  111. {
  112. doNetlistTest( "prefix_bus_alias" );
  113. }
  114. BOOST_AUTO_TEST_CASE( GroupBusMatching )
  115. {
  116. doNetlistTest( "group_bus_matching" );
  117. }
  118. BOOST_AUTO_TEST_CASE( TopLevelHierPins )
  119. {
  120. doNetlistTest( "top_level_hier_pins" );
  121. }
  122. BOOST_AUTO_TEST_CASE( BusEntries )
  123. {
  124. doNetlistTest( "bus_entries" );
  125. }
  126. BOOST_AUTO_TEST_CASE( LegacyPower )
  127. {
  128. doNetlistTest( "legacy_power" );
  129. }
  130. BOOST_AUTO_TEST_CASE( LegacyPower4 )
  131. {
  132. doNetlistTest( "legacy_power4" );
  133. }
  134. BOOST_AUTO_TEST_CASE( BusConnections )
  135. {
  136. doNetlistTest( "bus_connection" );
  137. }
  138. BOOST_AUTO_TEST_CASE( Issue14657 )
  139. {
  140. doNetlistTest( "issue14657" );
  141. }
  142. BOOST_AUTO_TEST_SUITE_END()