Salome HOME
bos #26457 Factorization of ORB initialization
[modules/kernel.git] / src / Container / TestSalome_file.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "Salome_file_i.hxx"
21 #include "ArgvKeeper.hxx"
22 #include "OpUtil.hxx"
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
26 #include "HDFascii.hxx"
27 #include <stdlib.h>
28
29 void print_infos(Engines::file*);
30 void print_state(Engines::SfState*);
31
32 void print_infos(Engines::file * infos) 
33 {
34   std::cerr << "-------------------------------------------------------------------" << std::endl;
35   std::cerr << "file_name = " << infos->file_name << std::endl;
36   std::cerr << "path = " << infos->path << std::endl;
37   std::cerr << "type = " << infos->type << std::endl;
38   std::cerr << "source_file_name = " << infos->source_file_name << std::endl;
39   std::cerr << "status = " << infos->status << std::endl;
40 }
41
42 void print_state(Engines::SfState * state) 
43 {
44   std::cerr << "-------------------------------------------------------------------" << std::endl;
45   std::cerr << "name = " << state->name << std::endl;
46   std::cerr << "hdf5_file_name = " <<  state->hdf5_file_name << std::endl;
47   std::cerr << "number_of_files = " <<  state->number_of_files << std::endl;
48   std::cerr << "files_ok = " <<  state->files_ok << std::endl;
49 }
50
51
52 int main (int argc, char * argv[])
53 {
54   system("rm toto cat test.hdf test2.hdf");
55
56   Salome_file_i file;
57   Salome_file_i file2;
58   Salome_file_i file3;
59   Salome_file_i file4;
60   Salome_file_i file5;
61   Engines::file * infos;
62   Engines::SfState * state;
63   Engines::files * all_infos;
64   PortableServer::POA_var root_poa;
65   PortableServer::POAManager_var pman;
66   CORBA::Object_var obj;
67
68   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
69   std::cerr << "Test of setLocalFile()" << std::endl;
70   file.setLocalFile("/tmp/toto");
71   infos = file.getFileInfos("toto");
72   print_infos(infos);
73
74
75   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
76   std::cerr << "Test of getFilesInfos()" << std::endl;
77   all_infos = file.getFilesInfos();
78   for (int i = 0; i < (int)all_infos->length(); i++)
79   {
80     print_infos(&((*all_infos)[i]));
81   }
82
83   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
84   std::cerr << "Test of getSalome_fileState()" << std::endl;
85   state = file.getSalome_fileState();
86   print_state(state);
87
88   // We start CORBA ...
89   SetArgcArgv(argc, argv);
90   CORBA::ORB_ptr orb = KERNEL::GetRefToORB();
91   obj = orb->resolve_initial_references("RootPOA");
92   root_poa = PortableServer::POA::_narrow(obj);
93   pman = root_poa->the_POAManager();
94   pman->activate();
95
96   file2.setLocalFile("/tmp/toto_distributed_source");
97   Engines::Salome_file_ptr file2_ref = file2._this();
98
99   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
100   std::cerr << "Test of setDistributedFile()" << std::endl;
101   file.setDistributedFile("/tmp/toto_distributed");
102   file.connectDistributedFile("toto_distributed", file2_ref);
103 //  file.setDistributedSourceFile("toto_distributed", "toto_distributed_source");
104   infos = file.getFileInfos("toto_distributed");
105   print_infos(infos);
106
107   // We create the files ... 
108   std::ostringstream oss;
109   oss << "/tmp/toto";
110   std::ofstream f(oss.str().c_str());
111   if (f) 
112     f << "blablabla" << std::endl;
113  
114   std::ostringstream oss2;
115   oss2 << "/tmp/toto_distributed_source";
116   std::ofstream f2(oss2.str().c_str());
117   if (f2) 
118     f2 << "bliblibli" << std::endl;
119
120   try 
121   {
122     file.recvFiles();
123   }
124   catch (SALOME::SALOME_Exception & e)
125   {
126     std::cerr << "Exception : " << e.details.text << std::endl;
127   }
128
129   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
130   std::cerr << "Test of getFilesInfos()" << std::endl;
131   all_infos = file.getFilesInfos();
132   for (int i = 0; i < (int)all_infos->length(); i++)
133   {
134     print_infos(&((*all_infos)[i]));
135   }
136
137   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
138   std::cerr << "Test of getSalome_fileState()" << std::endl;
139   state = file.getSalome_fileState();
140   print_state(state);
141
142   orb->destroy();
143
144   file3.setLocalFile("/tmp/toto");
145   file3.setLocalFile("/bin/cat");
146   state = file3.getSalome_fileState();
147   print_state(state);
148   file3.save_all("test.hdf");
149   file3.setLocalFile("/bin/tutu");
150   file3.save("test2.hdf");
151
152   file4.load("test.hdf");
153   all_infos = file4.getFilesInfos();
154   for (int i = 0; i < (int)all_infos->length(); i++)
155   {
156     print_infos(&((*all_infos)[i]));
157   }
158   state = file4.getSalome_fileState();
159   print_state(state);
160   file5.load("test2.hdf");
161   all_infos = file5.getFilesInfos();
162   for (int i = 0; i < (int)all_infos->length(); i++)
163   {
164     print_infos(&((*all_infos)[i]));
165   }
166   state = file5.getSalome_fileState();
167   print_state(state);
168
169   // Test of ConvertFromHDFToASCII
170   // and ConvertFromASCIIToHDF
171   std::cerr << "Test of ConvertFromASCIIToHDF" << std::endl;
172   HDFascii::ConvertFromASCIIToHDF("/tmp/toto"); // RETURN NULL !
173   std::cerr << "Test of ConvertFromHDFToASCII" << std::endl;
174   std::cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", false) << std::endl;
175   std::cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", true) << std::endl;
176
177   std::cerr << "End of tests" << std::endl;
178 }