File: discovery_loopback.cpp

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (93 lines) | stat: -rw-r--r-- 3,342 bytes parent folder | download
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
#include <boost/shared_array.hpp>

#include <gtest/gtest.h>
#include <RobotRaconteur/ServiceDefinition.h>
#include <RobotRaconteur/RobotRaconteurNode.h>

#include "com__robotraconteur__testing__TestService1.h"
#include "com__robotraconteur__testing__TestService1_stubskel.h"

#include "ServiceTestClient.h"
#include "ServiceTest.h"
#include "robotraconteur_generated.h"
#include "service_test_utils.h"

using namespace RobotRaconteur;
using namespace RobotRaconteur::test;
using namespace RobotRaconteurTest;

TEST(RobotRaconteurService, DiscoveryLoopback)
{
    std::vector<std::string> args;
    RR_SHARED_PTR<RobotRaconteurNode> client_node = RR_MAKE_SHARED<RobotRaconteurNode>();
    client_node->Init();
    ClientNodeSetup client_node_setup(client_node, ROBOTRACONTEUR_SERVICE_TYPES, args);

    uint32_t server_flags = RobotRaconteurNodeSetupFlags_SERVER_DEFAULT;
    server_flags &= ~RobotRaconteurNodeSetupFlags_LOCAL_TRANSPORT_START_SERVER;
    ServerNodeSetup node_setup(ROBOTRACONTEUR_SERVICE_TYPES, "discovery_test_server_node", 0, server_flags);

    RobotRaconteurTestServiceSupport s;
    s.RegisterServices(node_setup.GetTcpTransport());

    boost::this_thread::sleep(boost::posix_time::milliseconds(5000));

    std::vector<std::string> schemes;
    if (node_setup.GetTcpTransport())
    {
        schemes.push_back("rr+tcp");
    }
    // if (node_setup.GetLocalTransport())
    // {
    //     schemes.push_back("rr+local");
    // }
    BOOST_FOREACH (const std::string& scheme, schemes)
    {
        std::vector<std::string> schemes2;
        schemes2.push_back(scheme);
        std::vector<ServiceInfo2> discovered_services =
            client_node->FindServiceByType("com.robotraconteur.testing.TestService1.testroot", schemes2);

        std::cout << "Found " << discovered_services.size() << " services" << std::endl;

        std::set<std::string> expected_service_names;
        expected_service_names.insert("RobotRaconteurTestService");
        expected_service_names.insert("RobotRaconteurTestService_auth");

        EXPECT_GE(discovered_services.size(), 2);

        size_t found_services = 0;

        BOOST_FOREACH (ServiceInfo2 s, discovered_services)
        {
            EXPECT_LE(expected_service_names.erase(s.Name), 1);
            if (s.NodeName != "discovery_test_server_node")
                continue;
            EXPECT_EQ(s.RootObjectType, "com.robotraconteur.testing.TestService1.testroot");
            EXPECT_EQ(s.RootObjectImplements.size(), 1);
            EXPECT_EQ(s.RootObjectImplements.at(0), "com.robotraconteur.testing.TestService2.baseobj");
            if (s.Name == "RobotRaconteurTestService")
            {
                RR_SHARED_PTR<com::robotraconteur::testing::TestService1::testroot> c;
                ASSERT_NO_THROW(c = rr_cast<com::robotraconteur::testing::TestService1::testroot>(
                                    client_node->ConnectService(s.ConnectionURL)));
                EXPECT_NO_THROW(c->get_d1());
                EXPECT_NO_THROW(client_node->DisconnectService(c));
            }
            found_services++;
        }

        EXPECT_GE(found_services, 2);

        EXPECT_EQ(expected_service_names.size(), 0);
    }
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);

    int ret = RUN_ALL_TESTS();

    return ret;
}