SMBIOS Library
main.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
3  *
4  * Copyright (C) 2005 Dell Inc.
5  * by Michael Brown <Michael_E_Brown@dell.com>
6  * Licensed under the Open Software License version 2.1
7  *
8  * Alternatively, you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License,
11  * or (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  */
18 
19 // compat header should always be first header if including system headers
20 #include "smbios/compat.h"
21 
22 #include <string>
23 #include <string.h> // strncat, strndup, and friends
24 #include <fstream>
25 #include <iostream>
26 
27 #include <cppunit/extensions/TestFactoryRegistry.h>
28 #include <cppunit/ui/text/TestRunner.h>
29 #include <cppunit/XmlOutputter.h>
30 
31 using namespace std;
32 
34 char ** global_argv;
37 std::string global_testName;
40 
41 int
42 main (int argc, char **argv)
43 {
44  global_argc = argc;
45  global_argv = argv;
46 
47  if( argc < 5 )
48  {
49  cout <<
50  "\nusage:\n"
51  " <program> <cppunit_directory> <writeable_directory>\n"
52  " Where both directory names are required arguments.\n"
53  " cppunit_directory - location where platform/ directory is located.\n"
54  " writeable_directory- location of a writeable dir for unit test.\n"
55  " test_name - name of test.\n"
56  " test_dir - location of unit test data files.\n"
57  "\n"
58  << endl;
59  exit(1);
60  }
61 
62  // set up this global var. enough stuff uses it to make it a global...
63  global_programDirname = argv[1];
64  global_writeDirectory = argv[2];
65  global_testName = argv[3];
66  global_testDirectory = argv[4];
67 
68  std::ofstream outputFile("testResults.xml");
69  CppUnit::TextUi::TestRunner runner;
70 
71  CppUnit::TestFactoryRegistry & registry =
72  CppUnit::TestFactoryRegistry::getRegistry ();
73 
74  CppUnit::XmlOutputter* outputter = new CppUnit::XmlOutputter( &runner.result(), outputFile );
75 
76  runner.setOutputter(outputter);
77  runner.addTest (registry.makeTest ());
78 
79  bool wasSuccessful = runner.run ("", //std::string testName ="",
80  false, //bool doWait = false, (lets user press <return> after tests)
81  true, //bool doPrintResult = true,
82  false //bool doPrintProgress = true ); // prints dots "."
83  );
84 
85  outputFile.close();
86 
87  // need to use _reverse_ logic here because the shell is backwards!
88  return !wasSuccessful;
89 }