Salome HOME
introducing test on mesh extension, with resources generated first
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_Main.cxx
index 4248b2190a2bb38bb0811df53812d82a87352615..4b04a8fb4425f263cdc179ffe730466dca3a3ced 100644 (file)
 #include <TestViewer.h>
 #include <TestLib_Listener.h>
 #include <TestLib_Runner.h>
-#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewFrame.h>
 #include <SUIT_Session.h>
 #include <QApplication>
 #include <QColor>
 #include <QTest>
-#include <random.h>
+
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
+#ifdef WIN32
+QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO";
+QString TMP_DIR = QDir::tempPath();
+#else
+QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO";
+QString TMP_DIR = qgetenv( "HYDRO_ROOT_DIR" ) + "/test_ref";
+#endif
+
+
+int MAIN_W = 800, MAIN_H = 600;
 
 int main( int argc, char* argv[] )
 {
-  test_srand( 0 );
-
   QApplication anApp( argc, argv );
   SUIT_Session aSession;
+  aSession.startApplication("std");
 
-  OCCViewer_ViewWindow* aWindow = TestViewer::viewWindow();
+  QDir().mkdir( TMP_DIR );
 
-  int W = 800, H = 600;
-  aWindow->setGeometry( 200, 200, W, H );
+  OCCViewer_ViewFrame* aWindow = TestViewer::viewWindow();
+
+  aWindow->setGeometry( 400, 100, MAIN_W, MAIN_H );
   aWindow->show();
-  QTest::qWaitForWindowShown( aWindow );
+  QTest::qWaitForWindowExposed( aWindow );
 
   int dy = 34;
   //std::cout << dx << "," << dy << std::endl;
-  aWindow->resize( W, H+dy );
+  aWindow->resize( MAIN_W, MAIN_H+dy );
   anApp.processEvents();
 
   std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
@@ -55,21 +68,25 @@ int main( int argc, char* argv[] )
   // Create the event manager and test controller
   CppUnit::TestResult controller;
 
-  // Add a listener that colllects test result
+  // Add a listener that collects test result
   CppUnit::TestResultCollector result;
-  controller.addListener( &result );        
+  controller.addListener( &result );
 
   // Add a listener that print dots as test run.
   TestLib_Listener progress;
-  controller.addListener( &progress );      
+  controller.addListener( &progress );
 
-  CppUnit::TestFactoryRegistry& registry = 
+  CppUnit::TestFactoryRegistry& registry =
     CppUnit::TestFactoryRegistry::getRegistry();
   // Add the top suite to the test runner
   TestLib_Runner runner;
+#ifdef WIN32
   QString aPath = qgetenv( "HYDRO_SRC_DIR" ) + "/src/tests.cfg";
+#else
+  QString aPath = qgetenv( "HYDRO_ROOT_DIR" ) + "/tests.cfg";
+#endif
   runner.Load( aPath.toStdString() );
-  runner.addTest( registry.makeTest() );   
+  runner.addTest( registry.makeTest() );
   try
   {
     std::cout << "Running tests "  << testPath << "..." << std::endl;
@@ -83,12 +100,30 @@ int main( int argc, char* argv[] )
   }
   catch ( std::invalid_argument &e )  // Test path not resolved
   {
-    std::cerr  <<  std::endl  
+    std::cerr  <<  std::endl
       <<  "ERROR: "  <<  e.what()
       << std::endl;
     return 0;
   }
+  bool isOK = result.wasSuccessful();
+
+#ifndef WIN32
+  DEBTRACE("End of tests");
+#endif
+
+  aWindow->close();
+  aSession.closeSession();
+  anApp.exit(!isOK);
+
+#ifndef WIN32
+  DEBTRACE("--- TODO: exception on exit..."); // TODO: exception on exit...
+#endif
+
+  int ms = progress.GetCompleteTimeInMS();
+  printf( "\n\n" );
+  printf( "%i TESTS in %i SUITES\n", progress.GetNbTests(), progress.GetNbSuites() );
+  printf( "COMPLETE TESTS TIME: %i ms\n", ms );
+  progress.DumpFailures();
 
-  //anApp.exec();
   return result.wasSuccessful() ? 0 : 1;
 }