Back to index

salome-kernel  6.5.0
TestSalome_file.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "Salome_file_i.hxx"
00021 #include <iostream>
00022 #include <fstream>
00023 #include <sstream>
00024 #include "HDFascii.hxx"
00025 #include <stdlib.h>
00026 
00027 void print_infos(Engines::file*);
00028 void print_state(Engines::SfState*);
00029 
00030 void print_infos(Engines::file * infos) 
00031 {
00032   std::cerr << "-------------------------------------------------------------------" << std::endl;
00033   std::cerr << "file_name = " << infos->file_name << std::endl;
00034   std::cerr << "path = " << infos->path << std::endl;
00035   std::cerr << "type = " << infos->type << std::endl;
00036   std::cerr << "source_file_name = " << infos->source_file_name << std::endl;
00037   std::cerr << "status = " << infos->status << std::endl;
00038 }
00039 
00040 void print_state(Engines::SfState * state) 
00041 {
00042   std::cerr << "-------------------------------------------------------------------" << std::endl;
00043   std::cerr << "name = " << state->name << std::endl;
00044   std::cerr << "hdf5_file_name = " <<  state->hdf5_file_name << std::endl;
00045   std::cerr << "number_of_files = " <<  state->number_of_files << std::endl;
00046   std::cerr << "files_ok = " <<  state->files_ok << std::endl;
00047 }
00048 
00049 
00050 int main (int argc, char * argv[])
00051 {
00052   system("rm toto cat test.hdf test2.hdf");
00053 
00054   Salome_file_i file;
00055   Salome_file_i file2;
00056   Salome_file_i file3;
00057   Salome_file_i file4;
00058   Salome_file_i file5;
00059   Engines::file * infos;
00060   Engines::SfState * state;
00061   Engines::files * all_infos;
00062   PortableServer::POA_var root_poa;
00063   PortableServer::POAManager_var pman;
00064   CORBA::Object_var obj;
00065 
00066   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00067   std::cerr << "Test of setLocalFile()" << std::endl;
00068   file.setLocalFile("/tmp/toto");
00069   infos = file.getFileInfos("toto");
00070   print_infos(infos);
00071 
00072 
00073   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00074   std::cerr << "Test of getFilesInfos()" << std::endl;
00075   all_infos = file.getFilesInfos();
00076   for (int i = 0; i < all_infos->length(); i++)
00077   {
00078     print_infos(&((*all_infos)[i]));
00079   }
00080 
00081   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00082   std::cerr << "Test of getSalome_fileState()" << std::endl;
00083   state = file.getSalome_fileState();
00084   print_state(state);
00085 
00086   // We start CORBA ...
00087   CORBA::ORB_ptr orb = CORBA::ORB_init(argc , argv);
00088   obj = orb->resolve_initial_references("RootPOA");
00089   root_poa = PortableServer::POA::_narrow(obj);
00090   pman = root_poa->the_POAManager();
00091   pman->activate();
00092 
00093   file2.setLocalFile("/tmp/toto_distributed_source");
00094   Engines::Salome_file_ptr file2_ref = file2._this();
00095 
00096   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00097   std::cerr << "Test of setDistributedFile()" << std::endl;
00098   file.setDistributedFile("/tmp/toto_distributed");
00099   file.connectDistributedFile("toto_distributed", file2_ref);
00100 //  file.setDistributedSourceFile("toto_distributed", "toto_distributed_source");
00101   infos = file.getFileInfos("toto_distributed");
00102   print_infos(infos);
00103 
00104   // We create the files ... 
00105   std::ostringstream oss;
00106   oss << "/tmp/toto";
00107   std::ofstream f(oss.str().c_str());
00108   if (f) 
00109     f << "blablabla" << std::endl;
00110  
00111   std::ostringstream oss2;
00112   oss2 << "/tmp/toto_distributed_source";
00113   std::ofstream f2(oss2.str().c_str());
00114   if (f2) 
00115     f2 << "bliblibli" << std::endl;
00116 
00117   try 
00118   {
00119     file.recvFiles();
00120   }
00121   catch (SALOME::SALOME_Exception & e)
00122   {
00123     std::cerr << "Exception : " << e.details.text << std::endl;
00124   }
00125 
00126   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00127   std::cerr << "Test of getFilesInfos()" << std::endl;
00128   all_infos = file.getFilesInfos();
00129   for (int i = 0; i < all_infos->length(); i++)
00130   {
00131     print_infos(&((*all_infos)[i]));
00132   }
00133 
00134   std::cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
00135   std::cerr << "Test of getSalome_fileState()" << std::endl;
00136   state = file.getSalome_fileState();
00137   print_state(state);
00138 
00139   orb->destroy();
00140 
00141   file3.setLocalFile("/tmp/toto");
00142   file3.setLocalFile("/bin/cat");
00143   state = file3.getSalome_fileState();
00144   print_state(state);
00145   file3.save_all("test.hdf");
00146   file3.setLocalFile("/bin/tutu");
00147   file3.save("test2.hdf");
00148 
00149   file4.load("test.hdf");
00150   all_infos = file4.getFilesInfos();
00151   for (int i = 0; i < all_infos->length(); i++)
00152   {
00153     print_infos(&((*all_infos)[i]));
00154   }
00155   state = file4.getSalome_fileState();
00156   print_state(state);
00157   file5.load("test2.hdf");
00158   all_infos = file5.getFilesInfos();
00159   for (int i = 0; i < all_infos->length(); i++)
00160   {
00161     print_infos(&((*all_infos)[i]));
00162   }
00163   state = file5.getSalome_fileState();
00164   print_state(state);
00165 
00166   // Test of ConvertFromHDFToASCII
00167   // and ConvertFromASCIIToHDF
00168   std::cerr << "Test of ConvertFromASCIIToHDF" << std::endl;
00169   HDFascii::ConvertFromASCIIToHDF("/tmp/toto"); // RETURN NULL !
00170   std::cerr << "Test of ConvertFromHDFToASCII" << std::endl;
00171   std::cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", false) << std::endl;
00172   std::cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", true) << std::endl;
00173 
00174   std::cerr << "End of tests" << std::endl;
00175 }