From 69b3259a5e47a5b46b251e57ff3be04b09ffeec3 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Wed, 28 Aug 2013 16:10:15 +0200
Subject: [PATCH] Fix in running all python functional tests from Windows

---
 App/src/DrawHelper.cpp                        |  3 +-
 BornAgain.pro                                 | 16 ++-------
 Core/Tools/src/Utils.cpp                      | 11 +++----
 .../CylindersAndPrisms.py                     | 12 ++++---
 Tests/FunctionalTests/TestCore/TestCore.py    |  7 ++--
 Tests/FunctionalTests/TestFit/TestFit.py      |  4 ++-
 shared.pri                                    | 33 ++++++++-----------
 7 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/App/src/DrawHelper.cpp b/App/src/DrawHelper.cpp
index 38afcc969bc..6c41d261df7 100644
--- a/App/src/DrawHelper.cpp
+++ b/App/src/DrawHelper.cpp
@@ -43,6 +43,7 @@
 #include "TFile.h"
 #include "TDatime.h"
 #include "TSystem.h"
+#include <cstdlib>
 
 std::vector<TCanvas *> DrawHelper::m_registered_canvases =
     std::vector<TCanvas *>();
@@ -66,7 +67,7 @@ void DrawHelper::ExecuteMagnifier(int event, int px, int py, TObject *sel)
   if ( event == kButton1Double ) {
     TCanvas *c = (TCanvas *)gTQSender;
     char cname[256];
-    sprintf(cname,"%s_%d",c->GetTitle(),(int)time(0));
+    sprintf(cname,"%s_%d",c->GetTitle(),std::rand());
     TPad *pad = c->Pick(px, py, 0);
     TPad *pad_new = dynamic_cast<TPad *>(pad->Clone());
     pad_new->SetPad(0.0, 0.0, 1.0, 1.0);
diff --git a/BornAgain.pro b/BornAgain.pro
index 0a52de15f02..1abc57abdb5 100644
--- a/BornAgain.pro
+++ b/BornAgain.pro
@@ -5,24 +5,12 @@ include($$PWD/shared.pri)
 SUBDIRS += Core
 SUBDIRS += ThirdParty/gtest
 SUBDIRS += Tests/UnitTests/TestCore
-#TestCore.depends = ThirdParty/gtest
-
 SUBDIRS += Tests/FunctionalTests/TestCore
-
-#isEmpty(ROOT_FRAMEWORK) {
-#    message("No ROOT installation found. Additional library libRootMinimizers.so will be compiled.")
-    SUBDIRS += ThirdParty/RootMinimizers
-#}
-
-#SUBDIRS += ThirdParty/RootMathMore
-
+SUBDIRS += ThirdParty/RootMinimizers
 SUBDIRS += Fit
 SUBDIRS += Tests/FunctionalTests/TestFit
 
-!isEmpty(ROOT_FRAMEWORK) {
-    SUBDIRS += App
-}
-
+#!isEmpty(ROOT_FRAMEWORK): SUBDIRS += App
 
 # compilation in lister order
 CONFIG += ordered
diff --git a/Core/Tools/src/Utils.cpp b/Core/Tools/src/Utils.cpp
index 19a6d8c5902..0c60e215f6d 100644
--- a/Core/Tools/src/Utils.cpp
+++ b/Core/Tools/src/Utils.cpp
@@ -129,15 +129,14 @@ std::string Utils::FileSystem::GetPathToExecutable(const std::string& argv0)
 }
 
 
-// TODO Remove this temporary ifdef
 std::string Utils::FileSystem::GetPathToData(const std::string& rel_data_path, const std::string& argv0)
 {
-#ifdef _WIN32
-    // windows build place executable in additional sub-directory 'release'
-    std::string result = (boost::filesystem::canonical( argv0.c_str() ).parent_path() / boost::filesystem::path("../") / boost::filesystem::path(rel_data_path)).string();
-#else
+//#ifdef _WIN32
+//    // windows build place executable in additional sub-directory 'release'
+//    std::string result = (boost::filesystem::canonical( argv0.c_str() ).parent_path() / boost::filesystem::path("../") / boost::filesystem::path(rel_data_path)).string();
+//#else
     std::string result = (boost::filesystem::canonical( argv0.c_str() ).parent_path() / boost::filesystem::path(rel_data_path)).string();
-#endif
+//#endif
     return result;
 }
 
