Mercurial > irccd
comparison tests/src/libirccd/command-plugin-load/main.cpp @ 773:8c44bbcbbab9
Misc: style, cleanup and update
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 26 Oct 2018 13:01:00 +0200 |
parents | 35c1517d705d |
children |
comparison
equal
deleted
inserted
replaced
772:f5ccf65ae929 | 773:8c44bbcbbab9 |
---|---|
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 class broken : public plugin { | 30 class broken : public plugin { |
31 public: | 31 public: |
32 broken() | 32 broken() |
33 : plugin("broken") | 33 : plugin("broken") |
34 { | 34 { |
35 } | 35 } |
36 | 36 |
37 auto get_name() const noexcept -> std::string_view override | 37 auto get_name() const noexcept -> std::string_view override |
38 { | 38 { |
39 return "broken"; | 39 return "broken"; |
40 } | 40 } |
41 | 41 |
42 void handle_load(irccd&) override | 42 void handle_load(irccd&) override |
43 { | 43 { |
44 throw std::runtime_error("broken"); | 44 throw std::runtime_error("broken"); |
45 } | 45 } |
46 }; | 46 }; |
47 | 47 |
48 class broken_loader : public plugin_loader { | 48 class broken_loader : public plugin_loader { |
49 public: | 49 public: |
50 broken_loader() | 50 broken_loader() |
51 : plugin_loader({}, { ".none" }) | 51 : plugin_loader({}, { ".none" }) |
52 { | 52 { |
53 } | 53 } |
54 | 54 |
55 auto open(std::string_view, std::string_view) -> std::shared_ptr<plugin> override | 55 auto open(std::string_view, std::string_view) -> std::shared_ptr<plugin> override |
56 { | 56 { |
57 return nullptr; | 57 return nullptr; |
58 } | 58 } |
59 | 59 |
60 auto find(std::string_view id) noexcept -> std::shared_ptr<plugin> override | 60 auto find(std::string_view id) noexcept -> std::shared_ptr<plugin> override |
61 { | 61 { |
62 if (id == "broken") | 62 if (id == "broken") |
63 return std::make_unique<broken>(); | 63 return std::make_unique<broken>(); |
64 | 64 |
65 return nullptr; | 65 return nullptr; |
66 } | 66 } |
67 }; | 67 }; |
68 | 68 |
69 class sample_loader : public plugin_loader { | 69 class sample_loader : public plugin_loader { |
70 public: | 70 public: |
71 sample_loader() | 71 sample_loader() |
72 : plugin_loader({}, { ".none" }) | 72 : plugin_loader({}, { ".none" }) |
73 { | 73 { |
74 } | 74 } |
75 | 75 |
76 auto open(std::string_view, std::string_view) -> std::shared_ptr<plugin> override | 76 auto open(std::string_view, std::string_view) -> std::shared_ptr<plugin> override |
77 { | 77 { |
78 return nullptr; | 78 return nullptr; |
79 } | 79 } |
80 | 80 |
81 auto find(std::string_view id) noexcept -> std::shared_ptr<plugin> override | 81 auto find(std::string_view id) noexcept -> std::shared_ptr<plugin> override |
82 { | 82 { |
83 if (id == "test") | 83 if (id == "test") |
84 return std::make_unique<mock_plugin>("test"); | 84 return std::make_unique<mock_plugin>("test"); |
85 | 85 |
86 return nullptr; | 86 return nullptr; |
87 } | 87 } |
88 }; | 88 }; |
89 | 89 |
90 class plugin_load_fixture : public command_fixture { | 90 class plugin_load_fixture : public command_fixture { |
91 public: | 91 public: |
92 plugin_load_fixture() | 92 plugin_load_fixture() |
93 { | 93 { |
94 irccd_.plugins().add_loader(std::make_unique<sample_loader>()); | 94 irccd_.plugins().add_loader(std::make_unique<sample_loader>()); |
95 irccd_.plugins().add_loader(std::make_unique<broken_loader>()); | 95 irccd_.plugins().add_loader(std::make_unique<broken_loader>()); |
96 irccd_.plugins().clear(); | 96 irccd_.plugins().clear(); |
97 irccd_.plugins().add(std::make_unique<mock_plugin>("already")); | 97 irccd_.plugins().add(std::make_unique<mock_plugin>("already")); |
98 } | 98 } |
99 }; | 99 }; |
100 | 100 |
101 } // !namespace | 101 } // !namespace |
102 | 102 |
103 BOOST_FIXTURE_TEST_SUITE(plugin_load_fixture_suite, plugin_load_fixture) | 103 BOOST_FIXTURE_TEST_SUITE(plugin_load_fixture_suite, plugin_load_fixture) |
104 | 104 |
105 BOOST_AUTO_TEST_CASE(basic) | 105 BOOST_AUTO_TEST_CASE(basic) |
106 { | 106 { |
107 const auto [json, code] = request({ | 107 const auto [json, code] = request({ |
108 { "command", "plugin-load" }, | 108 { "command", "plugin-load" }, |
109 { "plugin", "test" } | 109 { "plugin", "test" } |
110 }); | 110 }); |
111 | 111 |
112 BOOST_TEST(!code); | 112 BOOST_TEST(!code); |
113 BOOST_TEST(irccd_.plugins().has("test")); | 113 BOOST_TEST(irccd_.plugins().has("test")); |
114 } | 114 } |
115 | 115 |
116 BOOST_AUTO_TEST_SUITE(errors) | 116 BOOST_AUTO_TEST_SUITE(errors) |
117 | 117 |
118 BOOST_AUTO_TEST_CASE(invalid_identifier) | 118 BOOST_AUTO_TEST_CASE(invalid_identifier) |
119 { | 119 { |
120 const auto [json, code] = request({ | 120 const auto [json, code] = request({ |
121 { "command", "plugin-load" } | 121 { "command", "plugin-load" } |
122 }); | 122 }); |
123 | 123 |
124 BOOST_TEST(code == plugin_error::invalid_identifier); | 124 BOOST_TEST(code == plugin_error::invalid_identifier); |
125 BOOST_TEST(json["error"].get<int>() == plugin_error::invalid_identifier); | 125 BOOST_TEST(json["error"].get<int>() == plugin_error::invalid_identifier); |
126 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); | 126 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); |
127 } | 127 } |
128 | 128 |
129 BOOST_AUTO_TEST_CASE(not_found) | 129 BOOST_AUTO_TEST_CASE(not_found) |
130 { | 130 { |
131 const auto [json, code] = request({ | 131 const auto [json, code] = request({ |
132 { "command", "plugin-load" }, | 132 { "command", "plugin-load" }, |
133 { "plugin", "unknown" } | 133 { "plugin", "unknown" } |
134 }); | 134 }); |
135 | 135 |
136 BOOST_TEST(code == plugin_error::not_found); | 136 BOOST_TEST(code == plugin_error::not_found); |
137 BOOST_TEST(json["error"].get<int>() == plugin_error::not_found); | 137 BOOST_TEST(json["error"].get<int>() == plugin_error::not_found); |
138 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); | 138 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); |
139 } | 139 } |
140 | 140 |
141 BOOST_AUTO_TEST_CASE(already_exists) | 141 BOOST_AUTO_TEST_CASE(already_exists) |
142 { | 142 { |
143 const auto [json, code] = request({ | 143 const auto [json, code] = request({ |
144 { "command", "plugin-load" }, | 144 { "command", "plugin-load" }, |
145 { "plugin", "already" } | 145 { "plugin", "already" } |
146 }); | 146 }); |
147 | 147 |
148 BOOST_TEST(code == plugin_error::already_exists); | 148 BOOST_TEST(code == plugin_error::already_exists); |
149 BOOST_TEST(json["error"].get<int>() == plugin_error::already_exists); | 149 BOOST_TEST(json["error"].get<int>() == plugin_error::already_exists); |
150 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); | 150 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); |
151 } | 151 } |
152 | 152 |
153 BOOST_AUTO_TEST_CASE(exec_error) | 153 BOOST_AUTO_TEST_CASE(exec_error) |
154 { | 154 { |
155 const auto [json, code] = request({ | 155 const auto [json, code] = request({ |
156 { "command", "plugin-load" }, | 156 { "command", "plugin-load" }, |
157 { "plugin", "broken" } | 157 { "plugin", "broken" } |
158 }); | 158 }); |
159 | 159 |
160 BOOST_TEST(code == plugin_error::exec_error); | 160 BOOST_TEST(code == plugin_error::exec_error); |
161 BOOST_TEST(json["error"].get<int>() == plugin_error::exec_error); | 161 BOOST_TEST(json["error"].get<int>() == plugin_error::exec_error); |
162 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); | 162 BOOST_TEST(json["errorCategory"].get<std::string>() == "plugin"); |
163 } | 163 } |
164 | 164 |
165 BOOST_AUTO_TEST_SUITE_END() | 165 BOOST_AUTO_TEST_SUITE_END() |
166 | 166 |
167 BOOST_AUTO_TEST_SUITE_END() | 167 BOOST_AUTO_TEST_SUITE_END() |