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