apply AittOption
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 18 Aug 2022 10:47:54 +0000 (19:47 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 15 Sep 2022 05:27:27 +0000 (14:27 +0900)
- For applying global option in AITT instance.

18 files changed:
android/aitt/src/main/jni/aitt_jni.cc
common/AittDiscovery.cc
common/AittDiscovery.h
include/AITT.h
include/AittOption.h [new file with mode: 0644]
include/aitt_c.h
modules/webrtc/MqttServer.h
src/AITT.cc
src/AITTImpl.cc
src/AITTImpl.h
src/AittOption.cc [new file with mode: 0644]
src/aitt_c.cc
tests/AITT_manualtest.cc
tests/AITT_test.cc
tests/ModuleLoader_test.cc
tests/RequestResponse_test.cc
tests/aitt_c_manualtest.cc
tests/aitt_c_test.cc

index 801b906..841e9d3 100644 (file)
@@ -21,7 +21,7 @@ AittNativeInterface::CallbackContext AittNativeInterface::cbContext = {
 };
 
 AittNativeInterface::AittNativeInterface(std::string &mqId, std::string &ip, bool clearSession)
-      : cbObject(nullptr), aitt(mqId, ip, clearSession)
+      : cbObject(nullptr), aitt(mqId, ip, AittOption(clearSession, false))
 {
 }
 
index be3b65b..8f75103 100644 (file)
@@ -24,7 +24,7 @@
 
 namespace aitt {
 
-AittDiscovery::AittDiscovery(const std::string &id)
+AittDiscovery::AittDiscovery(const std::string &id, bool custom_broker)
       : id_(id), discovery_mq(id + "d", true), callback_handle(nullptr)
 {
 }
index 42e2314..fd6ba1d 100644 (file)
@@ -30,7 +30,7 @@ class AittDiscovery {
     using DiscoveryCallback = std::function<void(const std::string &clientId,
           const std::string &status, const void *msg, const int szmsg)>;
 
-    explicit AittDiscovery(const std::string &id);
+    explicit AittDiscovery(const std::string &id, bool custom_broker);
     void Start(const std::string &host, int port, const std::string &username,
           const std::string &password);
     void Stop();
index ac8cc0c..42ee6e2 100644 (file)
@@ -16,6 +16,7 @@
 #pragma once
 
 #include <AittException.h>
+#include <AittOption.h>
 #include <AittTypes.h>
 #include <MSG.h>
 
@@ -34,7 +35,8 @@ class API AITT {
           std::function<void(MSG *msg, const void *data, const size_t datalen, void *user_data)>;
     using ConnectionCallback = std::function<void(AITT &, int, void *user_data)>;
 
-    explicit AITT(const std::string &id, const std::string &ip_addr, bool clear_session = false);
+    explicit AITT(const std::string &id, const std::string &ip_addr,
+          AittOption option = AittOption(false, false));
     virtual ~AITT(void);
 
     void SetWillInfo(const std::string &topic, const void *data, const size_t datalen, AittQoS qos,
diff --git a/include/AittOption.h b/include/AittOption.h
new file mode 100644 (file)
index 0000000..40a4217
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 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 <AittTypes.h>
+
+class API AittOption {
+  public:
+    AittOption();
+    explicit AittOption(bool clear_session, bool use_custom_broker);
+    ~AittOption() = default;
+
+    void SetClearSession(bool val);
+    bool GetClearSession();
+    void SetUseCustomMqttBroker(bool val);
+    bool GetUseCustomMqttBroker();
+
+  private:
+    bool clear_session_;
+    bool use_custom_broker_;
+};
index 24ffce3..26d0366 100644 (file)
@@ -29,13 +29,18 @@ extern "C" {
 
 /**
  * @brief @a aitt_h is an opaque data structure to represent AITT service handle.
- * @since_tizen 7.0
  */
 typedef struct aitt_handle *aitt_h;
 
 /**
+ * @brief @a aitt_option_h is an opaque data structure to represent AITT option handle.
+ *        The option handle is used at aitt_new()
+ * @see aitt_new()
+ */
+typedef struct aitt_option *aitt_option_h;
+
+/**
  * @brief @a aitt_msg_h is an opaque data structure to represent AITT message handle.
- * @since_tizen 7.0
  * @see aitt_sub_fn
  * @see aitt_msg_get_topic()
  */
@@ -43,34 +48,29 @@ typedef void *aitt_msg_h;
 
 /**
  * @brief @a aitt_sub_h is an opaque data structure to represent AITT subscribe ID.
- * @since_tizen 7.0
  * @see aitt_subscribe(), aitt_unsubscribe()
  */
 typedef AittSubscribeID aitt_sub_h;
 
 /**
  * @brief Enumeration for protocol.
- * @since_tizen 7.0
  */
 typedef enum AittProtocol aitt_protocol_e;
 
 /**
  * @brief Enumeration for MQTT QoS.
  *        It only works with the AITT_TYPE_MQTT
- * @since_tizen 7.0
  */
 typedef enum AittQoS aitt_qos_e;
 
 /**
  * @brief Enumeration for AITT error code.
- * @since_tizen 7.0
  */
 typedef enum AittError aitt_error_e;
 
 /**
  * @brief Specify the type of function passed to aitt_subscribe().
  * @details When the aitt get message, it is called, immediately.
- * @since_tizen 7.0
  * @param[in] msg_handle aitt message handle. The handle has topic name and so on. @c aitt_msg_h
  * @param[in] msg pointer to the data received
  * @param[in] msg_len the size of the @c msg (bytes)
@@ -88,28 +88,56 @@ typedef void (
  * @brief Create a new AITT service instance.
  * @detail If id is NULL or empty string, id will be generated automatically.
  *         If my_ip is NULL or empty string, my_ip will be set as 127.0.0.1.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] id Unique identifier in local network
- * @param[in] my_ip Own device ip address for connecting by others
  * @return @c handle of AITT service
  *         otherwise NULL value on failure
  * @see aitt_destroy()
  */
-aitt_h aitt_new(const char *id, const char *my_ip);
+aitt_h aitt_new(const char *id, aitt_option_h option);
+
+/**
+ * @brief Release memory of the AITT service instance.
+ * @privlevel public
+ * @param[in] handle Handle of AITT service;
+ * @see aitt_new()
+ */
+void aitt_destroy(aitt_h handle);
+
+/**
+ * @brief Create a new AITT option instance.
+ * @detail Create AITT option which is used in aitt_new()
+ * @privlevel public
+ * @return @c handle of AITT option
+ *         otherwise NULL value on failure
+ * @see aitt_option_destroy()
+ */
+aitt_option_h aitt_option_new();
+
+/**
+ * @brief Release memory of the AITT option instance.
+ * @privlevel public
+ * @param[in] handle Handle of AITT option;
+ * @see aitt_option_new()
+ */
+void aitt_option_destroy(aitt_option_h handle);
 
 /**
  * @brief Enumeration for option.
- * @since_tizen 7.0
+ * @remarks The boolean value is case-insensitive @c true or @c false
+ *          and NULL is handled as @c false
  */
 typedef enum {
-    AITT_OPT_UNKNOWN, /**< Unknown */
+    AITT_OPT_UNKNOWN,       /**< Unknown */
+    AITT_OPT_MY_IP,         /**< Own device ip address for connecting by others */
+    AITT_OPT_CLEAN_SESSION, /**< A Boolean value whether broker clean all message and subscriptions
+                               on disconnect */
+    AITT_OPT_CUSTOM_BROKER, /**< A Boolean value whether AITT uses a custom broker. */
 } aitt_option_e;
 
 /**
  * @brief Set the contents of a @c handle related with @c option to @c value
  * @detail The @c value can be NULL for removing the content
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] option value of @a aitt_option_e.
@@ -121,11 +149,10 @@ typedef enum {
  *
  * @see aitt_get_option()
  */
-int aitt_set_option(aitt_h handle, aitt_option_e option, const char *value);
+int aitt_option_set(aitt_option_h handle, aitt_option_e option, const char *value);
 
 /**
  * @brief Returns the string value of a @c handle related with @c option
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] option value of @a aitt_option_e.
@@ -134,12 +161,11 @@ int aitt_set_option(aitt_h handle, aitt_option_e option, const char *value);
  *
  * @see aitt_set_option()
  */
-const char *aitt_get_option(aitt_h handle, aitt_option_e option);
+const char *aitt_option_get(aitt_option_h handle, aitt_option_e option);
 
 /**
  * @brief Configure will information for a aitt instance.
  * @detail By default, clients do not have a will. This must be called before calling aitt_connect()
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] topic the topic on which to publish the will.
@@ -159,17 +185,7 @@ int aitt_will_set(aitt_h handle, const char *topic, const void *msg, const size_
       aitt_qos_e qos, bool retain);
 
 /**
- * @brief Release memory of the AITT service instance.
- * @since_tizen 7.0
- * @privlevel public
- * @param[in] handle Handle of AITT service;
- * @see aitt_new()
- */
-void aitt_destroy(aitt_h handle);
-
-/**
  * @brief Connect to mqtt broker.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] broker_ip IP address of the broker to connect to
@@ -184,7 +200,6 @@ int aitt_connect(aitt_h handle, const char *broker_ip, int port);
 
 /**
  * @brief Connect to mqtt broker as aitt_connect(), but takes username and password.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] broker_ip IP address of the broker to connect to
@@ -202,7 +217,6 @@ int aitt_connect_full(aitt_h handle, const char *broker_ip, int port, const char
 
 /**
  * @brief Disconnect from the broker.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @return @c 0 on success
@@ -215,7 +229,6 @@ int aitt_disconnect(aitt_h handle);
 
 /**
  * @brief Publish a message on a given topic using MQTT, QoS0(At most once).
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] topic null terminated string of the topic to publish to.
@@ -231,7 +244,6 @@ int aitt_publish(aitt_h handle, const char *topic, const void *msg, const size_t
 
 /**
  * @brief Publish a message on a given topic as aitt_publish(), but takes protocols and qos.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] topic null terminated string of the topic to publish to.
@@ -251,7 +263,6 @@ int aitt_publish_full(aitt_h handle, const char *topic, const void *msg, const s
 /**
  * @brief Publish a message on a given topic as aitt_publish_full(),
  *        but takes reply topic and callback for the reply.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] topic null terminated string of the topic to publish to.
@@ -274,7 +285,6 @@ int aitt_publish_with_reply(aitt_h handle, const char *topic, const void *msg, c
 
 /**
  * @brief Send reply message to regarding topic.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] msg_handle Handle of published message(to reply).
@@ -293,7 +303,6 @@ int aitt_send_reply(aitt_h handle, aitt_msg_h msg_handle, const void *reply, con
 
 /**
  * @brief Get topic name from @c handle
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle aitt message handle
  * @return topic name on success otherwise NULL value on failure
@@ -303,7 +312,6 @@ const char *aitt_msg_get_topic(aitt_msg_h handle);
 /**
  * @brief Subscribe to a topic on MQTT with QoS0(at most once).
  * @details Sets a function to be called when the aitt get messages related with @c topic
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] topic null terminated string of the topic to subscribe to.
@@ -322,7 +330,6 @@ int aitt_subscribe(aitt_h handle, const char *topic, aitt_sub_fn cb, void *user_
 /**
  * @brief Subscribe to a topic, but takes protocols and qos.
  * @details Sets a function to be called when the aitt get messages related with @c topic
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] topic null terminated string of the topic to subscribe to.
@@ -343,7 +350,6 @@ int aitt_subscribe_full(aitt_h handle, const char *topic, aitt_sub_fn cb, void *
 /**
  * @brief Unsubscribe from a topic.
  * @details Removes the subscription of changes with given ID.
- * @since_tizen 7.0
  * @privlevel public
  * @param[in] handle Handle of AITT service
  * @param[in] sub_handle Handle of subscribed topic
index 7f93192..ad2a3d6 100644 (file)
@@ -54,8 +54,6 @@ class MqttServer : public IfaceServer {
     void UnsetRoomMessageArrivedCb(void) { room_message_arrived_cb_ = nullptr; }
 
   private:
-    static void MessageCallback(mosquitto *handle, void *mqtt_server, const mosquitto_message *msg,
-          const mosquitto_property *props);
     void OnConnect();
     void OnDisconnect();
     void ConnectCallBack(int status);
index 0c9b08d..4e2fb8b 100644 (file)
@@ -21,7 +21,7 @@
 
 namespace aitt {
 
-AITT::AITT(const std::string &id, const std::string &ip_addr, bool clear_session)
+AITT::AITT(const std::string &id, const std::string &ip_addr, AittOption option)
 {
     std::string valid_id = id;
     std::string valid_ip = ip_addr;
@@ -42,7 +42,7 @@ AITT::AITT(const std::string &id, const std::string &ip_addr, bool clear_session
     if (ip_addr.empty())
         valid_ip = "127.0.0.1";
 
-    pImpl = std::make_unique<AITT::Impl>(*this, valid_id, valid_ip, clear_session);
+    pImpl = std::make_unique<AITT::Impl>(*this, valid_id, valid_ip, option.GetClearSession());
 }
 
 AITT::~AITT(void)
@@ -129,5 +129,4 @@ void AITT::SendReply(MSG *msg, const void *data, size_t datalen, bool end)
     return pImpl->SendReply(msg, data, datalen, end);
 }
 
-
 }  // namespace aitt
index 1cca42e..18c5a38 100644 (file)
 
 namespace aitt {
 
-AITT::Impl::Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session)
-      : public_api(parent), id_(id), mq(id, clear_session), discovery(id), reply_id(0), modules{0}
+AITT::Impl::Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session,
+      bool custom_broker)
+      : public_api(parent),
+        id_(id),
+        mq(id, clear_session),
+        discovery(id, custom_broker),
+        reply_id(0),
+        modules{0}
 {
     // TODO: Validate my_ip
     ModuleLoader loader;
index f31c662..6c47bc1 100644 (file)
@@ -34,7 +34,8 @@ namespace aitt {
 
 class AITT::Impl {
   public:
-    Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session);
+    explicit Impl(AITT &parent, const std::string &id, const std::string &my_ip, bool clear_session,
+          bool custom_broker = false);
     virtual ~Impl(void);
 
     void SetWillInfo(const std::string &topic, const void *data, const size_t datalen, AittQoS qos,
diff --git a/src/AittOption.cc b/src/AittOption.cc
new file mode 100644 (file)
index 0000000..02e2299
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 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 "AittOption.h"
+
+AittOption::AittOption() : clear_session_(false), use_custom_broker_(false)
+{
+}
+
+AittOption::AittOption(bool clear_session, bool use_custom_mqtt_broker)
+      : clear_session_(clear_session), use_custom_broker_(use_custom_mqtt_broker)
+{
+}
+
+void AittOption::SetClearSession(bool val)
+{
+    clear_session_ = val;
+}
+
+bool AittOption::GetClearSession()
+{
+    return clear_session_;
+}
+
+void AittOption::SetUseCustomMqttBroker(bool val)
+{
+    use_custom_broker_ = val;
+}
+
+bool AittOption::GetUseCustomMqttBroker()
+{
+    return use_custom_broker_;
+}
index 1135353..dc33baf 100644 (file)
@@ -29,23 +29,32 @@ struct aitt_handle {
     bool connected;
 };
 
-API aitt_h aitt_new(const char *id, const char *my_ip)
+struct aitt_option {
+    const char *my_ip;
+    bool clear_session;
+    bool custom_broker;
+};
+
+API aitt_h aitt_new(const char *id, aitt_option_h option)
 {
     aitt_h handle = nullptr;
     try {
         std::string valid_id;
         std::string valid_ip;
+        AittOption aitt_option;
 
         if (id)
             valid_id = id;
 
-        if (my_ip)
-            valid_ip = my_ip;
-
-        DBG("id(%s), ip(%s)", valid_id.c_str(), valid_ip.c_str());
+        if (option) {
+            if (option->my_ip)
+                valid_ip = option->my_ip;
+            aitt_option.SetClearSession(option->clear_session);
+            aitt_option.SetUseCustomMqttBroker(option->custom_broker);
+        }
 
         handle = new aitt_handle();
-        handle->aitt = new AITT(valid_id, valid_ip, true);
+        handle->aitt = new AITT(valid_id, valid_ip, aitt_option);
         handle->connected = false;
     } catch (std::exception &e) {
         ERR("new() Fail(%s)", e.what());
@@ -55,19 +64,82 @@ API aitt_h aitt_new(const char *id, const char *my_ip)
     return handle;
 }
 
-API int aitt_set_option(aitt_h handle, aitt_option_e option, const char *value)
+API void aitt_destroy(aitt_h handle)
+{
+    if (handle == nullptr) {
+        ERR("handle is NULL");
+        return;
+    }
+
+    try {
+        delete handle->aitt;
+        delete handle;
+    } catch (std::exception &e) {
+        ERR("delete() Fail(%s)", e.what());
+    }
+}
+
+API aitt_option_h aitt_option_new()
+{
+    aitt_option_h handle = nullptr;
+
+    try {
+        handle = new aitt_option();
+        handle->my_ip = nullptr;
+        handle->clear_session = false;
+        handle->custom_broker = false;
+    } catch (std::exception &e) {
+        ERR("new() Fail(%s)", e.what());
+    }
+
+    return handle;
+}
+
+void aitt_option_destroy(aitt_option_h handle)
+{
+    if (handle == nullptr) {
+        ERR("handle is NULL");
+        return;
+    }
+
+    try {
+        delete handle;
+    } catch (std::exception &e) {
+        ERR("delete() Fail(%s)", e.what());
+    }
+}
+
+static int _option_set_bool(const char *value, bool &dest)
+{
+    if (value) {
+        dest = (STR_EQ == strcasecmp(value, "true"));
+        if (false == dest && STR_EQ != strcasecmp(value, "false")) {
+            ERR("Unknown value(%s)", value);
+            return AITT_ERROR_INVALID_PARAMETER;
+        }
+    } else {
+        dest = false;
+    }
+    return AITT_ERROR_NONE;
+}
+
+API int aitt_option_set(aitt_option_h handle, aitt_option_e option, const char *value)
 {
     RETV_IF(handle == nullptr, AITT_ERROR_INVALID_PARAMETER);
 
     switch (option) {
-    case AITT_OPT_UNKNOWN:
+    case AITT_OPT_MY_IP:
         try {
-            // something to do
+            handle->my_ip = value;
         } catch (std::exception &e) {
             ERR("string() Fail(%s)", e.what());
             return AITT_ERROR_SYSTEM;
         }
         break;
+    case AITT_OPT_CLEAN_SESSION:
+        return _option_set_bool(value, handle->clear_session);
+    case AITT_OPT_CUSTOM_BROKER:
+        return _option_set_bool(value, handle->custom_broker);
     default:
         ERR("Unknown option(%d)", option);
         return AITT_ERROR_INVALID_PARAMETER;
@@ -76,13 +148,17 @@ API int aitt_set_option(aitt_h handle, aitt_option_e option, const char *value)
     return AITT_ERROR_NONE;
 }
 
-API const char *aitt_get_option(aitt_h handle, aitt_option_e option)
+API const char *aitt_option_get(aitt_option_h handle, aitt_option_e option)
 {
     RETV_IF(handle == nullptr, nullptr);
 
     switch (option) {
-    case AITT_OPT_UNKNOWN:
-        return "Unknown";
+    case AITT_OPT_MY_IP:
+        return handle->my_ip;
+    case AITT_OPT_CLEAN_SESSION:
+        return (handle->clear_session) ? "true" : "false";
+    case AITT_OPT_CUSTOM_BROKER:
+        return (handle->custom_broker) ? "true" : "false";
     default:
         ERR("Unknown option(%d)", option);
     }
@@ -104,21 +180,6 @@ API int aitt_will_set(aitt_h handle, const char *topic, const void *msg, const s
     return AITT_ERROR_NONE;
 }
 
-API void aitt_destroy(aitt_h handle)
-{
-    if (handle == nullptr) {
-        ERR("handle is NULL");
-        return;
-    }
-
-    try {
-        delete handle->aitt;
-        delete handle;
-    } catch (std::exception &e) {
-        ERR("delete() Fail(%s)", e.what());
-    }
-}
-
 static bool is_valid_ip(const char *ip)
 {
     RETV_IF(ip == nullptr, false);
index cea0fcf..0e57ccb 100644 (file)
@@ -32,7 +32,7 @@ class AITTManualTest : public testing::Test, public AittTests {
 TEST_F(AITTManualTest, WillSet_P)
 {
     try {
-        AITT aitt("", LOCAL_IP, true);
+        AITT aitt("", LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Subscribe(
               "test/AITT_will",
@@ -45,7 +45,7 @@ TEST_F(AITTManualTest, WillSet_P)
 
         int pid = fork();
         if (pid == 0) {
-            AITT aitt_will("test_will_AITT", LOCAL_IP, true);
+            AITT aitt_will("test_will_AITT", LOCAL_IP, AittOption(true, false));
             aitt_will.SetWillInfo("test/AITT_will", TEST_MSG, sizeof(TEST_MSG),
                   AITT_QOS_AT_LEAST_ONCE, false);
             aitt_will.Connect();
index 2305937..b9aa8c4 100644 (file)
@@ -34,7 +34,7 @@ class AITTTest : public testing::Test, public AittTests {
     void pubsub_template(const char *test_msg, AittProtocol protocol)
     {
         try {
-            AITT aitt(clientId, LOCAL_IP, true);
+            AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
             aitt.Connect();
             aitt.Subscribe(
                   testTopic,
@@ -66,7 +66,7 @@ class AITTTest : public testing::Test, public AittTests {
 TEST_F(AITTTest, Positive_Create_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
     } catch (std::exception &e) {
         FAIL() << "Unexpected exception: " << e.what();
     }
@@ -75,7 +75,7 @@ TEST_F(AITTTest, Positive_Create_Anytime)
 TEST_F(AITTTest, SetConnectionCallback_P_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.SetConnectionCallback(
               [&](AITT &handle, int status, void *user_data) {
                   AITTTest *test = static_cast<AITTTest *>(user_data);
@@ -105,7 +105,7 @@ TEST_F(AITTTest, SetConnectionCallback_P_Anytime)
 TEST_F(AITTTest, UnsetConnectionCallback_P_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.SetConnectionCallback(
               [&](AITT &handle, int status, void *user_data) {
                   AITTTest *test = static_cast<AITTTest *>(user_data);
@@ -136,7 +136,7 @@ TEST_F(AITTTest, UnsetConnectionCallback_P_Anytime)
 TEST_F(AITTTest, Positive_Connect_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
     } catch (std::exception &e) {
         FAIL() << "Unexpected exception: " << e.what();
@@ -146,7 +146,7 @@ TEST_F(AITTTest, Positive_Connect_Anytime)
 TEST_F(AITTTest, Positive_Disconnect_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Disconnect();
     } catch (std::exception &e) {
@@ -157,7 +157,7 @@ TEST_F(AITTTest, Positive_Disconnect_Anytime)
 TEST_F(AITTTest, Positive_Connect_twice_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Disconnect();
         aitt.Connect();
@@ -169,7 +169,7 @@ TEST_F(AITTTest, Positive_Connect_twice_Anytime)
 TEST_F(AITTTest, Positive_Publish_MQTT_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Publish(testTopic, TEST_MSG, sizeof(TEST_MSG));
     } catch (std::exception &e) {
@@ -180,7 +180,7 @@ TEST_F(AITTTest, Positive_Publish_MQTT_Anytime)
 TEST_F(AITTTest, Positive_Publish_TCP_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Publish(testTopic, TEST_MSG, sizeof(TEST_MSG), AITT_TYPE_TCP);
     } catch (std::exception &e) {
@@ -191,7 +191,7 @@ TEST_F(AITTTest, Positive_Publish_TCP_Anytime)
 TEST_F(AITTTest, Positive_Publish_Multiple_Protocols_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Publish(testTopic, TEST_MSG, sizeof(TEST_MSG),
               (AittProtocol)(AITT_TYPE_MQTT | AITT_TYPE_TCP));
@@ -205,7 +205,7 @@ TEST_F(AITTTest, Positive_Publish_Multiple_Protocols_Anytime)
 TEST_F(AITTTest, Positive_Subscribe_WebRTC_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Subscribe(
               testTopic,
@@ -219,7 +219,7 @@ TEST_F(AITTTest, Positive_Subscribe_WebRTC_Anytime)
 TEST_F(AITTTest, Positive_Unsubscribe_MQTT_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         subscribeHandle = aitt.Subscribe(
               testTopic,
@@ -235,7 +235,7 @@ TEST_F(AITTTest, Positive_Unsubscribe_MQTT_Anytime)
 TEST_F(AITTTest, Positive_Unsubscribe_TCP_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         subscribeHandle = aitt.Subscribe(
               testTopic,
@@ -261,7 +261,7 @@ TEST_F(AITTTest, Positve_Publish_0_MQTT_Anytime)
 TEST_F(AITTTest, Positve_Unsubscribe_in_Subscribe_MQTT_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         subscribeHandle = aitt.Subscribe(
               testTopic,
@@ -296,7 +296,7 @@ TEST_F(AITTTest, Positve_Unsubscribe_in_Subscribe_MQTT_Anytime)
 TEST_F(AITTTest, Positve_Subscribe_in_Subscribe_MQTT_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         subscribeHandle = aitt.Subscribe(
               testTopic,
@@ -355,7 +355,7 @@ TEST_F(AITTTest, Positve_Publish_0_TCP_Anytime)
 TEST_F(AITTTest, Positve_PublishSubscribe_Multiple_Protocols_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
         aitt.Subscribe(
               testTopic,
@@ -549,7 +549,7 @@ TEST_F(AITTTest, WillSet_N_Anytime)
 {
     EXPECT_THROW(
           {
-              AITT aitt_will("", LOCAL_IP, true);
+              AITT aitt_will("", LOCAL_IP, AittOption(true, false));
               aitt_will.SetWillInfo("+", "will msg", 8, AITT_QOS_AT_MOST_ONCE, false);
               aitt_will.Connect();
               aitt_will.Disconnect();
index f693401..12437f3 100644 (file)
@@ -26,7 +26,7 @@ using ModuleLoader = aitt::ModuleLoader;
 
 class ModuleLoaderTest : public testing::Test {
   public:
-    ModuleLoaderTest(void) : discovery("test") {}
+    ModuleLoaderTest(void) : discovery("test", false) {}
 
   protected:
     void SetUp() override {}
index d723e3b..28e0914 100644 (file)
@@ -80,7 +80,7 @@ class AITTRRTest : public testing::Test, public AittTests {
         bool reply_ok[2];
         sub_ok = reply_ok[0] = reply_ok[1] = false;
 
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
 
         aitt.Subscribe(rr_topic.c_str(),
@@ -122,7 +122,7 @@ class AITTRRTest : public testing::Test, public AittTests {
         bool sub_ok, reply1_ok, reply2_ok;
         sub_ok = reply1_ok = reply2_ok = false;
 
-        AITT sub_aitt(clientId + "sub", LOCAL_IP, true);
+        AITT sub_aitt(clientId + "sub", LOCAL_IP, AittOption(true, false));
         INFO("Constructor Success");
 
         sub_aitt.Connect();
@@ -135,7 +135,7 @@ class AITTRRTest : public testing::Test, public AittTests {
                   sub_ok = true;
               });
 
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
 
         using namespace std::placeholders;
@@ -172,7 +172,7 @@ TEST_F(AITTRRTest, RequestResponse_P_Anytime)
     sub_ok = reply_ok = false;
 
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
 
         aitt.Subscribe(rr_topic.c_str(),
@@ -209,7 +209,7 @@ TEST_F(AITTRRTest, RequestResponse_asymmetry_Anytime)
     sub_ok = reply_ok = false;
 
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
 
         aitt.Subscribe(rr_topic.c_str(),
@@ -277,7 +277,7 @@ TEST_F(AITTRRTest, RequestResponse_sync_P_Anytime)
     sub_ok = reply1_ok = false;
 
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
 
         aitt.Subscribe(rr_topic.c_str(),
@@ -335,7 +335,7 @@ TEST_F(AITTRRTest, RequestResponse_sync_in_sync_P_Anytime)
 TEST_F(AITTRRTest, RequestResponse_timeout_P_Anytime)
 {
     try {
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
 
         int ret = aitt.PublishWithReplySync(
@@ -358,7 +358,7 @@ TEST_F(AITTRRTest, RequestResponse_timeout_restart_P_Anytime)
     sub_ok = reply_ok = false;
 
     try {
-        AITT sub_aitt(clientId + "sub", LOCAL_IP, true);
+        AITT sub_aitt(clientId + "sub", LOCAL_IP, AittOption(true, false));
         sub_aitt.Connect();
         sub_aitt.Subscribe(rr_topic.c_str(),
               [&](aitt::MSG *msg, const void *data, const size_t datalen, void *cbdata) {
@@ -368,7 +368,7 @@ TEST_F(AITTRRTest, RequestResponse_timeout_restart_P_Anytime)
                   sub_ok = true;
               });
 
-        AITT aitt(clientId, LOCAL_IP, true);
+        AITT aitt(clientId, LOCAL_IP, AittOption(true, false));
         aitt.Connect();
 
         int ret = aitt.PublishWithReplySync(
index 6085ea5..016b549 100644 (file)
@@ -23,7 +23,7 @@
 TEST(AITT_C_MANUAL, will_set_P)
 {
     int ret;
-    aitt_h handle = aitt_new("test14", LOCAL_IP);
+    aitt_h handle = aitt_new("test14", nullptr);
     ASSERT_NE(handle, nullptr);
 
     ret = aitt_connect(handle, LOCAL_IP, 1883);
@@ -46,7 +46,7 @@ TEST(AITT_C_MANUAL, will_set_P)
 
     int pid = fork();
     if (pid == 0) {
-        aitt_h handle_will = aitt_new("test_will", LOCAL_IP);
+        aitt_h handle_will = aitt_new("test_will", nullptr);
         ASSERT_NE(handle_will, nullptr);
 
         ret = aitt_will_set(handle_will, "test/topic_will", TEST_C_MSG, strlen(TEST_C_MSG),
@@ -88,7 +88,7 @@ TEST(AITT_C_MANUAL, will_set_P)
 // Set user/passwd in mosquitto.conf before testing
 TEST(AITT_C_MANUAL, connect_id_passwd_P)
 {
-    aitt_h handle = aitt_new("test15", LOCAL_IP);
+    aitt_h handle = aitt_new("test15", nullptr);
     ASSERT_NE(handle, nullptr);
 
     int ret = aitt_connect_full(handle, LOCAL_IP, 1883, "testID", "testPasswd");
index a83f88d..93cff1f 100644 (file)
 
 TEST(AITT_C_INTERFACE, new_P_Anytime)
 {
-    aitt_h handle = aitt_new("test1", LOCAL_IP);
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    aitt_h handle = aitt_new("test1", option);
+    aitt_option_destroy(option);
     EXPECT_TRUE(handle != nullptr);
     aitt_destroy(handle);
 
@@ -31,59 +35,91 @@ TEST(AITT_C_INTERFACE, new_P_Anytime)
     EXPECT_TRUE(handle != nullptr);
     aitt_destroy(handle);
 
-    handle = aitt_new("", "");
+    handle = aitt_new("", nullptr);
     EXPECT_TRUE(handle != nullptr);
     aitt_destroy(handle);
 }
 
 TEST(AITT_C_INTERFACE, destroy_P_Anytime)
 {
-    aitt_h handle = aitt_new("test2", LOCAL_IP);
+    aitt_h handle = aitt_new("test2", nullptr);
     ASSERT_NE(handle, nullptr);
 
     aitt_destroy(handle);
     aitt_destroy(nullptr);
 }
 
-// TODO:: Not yet Support
-/*
 TEST(AITT_C_INTERFACE, option_P_Anytime)
 {
-    aitt_h handle = aitt_new("test3");
-    ASSERT_NE(handle, nullptr);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
 
-    int ret = aitt_set_option(handle, AITT_OPT_MY_IP, LOCAL_IP);
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
     EXPECT_EQ(ret, AITT_ERROR_NONE);
-    EXPECT_STREQ(LOCAL_IP, aitt_get_option(handle, AITT_OPT_MY_IP));
+    EXPECT_STREQ(LOCAL_IP, aitt_option_get(option, AITT_OPT_MY_IP));
 
-    ret = aitt_set_option(handle, AITT_OPT_MY_IP, NULL);
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, nullptr);
     EXPECT_EQ(ret, AITT_ERROR_NONE);
-    EXPECT_EQ(NULL, aitt_get_option(handle, AITT_OPT_MY_IP));
+    EXPECT_STREQ(nullptr, aitt_option_get(option, AITT_OPT_MY_IP));
 
-    aitt_destroy(handle);
+    ret = aitt_option_set(option, AITT_OPT_CLEAN_SESSION, "TRUE");
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+    EXPECT_STREQ("true", aitt_option_get(option, AITT_OPT_CLEAN_SESSION));
+
+    ret = aitt_option_set(option, AITT_OPT_CLEAN_SESSION, nullptr);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+    EXPECT_STREQ("false", aitt_option_get(option, AITT_OPT_CLEAN_SESSION));
+
+    ret = aitt_option_set(option, AITT_OPT_CUSTOM_BROKER, "TRUE");
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+    EXPECT_STREQ("true", aitt_option_get(option, AITT_OPT_CUSTOM_BROKER));
+
+    ret = aitt_option_set(option, AITT_OPT_CUSTOM_BROKER, nullptr);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+    EXPECT_STREQ("false", aitt_option_get(option, AITT_OPT_CUSTOM_BROKER));
+
+    aitt_option_destroy(option);
 }
 
 TEST(AITT_C_INTERFACE, option_N_Anytime)
 {
-    aitt_h handle = aitt_new("test4");
-    ASSERT_NE(handle, nullptr);
+    int ret;
 
-    int ret = aitt_set_option(handle, AITT_OPT_UNKNOWN, LOCAL_IP);
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_UNKNOWN, LOCAL_IP);
     EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
 
-    ret = aitt_set_option(nullptr, AITT_OPT_MY_IP, LOCAL_IP);
+    ret = aitt_option_set(option, AITT_OPT_CLEAN_SESSION, "OFF");
     EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
 
-    aitt_destroy(handle);
+    ret = aitt_option_set(option, AITT_OPT_CUSTOM_BROKER, "Off");
+    EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
+
+    ret = aitt_option_set(nullptr, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
+
+    aitt_option_destroy(option);
 }
-*/
 
 TEST(AITT_C_INTERFACE, connect_disconnect_P_Anytime)
 {
-    aitt_h handle = aitt_new("test5", LOCAL_IP);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+    aitt_h handle = aitt_new("test5", option);
+    aitt_option_destroy(option);
     ASSERT_NE(handle, nullptr);
 
-    int ret = aitt_connect(handle, LOCAL_IP, 1883);
+    ret = aitt_connect(handle, LOCAL_IP, 1883);
     ASSERT_EQ(ret, AITT_ERROR_NONE);
 
     ret = aitt_disconnect(handle);
@@ -94,11 +130,13 @@ TEST(AITT_C_INTERFACE, connect_disconnect_P_Anytime)
 
 TEST(AITT_C_INTERFACE, connect_N_Anytime)
 {
-    aitt_h handle = aitt_new("test6", LOCAL_IP);
+    int ret;
+
+    aitt_h handle = aitt_new("test6", nullptr);
     ASSERT_NE(handle, nullptr);
 
     aitt_h invalid_handle = nullptr;
-    int ret = aitt_connect(invalid_handle, LOCAL_IP, 1883);
+    ret = aitt_connect(invalid_handle, LOCAL_IP, 1883);
     EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
 
     const char *invalid_ip = "1.2.3";
@@ -118,10 +156,12 @@ TEST(AITT_C_INTERFACE, connect_N_Anytime)
 
 TEST(AITT_C_INTERFACE, disconnect_N_Anytime)
 {
-    int ret = aitt_disconnect(nullptr);
+    int ret;
+
+    ret = aitt_disconnect(nullptr);
     EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
 
-    aitt_h handle = aitt_new("test7", LOCAL_IP);
+    aitt_h handle = aitt_new("test7", nullptr);
     ASSERT_NE(handle, nullptr);
 
     ret = aitt_disconnect(handle);
@@ -132,10 +172,19 @@ TEST(AITT_C_INTERFACE, disconnect_N_Anytime)
 
 TEST(AITT_C_INTERFACE, pub_sub_P_Anytime)
 {
-    aitt_h handle = aitt_new("test8", LOCAL_IP);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+    aitt_h handle = aitt_new("test8", option);
+    aitt_option_destroy(option);
     ASSERT_NE(handle, nullptr);
 
-    int ret = aitt_connect(handle, LOCAL_IP, 1883);
+    ret = aitt_connect(handle, LOCAL_IP, 1883);
     ASSERT_EQ(ret, AITT_ERROR_NONE);
 
     GMainLoop *loop = g_main_loop_new(nullptr, FALSE);
@@ -167,10 +216,19 @@ TEST(AITT_C_INTERFACE, pub_sub_P_Anytime)
 
 TEST(AITT_C_INTERFACE, pub_N_Anytime)
 {
-    aitt_h handle = aitt_new("test9", LOCAL_IP);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+    aitt_h handle = aitt_new("test9", option);
+    aitt_option_destroy(option);
     ASSERT_NE(handle, nullptr);
 
-    int ret = aitt_connect(handle, nullptr, 1883);
+    ret = aitt_connect(handle, nullptr, 1883);
     EXPECT_NE(ret, AITT_ERROR_NONE);
 
     ret = aitt_publish(handle, TEST_C_TOPIC, TEST_C_MSG, strlen(TEST_C_MSG));
@@ -194,11 +252,20 @@ TEST(AITT_C_INTERFACE, pub_N_Anytime)
 
 TEST(AITT_C_INTERFACE, sub_N_Anytime)
 {
-    aitt_h handle = aitt_new("test10", LOCAL_IP);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+    aitt_h handle = aitt_new("test10", option);
+    aitt_option_destroy(option);
     aitt_sub_h sub_handle = nullptr;
     ASSERT_NE(handle, nullptr);
 
-    int ret = aitt_connect(handle, nullptr, 1883);
+    ret = aitt_connect(handle, nullptr, 1883);
     EXPECT_NE(ret, AITT_ERROR_NONE);
 
     ret = aitt_subscribe(
@@ -230,10 +297,19 @@ TEST(AITT_C_INTERFACE, sub_N_Anytime)
 
 TEST(AITT_C_INTERFACE, pub_with_reply_send_reply_P_Anytime)
 {
-    aitt_h handle = aitt_new("test11", LOCAL_IP);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+    aitt_h handle = aitt_new("test11", option);
+    aitt_option_destroy(option);
     ASSERT_NE(handle, nullptr);
 
-    int ret = aitt_connect(handle, LOCAL_IP, 1883);
+    ret = aitt_connect(handle, LOCAL_IP, 1883);
     ASSERT_EQ(ret, AITT_ERROR_NONE);
 
     GMainLoop *loop = g_main_loop_new(nullptr, FALSE);
@@ -272,10 +348,19 @@ TEST(AITT_C_INTERFACE, pub_with_reply_send_reply_P_Anytime)
 
 TEST(AITT_C_INTERFACE, pub_with_reply_N_Anytime)
 {
-    aitt_h handle = aitt_new("test12", LOCAL_IP);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+    aitt_h handle = aitt_new("test12", option);
+    aitt_option_destroy(option);
     ASSERT_NE(handle, nullptr);
 
-    int ret = aitt_connect(handle, LOCAL_IP, 1883);
+    ret = aitt_connect(handle, LOCAL_IP, 1883);
     ASSERT_EQ(ret, AITT_ERROR_NONE);
 
     ret = aitt_publish_with_reply(
@@ -304,10 +389,19 @@ TEST(AITT_C_INTERFACE, pub_with_reply_N_Anytime)
 
 TEST(AITT_C_INTERFACE, sub_unsub_P_Anytime)
 {
-    aitt_h handle = aitt_new("test13", LOCAL_IP);
+    int ret;
+
+    aitt_option_h option = aitt_option_new();
+    ASSERT_NE(option, nullptr);
+
+    ret = aitt_option_set(option, AITT_OPT_MY_IP, LOCAL_IP);
+    EXPECT_EQ(ret, AITT_ERROR_NONE);
+
+    aitt_h handle = aitt_new("test13", option);
+    aitt_option_destroy(option);
     ASSERT_NE(handle, nullptr);
 
-    int ret = aitt_connect(handle, LOCAL_IP, 1883);
+    ret = aitt_connect(handle, LOCAL_IP, 1883);
     ASSERT_EQ(ret, AITT_ERROR_NONE);
 
     static unsigned int sub_call_count = 0;
@@ -365,6 +459,8 @@ TEST(AITT_C_INTERFACE, sub_unsub_P_Anytime)
 
 TEST(AITT_C_INTERFACE, will_set_N_Anytime)
 {
-    int ret = aitt_will_set(nullptr, "test/will_topic", "test", 4, AITT_QOS_AT_MOST_ONCE, false);
+    int ret;
+
+    ret = aitt_will_set(nullptr, "test/will_topic", "test", 4, AITT_QOS_AT_MOST_ONCE, false);
     EXPECT_EQ(ret, AITT_ERROR_INVALID_PARAMETER);
 }