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

Revision 2772, 6.7 kB (checked in by robert, 10 years ago)

Removed include <iostream> where possible, replacing with istream or ostream and changing
std::cout/cerr to osg::notify().

  • 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
5#include <osg/Matrix>
6
7#include <iostream>
8
9void testFrustum(double left,double right,double bottom,double top,double zNear,double zFar)
10{
11    osg::Matrix f;
12    f.makeFrustum(left,right,bottom,top,zNear,zFar);
13
14    double c_left=0;
15    double c_right=0;
16    double c_top=0;
17    double c_bottom=0;
18    double c_zNear=0;
19    double c_zFar=0;
20   
21   
22    std::cout << "testFrustum"<<f.getFrustum(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar)<<std::endl;
23    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl;
24    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl;
25
26    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl;
27    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl;
28
29    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
30    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
31   
32    std::cout << std::endl;
33}
34
35void testOrtho(double left,double right,double bottom,double top,double zNear,double zFar)
36{
37    osg::Matrix f;
38    f.makeOrtho(left,right,bottom,top,zNear,zFar);
39
40    double c_left=0;
41    double c_right=0;
42    double c_top=0;
43    double c_bottom=0;
44    double c_zNear=0;
45    double c_zFar=0;
46
47    std::cout << "testOrtho "<< f.getOrtho(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar) << std::endl;
48    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl;
49    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl;
50
51    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl;
52    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl;
53
54    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
55    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
56   
57    std::cout << std::endl;
58}
59
60void testPerspective(double fovy,double aspect,double zNear,double zFar)
61{
62    osg::Matrix f;
63    f.makePerspective(fovy,aspect,zNear,zFar);
64
65    double c_fovy=0;
66    double c_aspect=0;
67    double c_zNear=0;
68    double c_zFar=0;
69
70    std::cout << "testPerspective "<< f.getPerspective(c_fovy,c_aspect,c_zNear,c_zFar) << std::endl;
71    std::cout << "  fovy = "<<fovy<<" compute "<<c_fovy<<std::endl;
72    std::cout << "  aspect = "<<aspect<<" compute "<<c_aspect<<std::endl;
73
74    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
75    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
76   
77    std::cout << std::endl;
78}
79
80void testLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)
81{
82    osg::Matrix mv;
83    mv.makeLookAt(eye,center,up);
84   
85    osg::Vec3 c_eye,c_center,c_up;
86    mv.getLookAt(c_eye,c_center,c_up);
87   
88    std::cout << "testLookAt"<<std::endl;
89    std::cout << "  eye "<<eye<< " compute "<<c_eye<<std::endl;
90    std::cout << "  eye "<<center<< " compute "<<c_center<<std::endl;
91    std::cout << "  eye "<<up<< " compute "<<c_up<<std::endl;
92   
93    std::cout << std::endl;
94   
95}
96
97void sizeOfTest()
98{
99  std::cout<<"sizeof(bool)=="<<sizeof(bool)<<std::endl;
100  std::cout<<"sizeof(char)=="<<sizeof(char)<<std::endl;
101  std::cout<<"sizeof(short)=="<<sizeof(short)<<std::endl;
102  std::cout<<"sizeof(int)=="<<sizeof(int)<<std::endl;
103  std::cout<<"sizeof(long)=="<<sizeof(long)<<std::endl;
104  std::cout<<"sizeof(long int)=="<<sizeof(long int)<<std::endl;
105
106#if defined(_MSC_VER)
107  // long long isn't supported on VS6.0...
108  std::cout<<"sizeof(__int64)=="<<sizeof(__int64)<<std::endl;
109#else
110  std::cout<<"sizeof(long long)=="<<sizeof(long long)<<std::endl;
111#endif
112  std::cout<<"sizeof(float)=="<<sizeof(float)<<std::endl;
113  std::cout<<"sizeof(double)=="<<sizeof(double)<<std::endl;
114}
115
116int main( int argc, char** argv )
117{
118    osg::ArgumentParser arguments(&argc,argv);
119
120    // set up the usage document, in case we need to print out how to use this program.
121    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which runs units tests.");
122    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options]");
123    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
124    arguments.getApplicationUsage()->addCommandLineOption("qt","Display qualified tests.");
125    arguments.getApplicationUsage()->addCommandLineOption("sizeof","Display sizeof tests.");
126    arguments.getApplicationUsage()->addCommandLineOption("matrix","Display qualified tests.");
127 
128
129    if (arguments.argc()<=1)
130    {
131        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
132        return 1;
133    }
134
135    bool printQualifiedTest = false;
136    while (arguments.read("qt")) printQualifiedTest = true;
137
138    bool printMatrixTest = false;
139    while (arguments.read("matrix")) printMatrixTest = true;
140
141    bool printSizeOfTest = false;
142    while (arguments.read("sizeof")) printSizeOfTest = true;
143
144    // if user request help write it out to cout.
145    if (arguments.read("-h") || arguments.read("--help"))
146    {
147        std::cout<<arguments.getApplicationUsage()->getCommandLineUsage()<<std::endl;
148        arguments.getApplicationUsage()->write(std::cout,arguments.getApplicationUsage()->getCommandLineOptions());
149        return 1;
150    }
151
152    // any option left unread are converted into errors to write out later.
153    arguments.reportRemainingOptionsAsUnrecognized();
154
155    // report any errors if they have occured when parsing the program aguments.
156    if (arguments.errors())
157    {
158        arguments.writeErrorMessages(std::cout);
159        return 1;
160    }
161   
162
163    if (printMatrixTest)
164    {
165        std::cout<<"******   Running matrix tests   ******"<<std::endl;
166
167        testFrustum(-1,1,-1,1,1,1000);
168        testFrustum(0,1,1,2,2.5,100000);
169
170        testOrtho(0,1,1,2,2.1,1000);
171        testOrtho(-1,10,1,20,2.5,100000);
172
173        testPerspective(20,1,1,1000);
174        testPerspective(90,2,1,1000);
175
176        testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(0.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
177        testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(1.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
178
179    }
180   
181    if (printSizeOfTest)
182    {
183        std::cout<<"**** sizeof() tests  ******"<<std::endl;
184       
185        sizeOfTest();
186
187        std::cout<<std::endl;
188    }
189
190
191    if (printQualifiedTest)
192    {
193         std::cout<<"*****   Qualified Tests  ******"<<std::endl;
194
195         osgUtx::QualifiedTestPrinter printer;
196         osgUtx::TestGraph::instance().root()->accept( printer );   
197         std::cout<<std::endl;
198    }
199
200    std::cout<<"******   Running tests   ******"<<std::endl;
201
202    // Global Data or Context
203    osgUtx::TestContext ctx;
204    osgUtx::TestRunner runner( ctx );
205    runner.specify("root");
206
207    osgUtx::TestGraph::instance().root()->accept( runner );
208
209    return 0;
210}
Note: See TracBrowser for help on using the browser.