コード例 #1
0
ファイル: server.cpp プロジェクト: svn2github/ACE-Middleware
int test_orb (CORBA::ORB_ptr orb)
{
    int errors = 0;

    POA_TestModule::test* test = 0;
    ACE_NEW_RETURN (test,
                    test_i, 1);
    PortableServer::ServantBase_var safe (test);

    CORBA::Object_var object = test->_this ();

    orb->register_initial_reference ("ORBMyService",
                                     object.in ());

    bool invalid_name = false;
    try
    {
        // Registering with an empty string should give an exception
        orb->register_initial_reference ("",
                                         object.in ());
    }
    catch (const CORBA::ORB::InvalidName&)
    {
        invalid_name = true;
    }
    catch (const CORBA::Exception&)
    {
    }

    if (!invalid_name)
    {
        errors++;
        ACE_ERROR ((LM_ERROR, "ERROR: Registering with an empty string with the ORB"
                    "doesn't throw an exception\n"));
    }

    bool duplicate_name = false;
    try
    {
        // Registering with an duplicate string should give an exception
        orb->register_initial_reference ("ORBMyService",
                                         object.in ());
    }
    catch (const CORBA::ORB::InvalidName&)
    {
        duplicate_name = true;
    }
    catch (const CORBA::Exception&)
    {
    }

    if (!duplicate_name)
    {
        errors++;
        ACE_ERROR ((LM_ERROR, "ERROR: Registering with a duplicate with ORB "
                    "doesn't throw the expected exception\n"));
    }

    bool invalid_object = false;
    try
    {
        // Registering with a nil object
        orb->register_initial_reference ("ORBNilServer",
                                         CORBA::Object::_nil());
    }
    catch (const CORBA::BAD_PARAM& ex)
    {
        if ((ex.minor() & 0xFFFU) == 27)
        {
            invalid_object = true;
        }
    }
    catch (const CORBA::Exception&)
    {
    }

    if (!invalid_object)
    {
        errors++;
        ACE_ERROR ((LM_ERROR, "ERROR: Registering with a nil object to ORB "
                    "doesn't throw bad param with minor code 27\n"));
    }

    return errors;
}
コード例 #2
0
void
Server_ORBInitializer::pre_init (
    PortableInterceptor::ORBInitInfo_ptr orbinitinfo)
{
    POA_TestModule::test* test = 0;
    ACE_NEW (test,
             test_i);
    PortableServer::ServantBase_var safe (test);

    CORBA::Object_var object = test->_this ();

    orbinitinfo->register_initial_reference ("MyService",
            object.in ());

    bool invalid_name = false;
    try
    {
        // Registering with an empty string should give an exception
        orbinitinfo->register_initial_reference ("",
                object.in ());
    }
    catch (const PortableInterceptor::ORBInitInfo::InvalidName&)
    {
        invalid_name = true;
    }
    catch (const CORBA::Exception&)
    {
    }

    if (!invalid_name)
        ACE_ERROR ((LM_ERROR, "ERROR: Registering with an empty string doesn't "
                    "throw an exception\n"));

    bool duplicate_name = false;
    try
    {
        // Registering with an duplicate string should give an exception
        orbinitinfo->register_initial_reference ("MyService",
                object.in ());
    }
    catch (const PortableInterceptor::ORBInitInfo::InvalidName&)
    {
        duplicate_name = true;
    }
    catch (const CORBA::Exception&)
    {
    }

    if (!duplicate_name)
        ACE_ERROR ((LM_ERROR, "ERROR: Registering with a duplicate with ORBInitInfo "
                    "doesn't throw the expected exception\n"));

    bool invalid_object = false;
    try
    {
        // Registering with a nil object
        orbinitinfo->register_initial_reference ("NilServer",
                CORBA::Object::_nil());
    }
    catch (const CORBA::BAD_PARAM& ex)
    {
        if (ex.minor () == (CORBA::OMGVMCID | 27))
        {
            invalid_object = true;
        }
    }
    catch (const CORBA::Exception&)
    {
    }

    if (!invalid_object)
        ACE_ERROR ((LM_ERROR, "ERROR: Registering with a nil object to ORBInitInfo "
                    "doesn't throw bad param with OMG minor code 27\n"));
}