diff --git a/Examples/python/ex001_CylindersAndPrisms/CylindersAndPrisms.py b/Examples/python/ex001_CylindersAndPrisms/CylindersAndPrisms.py
index 024eb901bca..e747e624948 100644
--- a/Examples/python/ex001_CylindersAndPrisms/CylindersAndPrisms.py
+++ b/Examples/python/ex001_CylindersAndPrisms/CylindersAndPrisms.py
@@ -1,5 +1,5 @@
 # IsGISAXS01 example: Mixture of cylinders and prisms without interference
-import sys, os, numpy
+import sys, os, numpy, pylab, matplotlib
 
 sys.path.append(os.path.abspath(
                 os.path.join(os.path.split(__file__)[0], '..', '..', '..', 'lib')
@@ -8,7 +8,7 @@ sys.path.append(os.path.abspath(
 sys.path.append(os.path.abspath(os.path.join(os.path.split(__file__)[0],'..')))
 
 from libBornAgainCore import *
-from utils.show2d import PlotNumpyArray
+#from utils.show2d import PlotNumpyArray
 
 
 # ----------------------------------
@@ -53,7 +53,11 @@ def RunSimulation():
 # main()
 #-------------------------------------------------------------
 if __name__ == '__main__':
-    result = RunSimulation()
-    PlotNumpyArray(result)
+    result = RunSimulation() + 1 # for log scale
+    pylab.imshow(numpy.rot90(result, 1), 
+                 norm=matplotlib.colors.LogNorm(), 
+                 extent=[-1.0, 1.0, 0, 2.0])
+    pylab.show()    
+    
 
 
diff --git a/Tests/FunctionalTests/TestCore/TestCore.py b/Tests/FunctionalTests/TestCore/TestCore.py
index 9d40d63af4a..12b4f0c357f 100755
--- a/Tests/FunctionalTests/TestCore/TestCore.py
+++ b/Tests/FunctionalTests/TestCore/TestCore.py
@@ -4,6 +4,7 @@ import sys
 import os
 import subprocess
 import time
+import platform
 
 
 Tests = [
@@ -25,7 +26,8 @@ test_info = []
 
 # run system command and catch multiline stdout and stderr
 def run_command(command):
-  p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell = True)
+  
   p.wait()
   return iter(p.stdout.readline, b''), iter(p.stderr.readline, b'')
 
@@ -56,8 +58,9 @@ def runTests():
   print ">>> Running TestCore, {0:-2d} tests total ...".format(len(Tests))
   for testName in Tests:
     command =  testName+"/"+testName # i.e. "path/executable" like "IsGISAXS01/IsGISAXS01"
+    if "Windows" in platform.system(): command =  testName+"\\"+testName+".exe"
     path = os.path.split(__file__)[0]
-    if path: command = path + "/" + command
+    if path: command = os.path.join(path, command)
     print "Running test ", testName
     start_time = time.time()
     stdout, stderr = run_command(command)
diff --git a/Tests/FunctionalTests/TestFit/TestFit.py b/Tests/FunctionalTests/TestFit/TestFit.py
index 1cde00a6ffe..e4ac064049d 100755
--- a/Tests/FunctionalTests/TestFit/TestFit.py
+++ b/Tests/FunctionalTests/TestFit/TestFit.py
@@ -5,6 +5,7 @@ import sys
 import os
 import subprocess
 import time
+import platform
 
 Tests = [
     "TestFit01",
@@ -44,8 +45,9 @@ def runTests():
   print ">>> Running TestFit, {0:-2d} tests total ...".format(len(Tests))
   for testName in Tests:
     command =  testName+"/"+testName # i.e. "path/executable" like "IsGISAXS01/IsGISAXS01"
+    if "Windows" in platform.system(): command =  testName+"\\"+testName+".exe"
     path = os.path.split(__file__)[0]
-    if path: command = path + "/" + command
+    if path: command = os.path.join(path, command)
     print "Running test ", testName
     start_time = time.time()
     stdout, stderr = run_command(command)
diff --git a/shared.pri b/shared.pri
index 2a90f0fa721..00f93c052cb 100644
--- a/shared.pri
+++ b/shared.pri
@@ -194,7 +194,9 @@ QMAKE_CXXFLAGS_DEBUG += -fdiagnostics-show-option # to find out in gcc which opt
 
 # Eigen alighnment under windows, warnings from boost
 win32{
-    QMAKE_CXXFLAGS += -mincoming-stack-boundary=2 -Wno-unused-local-typedefs
+    QMAKE_CXXFLAGS += -mincoming-stack-boundary=2 -Wno-unused-local-typedefs -Wno-attributes -Wno-unknown-pragmas
+#    QMAKE_CXXFLAGS += -D_MSC_VER=1301
+#    QMAKE_CXXFLAGS += -DTYPENAME=typename
 }
 
 # Because of clang which knows nothing about unused_local_typedefs pragma
@@ -222,7 +224,7 @@ macx|unix {
     ROOT_FRAMEWORK = $$system(root-config --prefix)
 }
 win32 {
-#    ROOT_FRAMEWORK = "C:/root"
+    ROOT_FRAMEWORK = "C:/root"
 }
 
 # -----------------------------------------------------------------------------
@@ -292,39 +294,23 @@ CONFIG(BORNAGAIN_PYTHON) {
     # we do not have python
     error("Can not find any sign of python")
   } else {
-    #pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include/python\' + sys.version[:3])\" ")
-    #pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/libs\' )\" ")
     pythonvers=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
     pythonnumpy=$$system("$${WhichPython} -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
-    # we have python
     macx|unix {
       pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include/python\' + sys.version[:3])\" ")
       pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/lib\' )\" ")
-#      pythonvers=$$system("python -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
-#      pythonsysincdir=$$system("python -c 'import sys; sys.stdout.write(sys.prefix + \"/include/python\" + sys.version[:3])'")
-#      pythonsyslibdir=$$system("python -c 'import sys; sys.stdout.write(sys.prefix + \"/lib\" )'")
-#      pythonnumpy=$$system("python -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
     }
     win32 {
       pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include')\" ")
       pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/libs\' )\" ")
-#      pythonsysincdir=$${WhichPython}/include
-#      pythonsyslibdir=$${WhichPython}/libs
-#      pythonvers=$$system("$${WhichPython}/python.exe -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
-#      pythonnumpy=$$system("$${WhichPython}/python.exe -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
     }
-#    pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include/python\' + sys.version[:3])\" ")
-#    pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/libs\' )\" ")
-#    pythonvers=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
-#    pythonnumpy=$$system("$${WhichPython} -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
-
     #message(pythonvers : $$pythonvers)
     #message(pythoninc  : $$pythonsysincdir)
     #message(pythonlib  : $$pythonsyslibdir)
     #message(pythonnumpy: $$pythonnumpy)
     lessThan(pythonvers, 2.6): error("BornAgain requires python 2.6 or greater")
+
     INCLUDEPATH += $$pythonsysincdir
-    #LIBS += -L$$pythonsyslibdir -lpython$$pythonvers -lboost_python
     macx|unix {
       PYTHON_LIB_DIRECTIVE=-lpython$$pythonvers
     }
@@ -333,7 +319,7 @@ CONFIG(BORNAGAIN_PYTHON) {
     }
     LIBS += -lboost_python$${BOOST_LIB_SUFFIX} -L$$pythonsyslibdir $$PYTHON_LIB_DIRECTIVE
 
-    # we need to know the location of numpy
+    # location of numpy
     !exists($$pythonnumpy/numpy/arrayobject.h): error("Can't find numpy/arrayobject.h in $$pythonnumpy, you have to install python-numpy-devel")
     INCLUDEPATH += $$pythonnumpy
   }
@@ -350,3 +336,10 @@ unix {
     RCC_DIR = $${OUT_PWD}/.rcc
     UI_DIR = $${OUT_PWD}/.uic
 }
+
+win32 {
+    Release:DESTDIR = $${OUT_PWD}
+    Debug:DESTDIR = $${OUT_PWD}
+}
+
+
-- 
GitLab