Salome HOME
Fix bug in test on 24 cores CPU test
[modules/kernel.git] / src / DF / testDF.cxx
index bc95c6c65f37ce976457a674d850ae3c367b2c76..6dd1ed683c972a9e450739a4da9902551cfb7821 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// 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.
+// 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
 #include "DF_Container.hxx"
 #include "DF_ChildIterator.hxx"
 
+#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>
@@ -68,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;
@@ -85,12 +88,21 @@ void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, in
 std::string GetUserName()
 {
 #ifdef WIN32
-  char*  pBuff = new char[UNLEN + 1];
+#ifdef UNICODE
+       wchar_t*  pBuff = new wchar_t[UNLEN + 1];
+#else
+       char*  pBuff = new char[UNLEN + 1];
+#endif
   DWORD  dwSize = UNLEN + 1;
   std::string retVal;
   GetUserName ( pBuff, &dwSize );
-  std::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
@@ -141,17 +153,7 @@ std::string GetDirFromPath(const std::string& thePath) {
 
 bool Exists(const std::string thePath) 
 {
-#ifdef WIN32 
-  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 );
 }
 
 
@@ -182,7 +184,7 @@ std::vector<std::string> splitString(const std::string& theValue, char separator
 }
 
 
-int main (int argc, char * argv[])
+int main ()
 {
   std::cout << "Test started " << std::endl;
   
@@ -247,7 +249,7 @@ int main (int argc, char * argv[])
   std::string s("012-56");
   
   int pos = s.find('-');
-  std::cout << "Fisrt part : " << s.substr(0, pos) << std::endl;
+  std::cout << "First part : " << s.substr(0, pos) << std::endl;
   std::cout << "Last part : " << s.substr(pos+1, s.size()) << std::endl;
 
   std::vector<std::string> vs = splitString("/dn20/salome/srn/salome2/", '/');