KiCad PCB EDA Suite
test_lib_table.cpp File Reference

Test suite for LIB_TABLE_BASE. More...

Go to the source code of this file.

Classes

class  TEST_LIB_TABLE_ROW
 A concrete implementation of LIB_TABLE_ROW that implements the minimum interface. More...
 
class  TEST_LIB_TABLE
 A concrete implementation of LIB_TABLE that implements the minimum interface for testing. More...
 
struct  LIB_ROW_DEFINITION
 Simple structure to contain data to set up a single TEST_LIB_TABLE_ROW. More...
 
struct  LIB_TABLE_TEST_FIXTURE
 Reusable test fixture with some basic pre-filled tables. More...
 

Functions

 BOOST_AUTO_TEST_CASE (Empty)
 Declare the test suite. More...
 
 BOOST_AUTO_TEST_CASE (EmptyWithFallback)
 Check size and emptiness on tables with fallback. More...
 
 BOOST_AUTO_TEST_CASE (Clear)
 Check table clearing function. More...
 
 BOOST_AUTO_TEST_CASE (Equal)
 Check table equality function. More...
 
 BOOST_AUTO_TEST_CASE (Indexing)
 Test indexing into the main table. More...
 
 BOOST_AUTO_TEST_CASE (HasLibrary)
 Test retrieval of libs by nickname. More...
 
 BOOST_AUTO_TEST_CASE (Descriptions)
 Test retrieval of libs by nickname. More...
 
 BOOST_AUTO_TEST_CASE (URIs)
 Test retrieval of libs by URI. More...
 
 BOOST_AUTO_TEST_CASE (LogicalLibs)
 Test retrieval of the logical libs function. More...
 

Variables

static const std::vector< LIB_ROW_DEFINITIONmain_lib_defs
 Set-up data for the re-used library row definitions. More...
 
static const std::vector< LIB_ROW_DEFINITIONfallback_lib_defs
 

Detailed Description

Test suite for LIB_TABLE_BASE.

This test is of a abstract class, so we will implement a cut-down version and only test the core logic. Tests of the concrete implementations's own logic should be done in the relevant tests.

Definition in file test_lib_table.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/9]

BOOST_AUTO_TEST_CASE ( Empty  )

Declare the test suite.

Check an empty table behaves correctly

Definition at line 210 of file test_lib_table.cpp.

211 {
212  TEST_LIB_TABLE table;
213 
214  // Tables start out empty
215  BOOST_CHECK_EQUAL( table.GetCount(), 0 );
216  BOOST_CHECK_EQUAL( true, table.IsEmpty() );
217 }
unsigned GetCount() const
Get the number of rows contained in the table.
A concrete implementation of LIB_TABLE that implements the minimum interface for testing.
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.

References LIB_TABLE::GetCount(), and LIB_TABLE::IsEmpty().

◆ BOOST_AUTO_TEST_CASE() [2/9]

BOOST_AUTO_TEST_CASE ( EmptyWithFallback  )

Check size and emptiness on tables with fallback.

Definition at line 223 of file test_lib_table.cpp.

224 {
225  // Fall back though another empty table to the real fallback
226  TEST_LIB_TABLE interposer_table( &m_fallbackTable );
227  TEST_LIB_TABLE table( &interposer_table );
228 
229  // Table has no elements...
230  BOOST_CHECK_EQUAL( table.GetCount(), 0 );
231 
232  // But it's not empty if we include the fallback
233  BOOST_CHECK_EQUAL( false, table.IsEmpty( true ) );
234 }
A concrete implementation of LIB_TABLE that implements the minimum interface for testing.

References LIB_TABLE::GetCount(), and LIB_TABLE::IsEmpty().

◆ BOOST_AUTO_TEST_CASE() [3/9]

BOOST_AUTO_TEST_CASE ( Clear  )

Check table clearing function.

Definition at line 240 of file test_lib_table.cpp.

241 {
242  m_mainTableNoFb.Clear();
243 
244  // Tables start out empty
245  BOOST_CHECK_EQUAL( m_mainTableNoFb.GetCount(), 0 );
246  BOOST_CHECK_EQUAL( true, m_mainTableNoFb.IsEmpty() );
247 }

◆ BOOST_AUTO_TEST_CASE() [4/9]

BOOST_AUTO_TEST_CASE ( Equal  )

Check table equality function.

Definition at line 253 of file test_lib_table.cpp.

254 {
255  // writing a boot print is a bit of faff, so just use BOOST_CHECK_EQUAL and bools
256 
257  // These two are identical, except the fallback (which isn't checked)
258  BOOST_CHECK_EQUAL( true, m_mainTableNoFb == m_mainTableWithFb );
259  BOOST_CHECK_EQUAL( false, m_mainTableNoFb != m_mainTableWithFb );
260 
261  // Modify one of them
262  m_mainTableWithFb.At( 1 ).SetNickName( "NewNickname" );
263  BOOST_CHECK_EQUAL( false, m_mainTableNoFb == m_mainTableWithFb );
264  BOOST_CHECK_EQUAL( true, m_mainTableNoFb != m_mainTableWithFb );
265 
266  // And check unequal (against empty)
267  TEST_LIB_TABLE empty_table;
268  BOOST_CHECK_EQUAL( false, m_mainTableNoFb == empty_table );
269  BOOST_CHECK_EQUAL( true, m_mainTableNoFb != empty_table );
270 }
A concrete implementation of LIB_TABLE that implements the minimum interface for testing.

