summaryrefslogtreecommitdiff
path: root/cpp/test/Common/TestCommon.cpp
blob: 0ff74d022e8d9fca18d5d450928acca868ec1d7a (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
// **********************************************************************
//
// Copyright (c) 2003-2017 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 <TestCommon.h>

#include <Ice/Communicator.h>

std::string
getTestEndpoint(const Ice::CommunicatorPtr& communicator, int num, const std::string& protocol)
{
    return getTestEndpoint(communicator->getProperties(), num, protocol);
}

std::string
getTestEndpoint(const Ice::PropertiesPtr& properties, int num, const std::string& prot)
{
    std::ostringstream ostr;
    std::string protocol = prot;
    if(protocol.empty())
    {
        protocol = properties->getPropertyWithDefault("Ice.Default.Protocol", "default");
    }

    int basePort = properties->getPropertyAsIntWithDefault("Test.BasePort", 12010);

    if(protocol == "bt")
    {
        //
        // For Bluetooth, there's no need to specify a port (channel) number.
        // The client locates the server using its address and a UUID.
        //
        switch(num)
        {
        case 0:
            ostr << "default -u 5e08f4de-5015-4507-abe1-a7807002db3d";
            break;
        case 1:
            ostr << "default -u dae56460-2485-46fd-a3ca-8b730e1e868b";
            break;
        case 2:
            ostr << "default -u 99e08bc6-fcda-4758-afd0-a8c00655c999";
            break;
        default:
            assert(false);
        }
    }
    else
    {
        ostr << protocol << " -p " << (basePort + num);
    }
    return ostr.str();
}

std::string
getTestHost(const Ice::PropertiesPtr& properties)
{
    return properties->getPropertyWithDefault("Ice.Default.Host", "127.0.0.1");
}

std::string
getTestProtocol(const Ice::PropertiesPtr& properties)
{
    return properties->getPropertyWithDefault("Ice.Default.Protocol", "tcp");
}

int
getTestPort(const Ice::PropertiesPtr& properties, int num)
{
    return properties->getPropertyAsIntWithDefault("Test.BasePort", 12010) + num;
}

Ice::InitializationData
getTestInitData(int& argc, char* argv[])
{
    Ice::InitializationData initData;
    initData.properties = Ice::createProperties(argc, argv);
    Ice::StringSeq args = Ice::argsToStringSeq(argc, argv);
    args = initData.properties->parseCommandLineOptions("Test", args);
    Ice::stringSeqToArgs(args, argc, argv);
    return initData;
}