File: plugin_manager_tests.cpp

package info (click to toggle)
pion 5.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,852 kB
  • ctags: 17,413
  • sloc: cpp: 13,965; sh: 10,263; perl: 269; makefile: 207; pascal: 152
file content (140 lines) | stat: -rw-r--r-- 4,230 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
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
134
135
136
137
138
139
140
// ---------------------------------------------------------------------
// pion:  a Boost C++ framework for building lightweight HTTP interfaces
// ---------------------------------------------------------------------
// Copyright (C) 2007-2012 Cloudmeter, Inc.  (http://www.cloudmeter.com)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//

#ifndef PION_STATIC_LINKING

#include <pion/config.hpp>
#include <pion/plugin_manager.hpp>
#include <pion/test/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/mpl/list.hpp>

using namespace pion;

#if defined(PION_CMAKE_BUILD)
    #include "plugin_path.hpp"
    static const std::string directoryOfPluginsForTests = PATH_TO_PLUGINS;
    #if defined(PION_WIN32)
        static const std::string sharedLibExt = ".dll";
    #else
        static const std::string sharedLibExt = ".so";
    #endif
#else

    #if defined(PION_WIN32)
        static const std::string directoryOfPluginsForTests = "plugins/.libs";
        static const std::string sharedLibExt = ".dll";
    #else
        #if defined(PION_XCODE)
            static const std::string directoryOfPluginsForTests = "../bin/Debug";
        #else
            static const std::string directoryOfPluginsForTests = "plugins/.libs";
        #endif
        static const std::string sharedLibExt = ".so";
    #endif
#endif


/// fixture for unit tests on a newly created plugin_manager
template <class T>
class new_plugin_manager_F : public plugin_manager<T> {
public:
    new_plugin_manager_F() {
        BOOST_REQUIRE(GET_DIRECTORY(m_old_cwd, DIRECTORY_MAX_SIZE) != NULL);
        BOOST_REQUIRE(CHANGE_DIRECTORY(directoryOfPluginsForTests.c_str()) == 0);
    }
    ~new_plugin_manager_F() {
        BOOST_CHECK(CHANGE_DIRECTORY(m_old_cwd) == 0);
    }

private:
    char m_old_cwd[DIRECTORY_MAX_SIZE+1];
};

struct InterfaceStub {
};

BOOST_AUTO_TEST_SUITE_FIXTURE_TEMPLATE(new_plugin_manager_S,
                                       boost::mpl::list<new_plugin_manager_F<InterfaceStub> >)

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkEmptyIsTrue) {
    BOOST_CHECK(F::empty());
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkLoad) {
    BOOST_CHECK(F::load("urn:id_1", "hasCreateAndDestroy") != NULL);
}

// TODO: tests for add(), find()

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkGet) {
    BOOST_CHECK(F::get("urn:id_2") == NULL);
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkRemove) {
    BOOST_CHECK_THROW(F::remove("urn:id_1"), error::plugin_not_found);
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkRun) {
    typename F::PluginRunFunction f;
    BOOST_CHECK_THROW(F::run("urn:id_3", f), error::plugin_not_found);
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkClear) {
    BOOST_CHECK_NO_THROW(F::clear());
}

BOOST_AUTO_TEST_SUITE_END()


/// fixture for unit tests on a plugin_manager with a plugin loaded
class plugin_manager_with_plugin_loaded_F : public new_plugin_manager_F<InterfaceStub> {
public:
    plugin_manager_with_plugin_loaded_F() {
        BOOST_REQUIRE(load("urn:id_1", "hasCreateAndDestroy") != NULL);
    }
    ~plugin_manager_with_plugin_loaded_F() {
    }
};

BOOST_AUTO_TEST_SUITE_FIXTURE_TEMPLATE(plugin_manager_with_plugin_loaded_S,
                                       boost::mpl::list<plugin_manager_with_plugin_loaded_F>)

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkEmptyIsFalse) {
    BOOST_CHECK(!F::empty());
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkLoadSecondPlugin) {
    BOOST_CHECK(F::load("urn:id_2", "hasCreateAndDestroy") != NULL);
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkLoadSecondPluginWithSameId) {
    BOOST_CHECK_THROW(F::load("urn:id_1", "hasCreateAndDestroy"), error::duplicate_plugin);
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkGet) {
    BOOST_CHECK(F::get("urn:id_1") != NULL);
    BOOST_CHECK(F::get("urn:id_2") == NULL);
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkRemove) {
    BOOST_CHECK_NO_THROW(F::remove("urn:id_1"));
    BOOST_CHECK(F::empty());
}

BOOST_AUTO_TEST_CASE_FIXTURE_TEMPLATE(checkClear) {
    BOOST_CHECK_NO_THROW(F::clear());
    BOOST_CHECK(F::empty());
}

// TODO: tests for add(), find(), run()

BOOST_AUTO_TEST_SUITE_END()

#endif // PION_STATIC_LINKING