Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
f92d6972
Commit
f92d6972
authored
Feb 03, 2011
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sweet C++ test program
parent
ad2a7e8a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
101 deletions
+127
-101
.bzrignore
.bzrignore
+2
-0
CMakeLists.txt
new/CMakeLists.txt
+3
-0
sch_lib_table.cpp
new/sch_lib_table.cpp
+0
-100
sch_lib_table.h
new/sch_lib_table.h
+1
-1
test_sch_lib_table.cpp
new/test_sch_lib_table.cpp
+121
-0
No files found.
.bzrignore
View file @
f92d6972
...
@@ -17,6 +17,8 @@ install_manifest.txt
...
@@ -17,6 +17,8 @@ install_manifest.txt
Documentation/doxygen
Documentation/doxygen
*.cmake
*.cmake
*.bak
*.bak
pcbnew/pcb_plot_params_keywords.cpp
pcbnew/pcb_plot_params_lexer.h
pcbnew/specctra_keywords.cpp
pcbnew/specctra_keywords.cpp
pcbnew/specctra_lexer.h
pcbnew/specctra_lexer.h
new/html
new/html
...
...
new/CMakeLists.txt
View file @
f92d6972
...
@@ -108,6 +108,9 @@ add_library( sweet SHARED
...
@@ -108,6 +108,9 @@ add_library( sweet SHARED
)
)
target_link_libraries
(
sweet
${
wxWidgets_LIBRARIES
}
)
target_link_libraries
(
sweet
${
wxWidgets_LIBRARIES
}
)
add_executable
(
test_sch_lib_table test_sch_lib_table.cpp
)
target_link_libraries
(
test_sch_lib_table sweet
)
#=====<USE_SWIG>============================================================
#=====<USE_SWIG>============================================================
# if you want a Python scripting layer on top for unit testing or driving.
# if you want a Python scripting layer on top for unit testing or driving.
...
...
new/sch_lib_table.cpp
View file @
f92d6972
...
@@ -340,103 +340,3 @@ bool LIB_TABLE::InsertRow( std::auto_ptr<ROW>& aRow, bool doReplace )
...
@@ -340,103 +340,3 @@ bool LIB_TABLE::InsertRow( std::auto_ptr<ROW>& aRow, bool doReplace )
return
false
;
return
false
;
}
}
#if 0 && defined(DEBUG)
// build this with a Debug CMAKE_BUILD_TYPE
void LIB_TABLE::Test()
{
// A pair of double quotes alone, is not really a legal DSN token since
// any duplicated double quote ("") is assumed to be a single double quote (")
// in any DSN lexer.
// To pass an empty string, we can pass " " to (options " "), or if you passed
// """" this would show up as "" with quotes present in the parser. The parser
// probably doesn't want a pair of double quotes, strlen() = 2.
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" );
LookupPart( lpid );
}
int main( int argc, char** argv )
{
LIB_TABLE lib_table;
try
{
// test exceptions:
// THROW_PARSE_ERROR( wxT("test problem"), wxT("input"), 23, 46 );
//THROW_IO_ERROR( wxT("io test") );
lib_table.Test();
}
catch( PARSE_ERROR& ioe ) // most derived class first
{
printf( "%s\n", (const char*) ioe.errorText.ToUTF8() );
printf( "%s%s",
ioe.inputLine.c_str(),
ioe.inputLine.empty() || *ioe.inputLine.rbegin() != '\n' ?
"\n" : "" ); // rare not to have \n at end
printf( "%*s^\n", ioe.byteIndex>=1 ? ioe.byteIndex-1 : 0, "" );
}
catch( IO_ERROR& ioe )
{
printf( "%s\n", (const char*) ioe.errorText.ToUTF8() );
}
return 0;
}
#endif
new/sch_lib_table.h
View file @
f92d6972
...
@@ -316,7 +316,7 @@ public:
...
@@ -316,7 +316,7 @@ public:
//----</read accessors>---------------------------------------------------
//----</read accessors>---------------------------------------------------
#if defined(DEBUG)
#if
1 ||
defined(DEBUG)
/// implement the tests in here so we can honor the priviledge levels of the
/// implement the tests in here so we can honor the priviledge levels of the
/// accessors, something difficult to do from int main(int, char**)
/// accessors, something difficult to do from int main(int, char**)
void
Test
();
void
Test
();
...
...
new/test_sch_lib_table.cpp
0 → 100644
View file @
f92d6972
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2010-2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2010 Kicad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <sch_lib_table.h>
#include <sch_lib_table_lexer.h>
#include <sch_lpid.h>
using
namespace
SCH
;
// 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
(
"
\n
test 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
(
"
\n
list 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"
);
LookupPart
(
lpid
);
}
int
main
(
int
argc
,
char
**
argv
)
{
LIB_TABLE
lib_table
;
try
{
// test exceptions:
// THROW_PARSE_ERROR( wxT("test problem"), wxT("input"), 23, 46 );
//THROW_IO_ERROR( wxT("io test") );
lib_table
.
Test
();
}
catch
(
PARSE_ERROR
&
ioe
)
// most derived class first
{
printf
(
"%s
\n
"
,
(
const
char
*
)
ioe
.
errorText
.
ToUTF8
()
);
printf
(
"%s%s"
,
ioe
.
inputLine
.
c_str
(),
ioe
.
inputLine
.
empty
()
||
*
ioe
.
inputLine
.
rbegin
()
!=
'\n'
?
"
\n
"
:
""
);
// rare not to have \n at end
printf
(
"%*s^
\n
"
,
ioe
.
byteIndex
>=
1
?
ioe
.
byteIndex
-
1
:
0
,
""
);
}
catch
(
IO_ERROR
&
ioe
)
{
printf
(
"%s
\n
"
,
(
const
char
*
)
ioe
.
errorText
.
ToUTF8
()
);
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment