-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+//
// 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
#include "NamingServiceTest.hxx"
#include "Utils_ORB_INIT.hxx"
#include "Utils_SINGLETON.hxx"
+#include "Basics_Utils.hxx"
+#include "SALOME_LifeCycleCORBA.hxx"
+#include "utilities.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
-using namespace std;
// --- uncomment to have some traces on standard error
// (useful only when adding new tests...)
#define DEVTRACE(msg)
#endif
+#ifdef WIN32
+#define setenv Kernel_Utils::setenv
+#endif
+
#define TRACEFILE "/tmp/traceUnitTest.log"
// ============================================================================
NSTEST_echo_i * anEcho = new NSTEST_echo_i(_num);
_num++;
NSTEST::echo_var anEchoRef = anEcho->_this();
+ anEcho->_remove_ref();
return anEchoRef._retn();
}
bp1->deleteInstance(bp1);
// --- trace on file
- char *theFileName = TRACEFILE;
+ const char *theFileName = TRACEFILE;
- string s = "file:";
+ std::string s = "file:";
s += theFileName;
//s="local";
//s="with_logger";
CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
- ofstream traceFile;
+ std::ofstream traceFile;
// traceFile.open(theFileName, ios::out | ios::trunc);
- traceFile.open(theFileName, ios::out | ios::app);
+ traceFile.open(theFileName, std::ios::out | std::ios::app);
CPPUNIT_ASSERT(traceFile); // file created empty, then closed
traceFile.close();
// --- Get or initialize the orb
int _argc = 1;
- char* _argv[] = {""};
+ char* _argv[] = {(char*)""};
ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
_orb = init(_argc , _argv ) ;
_myFactoryId = _root_poa->activate_object(_myFactory);
_factoryRef = _myFactory->_this();
_pman->activate();
+ _myFactory->_remove_ref();
}
//CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception);
NS.init_orb(_orb);
- char *root = NS.getIORaddr();
+ CORBA::String_var root = NS.getIORaddr();
CORBA::Object_var obj = _orb->string_to_object(root);
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
NamingServiceTest::testConstructorOrb()
{
SALOME_NamingService NS(_orb);
- char *root = NS.getIORaddr();
+ CORBA::String_var root = NS.getIORaddr();
CORBA::Object_var obj = _orb->string_to_object(root);
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
{
NSTEST::echo_var anEchoRef = myFactory->createInstance();
ref[i] = anEchoRef->getId();
- string name = "/nstestfirst/echo_";
+ std::string name = "/nstestfirst/echo_";
char anum[10];
sprintf(anum,"%d",ref[i]);
name += anum;
for (int i=0; i<NB_OBJS; i++)
{
- string name = "/nstestfirst/echo_";
+ std::string name = "/nstestfirst/echo_";
char anum[10];
sprintf(anum,"%d",ref[i]);
name += anum;
CPPUNIT_ASSERT(anEchoRef->getId() == ref[i]);
}
- string name = "/nstestfirst/echo";
+ std::string name = "/nstestfirst/echo";
obj = _NS.ResolveFirst(name.c_str());
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
NSTEST::echo_var anEchoRef = NSTEST::echo::_narrow(obj);
{
NSTEST::echo_var anEchoRef = myFactory->createInstance();
ref[i] = anEchoRef->getId();
- string name = "/nstestfirstrel/echo_";
+ std::string name = "/nstestfirstrel/echo_";
char anum[10];
sprintf(anum,"%d",ref[i]);
name += anum;
for (int i=0; i<NB_OBJS; i++)
{
_NS.Change_Directory("/nstestfirstrel");
- string name = "echo_";
+ std::string name = "echo_";
char anum[10];
sprintf(anum,"%d",ref[i]);
name += anum;
}
_NS.Change_Directory("/nstestfirstrel");
- string name = "echo";
+ std::string name = "echo";
obj = _NS.ResolveFirst(name.c_str());
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
}
void
NamingServiceTest::testResolveFirstUnknown()
{
- string name = "/notYeyRegistered";
+ std::string name = "/notYeyRegistered";
CORBA::Object_var obj= _NS.ResolveFirst(name.c_str());
CPPUNIT_ASSERT(CORBA::is_nil(obj));
_NS.Create_Directory("/myContext");
_NS.Change_Directory("/myContext");
- string name = "RelnotYeyRegistered";
+ std::string name = "RelnotYeyRegistered";
CORBA::Object_var obj = _NS.ResolveFirst(name.c_str());
CPPUNIT_ASSERT(CORBA::is_nil(obj));
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
obj = _NS.ResolveComponent("theHostName",
- "theContainerName",
- "theComponentName");
+ "theContainerName",
+ "theComponentName");
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
_NS.Register(anEchoRef2,
- "/Containers/theHostName/theContainerName_2/theComponentName");
+ "/Containers/theHostName/theContainerName_2/theComponentName");
obj = _NS.ResolveComponent("theHostName",
- "theContainerName",
- "theComponentName",
- 2);
+ "theContainerName",
+ "theComponentName",
+ 2);
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
NSTEST::echo_var anEchoRefb = NSTEST::echo::_narrow(obj);
CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefb));
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
obj = _NS.ResolveComponent("",
- "theContainerName",
- "theComponentName");
+ "theContainerName",
+ "theComponentName");
CPPUNIT_ASSERT(CORBA::is_nil(obj));
}
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
obj = _NS.ResolveComponent("anUnknownHostName",
- "theContainerName",
- "theComponentName");
+ "theContainerName",
+ "theComponentName");
CPPUNIT_ASSERT(CORBA::is_nil(obj));
}
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
_NS.Register(anEchoRef2,
- "/Containers/theHostName/aContainerName/aComponentName");
+ "/Containers/theHostName/aContainerName/aComponentName");
NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
_NS.Register(anEchoRef3,
- "/Containers/theHostName/otherContainerName/theComponentName");
+ "/Containers/theHostName/otherContainerName/theComponentName");
obj = _NS.ResolveComponent("anUnknownHostName",
- "",
- "theComponentName");
+ "",
+ "theComponentName");
CPPUNIT_ASSERT(CORBA::is_nil(obj));
obj = _NS.ResolveComponent("theHostName",
- "",
- "theComponentName");
+ "",
+ "theComponentName");
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj);
CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa));
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
_NS.Register(anEchoRef2,
- "/Containers/theHostName/aContainerName/aComponentName");
+ "/Containers/theHostName/aContainerName/aComponentName");
NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
_NS.Register(anEchoRef3,
- "/Containers/theHostName/otherContainerName/theComponentName");
+ "/Containers/theHostName/otherContainerName/theComponentName");
obj = _NS.ResolveComponent("theHostName",
- "anUnknownContainerName",
- "theComponentName");
+ "anUnknownContainerName",
+ "theComponentName");
CPPUNIT_ASSERT(CORBA::is_nil(obj));
}
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
_NS.Register(anEchoRef2,
- "/Containers/theHostName/EmptyContainerName/");
+ "/Containers/theHostName/EmptyContainerName/");
obj = _NS.ResolveComponent("theHostName",
- "EmptyContainerName",
- "");
+ "EmptyContainerName",
+ "");
CPPUNIT_ASSERT(CORBA::is_nil(obj));
}
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
obj = _NS.ResolveComponent("theHostName",
- "theContainerName",
- "anUnknownComponentName");
+ "theContainerName",
+ "anUnknownComponentName");
CPPUNIT_ASSERT(CORBA::is_nil(obj));
}
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
obj = _NS.ResolveComponent("theHostName",
- "theContainerName",
- "theComponentName",
- 25);
+ "theContainerName",
+ "theComponentName",
+ 25);
CPPUNIT_ASSERT(CORBA::is_nil(obj));
obj = _NS.ResolveComponent("theHostName",
- "theContainerName",
- "theComponentName",
- -25);
+ "theContainerName",
+ "theComponentName",
+ -25);
CPPUNIT_ASSERT(! CORBA::is_nil(obj));
}
void
NamingServiceTest::testContainerName()
{
- string ref0 = "FactoryServer";
- string ret = _NS.ContainerName("");
+ std::string ref0 = "FactoryServer";
+ std::string ret = _NS.ContainerName("");
CPPUNIT_ASSERT(ret == ref0);
ref0 = "MyContainerName";
void
NamingServiceTest::testContainerNameParams()
{
- Engines::MachineParameters params;
- params.container_name = "";
- params.hostname = "";
- params.OS = "";
- params.mem_mb = 0;
- params.cpu_clock = 0;
- params.nb_proc_per_node = 0;
- params.nb_node = 0;
- params.isMPI = false;
-
- string ref0 = "FactoryServer";
- string ret = _NS.ContainerName(params);
+ Engines::ContainerParameters params;
+ SALOME_LifeCycleCORBA::preSet(params);
+
+ std::string ref0 = "FactoryServer";
+ std::string ret = _NS.ContainerName(params);
CPPUNIT_ASSERT(ret == ref0);
ref0 = "MyContainerName";
void
NamingServiceTest::testBuildContainerNameForNS()
{
- string ref0 = "/Containers/theHostName/theContainerName";
- string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
+ std::string ref0 = "/Containers/theHostName/theContainerName";
+ std::string ret = _NS.BuildContainerNameForNS("theContainerName","theHostName");
CPPUNIT_ASSERT(ret == ref0);
ref0 = "/Containers/theHostName/FactoryServer";
void
NamingServiceTest::testBuildContainerNameForNSParams()
{
- Engines::MachineParameters params;
- params.container_name = "";
- params.hostname = "";
- params.OS = "";
- params.mem_mb = 0;
- params.cpu_clock = 0;
- params.nb_proc_per_node = 0;
- params.nb_node = 0;
- params.isMPI = false;
+ Engines::ContainerParameters params;
+ SALOME_LifeCycleCORBA::preSet(params);
params.container_name = "theContainerName";
- string ref0 = "/Containers/theHostName/theContainerName";
- string ret = _NS.BuildContainerNameForNS(params,"theHostName");
+ std::string ref0 = "/Containers/theHostName/theContainerName";
+ std::string ret = _NS.BuildContainerNameForNS(params,"theHostName");
CPPUNIT_ASSERT(ret == ref0);
params.container_name = "";
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
_NS.Register(anEchoRef2,
- "/Containers/theHostName/aContainerName/aComponentName");
+ "/Containers/theHostName/aContainerName/aComponentName");
NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
_NS.Register(anEchoRef3,
- "/Containers/theHostName/otherContainerName/theComponentName");
+ "/Containers/theHostName/otherContainerName/theComponentName");
NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
_NS.Register(anEchoRef4,
- "/Containers/anHostName/oneContainerName/theComponentName");
+ "/Containers/anHostName/oneContainerName/theComponentName");
_NS.Change_Directory("/Containers");
int occ= _NS.Find("theComponentName");
_NS.Change_Directory("/aaa/bbb/ccc/ddd/eee");
NSTEST::echo_var anEchoRef = myFactory->createInstance();
int val = anEchoRef->getId();
- string name = "echo_";
+ std::string name = "echo_";
char anum[10];
sprintf(anum,"%d",val);
name += anum;
_NS.Register(anEchoRef,name.c_str());
- string dirname = "/aaa/bbb/ccc/ddd/eee/";
+ std::string dirname = "/aaa/bbb/ccc/ddd/eee/";
dirname += name;
obj = _NS.Resolve(dirname.c_str());
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef,
- "/Containers/theHostName/theContainerName/theComponentName");
+ "/Containers/theHostName/theContainerName/theComponentName");
NSTEST::echo_var anEchoRef2 = myFactory->createInstance();
_NS.Register(anEchoRef2,
- "/Containers/theHostName/aContainerName/aComponentName");
+ "/Containers/theHostName/aContainerName/aComponentName");
NSTEST::echo_var anEchoRef3 = myFactory->createInstance();
_NS.Register(anEchoRef3,
- "/Containers/theHostName/otherContainerName/theComponentName");
+ "/Containers/theHostName/otherContainerName/theComponentName");
NSTEST::echo_var anEchoRef4 = myFactory->createInstance();
_NS.Register(anEchoRef4,
- "/Containers/anHostName/oneContainerName/theComponentName");
+ "/Containers/anHostName/oneContainerName/theComponentName");
_NS.Change_Directory("/Containers/theHostName/otherContainerName");
obj = _NS.Resolve("theComponentName");
void
NamingServiceTest::testCurrentDirectory()
{
- string path = "/aaa/bbb/ccc/ddd/eee";
+ std::string path = "/aaa/bbb/ccc/ddd/eee";
bool ret = _NS.Create_Directory(path.c_str());
CPPUNIT_ASSERT(ret);
_NS.Change_Directory(path.c_str());
- string curdir = _NS.Current_Directory();
+ char* acurdir = _NS.Current_Directory();
+ std::string curdir = acurdir;
+ free(acurdir);
CPPUNIT_ASSERT(curdir == path);
}
NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
- string path = "/Containers/theHostName/theContainerName/theComponentName";
+ std::string path = "/Containers/theHostName/theContainerName/theComponentName";
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef, path.c_str());
NSTEST::aFactory_var myFactory = NSTEST::aFactory::_narrow(obj);
CPPUNIT_ASSERT(!CORBA::is_nil(myFactory));
- string path = "/Containers/theHostName/theContainerName/theComponentName";
+ std::string path = "/Containers/theHostName/theContainerName/theComponentName";
NSTEST::echo_var anEchoRef = myFactory->createInstance();
_NS.Register(anEchoRef, path.c_str());
*/
// ============================================================================
-void NamingServiceTest::_destroyDirectoryRecurs(string path)
+void NamingServiceTest::_destroyDirectoryRecurs(std::string path)
{
- string current = path;
+ std::string current = path;
SCRUTE(path);
if (_NS.Change_Directory(path.c_str()))
{
- vector<string> subdirs = _NS.list_subdirs();
+ std::vector<std::string> subdirs = _NS.list_subdirs();
for (int i=0; i<subdirs.size(); i++)
- {
- string subpath=path + "/" +subdirs[i];
- _destroyDirectoryRecurs(subpath);
- }
+ {
+ std::string subpath=path + "/" +subdirs[i];
+ _destroyDirectoryRecurs(subpath);
+ }
if (_NS.Change_Directory(path.c_str()))
- {
- _NS.Destroy_FullDirectory(path.c_str());
- }
+ {
+ _NS.Destroy_FullDirectory(path.c_str());
+ }
}
}
{
_NS.Destroy_FullDirectory("/Containers");
CPPUNIT_ASSERT(_NS.Change_Directory("/Containers"));
- vector<string> subdirs = _NS.list_subdirs();
+ std::vector<std::string> subdirs = _NS.list_subdirs();
CPPUNIT_ASSERT(subdirs.size() >0);
_NS.list_directory_recurs();
- string path = "/Containers";
+ std::string path = "/Containers";
_destroyDirectoryRecurs(path);
CPPUNIT_ASSERT( ! _NS.Change_Directory("/Containers"));
_NS.Change_Directory("/");
void
NamingServiceTest::testGetIorAddr()
{
- char *root = _NS.getIORaddr();
+ CORBA::String_var root = _NS.getIORaddr();
CORBA::Object_var obj = _orb->string_to_object(root);
CPPUNIT_ASSERT(!CORBA::is_nil(obj));
}