50 std::unique_ptr<LINE_READER>
GetReader(
const wxString& aURI )
const override
52 return std::make_unique<STRING_LINE_READER>(
"",
"DUMMY_LIB_TABLE_IO Data" );
61 bool UrisAreEquivalent(
const wxString& aURI1,
const wxString& aURI2 )
const override
63 return aURI1 == aURI2;
66 std::unique_ptr<OUTPUTFORMATTER>
GetWriter(
const wxString& aURI )
const override
68 return std::make_unique<STRING_FORMATTER>();
80 TEST_LIB_TABLE_ROW(
const wxString& aNick,
const wxString& aURI,
const wxString& aOptions,
81 const wxString& aDescr )
86 const wxString
GetType()
const override
91 void SetType(
const wxString& aType )
override
99 return new TEST_LIB_TABLE_ROW( *
this );
116 TEST_LIB_TABLE(
LIB_TABLE* aFallback =
nullptr ) :
117 LIB_TABLE( aFallback,
std::make_unique<DUMMY_LIB_TABLE_IO>() )
128 void Parse( LIB_TABLE_LEXER* aLexer )
override
144struct LIB_ROW_DEFINITION
146 std::string m_nickname;
148 std::string m_description;
157static const std::vector<LIB_ROW_DEFINITION> main_lib_defs = {
167 "The second library",
178static const std::vector<LIB_ROW_DEFINITION> fallback_lib_defs = {
182 "The first fallback library",
188 "The second fallback library",
198struct LIB_TABLE_TEST_FIXTURE
200 LIB_TABLE_TEST_FIXTURE() : m_mainTableWithFb( &m_fallbackTable )
202 for(
const auto& lib : main_lib_defs )
204 m_mainTableNoFb.InsertRow( makeRowFromDef( lib ).release() );
205 m_mainTableWithFb.InsertRow( makeRowFromDef( lib ).release() );
208 for(
const auto& lib : fallback_lib_defs )
210 m_fallbackTable.InsertRow( makeRowFromDef( lib ).release() );
217 std::unique_ptr<TEST_LIB_TABLE_ROW> makeRowFromDef(
const LIB_ROW_DEFINITION& aDef )
219 auto row = std::make_unique<TEST_LIB_TABLE_ROW>(
220 aDef.m_nickname, aDef.m_uri,
"", aDef.m_description );
222 row->SetEnabled( aDef.m_enabled );
228 TEST_LIB_TABLE m_mainTableNoFb;
231 TEST_LIB_TABLE m_mainTableWithFb;
234 TEST_LIB_TABLE m_fallbackTable;
242BOOST_FIXTURE_TEST_SUITE( LibTable, LIB_TABLE_TEST_FIXTURE )
249 TEST_LIB_TABLE table;
252 BOOST_CHECK_EQUAL( table.GetCount(), 0 );
253 BOOST_CHECK_EQUAL(
true, table.IsEmpty() );
263 TEST_LIB_TABLE interposer_table( &m_fallbackTable );
264 TEST_LIB_TABLE table( &interposer_table );
267 BOOST_CHECK_EQUAL( table.GetCount(), 0 );
270 BOOST_CHECK_EQUAL(
false, table.IsEmpty(
true ) );
282 BOOST_CHECK_EQUAL(
true, m_mainTableNoFb == m_mainTableWithFb );
283 BOOST_CHECK_EQUAL(
false, m_mainTableNoFb != m_mainTableWithFb );
286 m_mainTableWithFb.At( 1 ).SetNickName(
"NewNickname" );
287 BOOST_CHECK_EQUAL(
false, m_mainTableNoFb == m_mainTableWithFb );
288 BOOST_CHECK_EQUAL(
true, m_mainTableNoFb != m_mainTableWithFb );
291 TEST_LIB_TABLE empty_table;
292 BOOST_CHECK_EQUAL(
false, m_mainTableNoFb == empty_table );
293 BOOST_CHECK_EQUAL(
true, m_mainTableNoFb != empty_table );
303 BOOST_CHECK_EQUAL( m_mainTableNoFb.GetCount(), 3 );
305 const auto& row0 = m_mainTableNoFb.At( 0 );
306 BOOST_CHECK_EQUAL( row0.GetNickName(),
"Lib1" );
308 const auto& row1 = m_mainTableNoFb.At( 1 );
309 BOOST_CHECK_EQUAL( row1.GetNickName(),
"Lib2" );
312 const auto& row2 = m_mainTableNoFb.At( 2 );
313 BOOST_CHECK_EQUAL( row2.GetNickName(),
"Lib3" );
326 BOOST_CHECK_EQUAL(
true, m_mainTableNoFb.HasLibrary(
"Lib1" ) );
329 BOOST_CHECK_EQUAL(
true, m_mainTableNoFb.HasLibrary(
"Lib3" ) );
330 BOOST_CHECK_EQUAL(
false, m_mainTableNoFb.HasLibrary(
"Lib3",
true ) );
332 BOOST_CHECK_EQUAL(
false, m_mainTableNoFb.HasLibrary(
"NotPresent" ) );
341 BOOST_CHECK_EQUAL(
"The first library", m_mainTableNoFb.GetDescription(
"Lib1" ) );
344 BOOST_CHECK_EQUAL(
"The third library", m_mainTableNoFb.GetDescription(
"Lib3" ) );
353 BOOST_CHECK_EQUAL(
"://lib/1", m_mainTableNoFb.GetFullURI(
"Lib1" ) );
355 const LIB_TABLE_ROW* row = m_mainTableNoFb.FindRowByURI(
"://lib/1" );
358 BOOST_CHECK_NE(
nullptr, row );
365 row = m_mainTableNoFb.FindRowByURI(
"this_uri_is_not_found" );
367 BOOST_CHECK_EQUAL(
nullptr, row );
376 auto logical_libs = m_mainTableNoFb.GetLogicalLibs();
379 const std::vector<wxString> exp_libs = {
384 BOOST_CHECK_EQUAL_COLLECTIONS(
385 logical_libs.begin(), logical_libs.end(), exp_libs.begin(), exp_libs.end() );
LIB_TABLE_IO abstracts the file I/O operations for the library table loading and saving.
virtual std::unique_ptr< OUTPUTFORMATTER > GetWriter(const wxString &aURI) const =0
Save the given table to the given URI.
virtual std::unique_ptr< LINE_READER > GetReader(const wxString &aURI) const =0
Create a reader for the given URI.
virtual bool CanSaveToUri(const wxString &aURI) const =0
Check if the given URI is writable.
virtual bool UrisAreEquivalent(const wxString &aURI1, const wxString &aURI2) const =0
Compare two URIs for equivalence.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
virtual LIB_TABLE_ROW * do_clone() const =0
virtual const wxString GetType() const =0
Return the type of library represented by this row.
virtual void SetType(const wxString &aType)=0
Change the type of library represented by this row that must be implemented in the derived object to ...
const wxString & GetNickName() const
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
virtual void Parse(LIB_TABLE_LEXER *aLexer)=0
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
virtual PROJECT::ELEM ProjectElementType()=0
ELEM
The set of #_ELEMs that a PROJECT can hold.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Empty)
Declare the test suite.