◆ BOOST_AUTO_TEST_CASE() [5/9]

BOOST_AUTO_TEST_CASE ( Indexing  )

Test indexing into the main table.

Definition at line 276 of file test_lib_table.cpp.

277 {
278  // Filled with the right row count
279  BOOST_CHECK_EQUAL( m_mainTableNoFb.GetCount(), 3 );
280 
281  const auto& row0 = m_mainTableNoFb.At( 0 );
282  BOOST_CHECK_EQUAL( row0.GetNickName(), "Lib1" );
283 
284  const auto& row1 = m_mainTableNoFb.At( 1 );
285  BOOST_CHECK_EQUAL( row1.GetNickName(), "Lib2" );
286 
287  // disable, but still in the index
288  const auto& row2 = m_mainTableNoFb.At( 2 );
289  BOOST_CHECK_EQUAL( row2.GetNickName(), "Lib3" );
290 
291  // check correct handling of out-of-bounds
292  // TODO: this doesn't work with boost::ptr_vector - that only asserts
293  // BOOST_CHECK_THROW( m_mainTableNoFb.At( 3 ), std::out_of_range );
294 }

◆ BOOST_AUTO_TEST_CASE() [6/9]

BOOST_AUTO_TEST_CASE ( HasLibrary  )

Test retrieval of libs by nickname.

Definition at line 300 of file test_lib_table.cpp.

301 {
302  BOOST_CHECK_EQUAL( true, m_mainTableNoFb.HasLibrary( "Lib1" ) );
303 
304  // disabled lib can be "not found" if checkEnabled is set
305  BOOST_CHECK_EQUAL( true, m_mainTableNoFb.HasLibrary( "Lib3" ) );
306  BOOST_CHECK_EQUAL( false, m_mainTableNoFb.HasLibrary( "Lib3", true ) );
307 
308  BOOST_CHECK_EQUAL( false, m_mainTableNoFb.HasLibrary( "NotPresent" ) );
309 }

◆ BOOST_AUTO_TEST_CASE() [7/9]

BOOST_AUTO_TEST_CASE ( Descriptions  )

Test retrieval of libs by nickname.

Definition at line 315 of file test_lib_table.cpp.

316 {
317  BOOST_CHECK_EQUAL( "The first library", m_mainTableNoFb.GetDescription( "Lib1" ) );
318 
319  // disabled lib works
320  BOOST_CHECK_EQUAL( "The third library", m_mainTableNoFb.GetDescription( "Lib3" ) );
321 }

◆ BOOST_AUTO_TEST_CASE() [8/9]

BOOST_AUTO_TEST_CASE ( URIs  )

Test retrieval of libs by URI.

Definition at line 327 of file test_lib_table.cpp.

328 {
329  BOOST_CHECK_EQUAL( "://lib/1", m_mainTableNoFb.GetFullURI( "Lib1" ) );
330 
331  const LIB_TABLE_ROW* row = m_mainTableNoFb.FindRowByURI( "://lib/1" );
332 
333  // should be found
334  BOOST_CHECK_NE( nullptr, row );
335 
336  if( row )
337  {
338  BOOST_CHECK_EQUAL( "Lib1", row->GetNickName() );
339  }
340 
341  row = m_mainTableNoFb.FindRowByURI( "this_uri_is_not_found" );
342 
343  BOOST_CHECK_EQUAL( nullptr, row );
344 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.

◆ BOOST_AUTO_TEST_CASE() [9/9]

BOOST_AUTO_TEST_CASE ( LogicalLibs  )

Test retrieval of the logical libs function.

Definition at line 350 of file test_lib_table.cpp.

351 {
352  auto logical_libs = m_mainTableNoFb.GetLogicalLibs();
353 
354  // The enabled library nicknames
355  const std::vector<wxString> exp_libs = {
356  "Lib1",
357  "Lib2",
358  };
359 
360  BOOST_CHECK_EQUAL_COLLECTIONS(
361  logical_libs.begin(), logical_libs.end(), exp_libs.begin(), exp_libs.end() );
362 }

Variable Documentation

◆ fallback_lib_defs

const std::vector<LIB_ROW_DEFINITION> fallback_lib_defs
static
Initial value:
= {
{
"FallbackLib1",
"://lib/fb1",
"The first fallback library",
true,
},
{
"FallbackLib2",
"://lib/fb2",
"The second fallback library",
false,
},
}

Definition at line 143 of file test_lib_table.cpp.

Referenced by LIB_TABLE_TEST_FIXTURE::LIB_TABLE_TEST_FIXTURE().

◆ main_lib_defs

const std::vector<LIB_ROW_DEFINITION> main_lib_defs
static
Initial value:
= {
{
"Lib1",
"://lib/1",
"The first library",
true,
},
{
"Lib2",
"://lib/2",
"The second library",
true,
},
{
"Lib3",
"://lib/3",
"The third library",
false,
},
}

Set-up data for the re-used library row definitions.

Definition at line 122 of file test_lib_table.cpp.

Referenced by LIB_TABLE_TEST_FIXTURE::LIB_TABLE_TEST_FIXTURE().