TestGLXGLContext.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00027 
00028 #include "../include/TestGLXGLContext.h"
00029 #include "../../include/PCMFileSystemManager.h"
00030 #include "../../include/PCMStringConverter.h"
00031 #include "../../include/PCMHost.h"
00032 #include "../../include/PCMNode.h"
00033 #include "../../include/PCMProcess.h"
00034 
00035 namespace ParCompMarkTest
00036 {
00037 
00038   void TestGLXGLContext::setUp()
00039   {
00040         std::string currentLogFile = "logs/TestGLXGLContext.log";
00041 
00042         if(Logger::getInstance() && Logger::getInstance()->getLogFileName() != currentLogFile)
00043          Logger::destroyInstance();
00044 
00045         if(!FileSystemManager::getInstance())
00046         {
00047          FileSystemManager::createInstance();
00048          FileSystemManager::getInstance()->setAppDirectory("./");
00049          FileSystemManager::getInstance()->initialize();
00050         }
00051 
00052         if(!Logger::getInstance())
00053         {
00054          Logger::createInstance();
00055          Logger::getInstance()->setLogFileName(currentLogFile);
00056          Logger::getInstance()->initialize();
00057         }
00058   }
00059 
00060  /*----------------------------------------------------------------------*/
00061 
00062   void TestGLXGLContext::tearDown()
00063   {
00064   }
00065 
00066  /*----------------------------------------------------------------------*/
00067 
00068   //
00069   // Constructor & destructor tests
00070   //
00071 
00072   void TestGLXGLContext::test_constructor_XDisplay__Pointer_GLXRenderWindow_p___XVisualInfo_p()
00073   {
00074 
00075         /*
00076          * You have to verify the following:
00077          * 
00078          * Create GLX context.
00079          */
00080 
00081         // Create display
00082         XDisplay::Pointer d(new XDisplay());
00083 
00084         // Null pointer error
00085         CPPUNIT_ASSERT_THROW(GLXGLContext::Pointer c(new GLXGLContext(d, 0, 0)), ParCompMark::Exception);
00086 
00087         // Create host (not use as singleton)
00088         Host *h = 0;
00089 
00090         CPPUNIT_ASSERT_NO_THROW(h = new Host("TestHost"));
00091 
00092         // Create node
00093         Node *n = 0;
00094 
00095         CPPUNIT_ASSERT_NO_THROW(n = new Node("TestNode", h));
00096 
00097         // Create process
00098         Process *p = 0;
00099 
00100         CPPUNIT_ASSERT_NO_THROW(p = new Process("TestProcess", n));
00101 
00102         // Create glx renderwindow
00103         GLXRenderWindow *win = 0;
00104 
00105         CPPUNIT_ASSERT_NO_THROW(win = new GLXRenderWindow(d, p, "Testwindow"));
00106 
00107         // Correct creation
00108         ::XVisualInfo visualInfo;
00109         CPPUNIT_ASSERT_NO_THROW(GLXGLContext::Pointer c(new GLXGLContext(d, win, &visualInfo)));
00110 
00111         // Do not delete object (we are not interested in destructors) 
00112   }
00113 
00114  /*----------------------------------------------------------------------*/
00115 
00116   void TestGLXGLContext::test_destructor()
00117   {
00118         // Tested at constructor
00119   }
00120 
00121  /*----------------------------------------------------------------------*/
00122 
00123   //
00124   // Method tests
00125   //
00126 
00127   void TestGLXGLContext::test_initialize()
00128   {
00129 
00130         /*
00131          * You have to verify the following:
00132          * 
00133          * Initialize the GL context.
00134          */
00135 
00136         XDisplay::Pointer d(new XDisplay());
00137         CPPUNIT_ASSERT_NO_THROW(d->initialize());
00138         Host *h = 0;
00139         Node *n = 0;
00140         Process *p = 0;
00141         GLXRenderWindow *win = 0;
00142 
00143         GLXGLContext::Pointer c;
00144         CPPUNIT_ASSERT_NO_THROW(h = new Host("TestHost"));
00145         CPPUNIT_ASSERT_NO_THROW(n = new Node("TestNode", h));
00146         CPPUNIT_ASSERT_NO_THROW(p = new Process("TestProcess", n));
00147         CPPUNIT_ASSERT_NO_THROW(win = new GLXRenderWindow(d, p, "Testwindow"));
00148 
00149         // Recreate, reinitialize properly
00150         XVisualInfo templ;
00151         int screen = DefaultScreen(d->getDisplay());
00152         int best_visual = d->findBestVisual(screen);
00153 
00154         templ.visualid = best_visual;
00155         int nmatch;
00156         XVisualInfo *visualInfo = 0;
00157 
00158         CPPUNIT_ASSERT_NO_THROW(visualInfo = XGetVisualInfo(d->getDisplay(), VisualIDMask, &templ, &nmatch));
00159 
00160         CPPUNIT_ASSERT_NO_THROW(c = new GLXGLContext(d, win, visualInfo));
00161         CPPUNIT_ASSERT_NO_THROW(c->initialize());
00162 
00163         // Test finalize after initialization
00164         CPPUNIT_ASSERT_NO_THROW(c->finalize());
00165 
00166         //
00167         // Test several contexts
00168         //
00169         const u32 testCount = 20;
00170 
00171         GLXGLContext::Pointer cs[testCount];
00172 
00173         // Create contexts
00174         for(u32 i = 0; i < testCount; i++)
00175         {
00176          CPPUNIT_ASSERT_NO_THROW(win = new GLXRenderWindow(d, p, "Testwindow #" + StringConverter::toString(i)));
00177          CPPUNIT_ASSERT_NO_THROW(cs[i] = new GLXGLContext(d, win, visualInfo));
00178         }
00179 
00180         // Initialize contexts
00181         for(u32 i = 0; i < testCount; i++)
00182         {
00183          CPPUNIT_ASSERT_NO_THROW(cs[i]->initialize());
00184         }
00185 
00186         // Finalize contexts
00187         for(u32 i = 0; i < testCount; i++)
00188         {
00189          CPPUNIT_ASSERT_NO_THROW(cs[i]->finalize());
00190         }
00191   }
00192 
00193  /*----------------------------------------------------------------------*/
00194 
00195   void TestGLXGLContext::test_finalize()
00196   {
00197 
00198         /*
00199          * You have to verify the following:
00200          * 
00201          * Finalize the GL context.
00202          */
00203 
00204         // Tested at initialize
00205   }
00206 
00207  /*----------------------------------------------------------------------*/
00208 
00209   void TestGLXGLContext::test_setCurrent()
00210   {
00211 
00212         /*
00213          * You have to verify the following:
00214          * 
00215          * Enable the context. All subsequent rendering commands will go here.
00216          */
00217 
00218         // Unable to test from here
00219   }
00220 
00221  /*----------------------------------------------------------------------*/
00222 
00223   void TestGLXGLContext::test_releaseCurrent()
00224   {
00225 
00226         /*
00227          * You have to verify the following:
00228          * 
00229          * Release the current context without assigning a new one.
00230          */
00231 
00232         // Unable to test from here
00233   }
00234 
00235  /*----------------------------------------------------------------------*/
00236 
00237   // To register the suite we add:
00239   CPPUNIT_TEST_SUITE_REGISTRATION(TestGLXGLContext);
00240 }