Salome HOME
Fix bug in test on 24 cores CPU test
[modules/kernel.git] / src / DF / testDF.cxx
index 69dd8920cb378a4c0982ec61d99b78ccb1a93a0c..6dd1ed683c972a9e450739a4da9902551cfb7821 100644 (file)
@@ -1,29 +1,30 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //File:    testDF.cxx
 //Author:  Sergey RUIN
-
+//
 #include <stdio.h>
-#include <iostream.h
+#include <iostream> 
 #include <vector>
 #include <string>
+#include <string.h>
 
 #include "DF_definitions.hxx"
 #include "DF_Application.hxx"
 #include "DF_Container.hxx"
 #include "DF_ChildIterator.hxx"
 
-#ifndef WNT
+#include "Basics_Utils.hxx"
+#include "Basics_DirUtils.hxx"
+
+#ifndef WIN32
+#include <unistd.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <pwd.h>
 #else
 #include <time.h>
+#include <windows.h>
 #include <lmcons.h>
 #endif
 
-using namespace std;
 
-void printStr(const string& theValue)
+void printStr(const std::string& theValue)
 {
-  cout << "printStr: " << theValue   << endl;
+  std::cout << "printStr: " << theValue   << std::endl;
 }
 
 void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, int& seconds)
 {
-#ifdef WNT
+#ifdef WIN32
   SYSTEMTIME    st;
 
   GetLocalTime ( &st );
@@ -67,9 +72,8 @@ void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, in
   struct tm transfert;
   struct timeval tval;
   struct timezone tzone;
-  int status;
-
-  status = gettimeofday( &tval, &tzone );
+  
+  gettimeofday( &tval, &tzone );
   memcpy(&transfert, localtime((time_t *)&tval.tv_sec), sizeof(tm));
   
   month    = transfert.tm_mon + 1;
@@ -81,25 +85,34 @@ void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, in
 #endif
 }
 
-string GetUserName()
+std::string GetUserName()
 {
-#ifdef WNT
-  char*  pBuff = new char[UNLEN + 1];
+#ifdef WIN32
+#ifdef UNICODE
+       wchar_t*  pBuff = new wchar_t[UNLEN + 1];
+#else
+       char*  pBuff = new char[UNLEN + 1];
+#endif
   DWORD  dwSize = UNLEN + 1;
-  string retVal;
+  std::string retVal;
   GetUserName ( pBuff, &dwSize );
-  string theTmpUserName(pBuff,(int)dwSize -1 );
+#ifdef UNICODE
+  std::wstring theTmpUserName(pBuff, (int)dwSize - 1);
+  retVal = Kernel_Utils::utf8_encode_s(theTmpUserName);
+#else
+  std::string theTmpUserName(pBuff, (int)dwSize - 1);
   retVal = theTmpUserName;
+#endif
   delete [] pBuff;
   return retVal;
 #else
  struct passwd *infos;
  infos = getpwuid(getuid()); 
- return string(infos->pw_name);
+ return std::string(infos->pw_name);
 #endif
 }
 
