libpgplotxx.a (C++ interface to PGPLOT)
pgtestxx.cc
Go to the documentation of this file.
1 
34 #define PGTESTXX_VERSION \
35  "PGTESTXX V1.0 test functions within the PGPLOT++ library"
36 
37 #include <iostream>
38 #include <string>
39 #include <tfxx/commandline.h>
40 #include <pgplotxx/pghandle.h>
41 #include <pgplotxx/pgplotxx.h>
42 
43 using std::cout;
44 using std::cerr;
45 using std::endl;
46 
53 /*======================================================================*/
54 
55 void printtitle(const std::string& s, const char& c)
56 {
57  cout << endl;
58  cout << s << endl;
59  for (int i=0; i<s.length(); ++i) { cout << c; }
60  cout << endl;
61 }
62 
63 void section(const std::string& s) { printtitle(s, '='); }
64 void subsection(const std::string& s) { printtitle(s, '-'); }
65 
66 #define CODE( line ) \
67  cout.width(40); \
68  cout.setf(std::ios_base::left, std::ios_base::adjustfield); \
69  cout << endl << std::string(#line)+std::string(";") << ": "; line
70 
71 #define ILLEGAL( line ) \
72  cout << "ILLEGAL (does not compile): " << #line << ";" << endl;
73 
74 /*======================================================================*/
75 // code to test handle class template
76 
79  public:
80  Handletestbaseclass(const int& i): Mval(i) { }
82  { cout << "destructor of Handletestbaseclass: "; this->print(cout); }
83  virtual void print(std::ostream& os) const
84  { cout << "Handletestbaseclass(" << Mval << ")" << endl; }
85  int basevalue() const { return Mval; }
86  int& basevalue() { return Mval; }
87  private:
88  int Mval;
89 }; // class Handletestbaseclass
90 
93  public:
95  Handletestclass(const int& i, const int& j): Tbase(i), Mval(j) { }
96  virtual ~Handletestclass()
97  { cout << "destructor of Handletestclass: "; this->print(cout); }
98  virtual void print(std::ostream& os) const
99  {
100  cout << "Handletestclass(" << this->basevalue() << ","
101  << Mval << ")" << endl;
102  }
103  int value() const { return Mval; }
104  int& value() { return Mval; }
105  private:
106  int Mval;
107 }; // class Handletestclass
108 
111 {
112  subsection("in function that accepts an instance of Handle<Handletestbaseclass>::Tcoc");
113  CODE( h->print(cout) );
114  ILLEGAL( h->basevalue()=60; )
115 }
116 
119 {
120  section("test handles");
121  subsection("create objects");
122  CODE( Handletestbaseclass B1(1) );
123  CODE( Handletestclass C1(2,3) );
124  subsection("create handle from object");
125  CODE( pgplot::Handle<Handletestclass> H1(C1) );
126  CODE( H1->value()=8 );
127  CODE( H1->print(cout) );
128  subsection("create handle to base from handle");
130  CODE( H1->basevalue()=9 );
131  CODE( H1->print(cout) );
132  CODE( H2->print(cout) );
133  CODE( H1->value()=-20 );
134  CODE( H2->basevalue()=-5 );
135  CODE( H2->print(cout) );
136  ILLEGAL( H2->value()=18 );
137  subsection("create handles directly");
140  subsection("create handle to constant base");
142  CODE( H5->print(cout) );
143  ILLEGAL( H5->basevalue()=-8 );
144  cout << endl;
145  CODE( testhandlefunction(H3) );
146  subsection("assignement using inheritance transparency");
147  CODE( H4->print(cout) );
148  CODE( H4=H3 );
149  CODE( H4->print(cout) );
150  CODE( H4->basevalue()=100 );
151  CODE( H3->print(cout) );
153  CODE( H6->print(cout) );
154  CODE( H6=H3 );
155  CODE( H6->print(cout) );
156  ILLEGAL( H6->basevalue()=64 );
157  subsection("finished");
158 }
159 
160 /*======================================================================*/
161 
162 int main(int iargc, char* argv[])
163 {
164 
165  // define usage information
166  char usage_text[]=
167  {
168  PGTESTXX_VERSION "\n"
169  "usage: pgtestxx [-all] [-handle]" "\n"
170  " or: pgtestxx --help|-h" "\n"
171  };
172 
173  // define full help text
174  char help_text[]=
175  {
176  "\n"
177  "-all run all tests" "\n"
178  "-handle test Handle class template" "\n"
179  };
180 
181  // define commandline options
182  using namespace tfxx::cmdline;
183  static Declare options[]=
184  {
185  // 0: print help
186  {"help",arg_no,"-"},
187  // 1: verbose mode
188  {"verbose",arg_no,"-"},
189  // 2: test handle
190  {"handle",arg_no,"-"},
191  // 3: run all tests
192  {"all",arg_no,"-"},
193  {NULL}
194  };
195 
196  // no arguments? print usage...
197  if (iargc<2)
198  {
199  cerr << usage_text << endl;
200  exit(0);
201  }
202 
203  // collect options from commandline
204  Commandline cmdline(iargc, argv, options);
205 
206  // help requested? print full help text...
207  if (cmdline.optset(0))
208  {
209  cerr << usage_text << endl;
210  cerr << help_text << endl;
212  exit(0);
213  }
214 
215  /*
216  // dummy operation: print option settings
217  for (int iopt=0; iopt<2; iopt++)
218  {
219  cout << "option: '" << options[iopt].opt_string << "'" << endl;
220  if (cmdline.optset(iopt)) { cout << " option was set"; }
221  else { cout << "option was not set"; }
222  cout << endl;
223  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
224  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
225  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
226  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
227  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
228  cout << " argument (bool): '";
229  if (cmdline.bool_arg(iopt))
230  { cout << "true"; } else { cout << "false"; }
231  cout << "'" << endl;
232  }
233  while (cmdline.extra()) { cout << cmdline.next() << endl; }
234 
235  // dummy operation: print rest of command line
236  while (cmdline.extra()) { cout << cmdline.next() << endl; }
237  */
238 
239  cout << PGTESTXX_VERSION << endl;
240  if (cmdline.optset(2) || cmdline.optset(3)) { testhandle(); }
241 }
242 
243 /* ----- END OF pgtestxx.cc ----- */
void printtitle(const std::string &s, const char &c)
Definition: pgtestxx.cc:55
virtual ~Handletestbaseclass()
Definition: pgtestxx.cc:81
void subsection(const std::string &s)
Definition: pgtestxx.cc:64
int & value()
Definition: pgtestxx.cc:104
virtual ~Handletestclass()
Definition: pgtestxx.cc:96
void testhandlefunction(const pgplot::Handle< Handletestbaseclass >::Tcoc &h)
Test function for inheritance transparency.
Definition: pgtestxx.cc:110
Handletestclass(const int &i, const int &j)
Definition: pgtestxx.cc:95
C++ interface for PGPLOT.
Test class for handles.
Definition: pgtestxx.cc:92
Handletestbaseclass Tbase
Definition: pgtestxx.cc:94
virtual void print(std::ostream &os) const
Definition: pgtestxx.cc:83
The handle class.
Definition: pghandle.h:219
Base class for handles.
Definition: pghandle.h:85
void section(const std::string &s)
Definition: pgtestxx.cc:63
Base class for testing handles.
Definition: pgtestxx.cc:78
Handletestbaseclass(const int &i)
Definition: pgtestxx.cc:80
int basevalue() const
Definition: pgtestxx.cc:85
int main(int iargc, char *argv[])
Definition: pgtestxx.cc:162
const char *const usage_escape_sequences
usage text for escape sequences
Definition: pgplotxx.cc:46
A handle class used within the PGPLOT++ library (prototypes)
int value() const
Definition: pgtestxx.cc:103
void testhandle()
Test handles.
Definition: pgtestxx.cc:118
virtual void print(std::ostream &os) const
Definition: pgtestxx.cc:98