Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
utXmlTunes.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Program: utXmlTunes
6 //
7 // File: utXmlTunes.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2016-02-01 15:14:45 -0700 (Mon, 01 Feb 2016) $
12  * $Rev: 4289 $
13  *
14  * \brief Unit test liblaelaps tuning.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2015-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #include <unistd.h>
50 #include <string.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <stdarg.h>
54 
55 #include <iostream>
56 #include <fstream>
57 #include <string>
58 
59 #include "rnr/rnrconfig.h"
60 #include "rnr/log.h"
61 #include "rnr/opts.h"
62 #include "rnr/pkg.h"
63 
64 #include "Laelaps/laelaps.h"
65 #include "Laelaps/laeTune.h"
66 #include "Laelaps/laeXmlTune.h"
67 
68 #include "version.h"
69 
70 using namespace std;
71 using namespace rnr;
72 using namespace laelaps;
73 
74 /*!
75  * \ingroup apps
76  * \defgroup unittest utXmlTunes
77  * \{
78  */
79 
80 #define APP_EC_OK 0 ///< success exit code
81 #define APP_EC_ARGS 2 ///< command-line options/arguments error exit code
82 #define APP_EC_EXEC 4 ///< execution exit code
83 
84 static char *Argv0; ///< the command
85 static char *ArgFileName; ///< XML file name
86 
87 /*!
88  * \brief Program information.
89  */
90 static OptsPgmInfo_T PgmInfo =
91 {
92  // usage_args
93  "<FILE>",
94 
95  // synopsis
96  "Unit test liblaelaps LaeTune and LaeXmlTune classes.",
97 
98  // long_desc =
99  "The %P command unit tests the liblaelap LaeTune and LaeXmlTune class "
100  "operation.",
101 
102  // diagnostics
103  NULL
104 };
105 
106 /*!
107  * \brief Command line options information.
108  */
109 static OptsInfo_T OptsInfo[] =
110 {
111  {NULL, }
112 };
113 
114 /*!
115  * \brief Main initialization.
116  *
117  * \param argc Command-line argument count.
118  * \param argv Command-line argument list.
119  *
120  * \par Exits:
121  * Program terminates on conversion error.
122  */
123 static void mainInit(int argc, char *argv[])
124 {
125  // name of this process
126  Argv0 = basename(argv[0]);
127 
128  // parse input options
129  argv = OptsGet(Argv0, &PkgInfo, &PgmInfo, OptsInfo, true, &argc, argv);
130 
131  if( argc < 1 )
132  {
133  fprintf(stderr, "Error: No Laelaps XMl tune file specified.\n");
134  exit(APP_EC_ARGS);
135  }
136  else
137  {
138  ArgFileName = argv[0];
139  }
140 }
141 
142 /*!
143  * \brief Main.
144  *
145  * \param argc Command-line argument count.
146  * \param argv Command-line argument list.
147  *
148  * \return Returns 0 on succes, non-zero on failure.
149  */
150 int main(int argc, char* argv[])
151 {
152  LaeTunes tunes;
153  LaeXmlTune xml;
154  int rc;
155 
156  mainInit(argc, argv);
157 
158  printf("--------------- Before parsing ---------------\n");
159  tunes.print();
160 
161  if( (rc = xml.loadFile(tunes, ArgFileName)) != LAE_OK )
162  {
163  printf("\nError: Failed to load/parse file %s\n", ArgFileName);
164  return APP_EC_EXEC;
165  }
166 
167  printf("\n");
168  printf("--------------- After parsing ---------------\n");
169  tunes.print();
170 
171  return APP_EC_OK;
172 }
173 
174 /*!
175  * \}
176  */
static char * Argv0
the command
Definition: utXmlTunes.cxx:84
Laelaps tuning data class.
Definition: laeTune.h:566
LaeXmlTune <b><i>Laelaps</i></b> XML tuning class.
Definition: laeXmlTune.h:71
virtual int loadFile(const std::string &strXmlFileName=LaeEtcTune)
Load XML file into DOM.
Definition: laeXmlTune.cxx:128
static void mainInit(int argc, char *argv[])
Main initialization.
Definition: utXmlTunes.cxx:123
void print(int indent=0)
Print out tuning parameters to stdout.
Definition: laeTune.cxx:447
static char * ArgFileName
XML file name.
Definition: utXmlTunes.cxx:85
<b><i>Laelaps</i></b> XML tuning class interface.
#define APP_EC_OK
success exit code
Definition: utXmlTunes.cxx:80
static OptsInfo_T OptsInfo[]
Command line options information.
Definition: utXmlTunes.cxx:109
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
static const PkgInfo_T PkgInfo
Definition: version.h:45
Laelaps tuning.
Package version information.
int main(int argc, char *argv[])
Main.
Definition: utRobot.cxx:138
#define APP_EC_EXEC
execution exit code
Definition: utXmlTunes.cxx:82
#define APP_EC_ARGS
command-line options/arguments error exit code
Definition: utXmlTunes.cxx:81
static OptsPgmInfo_T PgmInfo
Program information.
Definition: utXmlTunes.cxx:90
Top-level package include file.