root/OpenSceneGraph/trunk/examples/osgunittests/osgunittests.cpp @ 1815

Revision 1815, 2.0 kB (checked in by robert, 12 years ago)

Added the usage report to the examples for when no arguments are passed
to the examples.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osg/UnitTestFramework>
2#include <osg/ArgumentParser>
3#include <osg/ApplicationUsage>
4
5int main( int argc, char** argv )
6{
7    osg::ArgumentParser arguments(&argc,argv);
8
9    // set up the usage document, in case we need to print out how to use this program.
10    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options]");
11    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
12    arguments.getApplicationUsage()->addCommandLineOption("qt","Display qualified tests.");
13 
14
15    bool printQualifiedTest = false;
16    while (arguments.read("qt")) printQualifiedTest = true;
17
18    // if user request help write it out to cout.
19    if (arguments.read("-h") || arguments.read("--help"))
20    {
21        std::cout<<arguments.getApplicationUsage()->getCommandLineUsage()<<std::endl;
22        arguments.getApplicationUsage()->write(std::cout,arguments.getApplicationUsage()->getCommandLineOptions());
23        return 1;
24    }
25
26    // any option left unread are converted into errors to write out later.
27    arguments.reportRemainingOptionsAsUnrecognized();
28
29    // report any errors if they have occured when parsing the program aguments.
30    if (arguments.errors())
31    {
32        arguments.writeErrorMessages(std::cout);
33        return 1;
34    }
35   
36    if (arguments.argc()<=1)
37    {
38        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
39        return 1;
40    }
41
42
43    if (printQualifiedTest)
44    {
45         std::cout<<"*****   Qualified Tests  ******"<<std::endl;
46
47         osgUtx::QualifiedTestPrinter printer;
48         osgUtx::TestGraph::instance().root()->accept( printer );   
49         std::cout<<std::endl;
50    }
51
52    std::cout<<"******   Running tests   ******"<<std::endl;
53
54    // Global Data or Context
55    osgUtx::TestContext ctx;
56    osgUtx::TestRunner runner( ctx );
57    runner.specify("root");
58
59    osgUtx::TestGraph::instance().root()->accept( runner );
60
61    return 0;
62}
Note: See TracBrowser for help on using the browser.