Salome HOME
CCAR: _id not initialized
[modules/kernel.git] / src / Container / TestSalome_file.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 #include "Salome_file_i.hxx"
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
26 #include "HDFascii.hxx"
27 #include <stdlib.h>
28
29 using namespace std;
30
31 void print_infos(Engines::file * infos) 
32 {
33   cerr << "-------------------------------------------------------------------" << endl;
34   cerr << "file_name = " << infos->file_name << endl;
35   cerr << "path = " << infos->path << endl;
36   cerr << "type = " << infos->type << endl;
37   cerr << "source_file_name = " << infos->source_file_name << endl;
38   cerr << "status = " << infos->status << endl;
39 }
40
41 void print_state(Engines::SfState * state) 
42 {
43   cerr << "-------------------------------------------------------------------" << endl;
44   cerr << "name = " << state->name << endl;
45   cerr << "hdf5_file_name = " <<  state->hdf5_file_name << endl;
46   cerr << "number_of_files = " <<  state->number_of_files << endl;
47   cerr << "files_ok = " <<  state->files_ok << endl;
48 }
49
50
51 int main (int argc, char * argv[])
52 {
53   system("rm toto cat test.hdf test2.hdf");
54
55   Salome_file_i file;
56   Salome_file_i file2;
57   Salome_file_i file3;
58   Salome_file_i file4;
59   Salome_file_i file5;
60   Engines::file * infos;
61   Engines::SfState * state;
62   Engines::files * all_infos;
63   PortableServer::POA_var root_poa;
64   PortableServer::POAManager_var pman;
65   CORBA::Object_var obj;
66
67   cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
68   cerr << "Test of setLocalFile()" << endl;
69   file.setLocalFile("/tmp/toto");
70   infos = file.getFileInfos("toto");
71   print_infos(infos);
72
73
74   cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
75   cerr << "Test of getFilesInfos()" << endl;
76   all_infos = file.getFilesInfos();
77   for (int i = 0; i < all_infos->length(); i++)
78   {
79     print_infos(&((*all_infos)[i]));
80   }
81
82   cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
83   cerr << "Test of getSalome_fileState()" << endl;
84   state = file.getSalome_fileState();
85   print_state(state);
86
87   // We start CORBA ...
88   CORBA::ORB_ptr orb = CORBA::ORB_init(argc , argv);
89   obj = orb->resolve_initial_references("RootPOA");
90   root_poa = PortableServer::POA::_narrow(obj);
91   pman = root_poa->the_POAManager();
92   pman->activate();
93
94   file2.setLocalFile("/tmp/toto_distributed_source");
95   Engines::Salome_file_ptr file2_ref = file2._this();
96
97   cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
98   cerr << "Test of setDistributedFile()" << endl;
99   file.setDistributedFile("/tmp/toto_distributed");
100   file.connectDistributedFile("toto_distributed", file2_ref);
101 //  file.setDistributedSourceFile("toto_distributed", "toto_distributed_source");
102   infos = file.getFileInfos("toto_distributed");
103   print_infos(infos);
104
105   // We create the files ... 
106   std::ostringstream oss;
107   oss << "/tmp/toto";
108   std::ofstream f(oss.str().c_str());
109   if (f) 
110     f << "blablabla" << std::endl;
111  
112   std::ostringstream oss2;
113   oss2 << "/tmp/toto_distributed_source";
114   std::ofstream f2(oss2.str().c_str());
115   if (f2) 
116     f2 << "bliblibli" << std::endl;
117
118   try 
119   {
120     file.recvFiles();
121   }
122   catch (SALOME::SALOME_Exception & e)
123   {
124     cerr << "Exception : " << e.details.text << endl;
125   }
126
127   cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
128   cerr << "Test of getFilesInfos()" << endl;
129   all_infos = file.getFilesInfos();
130   for (int i = 0; i < all_infos->length(); i++)
131   {
132     print_infos(&((*all_infos)[i]));
133   }
134
135   cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
136   cerr << "Test of getSalome_fileState()" << endl;
137   state = file.getSalome_fileState();
138   print_state(state);
139
140   orb->destroy();
141
142   file3.setLocalFile("/tmp/toto");
143   file3.setLocalFile("/bin/cat");
144   state = file3.getSalome_fileState();
145   print_state(state);
146   file3.save_all("test.hdf");
147   file3.setLocalFile("/bin/tutu");
148   file3.save("test2.hdf");
149
150   file4.load("test.hdf");
151   all_infos = file4.getFilesInfos();
152   for (int i = 0; i < all_infos->length(); i++)
153   {
154     print_infos(&((*all_infos)[i]));
155   }
156   state = file4.getSalome_fileState();
157   print_state(state);
158   file5.load("test2.hdf");
159   all_infos = file5.getFilesInfos();
160   for (int i = 0; i < all_infos->length(); i++)
161   {
162     print_infos(&((*all_infos)[i]));
163   }
164   state = file5.getSalome_fileState();
165   print_state(state);
166
167   // Test of ConvertFromHDFToASCII
168   // and ConvertFromASCIIToHDF
169   cerr << "Test of ConvertFromASCIIToHDF" << endl;
170   HDFascii::ConvertFromASCIIToHDF("/tmp/toto"); // RETURN NULL !
171   cerr << "Test of ConvertFromHDFToASCII" << endl;
172   cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", false) << endl;
173   cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", true) << endl;
174
175   cerr << "End of tests" << endl;
176 }