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