appkit  1.5.1
RoadNarrows Robotics Application Kit
utLogBook.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: appkit
4 //
5 // Program: utLogBook
6 //
7 // File: utLogBook.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-11-09 17:38:34 -0700 (Mon, 09 Nov 2015) $
12  * $Rev: 4195 $
13  *
14  * \brief Unit test LogBook class.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2017-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  * @EulaEnd@
26  */
27 ////////////////////////////////////////////////////////////////////////////////
28 
29 #include <unistd.h>
30 #include <termios.h>
31 #include <string.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 
36 #include <iostream>
37 #include <fstream>
38 #include <string>
39 #include <map>
40 
41 #include "rnr/rnrconfig.h"
42 #include "rnr/log.h"
43 #include "rnr/opts.h"
44 #include "rnr/pkg.h"
45 
46 #include "rnr/appkit/LogBook.h"
47 
48 #include "version.h"
49 
50 using namespace std;
51 using namespace rnr;
52 
53 /*!
54  * \ingroup apps
55  * \defgroup unittest utCommandLine
56  * \{
57  */
58 
59 #define APP_EC_OK 0 ///< success exit code
60 #define APP_EC_ARGS 2 ///< command-line options/arguments error exit code
61 #define APP_EC_EXEC 4 ///< execution exit code
62 
63 static char *Argv0; ///< the command
64 
65 /*!
66  * \brief Program information.
67  */
68 static OptsPgmInfo_T PgmInfo =
69 {
70  // usage_args
71  NULL,
72 
73  // synopsis
74  "Unit test librnr_appkit LogBook class.",
75 
76  // long_desc =
77  "The %P command unit tests the librnr_appkit LogBook operation.",
78 
79  // diagnostics
80  NULL
81 };
82 
83 /*!
84  * \brief Command line options information.
85  */
86 static OptsInfo_T OptsInfo[] =
87 {
88  {NULL, }
89 };
90 
91 
92 /*!
93  * \brief Main initialization.
94  *
95  * \param argc Command-line argument count.
96  * \param argv Command-line argument list.
97  *
98  * \par Exits:
99  * Program terminates on conversion error.
100  */
101 static void mainInit(int argc, char *argv[])
102 {
103  // name of this process
104  Argv0 = basename(argv[0]);
105 
106  // parse input options
107  argv = OptsGet(Argv0, &PkgInfo, &PgmInfo, OptsInfo, true, &argc, argv);
108 }
109 
110 static string HdrSep("-------------------------------------------------------");
111 
112 static void printTestHdr(const string strSynopsis)
113 {
114  cout << endl << HdrSep << endl;
115  cout << strSynopsis << endl;
116  cout << HdrSep << endl;
117 }
118 
119 static void captainsLogMuddsWomen(LogBook &log)
120 {
121  log.setName("Captain's Log, USS Enterprise - Mudd's Women");
122 
123  log << bookmark("Captain's Log, Stardate 1328.8.")
124  << "The USS Enterprise in pursuit of an unidentified vessel."
125  << eoe;
126 
127  log << bookmark("Captain's Log, Stardate 1329.1.")
128  <<
129 "We've taken aboard from unregistered transport vessel, its captain,\n"
130 "and three unusual females. These women have a mysterious magnetic effect on\n"
131 "the male members of my crew. Including myself. Explanation unknown at present."
132  << eoe;
133 
134  log << bookmark("Captain's Log, Stardate 1329.2.")
135  <<
136 "On board the USS Enterprise, a ship's hearing has been convened against the\n"
137 "transport vessel's captain. I'm becoming concerned about the almost hypnotic\n"
138 "effect produced by the women."
139  << eoe;
140 
141  log << bookmark("Captain's Log, Stardate 1330.1.")
142  <<
143 "Position, 14 hours out of Rigel XII. We're on auxiliary impulse engines.\n"
144 "Fuel low, barely sufficient to achieve orbit over the planet. Lithium\n"
145 "replacements are now imperative. The effect of Mudd's women on my crew\n"
146 "continues to grow, still totally unexplained. Harry Mudd is confined to his\n"
147 "quarters under guard."
148  << eoe;
149 
150  log << bookmark("Captain's Log, Supplemental 1.")
151  <<
152 "Transporting down to surface of planet Rigel XII to acquire replacement\n"
153 "lithium crystals. Expect further difficulty from miners."
154  << eoe;
155 
156  log << bookmark("Captain's Log, Supplemental 2.")
157  <<
158 "I've transported aboard the Enterprise to implement search with infrared\n"
159 "scanners and sensing system. Magnetic storms on the planet's surface are\n"
160 "cutting down speed and efficiency of our equipment. Search now in progress\n"
161 "for three hours, 18 minutes."
162  << eoe;
163 
164  log << bookmark("Captain's Log, Supplemental 3.")
165  <<
166 "Have expended all but 43 minutes of power. Ship's condition: critical.\n"
167 "Search now in progress, 7 hours, 31 minutes. Magnetic storms are easing."
168  << eoe;
169 }
170 
171 static void captainsLogManTrap(LogBook &log)
172 {
173  log.setName("Captain's Log, USS Enterprise - The Man Trap");
174 
175  log << bookmark("Captain's Log, Stardate 1513.1.")
176  <<
177 "Our position, orbiting planet M-113. On board the Enterprise, Mr. Spock,\n"
178 "temporarily in command. On the planet, the ruins of an ancient and long dead\n"
179 "civilization. Ship's surgeon McCoy and myself are now beaming down to the\n"
180 "planet's surface. Our mission, routine medical examination of archaeologist\n"
181 "Robert Crater, and his wife, Nancy. Routine, but for the fact that Nancy\n"
182 "Crater is that one woman in Dr. McCoy's past."
183  << eoe;
184 
185  log << bookmark("Captain's Log, additional entry 1.")
186  <<
187 "Since our mission was routine, we had beamed down to the planet without\n"
188 "suspicion. We were totally unaware that each member of the landing party was\n"
189 "seeing a different woman. A different Nancy Crater."
190  << eoe;
191 
192  log << bookmark("Captain's Log, Stardate 1513.4.")
193  <<
194 "In orbit around planet M-113. One crewman, member of the landing party, dead\n"
195 "by violence. Cause, unknown. We are certain the cause of death was not poison."
196  << eoe;
197 
198  log << bookmark("Captain's Log, Stardate 1513.8.")
199  <<
200 "I am now certain that the violent death of my crewman was caused by some\n"
201 "strange lifeform."
202  << eoe;
203 
204  log << bookmark("Captain's Log, additional 2.")
205  <<
206 "Armed and able-bodied crewmen are not attacked and slaughtered this easily.\n"
207 "Apparently the killer can immobilize them as it approaches, perhaps with\n"
208 "some hypnotic or paralyzing power. The answer lies with Professor Crater."
209  << eoe;
210 
211  log << bookmark("Captain's Log, continuing.")
212  <<
213 "The Enterprise has been invaded by a creature capable of assuming any form,\n"
214 "and with the capacity to paralyze and draw the life from any one of us."
215  << eoe;
216 }
217 
218 static void printMarks(LogBook &log, int whence)
219 {
221 
222  cout << "+getBookMarks, whence = " << whence << endl;
223  size_t n = log.getBookMarks(list, whence);
224 
225  for(size_t i = 0; i < n; ++i)
226  {
227  cout << i << ": \"" << list[i].m_strMark
228  << "\", " << list[i].m_index << endl;
229  }
230 }
231 
232 static void testLogAttrs(LogBook &log, bool bIsTest = true)
233 {
234  if( bIsTest )
235  {
236  printTestHdr("Test LogBook Attributes");
237  }
238 
239  cout << "Name: " << log.getName() << endl;
240  cout << "max_size: " << log.max_size() << endl;
241  cout << "size: " << log.size() << endl;
242  cout << "total_ever: " << log.numOfTotalEver() << endl;
243  cout << "flags: " << "0x" << hex << log.getFlags() << dec << endl;
244 }
245 
246 static void testLogEdits(LogBook &log)
247 {
248  char tcnt = 'A';
249 
250  printTestHdr("Test LogBook Edits");
251 
252  cout << endl << "++Current State" << endl;
253 
254  // print bookmarks and text only
255  log.setFlags(LogBook::FlagOMark);
256  cout << "+log.getflags 0x" << hex << log.getFlags() << dec << endl;
257 
258  //log.orFlags(LogBook::FlagDebug);
259 
260  cout << "+log attrs" << endl;
261  testLogAttrs(log, false);
262 
263  cout << "+cout << log" << endl;
264  cout << log;
265 
266  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
267  // Test creating a default log and inserting some entries.
268  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
269  cout << endl << "++Test " << tcnt++ << endl;
270  cout << "+create logMudd with defaults" << endl;
271 
272  LogBook logMudd;
273 
274  logMudd.setFlags(LogBook::FlagOMark);
275 
276  cout << "+insert entries" << endl;
277  captainsLogMuddsWomen(logMudd);
278 
279  cout << "+logMudd attrs" << endl;
280  testLogAttrs(logMudd, false);
281 
282  cout << "+cout << logMudd" << endl;
283  cout << logMudd;
284 
285  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
286  // Test creating a another log and inserting some entries.
287  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
288  cout << endl << "++Test " << tcnt++ << endl;
289  cout << "+create logTrap with 24 max entries" << endl;
290 
291  LogBook logTrap("Temp Name", 24);
292 
293  logTrap.setFlags(LogBook::FlagOMark);
294 
295  cout << "+insert entries" << endl;
296  captainsLogManTrap(logTrap);
297 
298  cout << "+logTrap attrs" << endl;
299  testLogAttrs(logTrap, false);
300 
301  cout << "+cout << logTrap" << endl;
302  cout << logTrap;
303 
304  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
305  // Test assignment with populated log
306  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
307  cout << endl << "++Test " << tcnt++ << endl;
308  cout << "+logTrap = logMudd" << endl;
309  logTrap = logMudd;
310 
311  cout << "+logTrap attrs" << endl;
312  testLogAttrs(logTrap, false);
313 
314  cout << "+cout << logTrap" << endl;
315  cout << logTrap;
316 
317  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
318  // Test merge with populated log
319  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
320  cout << endl << "++Test " << tcnt++ << endl;
321  cout << "+logTrap << logMudd" << endl;
322  logTrap << logMudd;
323 
324  cout << "+logTrap attrs" << endl;
325  testLogAttrs(logTrap, false);
326 
327  cout << "+cout << logTrap" << endl;
328  cout << logTrap;
329 
330  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
331  // Test clear
332  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
333  cout << endl << "++Test " << tcnt++ << endl;
334  cout << "+log.clear" << endl;
335  log.clear();
336 
337  cout << "+log attrs" << endl;
338  testLogAttrs(log, false);
339 
340  cout << "+cout << log" << endl;
341  cout << log;
342 
343  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
344  // Test merge with cleared log of smaller size
345  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
346  cout << endl << "++Test " << tcnt++ << endl;
347  cout << "+re-creating logTrap entries" << endl;
348  logTrap.clear();
349  captainsLogManTrap(logTrap);
350 
351  cout << "+log << logMudd << logTrap" << endl;
352  log << logMudd << logTrap;
353 
354  cout << "+log attrs" << endl;
355  testLogAttrs(log, false);
356 
357  cout << "+cout << log" << endl;
358  cout << log;
359 
360  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
361  // Test erase entries.
362  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
363  cout << endl << "++Test " << tcnt++ << endl;
364  size_t n = 2;
365  int whence = LogBook::OLDEST;
366 
367  cout << "+log.eraseEntries(n=" << n << ", whence=" << whence << ")" << endl;
368  log.eraseEntries(n, whence);
369 
370  cout << "+cout << log" << endl;
371  cout << log;
372 
373  cout << endl << "++Test " << tcnt++ << endl;
374  whence = LogBook::NEWEST;
375 
376  cout << "+log.eraseEntries(n=" << n << ", whence=" << whence << ")" << endl;
377  log.eraseEntries(n, whence);
378 
379  cout << "+cout << log" << endl;
380  cout << log;
381 
382  cout << "+log attrs" << endl;
383  testLogAttrs(log, false);
384 
385  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
386  // Test erase entries to mark.
387  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
388  cout << endl << "++Test " << tcnt++ << endl;
390  string mark;
391 
392  whence = LogBook::OLDEST;
393  n = log.getBookMarks(list, whence);
394 
395  mark = list[1].m_strMark;
396 
397  cout << "+log.eraseEntries(mark=\"" << mark << "\", whence="
398  << whence << ")" << endl;
399  log.eraseToMark(mark, whence);
400 
401  cout << "+cout << log" << endl;
402  cout << log;
403 
404  cout << endl << "++Test " << tcnt++ << endl;
405  whence = LogBook::NEWEST;
406  mark = list[list.size()-1].m_strMark;
407 
408  cout << "+log.eraseEntries(mark=\"" << mark << "\", whence="
409  << whence << ")" << endl;
410  log.eraseToMark(mark, whence);
411 
412  cout << "+cout << log" << endl;
413  cout << log;
414 
415  cout << "+log attrs" << endl;
416  testLogAttrs(log, false);
417 }
418 
419 static void testLogOutput(LogBook &log)
420 {
421  char tcnt = 'A';
422 
423  printTestHdr("Test LogBook Output");
424 
425  // print all fields
426  log.setFlags(LogBook::FlagOAllF);
427  cout << "+getflags 0x" << hex << log.getFlags() << dec << endl;
428 
429  //log.orFlags(LogBook::FlagDebug);
430 
431  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
432  // Test full output, forward direction
433  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
434  cout << endl << "++Test " << tcnt++ << endl;
435  cout << "+operator<<(os, log), forward" << endl;
436  cout << log;
437 
438  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
439  // Test full output, forward direction
440  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
441  cout << endl << "++Test " << tcnt++ << endl;
442  log.orFlags(LogBook::FlagORev);
443  cout << "+getflags 0x" << hex << log.getFlags() << dec << endl;
444 
445  cout << "+operator<<(os, log), reverse" << endl;
446  cout << log;
447 
449  int whence = LogBook::OLDEST;
450 
451  printMarks(log, whence);
452  size_t n = log.getBookMarks(list, whence);
453 
454  unsigned flagsFwd = LogBook::FlagONum | LogBook::FlagOMark;
455  unsigned flagsRev = flagsFwd | LogBook::FlagORev;
456 
457  for(size_t i = 0; i < n; ++i)
458  {
459  for(int endpt = LogBook::OLDEST; endpt <= LogBook::NEWEST; ++endpt)
460  {
461  cout << endl << "++Test " << tcnt++ << endl;
462  cout << "+printToMark(mark=\"" << list[i].m_strMark << "\", endpt="
463  << endpt << "), forward"
464  << endl;
465  log.setFlags(flagsFwd);
466  log.printToMark(cout, list[i].m_strMark, endpt);
467 
468  cout << endl << "++Test " << tcnt++ << endl;
469  cout << "+printToMark(mark=\"" << list[i].m_strMark << "\", endpt="
470  << endpt << "), reverse"
471  << endl;
472  log.setFlags(flagsRev);
473  log.printToMark(cout, list[i].m_strMark, endpt);
474  }
475  }
476 }
477 
478 static void testLogFundamentals(LogBook &log)
479 {
480  char buf[64];
481 
482  // fundamental data
483  const bool vBool = true;
484  char vChar = 'z';
485  byte_t vByte = 43;
486  short vShort = -9;
487  unsigned short vUShort = 9;
488  int vInt = 53;
489  unsigned vUInt = 53;
490  long vLong = -153;
491  unsigned long vULong = 153;
492  long long vLongLong = 0xffffffff;
493  unsigned long long vULongLong = 0x7fffffff;
494  float vFloat = -4.1414;
495  double vDouble = -9e-12;
496  long double vLongDouble = -9e-12;
497  char * vS = buf;
498  void * vVoid = (void *)vS;
499  strcpy(buf, "hello");
500  const char * vConstS = "good bye";
501  const string vConstStr("constant pain");
502  string vStr("pleasure");
503 
504  // test tracking data
505  char tcnt = 'A'; // subtest count
506  int ecnt = 0, mcnt = 0; // entry and mark counts
507  string li("(p) "); // entry "list type" bullet
508  string what; // test whate
509 
510  printTestHdr("Test LogBook Fundamentals");
511 
512  // remember this marks
513  string mark0("Test Fundamentals (top)");
514  string mark1;
515  string mark2;
516  string mark;
517 
518  //log.orFlags(LogBook::FlagDebug);
519 
520  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
521  // Test bookmark, constants, endl os manipulator.
522  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
523  cout << endl << "++Test " << tcnt++ << endl;
524  li[1] = 'a' + ecnt;
525  what = "constants";
526 
527  log << bookmark(mark0) << li << what << ": "
528  << 1 << " \"lonely number\" " << 0x13 << " endl" << endl
529  << "Second line of entry." << eoe;
530 
531  cout << "+inserted bookmark " << mcnt++ << ": \"" << mark0 << "\""
532  << " and entry " << ecnt++ << ": \"" << li << what << "...\"" << endl;
533 
534  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
535  // Test bool.
536  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
537  cout << endl << "++Test " << tcnt++ << endl;
538  li[1] = 'a' + ecnt;
539  what = "bool";
540 
541  log << li << what << ": " << vBool << eoe;
542 
543  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
544  << endl;
545 
546  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
547  // Test bookmark, ints, and hex manipulator.
548  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
549  cout << endl << "++Test " << tcnt++ << endl;
550  li[1] = 'a' + ecnt;
551  what = "hex & dec int";
552 
553  mark1 = li + "only the lonely";
554  log << bookmark(mark1.c_str()); // use char* for this test
555 
556  cout << "+inserted bookmark " << mcnt++ << ": \"" << mark1 << "\"" << endl;
557 
558  log << li << what << ": " << hex << vInt << dec << " " << vInt << eoe;
559 
560  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
561  << endl;
562 
563  // Validate bookmarks.
564  printMarks(log, LogBook::OLDEST);
565  printMarks(log, LogBook::NEWEST);
566 
567  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
568  // Test getting entry at mark.
569  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
570  cout << endl << "++Test " << tcnt++ << endl;
571  cout << "+textAt(mark), where mark is good, bad, good " << endl;
572  cout << "0: " << log.textAt(mark0) << endl;
573  cout << "1: " << log.textAt("bad mark") << endl;
574  cout << "2: " << log.textAt(mark1) << endl;
575 
576  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
577  // Test char and byte.
578  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
579  cout << endl << "++Test " << tcnt++ << endl;
580  li[1] = 'a' + ecnt;
581  what = "char & byte";
582 
583  log << li << what << ": " << vChar << " " << vByte << eoe;
584 
585  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
586  << endl;
587 
588  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
589  // Test shorts.
590  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
591  cout << endl << "++Test " << tcnt++ << endl;
592  li[1] = 'a' + ecnt;
593  what = "short & ushort";
594 
595  log << li << what << ": " << vShort << " " << vUShort << eoe;
596 
597  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
598  << endl;
599 
600  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
601  // Test anonymous mark and ints.
602  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
603  cout << endl << "++Test " << tcnt++ << endl;
604  li[1] = 'a' + ecnt;
605  what = "int & uint";
606  mark = "anon@ints";
607 
608  log << bookmark << li << what << ": " << vInt << " " << vUInt << eoe;
609 
610  cout << "+inserted bookmark " << mcnt++ << ": \"" << mark << "\""
611  << " and entry " << ecnt++ << ": \"" << li << what << "...\"" << endl;
612 
613  // Validate bookmarks.
614  printMarks(log, LogBook::OLDEST);
615 
616  // Set up output flags for these fundamental tests.
617  log.orFlags(LogBook::FlagOMark);
618  cout << "+getflags 0x" << hex << log.getFlags() << dec << endl;
619 
620  // Validate log book.
621  cout << "+operator<<(os, log)" << endl;
622  cout << log;
623 
624  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
625  // Test longs.
626  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
627  cout << endl << "++Test " << tcnt++ << endl;
628  li[1] = 'a' + ecnt;
629  what = "long & ulong";
630 
631  log << li << what << ": " << vLong << " " << vULong << eoe;
632 
633  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
634  << endl;
635 
636  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
637  // Test anonymous mark and longlongs.
638  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
639  cout << endl << "++Test " << tcnt++ << endl;
640  li[1] = 'a' + ecnt;
641  what = "longlong & ulonglong";
642  mark = "anon@longlong";
643 
644  log << bookmark << li << what << ": "
645  << vLongLong << "(0x" << hex << vLongLong << dec << ") "
646  << vULongLong << "(0x" << hex << vULongLong << dec << ") "
647  << eoe;
648 
649  cout << "+inserted bookmark " << mcnt++ << ": \"" << mark << "\""
650  << " and entry " << ecnt++ << ": \"" << li << what << "...\"" << endl;
651 
652  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
653  // Test float.
654  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
655  cout << endl << "++Test " << tcnt++ << endl;
656  li[1] = 'a' + ecnt;
657  what = "float";
658 
659  log << li << what << ": " << vFloat << eoe;
660 
661  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
662  << endl;
663 
664  // Validate bookmarks.
665  printMarks(log, LogBook::OLDEST);
666 
667  // Validate log book.
668  cout << "+operator<<(os, log)" << endl;
669  cout << log;
670 
671  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
672  // Test inserting pending mark, then inserting double entry.
673  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
674  cout << endl << "++Test " << tcnt++ << endl;
675  li[1] = 'a' + ecnt;
676  what = "double";
677  mark2 = li + "DoubleFun";
678 
679  log << bookmark(mark2);
680 
681  cout << "+inserted pending bookmark " << mcnt++
682  << ": \"" << mark2 << "\"" << endl;
683 
684  // Validate log book (no pending mark should be in book).
685  cout << "+operator<<(os, log)" << endl;
686  cout << log;
687 
688  log << li << what << ": " << vDouble << eoe;
689 
690  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
691  << endl;
692 
693  // Validate log book.
694  cout << "+operator<<(os, log)" << endl;
695  cout << log;
696 
697  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
698  // Test longdouble.
699  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
700  cout << endl << "++Test " << tcnt++ << endl;
701  li[1] = 'a' + ecnt;
702  what = "longdouble";
703 
704  log << li << what << ": " << vLongDouble << eoe;
705 
706  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
707  << endl;
708 
709  // Validate log book.
710  cout << "+operator<<(os, log)" << endl;
711  cout << log;
712 
713  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
714  // Test char* and const char*.
715  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
716  cout << endl << "++Test " << tcnt++ << endl;
717  li[1] = 'a' + ecnt;
718  what = "char* & const char*";
719 
720  log << li << what << ": " << vS << " " << vConstS << eoe;
721 
722  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
723  << endl;
724 
725  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
726  // Test void*.
727  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
728  cout << endl << "++Test " << tcnt++ << endl;
729  li[1] = 'a' + ecnt;
730  what = "void*";
731 
732  log << li << what << ": " << vVoid << eoe;
733 
734  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
735  << endl;
736 
737  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
738  // Test string and const string
739  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
740  cout << endl << "++Test " << tcnt++ << endl;
741  li[1] = 'a' + ecnt;
742  what = "string & const string";
743 
744  log << li << what << ": " << vStr << " " << vConstStr << eoe;
745 
746  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
747  << endl;
748 
749  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
750  // Fini
751  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
752  cout << endl << "++Test " << tcnt++ << endl;
753  li[1] = 'a' + ecnt;
754  what = "End of Fundamentals";
755 
756  log << li << what << eoe;
757 
758  cout << "+inserted entry " << ecnt++ << ": \"" << li << what << "...\""
759  << endl;
760 
761  // Validate log book.
762  cout << "+operator<<(os, log)" << endl;
763  cout << log;
764 }
765 
766 /*!
767  * \brief Main.
768  *
769  * \param argc Command-line argument count.
770  * \param argv Command-line argument list.
771  *
772  * \return Returns 0 on succes, non-zero on failure.
773  */
774 int main(int argc, char* argv[])
775 {
776  string strName("Star Trek Log");
777 
778  mainInit(argc, argv);
779 
780  LogBook log(strName, 10);
781 
782  testLogAttrs(log);
783 
784  testLogFundamentals(log);
785 
786  testLogAttrs(log);
787 
788  testLogOutput(log);
789 
790  testLogEdits(log);
791 
792  testLogAttrs(log);
793 
794  return APP_EC_OK;
795 }
796 
797 /*!
798  * \}
799  */
unsigned setFlags(const unsigned uFlags)
Set the current formatting flags.
Definition: LogBook.h:630
static char * Argv0
the command
Definition: utLogBook.cxx:63
static void mainInit(int argc, char *argv[])
Main initialization.
Definition: utLogBook.cxx:101
void setName(const std::string &strName)
Set the name of the log book.
Definition: LogBook.h:568
size_t getBookMarks(BookMarkList &list, int whence) const
Get a sorted list of bookmark labels.
Definition: LogBook.cxx:594
size_t numOfTotalEver() const
Return the total number of entries ever added during log book&#39;s life.
Definition: LogBook.h:608
unsigned orFlags(const unsigned uFlags)
Or new flags into the current formatting flags.
Definition: LogBook.h:643
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
const std::string & getName() const
Get the name of the log book.
Definition: LogBook.h:558
LogBook class interface.
#define APP_EC_OK
success exit code
Definition: utLogBook.cxx:59
static OptsInfo_T OptsInfo[]
Command line options information.
Definition: utLogBook.cxx:86
LogBook & eoe(LogBook &log)
LogBook end-of-entry stream manipulator.
Definition: LogBook.cxx:926
static const PkgInfo_T PkgInfo
Definition: version.h:45
unsigned getFlags() const
Get the current formatting flags.
Definition: LogBook.h:618
const size_t max_size() const
Return the maximum number entries the log book can hold.
Definition: LogBook.h:578
LogBook & bookmark(LogBook &log)
LogBook bookmark stream manipulator.
Definition: LogBook.cxx:932
Package version information.
std::vector< BookMark > BookMarkList
bookmark list type
Definition: LogBook.h:197
int main(int argc, char *argv[])
Main.
Definition: utLogBook.cxx:774
const std::string & textAt(const std::string &strMark) const
Get the entry text at the bookmark.
Definition: LogBook.h:482
RoadNarrows Robotics.
Definition: Camera.h:74
static OptsPgmInfo_T PgmInfo
Program information.
Definition: utLogBook.cxx:68