KiCad PCB EDA Suite
specctra_test.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 // unit test the specctra.cpp file. You can use the beautifiers below to output
27 // exactly what you read in but beautified and without #comments. This can
28 // then be used along with program 'diff' to test the parsing and formatting
29 // of every element. You may have to run the first output back through to
30 // get two files that should match, the 2nd and 3rd outputs.
31 
32 
33 
34 #include <cstdarg>
35 #include <cstdio>
36 
37 #include "specctra.h"
38 #include <common.h>
39 
40 
41 using namespace DSN;
42 
43 
44 int main( int argc, char** argv )
45 {
46 // wxString filename( wxT("/tmp/fpcroute/Sample_1sided/demo_1sided.dsn") );
47 // wxString filename( wxT("/tmp/testdesigns/test.dsn") );
48 // wxString filename( wxT("/tmp/testdesigns/test.ses") );
49  wxString filename( wxT("/tmp/specctra_big.dsn") );
50 
51  SPECCTRA_DB db;
52  bool failed = false;
53 
54  LOCALE_IO toggle; // Temporary switch the locale to standard C to r/w floats
55 
56  if( argc == 2 )
57  {
58  filename = FROM_UTF8( argv[1] );
59  }
60 
61  try
62  {
63 // db.LoadPCB( filename );
64  db.LoadSESSION( filename );
65  }
66  catch( const IO_ERROR& ioe )
67  {
68  fprintf( stderr, "%s\n", TO_UTF8(ioe.What()) );
69  failed = true;
70  }
71 
72  if( !failed )
73  fprintf( stderr, "loaded OK\n" );
74 
75  // export what we read in, making this test program basically a beautifier
76  // hose the beautified DSN file to stdout. If an exception occurred,
77  // we will be outputting only a portion of what we wanted to read in.
78  db.SetFILE( stdout );
79 
80 #if 0
81  // export a PCB
82  DSN::PCB* pcb = db.GetPCB();
83  pcb->Format( &db, 0 );
84 
85 #else
86  // export a SESSION file.
87  DSN::SESSION* ses = db.GetSESSION();
88  ses->Format( &db, 0 );
89 #endif
90 }
91 
92 //-----<dummy code>---------------------------------------------------
93 
94 // a dummy to satisfy link of specctra_test without pulling in BOARD stuff.
96 {
97  return 0;
98 }
99 
100 // a dummy to satisfy link of specctra_test without pulling in BOARD stuff.
101 wxString BOARD::GetLayerName( LAYER_NUM aLayer ) const
102 {
103  return wxEmptyString;
104 }
105 
106 //-----</dummy code>--------------------------------------------------
107 
108 //EOF
void LoadSESSION(const wxString &aFilename)
Function LoadSESSION is a recursive descent parser for a SPECCTRA DSN "session" file.
Definition: specctra.cpp:262
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
This source file implements export and import capabilities to the specctra dsn file format.
Definition: specctra.cpp:62
SESSION * GetSESSION()
Definition: specctra.h:3900
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:202
void Format(OUTPUTFORMATTER *out, int nestLevel) override
Function Format writes this object as ASCII out to an OUTPUTFORMATTER according to the SPECCTRA DSN f...
Definition: specctra.h:3572
SESSION corresponds to the <session_file_descriptor> in the specctra dsn spec.
Definition: specctra.h:3533
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
PCB * GetPCB()
Definition: specctra.h:3889
int main(int argc, char **argv)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void Format(OUTPUTFORMATTER *out, int nestLevel) override
Function Format writes this object as ASCII out to an OUTPUTFORMATTER according to the SPECCTRA DSN f...
Definition: specctra.h:3176
SPECCTRA_DB holds a DSN data tree, usually coming from a DSN file.
Definition: specctra.h:3607
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
int GetCopperLayerCount() const
Function GetCopperLayerCount.
The common library.
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76