summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/facets/AllTests.cpp
blob: 620b826905ec3aa00ac5108c2f678b8f0e46e4a2 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// **********************************************************************
//
// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#include <Ice/Ice.h>
#include <TestCommon.h>
#include <Test.h>

using namespace std;
using namespace Test;

class EmptyI : virtual public Empty
{
};

GPrx
allTests(const Ice::CommunicatorPtr& communicator)
{
    cout << "testing facet registration exceptions... " << flush;
    Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("FacetExceptionTestAdapter");
    Ice::ObjectPtr obj = new EmptyI;
    adapter->add(obj, Ice::stringToIdentity("d"));
    adapter->addFacet(obj, Ice::stringToIdentity("d"), "facetABCD");
    bool gotException = false;
    try
    {
	adapter->addFacet(obj, Ice::stringToIdentity("d"), "facetABCD");
    }
    catch(Ice::AlreadyRegisteredException&)
    {
	gotException = true;
    }
    test(gotException);
    adapter->removeFacet(Ice::stringToIdentity("d"), "facetABCD");
    gotException = false;
    try
    {
	adapter->removeFacet(Ice::stringToIdentity("d"), "facetABCD");
    }
    catch(Ice::NotRegisteredException&)
    {
	gotException = true;
    }
    test(gotException);
    cout << "ok" << endl;

    cout << "testing removeAllFacets..." << flush;
    Ice::ObjectPtr obj1 = new EmptyI;
    Ice::ObjectPtr obj2 = new EmptyI;
    adapter->addFacet(obj1, Ice::stringToIdentity("id1"), "f1");
    adapter->addFacet(obj2, Ice::stringToIdentity("id1"), "f2");
    Ice::ObjectPtr obj3 = new EmptyI;
    adapter->addFacet(obj1, Ice::stringToIdentity("id2"), "f1");
    adapter->addFacet(obj2, Ice::stringToIdentity("id2"), "f2");
    adapter->addFacet(obj3, Ice::stringToIdentity("id2"), "");
    Ice::FacetMap fm = adapter->removeAllFacets(Ice::stringToIdentity("id1"));
    test(fm.size() == 2);
    test(fm["f1"] == obj1);
    test(fm["f2"] == obj2);
    gotException = false;
    try
    {
	adapter->removeAllFacets(Ice::stringToIdentity("id1"));
    }
    catch(Ice::NotRegisteredException&)
    {
	gotException = true;
    }
    test(gotException);
    fm = adapter->removeAllFacets(Ice::stringToIdentity("id2"));
    test(fm.size() == 3);
    test(fm["f1"] == obj1);
    test(fm["f2"] == obj2);
    test(fm[""] == obj3);
    cout << "ok" << endl;

    adapter->deactivate();

    cout << "testing stringToProxy... " << flush;
    string ref = "d:default -p 12345 -t 10000";
    Ice::ObjectPrx db = communicator->stringToProxy(ref);
    test(db);
    cout << "ok" << endl;

    cout << "testing checked cast... " << flush;
    DPrx d = DPrx::checkedCast(db);
    test(d);
    test(d == db);
    cout << "ok" << endl;

    cout << "testing non-facets A, B, C, and D... " << flush;
    test(d->callA() == "A");
    test(d->callB() == "B");
    test(d->callC() == "C");
    test(d->callD() == "D");
    cout << "ok" << endl;

    cout << "testing facets A, B, C, and D... " << flush;
    DPrx df = DPrx::checkedCast(d, "facetABCD");
    test(df);
    test(df->callA() == "A");
    test(df->callB() == "B");
    test(df->callC() == "C");
    test(df->callD() == "D");
    cout << "ok" << endl;

    cout << "testing facets E and F... " << flush;
    FPrx ff = FPrx::checkedCast(d, "facetEF");
    test(ff);
    test(ff->callE() == "E");
    test(ff->callF() == "F");
    cout << "ok" << endl;

    cout << "testing facet G... " << flush;
    GPrx gf = GPrx::checkedCast(ff, "facetGH");
    test(gf);
    test(gf->callG() == "G");
    cout << "ok" << endl;

    cout << "testing whether casting preserves the facet... " << flush;
    HPrx hf = HPrx::checkedCast(gf);
    test(hf);
    test(hf->callG() == "G");
    test(hf->callH() == "H");
    cout << "ok" << endl;

    return gf;
}