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

Revision 3601, 7.7 kB (checked in by robert, 9 years ago)

Added sizeof tests of istream::pos_type and off_type to osgunittests.

Added debuggin messages to endian handling code in Archive::open().

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