-string GetNameFromPath(const string& thePath) {
+std::string GetNameFromPath(const std::string& thePath) {
   if (thePath.empty()) return "";
   int pos1 = thePath.rfind('/');
   int pos2 = thePath.rfind('\\');
@@ -108,11 +121,11 @@ string GetNameFromPath(const string& thePath) {
   return thePath;
 }
 
-string GetDirFromPath(const string& thePath) {
+std::string GetDirFromPath(const std::string& thePath) {
   if (thePath.empty()) return "";
 
   int pos = thePath.rfind('/');
-  string path;
+  std::string path;
   if(pos > 0) {
     path = thePath.substr(0, pos+1);
   }
@@ -128,8 +141,8 @@ string GetDirFromPath(const string& thePath) {
     path = thePath+"/";
   }
   
-#ifdef WNT  //Check if the only disk letter is given as path
-  if(path.size() == 2 && path[1] == ":") path +='\\';
+#ifdef WIN32  //Check if the only disk letter is given as path
+  if(path.size() == 2 && path[1] == ':') path +='\\';
 #endif
 
   for(int i = 0, len = path.size(); i<len; i++) 
@@ -138,30 +151,20 @@ string GetDirFromPath(const string& thePath) {
 }
 
 
-bool Exists(const string thePath) 
+bool Exists(const std::string thePath) 
 {
-#ifdef WNT 
-  if (  GetFileAttributes (  thePath.c_str()  ) == 0xFFFFFFFF  ) { 
-    if (  GetLastError () != ERROR_FILE_NOT_FOUND  ) {
-      return false;
-    }
-  }
-#else 
-  int status = access ( thePath.c_str() , F_OK ); 
-  if (status != 0) return false;
-#endif
-  return true;
+       return Kernel_Utils::IsExists( thePath );
 }
 
 
-string divideString(const string& theValue, int nbChars)
+std::string divideString(const std::string& theValue, int nbChars)
 {
   return theValue.substr(nbChars, theValue.size());
 }
 
-vector<string> splitString(const string& theValue, char separator)
+std::vector<std::string> splitString(const std::string& theValue, char separator)
 {
-  vector<string> vs;
+  std::vector<std::string> vs;
   if(theValue[0] == separator && theValue.size() == 1) return vs;
   int pos = theValue.find(separator);
   if(pos < 0) {
@@ -169,26 +172,26 @@ vector<string> splitString(const string& theValue, char separator)
     return vs;
   }
  
-  string s = theValue;
+  std::string s = theValue;
   if(s[0] == separator) s = s.substr(1, s.size());
   while((pos = s.find(separator)) >= 0) {
     vs.push_back(s.substr(0, pos));
     s = s.substr(pos+1, s.size());
   }
-              
+               
   if(!s.empty() && s[0] != separator) vs.push_back(s);
   return vs;
 }
 
 
-int main (int argc, char * argv[])
+int main ()
 {
-  cout << "Test started " << endl;
+  std::cout << "Test started " << std::endl;
   
   DF_Application* appli = new DF_Application;
+  /*  
   DF_Document* doc1 = appli->NewDocument("doc_1");
   
-  /*  
   DF_Label root1 = doc1->Main();
   DF_Label child = root1.FindChild(3, true); //0:1:3
   
@@ -198,23 +201,23 @@ int main (int argc, char * argv[])
 
   DF_Attribute* attr = NULL;
   if(!(attr = child.FindAttribute(DF_Container::GetID()))) {
-    cout << "Attribute wasn't found" << endl;
+    std::cout << "Attribute wasn't found" << std::endl;
   }
   else {
     attr1 = dynamic_cast<DF_Container*>(attr);
-    cout << "Attribute was found " << " HasID " << attr1->HasIntID("eighteen") << " value = " << attr1->GetInt("eighteen")<< endl;
+    std::cout << "Attribute was found " << " HasID " << attr1->HasIntID("eighteen") << " value = " << attr1->GetInt("eighteen")<< std::endl;
   }
   
   DF_Container *attr2 = (DF_Container*)child.FindAttribute(DF_Container::GetID());    
 
   if(!attr2) cout << "Can't find the attribute" << endl;
 
-  cout << "Change find : " << attr2->GetInt("eighteen") << endl;
+  std::cout << "Change find : " << attr2->GetInt("eighteen") << std::endl;
 
 
-  cout << "Forgetting " << child.ForgetAttribute(DF_Container::GetID()) << endl;
+  std::cout << "Forgetting " << child.ForgetAttribute(DF_Container::GetID()) << std::endl;
    if(!child.FindAttribute(DF_Container::GetID())) {
-    cout << "Attribute wasn't found" << endl;
+    std::cout << "Attribute wasn't found" << std::endl;
   }
 
 
@@ -224,8 +227,8 @@ int main (int argc, char * argv[])
     
   child.NewChild();//0:1:4:2
 
-  cout << "Is equal " << (child == child)   << endl;
-  cout << "Is equal " << (child == root1)   << endl;
+  std::cout << "Is equal " << (child == child)   << std::endl;
+  std::cout << "Is equal " << (child == root1)   << std::endl;
 
   child = root1.NewChild(); //0:1:5
 
@@ -236,24 +239,24 @@ int main (int argc, char * argv[])
   DF_ChildIterator CI(root1.Father(), true);
   //root1.dump();
   for(; CI.More(); CI.Next()) {
-    cout << CI.Value().Entry() << endl;
+    std::cout << CI.Value().Entry() << std::endl;
     //CI.Value().dump();
   }
 
   DF_Label L = DF_Label::Label(child, "0:1:4:1");
-  cout << "Found Label " <<  L.Entry()   << endl;
+  std::cout << "Found Label " <<  L.Entry()   << std::endl;
 
   std::string s("012-56");
   
   int pos = s.find('-');
-  cout << "Fisrt part : " << s.substr(0, pos) << endl;
-  cout << "Last part : " << s.substr(pos+1, s.size()) << endl;
+  std::cout << "First part : " << s.substr(0, pos) << std::endl;
+  std::cout << "Last part : " << s.substr(pos+1, s.size()) << std::endl;
 
-  vector<string> vs = splitString("/dn20/salome/srn/salome2/", '/');
+  std::vector<std::string> vs = splitString("/dn20/salome/srn/salome2/", '/');
   for(int i = 0; i<vs.size(); i++)
-    cout << vs[i] << endl;
+    std::cout << vs[i] << std::endl;
 
-  cout << "Diveded str = " << divideString("abcdefg",3) << endl;
+  std::cout << "Diveded str = " << divideString("abcdefg",3) << std::endl;
   
   //mkdir("/dn20/salome/srn/salome2", 0x1ff);
 
@@ -271,9 +274,9 @@ int main (int argc, char * argv[])
   
   int month=0,day=0,year=0,hh=0,mn=0,ss=0;
   GetSystemDate(year, month, day, hh, mn, ss);
-  cout << "Date: " << year << " " << month << " " << day << " " << hh << " " << mn << " " << ss << endl;
+  std::cout << "Date: " << year << " " << month << " " << day << " " << hh << " " << mn << " " << ss << std::endl;
 
-  string t("absd");
+  std::string t("absd");
   t.insert(t.begin(), 'b');
   cout << "Result = " << t   << endl;
   char* cstr = (char*)t.c_str();
@@ -299,13 +302,13 @@ int main (int argc, char * argv[])
   DF_ChildIterator CI2(so5, true);
   so5.dump();
   for(; CI2.More(); CI2.Next()) {
-    cout << " ###### Found child with entry = " << CI2.Value().Entry() << endl;
+    std::cout << " ###### Found child with entry = " << CI2.Value().Entry() << std::endl;
     //CI2.Value().dump();
   }
 
   delete appli;    
 
-  cout << "Test finished " << endl;    
+  std::cout << "Test finished " << std::endl;    
   return 0;
 }