// If LIB_TABLE::Test() is conditioned on DEBUG being defined, build with // CMAKE_BUILD_TYPE=Debug, otherwise don't worry about it, because it will work // on any CMAKE_BUILD_TYPE, including Release. void LIB_TABLE::Test() { SCH_LIB_TABLE_LEXER slr( "(lib_table \n" " (lib (logical www) (type http) (full_uri http://kicad.org/libs) (options \"\"))\n" " (lib (logical meparts) (type dir) (full_uri /tmp/eeschema-lib) (options useVersioning))\n" // " (lib (logical meparts) (type dir) (full_uri /tmp/eeschema-lib) (options \"\"))\n" " (lib (logical old-project) (type schematic)(full_uri /tmp/old-schematic.sch) (options \"\"))\n" ")\n" , wxT( "inline text" ) // source ); // read the "( lib_table" pair of tokens slr.NextTok(); slr.NextTok(); // parse the rest of input to slr Parse( &slr ); STRING_FORMATTER sf; // format this whole table into sf, it will be sorted by logicalName. Format( &sf, 0 ); printf( "test 'Parse() <-> Format()' round tripping:\n" ); printf( "%s", sf.GetString().c_str() ); printf( "\ntest a lookup of 'www':\n" ); const LIB_TABLE::ROW* www = FindRow( "www" ); if( www ) { // found, print it just to prove it. sf.Clear(); www->Format( &sf, 1 ); printf( "%s", sf.GetString().c_str() ); } else printf( "not found\n" ); printf( "\nlist of logical libraries:\n" ); STRINGS logNames = GetLogicalLibs(); for( STRINGS::const_iterator it = logNames.begin(); it!=logNames.end(); ++it ) { printf( "logicalName: %s\n", it->c_str() ); } // find a part LPID lpid( "meparts:tigers/ears" ); PART* part = LookupPart( lpid ); sf.Clear(); part->Format( &sf, 0, 0 ); printf( "%s", sf.GetString().c_str() ); }
void DIR_LIB_SOURCE::Test( int argc, char** argv ) { STRINGS partnames; STRINGS sweets; try { STRINGS::const_iterator pn; // DIR_LIB_SOURCE uut( argv[1] ? argv[1] : "", "" ); DIR_LIB_SOURCE uut( argv[1] ? argv[1] : "", "useVersioning" ); // show the cached content, only the directory information is cached, // parts are cached in class LIB, not down here. uut.Show(); uut.GetCategoricalPartNames( &partnames, "lions" ); printf( "\nGetCategoricalPartNames( aCatagory = 'lions' ):\n" ); for( STRINGS::const_iterator it = partnames.begin(); it!=partnames.end(); ++it ) { printf( " '%s'\n", it->c_str() ); } uut.ReadParts( &sweets, partnames ); printf( "\nSweets for Category = 'lions' parts:\n" ); pn = partnames.begin(); for( STRINGS::const_iterator it = sweets.begin(); it!=sweets.end(); ++it, ++pn ) { printf( " %s: %s", pn->c_str(), it->c_str() ); } // fetch the part names for ALL categories. uut.GetCategoricalPartNames( &partnames ); printf( "\nGetCategoricalPartNames( aCategory = '' i.e. ALL):\n" ); for( STRINGS::const_iterator it = partnames.begin(); it!=partnames.end(); ++it ) { printf( " '%s'\n", it->c_str() ); } uut.ReadParts( &sweets, partnames ); printf( "\nSweets for ALL parts:\n" ); pn = partnames.begin(); for( STRINGS::const_iterator it = sweets.begin(); it!=sweets.end(); ++it, ++pn ) { printf( " %s: %s", pn->c_str(), it->c_str() ); } } catch( std::exception& ex ) { printf( "std::exception\n" ); } catch( IO_ERROR& ioe ) { printf( "exception: %s\n", (const char*) ioe.errorText.ToUTF8() ) ); } }