/* Copyright (c) 2022 Cedalo GmbH */ // clang-format off #include "mosquitto_internal.h" // keep this at the top for `#define uthash_free` #include "ctrl_shell.h" #include "ctrl_shell_internal.h" #include "json_help.h" #include "utlist.h" // clang-format on #include #include #include #include "ctrl_shell_mock.hpp" #include "libmosquitto_mock.hpp" #include "pthread_mock.hpp" extern "C" { char **completion_matcher(const char *text, int start, int end); char *completion_generator(const char *text, int state); void ctrl_shell__cleanup(void); } namespace t = testing; class CtrlShellCompletionTest : public ::t::Test { public: ::t::StrictMock ctrl_shell_mock_{}; ::t::StrictMock libmosquitto_mock_{}; ::t::StrictMock pthread_mock_{}; void expect_setup() { EXPECT_CALL(pthread_mock_, pthread_cond_timedwait(t::_, t::_, t::_)) .WillRepeatedly(t::Invoke([](pthread_cond_t *, pthread_mutex_t *, const struct timespec *){ data.response_received = true; return 0; })); EXPECT_CALL(libmosquitto_mock_, mosquitto_subscribe(t::_, t::_, t::_, 1)) .WillRepeatedly(t::Return(0)); EXPECT_CALL(libmosquitto_mock_, mosquitto_publish(t::_, nullptr, t::_, t::_, t::_, 1, false)) .WillRepeatedly(t::Return(0)); rl_readline_name = "mosquitto_ctrl"; rl_completion_entry_function = completion_generator; rl_attempted_completion_function = completion_matcher; ctrl_shell__load_module(ctrl_shell__dynsec_init); } void expect_outputs(const char **outputs, size_t count) { for(size_t i=0; i