summaryrefslogtreecommitdiff
path: root/mock
diff options
context:
space:
mode:
Diffstat (limited to 'mock')
-rw-r--r--mock/MQMockTest.h37
-rw-r--r--mock/MQTTMock.h50
-rw-r--r--mock/mosquitto.cc110
3 files changed, 197 insertions, 0 deletions
diff --git a/mock/MQMockTest.h b/mock/MQMockTest.h
new file mode 100644
index 0000000..307640b
--- /dev/null
+++ b/mock/MQMockTest.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021-2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <gmock/gmock.h>
+
+#include "MQTTMock.h"
+
+class MQMockTest : public ::testing::Test {
+ protected:
+ void SetUp() override { mqttMock = new MQTTMock; }
+
+ void TearDown() override
+ {
+ delete mqttMock;
+ mqttMock = nullptr;
+ }
+
+ public:
+ static MQTTMock &GetMock(void) { return *mqttMock; }
+
+ private:
+ static MQTTMock *mqttMock;
+};
diff --git a/mock/MQTTMock.h b/mock/MQTTMock.h
new file mode 100644
index 0000000..10d484e
--- /dev/null
+++ b/mock/MQTTMock.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2021-2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <gmock/gmock.h>
+
+class MQTTMock {
+ public:
+ MQTTMock(void) = default;
+ virtual ~MQTTMock(void) = default;
+
+ MOCK_METHOD0(mosquitto_lib_init, int(void));
+ MOCK_METHOD0(mosquitto_lib_cleanup, int(void));
+ MOCK_METHOD3(mosquitto_new, struct mosquitto *(const char *id, bool clean_session, void *obj));
+ MOCK_METHOD3(mosquitto_int_option, int(struct mosquitto *mosq, int option, int value));
+ MOCK_METHOD1(mosquitto_destroy, void(struct mosquitto *mosq));
+ MOCK_METHOD3(mosquitto_username_pw_set,
+ int(struct mosquitto *mosq, const char *username, const char *password));
+ MOCK_METHOD6(mosquitto_will_set, int(struct mosquitto *mosq, const char *topic, int payloadlen,
+ const void *payload, int qos, bool retain));
+ MOCK_METHOD1(mosquitto_will_clear, int(struct mosquitto *mosq));
+ MOCK_METHOD4(mosquitto_connect,
+ int(struct mosquitto *mosq, const char *host, int port, int keepalive));
+ MOCK_METHOD1(mosquitto_disconnect, int(struct mosquitto *mosq));
+ MOCK_METHOD7(mosquitto_publish,
+ int(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen,
+ const void *payload, int qos, bool retain));
+ MOCK_METHOD4(mosquitto_subscribe,
+ int(struct mosquitto *mosq, int *mid, const char *sub, int qos));
+ MOCK_METHOD3(mosquitto_unsubscribe, int(struct mosquitto *mosq, int *mid, const char *sub));
+ MOCK_METHOD1(mosquitto_loop_start, int(struct mosquitto *mosq));
+ MOCK_METHOD2(mosquitto_loop_stop, int(struct mosquitto *mosq, bool force));
+ MOCK_METHOD2(mosquitto_message_v5_callback_set,
+ void(struct mosquitto *mosq,
+ void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *,
+ const struct mqtt5__property *)));
+};
diff --git a/mock/mosquitto.cc b/mock/mosquitto.cc
new file mode 100644
index 0000000..5ea4f1b
--- /dev/null
+++ b/mock/mosquitto.cc
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2021-2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <cstring>
+
+#include "MQMockTest.h"
+#include "MQTTMock.h"
+
+MQTTMock *MQMockTest::mqttMock = nullptr;
+
+extern "C" {
+
+int mosquitto_lib_init(void)
+{
+ return MQMockTest::GetMock().mosquitto_lib_init();
+}
+
+int mosquitto_lib_cleanup(void)
+{
+ return MQMockTest::GetMock().mosquitto_lib_cleanup();
+}
+
+struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj)
+{
+ return MQMockTest::GetMock().mosquitto_new(id, clean_session, obj);
+}
+
+int mosquitto_int_option(struct mosquitto *mosq, int option, int value)
+{
+ return MQMockTest::GetMock().mosquitto_int_option(mosq, option, value);
+}
+
+void mosquitto_destroy(struct mosquitto *mosq)
+{
+ return MQMockTest::GetMock().mosquitto_destroy(mosq);
+}
+
+int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password)
+{
+ return MQMockTest::GetMock().mosquitto_username_pw_set(mosq, username, password);
+}
+
+int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen,
+ const void *payload, int qos, bool retain)
+{
+ return MQMockTest::GetMock().mosquitto_will_set(mosq, topic, payloadlen, payload, qos, retain);
+}
+
+int mosquitto_will_clear(struct mosquitto *mosq)
+{
+ return MQMockTest::GetMock().mosquitto_will_clear(mosq);
+}
+
+int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive)
+{
+ return MQMockTest::GetMock().mosquitto_connect(mosq, host, port, keepalive);
+}
+
+int mosquitto_disconnect(struct mosquitto *mosq)
+{
+ return MQMockTest::GetMock().mosquitto_disconnect(mosq);
+}
+
+int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen,
+ const void *payload, int qos, bool retain)
+{
+ return MQMockTest::GetMock().mosquitto_publish(mosq, mid, topic, payloadlen, payload, qos,
+ retain);
+}
+
+int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos)
+{
+ return MQMockTest::GetMock().mosquitto_subscribe(mosq, mid, sub, qos);
+}
+
+int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub)
+{
+ return MQMockTest::GetMock().mosquitto_unsubscribe(mosq, mid, sub);
+}
+
+int mosquitto_loop_start(struct mosquitto *mosq)
+{
+ return MQMockTest::GetMock().mosquitto_loop_start(mosq);
+}
+
+int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
+{
+ return MQMockTest::GetMock().mosquitto_loop_stop(mosq, force);
+}
+
+void mosquitto_message_v5_callback_set(struct mosquitto *mosq,
+ void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *,
+ const struct mqtt5__property *))
+{
+ return MQMockTest::GetMock().mosquitto_message_v5_callback_set(mosq, on_message);
+}
+
+} // extern "C"