File: test-cxx-build.cpp

package info (click to toggle)
mptcpd 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,612 kB
  • sloc: ansic: 9,472; sh: 5,154; makefile: 467; cpp: 61
file content (127 lines) | stat: -rw-r--r-- 3,194 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: BSD-3-Clause
/**
 * @file test-cxx-build.cpp
 *
 * @brief Verify mptcpd API can be used in C++ code.
 *
 * Copyright (c) 2019, 2021-2022, Intel Corporation
 */

#include <ell/main.h>
#include <ell/idle.h>
#include <ell/log.h>

#include <mptcpd/path_manager.h>   // Include to test build under C++.
#include <mptcpd/network_monitor.h>
#include <mptcpd/plugin.h>

#include <mptcpd/private/network_monitor.h>
#include <mptcpd/private/plugin.h>

#include "test-plugin.h"

#undef NDEBUG
#include <cassert>


/**
 * @class test_nm
 *
 * @brief Encapsulate a @c mptcpd_nm object.
 *
 * @note This class is only intended to exercise @c mptcpd network
 *       monitor operations when using a C++ compiler.  It is not
 *       intended to be used as a model for how the operations should
 *       be encapsulated in production code.
 */
class test_nm
{
public:

        test_nm() : nm_(mptcpd_nm_create(0)) { assert(this->nm_); }
        ~test_nm() { mptcpd_nm_destroy (this->nm_); }

private:
        test_nm(test_nm const &);
        void operator=(test_nm const &);

private:
        mptcpd_nm *const nm_;
};

/**
 * @class test_plugin
 *
 * @brief Encapsulate @c mptcpd plugin operations.
 *
 * @note This class is only intended to exercise @c mptcpd plugin
 *       operations when using a C++ compiler.  It is not intended to
 *       be used as a model for how the operations should be
 *       encapsulated in production code.
 */
class test_plugin
{
public:
        test_plugin()
                : pm(NULL)
        {
                static char const dir[]            = TEST_PLUGIN_DIR;
                static char const default_plugin[] = TEST_PLUGIN_FOUR;
                struct mptcpd_pm *const pm = NULL;

                bool const loaded =
                        mptcpd_plugin_load(dir, default_plugin, NULL, this->pm);
                assert(loaded);

                static struct plugin_call_args const args = {
                        .token    = test_token_4,
                        .raddr_id = test_raddr_id_4,
                        .laddr    = (struct sockaddr const *) &test_laddr_4,
                        .raddr    = (struct sockaddr const *) &test_raddr_4,
                        .backup   = test_backup_4
                };

                call_plugin_ops(&test_count_4, &args);
        }

        ~test_plugin() { mptcpd_plugin_unload(this->pm); }

private:
        test_plugin(test_plugin const &);
        void operator=(test_plugin const &);
private:
        struct mptcpd_pm *const pm;
};


int main()
{
        if (!l_main_init())
                return -1;

        l_log_set_stderr();

        /**
         * @note As of ELL 0.17 uncommenting the below call to
         *       l_debug_enable() causes link-time unresolved symbol
         *       errors caused by the @c __start___ell_debug and
         *       @c __stop___ell_debug symbols not being exported from
         *       the ELL shared library.
         */
        // l_debug_enable("*");

        test_nm nm;
        test_plugin p;

        (void) nm;
        (void) p;

        return l_main_exit() ? 0 : -1;
}


/*
  Local Variables:
  c-file-style: "linux"
  End:
*/