Salome HOME
Moved test configuration from CMake variables to a configuration file
[tools/libbatch.git] / src / Local / Test / Exec_Test.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * Exec_Test.cxx :
24  *
25  * Author : Renaud BARATE - EDF R&D
26  * Date   : May 2009
27  *
28  */
29
30 #include <iostream>
31 #include <fstream>
32 #include <string>
33
34 using namespace std;
35
36 int main(int argc, char** argv)
37 {
38   if (argc != 4) {
39     cerr << "Exec_Test expects three parameters, usage: Exec_Test <scriptA> <scriptB> <result>" << endl;
40     return 1;
41   }
42
43   const char * scriptAFileName = argv[1];
44   const char * scriptBFileName = argv[2];
45   const char * resultFileName = argv[3];
46
47   ifstream scriptAStream(scriptAFileName);
48   std::string line;
49   int a = 0;
50   while (getline(scriptAStream, line)) {
51     if (line.compare(0, 2, string("a=")) == 0) {
52       a = strtol(line.substr(2).c_str(), NULL, 10);
53     }
54   }
55   scriptAStream.close();
56   if (a == 0) {
57     cerr << "Exec_Test couldn't parse value \"a\" in " << scriptAFileName << endl;
58     return 1;
59   }
60
61   ifstream scriptBStream(scriptBFileName);
62   int b = 0;
63   while (getline(scriptBStream, line)) {
64     if (line.compare(0, 2, string("b=")) == 0) {
65       b = strtol(line.substr(2).c_str(), NULL, 10);
66     }
67   }
68   scriptBStream.close();
69   if (b == 0) {
70     cerr << "Exec_Test couldn't parse value \"b\" in " << scriptBFileName << endl;
71     return 1;
72   }
73
74   int c = a * b;
75   ofstream resultStream(resultFileName);
76   resultStream << "c = " << c;
77   resultStream.close();
78   return 0;
79 }