summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/tests/NameServiceTest/clt_main.cpp
blob: fdccfc5b3374e8ce598f72674a032903af5ab708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// $Id$
#include "ace/String_Base.h"
#include <orbsvcs/orbsvcs/CosNamingC.h>
#include "DAnCE/Logger/Log_Macros.h"
#include "RegistrationPath.h"
#include "DummyC.h"

using namespace NameServiceTest;


int ACE_TMAIN (int argc, ACE_TCHAR * argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService");
//        CosNaming::NamingContext_var naming = CosNaming::NamingContext::_narrow(naming_obj.in());
//        CosNaming::Name name(1);
//
//        name.length(1);
//
//        name[0].id = CORBA::string_dup("Dummy");
//        name[0].kind = CORBA::string_dup("");
//
//        CORBA::Object_ptr res_obj = naming->resolve(name);
//        if ( CORBA::is_nil(res_obj) )
//        {
//            DANCE_ERROR((LM_ERROR, "[%M] Failed to resolve object. The test failed.\n"));
//            return 1;
//        }
//        DANCE_DEBUG((LM_DEBUG, "[%M] resolve object : ok.\n"));
//
//        Dummy_var res_dummy_obj = Dummy::_narrow(res_obj);
//        if ( CORBA::is_nil(res_dummy_obj) )
//        {
//            DANCE_ERROR((LM_ERROR, "[%M] Failed to narrow the resolved object to custom type. The test failed.\n"));
//            return 1;
//        }
//        DANCE_DEBUG((LM_DEBUG, "[%M] resolved object -> dummy : ok.\n"));
//
//        DANCE_DEBUG((LM_DEBUG, "[%M] Dummy object returned : %s.", res_dummy_obj->sayHello()));
//        DANCE_DEBUG((LM_DEBUG, "[%M] The test succeeded."));
      //glasgow.headquarters.eclipsesp.com:12345
      ACE_CString url = "corbaname:rir:#app1.DeploymentPlan/Dummy";
//        url += app_name;
//        url += "/";
//        url += inst_name;
//        url += "/";
//        url += port_name;
      DANCE_DEBUG((LM_DEBUG, "[%M] URL : %s\n", url.c_str()));

      CORBA::Object_var obj = orb->string_to_object (url.c_str());
      if (CORBA::is_nil (obj))
        {
          DANCE_ERROR((LM_ERROR, "[%M] Failed to convert url to object. The test failed.\n"));
          return 1;
        }
      DANCE_DEBUG((LM_DEBUG, "[%M] URL -> object : ok.\n"));

      Dummy_var dummy_obj = Dummy::_narrow (obj);
      if (CORBA::is_nil (dummy_obj))
        {
          DANCE_ERROR((LM_ERROR, "[%M] Failed to narrow the object to custom type. The test failed.\n"));
          return 1;
        }
      DANCE_DEBUG((LM_DEBUG, "[%M] object -> dummy : ok.\n"));

      DANCE_DEBUG((LM_DEBUG, "[%M] Dummy object returned : %C.", dummy_obj->sayHello()));
      DANCE_DEBUG((LM_DEBUG, "[%M] The test succeeded."));
      return 0;
    }
  catch (const CORBA::Exception & e)
    {
      DANCE_ERROR((LM_ERROR, "[%M] A CORBA exception \"%C\" (%C) was thrown. The test failed."
                   , e._name(), e._info().c_str()));
      return 1;
    }
  catch (...)
    {
      DANCE_ERROR((LM_ERROR, "[%M] An exception was thrown. The test failed."));
      return 1;
    }
}