Rename test_service to test_config and add more tests 43/224443/6
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 10 Feb 2020 12:32:29 +0000 (21:32 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 6 Apr 2020 00:00:34 +0000 (09:00 +0900)
Change-Id: I9ffd7137081d1b61f9049f6b8371463ffc1cebca

inc/multi_assistant_config.h
src/multi_assistant_config.cpp
tests/utc/CMakeLists.txt
tests/utc/config/CMakeLists.txt [moved from tests/utc/service/CMakeLists.txt with 80% similarity]
tests/utc/config/test_config.cpp [new file with mode: 0644]
tests/utc/service/main.cpp [deleted file]

index cec7c12..a84c54d 100644 (file)
@@ -108,6 +108,9 @@ public:
        int mas_config_get_custom_wake_word_num(
                char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
                char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+       bool mas_config_has_custom_wake_word(const char* wake_word, const char* language,
+               char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+               char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
 private:
        int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback,
                const char *path, void* user_data);
index 243740f..f636d01 100644 (file)
@@ -390,9 +390,24 @@ int CConfig::mas_config_get_custom_wake_word_num(
 {
        int num = 0;
        for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
-               if (strlen(wakeup_word_storage[loop]) > 0) {
+               if (0 < strlen(wakeup_word_storage[loop])) {
                        num++;
                }
        }
        return num;
 }
+
+bool CConfig::mas_config_has_custom_wake_word(const char* wake_word, const char* language,
+       char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+       char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+{
+       if (nullptr == wake_word || nullptr == language) return false;
+
+       for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+               if (0 == strncmp(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN) &&
+                       0 == strncmp(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
+                       return true;
+               }
+       }
+       return false;
+}
index 2c2f631..145e97a 100644 (file)
@@ -1,3 +1,3 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
-ADD_SUBDIRECTORY(service)
+ADD_SUBDIRECTORY(config)
similarity index 80%
rename from tests/utc/service/CMakeLists.txt
rename to tests/utc/config/CMakeLists.txt
index b9d543b..ad3d302 100644 (file)
@@ -12,7 +12,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
 ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
 
 SET(TEST_SOURCES
-       main.cpp
+       test_config.cpp
        ${CMAKE_SOURCE_DIR}/src/multi_assistant_config.cpp
 )
 
@@ -34,14 +34,14 @@ FIND_PACKAGE(GTest REQUIRED)
 INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS})
 LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS})
 
-SET(TEST_SERVICE test-service)
-ADD_EXECUTABLE(${TEST_SERVICE}
+SET(TEST_CONFIG test-config)
+ADD_EXECUTABLE(${TEST_CONFIG}
        ${TEST_SOURCES}
        )
 
-TARGET_LINK_LIBRARIES(${TEST_SERVICE} -ldl ${GTEST_LIBRARIES} pthread
+TARGET_LINK_LIBRARIES(${TEST_CONFIG} -ldl ${GTEST_LIBRARIES} pthread
        ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS})
 
-INSTALL(TARGETS ${TEST_SERVICE} DESTINATION bin)
+INSTALL(TARGETS ${TEST_CONFIG} DESTINATION bin)
 
-ADD_TEST(NAME ${TEST_SERVICE} COMMAND ${TEST_SERVICE})
+ADD_TEST(NAME ${TEST_CONFIG} COMMAND ${TEST_CONFIG})
diff --git a/tests/utc/config/test_config.cpp b/tests/utc/config/test_config.cpp
new file mode 100644 (file)
index 0000000..6a92495
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2018 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 <gtest/gtest.h>
+
+#include "multi_assistant_config.h"
+
+#include <string>
+
+class StorageWithEmptyWakeWord : public testing::Test {
+public:
+       StorageWithEmptyWakeWord() {
+       }
+       virtual ~StorageWithEmptyWakeWord() {
+       }
+       void SetUp() override {
+               memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage));
+               memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage));
+       }
+       void TearDown() override {
+       }
+       CConfig config;
+       char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
+       char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
+};
+
+class StorageWithAnArbitraryWakeWord : public testing::Test {
+public:
+       StorageWithAnArbitraryWakeWord() {
+       }
+       virtual ~StorageWithAnArbitraryWakeWord() {
+       }
+       void SetUp() override {
+               memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage));
+               memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage));
+
+               config.mas_config_add_custom_wake_word(
+                       preloaded_wake_word.c_str(), preloaded_language.c_str(),
+                       wakeup_word_storage,
+                       wakeup_language_storage);
+       }
+       void TearDown() override {
+       }
+       const std::string preloaded_wake_word{"Hi Preloaded"};
+       const std::string preloaded_language{"pr_LD"};
+       CConfig config;
+       char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
+       char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
+};
+
+TEST_F(StorageWithEmptyWakeWord, HasOneWakeWordAfterAdd) {
+       const std::string arbitrary_wake_word{"Hi Tizen"};
+       const std::string arbitrary_language{"ar_LA"};
+
+       config.mas_config_add_custom_wake_word(
+               arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       int wake_word_num = config.mas_config_get_custom_wake_word_num(
+               wakeup_word_storage, wakeup_language_storage);
+       ASSERT_EQ(wake_word_num, 1);
+}
+
+TEST_F(StorageWithEmptyWakeWord, HasTwoWakeWordsWhenDifferentLanguageAdded) {
+       const std::string arbitrary_wake_word{"Hi Tizen"};
+       const std::string arbitrary_language1{"ar_LA1"};
+       const std::string arbitrary_language2{"ar_LA2"};
+       config.mas_config_add_custom_wake_word(
+               arbitrary_wake_word.c_str(), arbitrary_language1.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       config.mas_config_add_custom_wake_word(
+               arbitrary_wake_word.c_str(), arbitrary_language2.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       int wake_word_num = config.mas_config_get_custom_wake_word_num(
+               wakeup_word_storage, wakeup_language_storage);
+       ASSERT_EQ(wake_word_num, 2);
+}
+
+TEST_F(StorageWithEmptyWakeWord, RemovalFailsWhenNoMatchingEntryExists) {
+       const std::string arbitrary_wake_word{"Hi Tizen"};
+       const std::string arbitrary_language{"ar_LA"};
+
+       int ret = config.mas_config_remove_custom_wake_word(
+               arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       ASSERT_EQ(ret, -1);
+}
+
+TEST_F(StorageWithAnArbitraryWakeWord, StillHasOneWakeWordAfterDuplicatedAdd) {
+       config.mas_config_add_custom_wake_word(
+               preloaded_wake_word.c_str(), preloaded_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       int wake_word_num = config.mas_config_get_custom_wake_word_num(
+               wakeup_word_storage, wakeup_language_storage);
+       ASSERT_EQ(wake_word_num, 1);
+}
+
+TEST_F(StorageWithAnArbitraryWakeWord, HasZeroWakeWordAfterRemoval) {
+       config.mas_config_remove_custom_wake_word(
+               preloaded_wake_word.c_str(), preloaded_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       int wake_word_num = config.mas_config_get_custom_wake_word_num(
+               wakeup_word_storage, wakeup_language_storage);
+       ASSERT_EQ(wake_word_num, 0);
+}
+
+TEST_F(StorageWithAnArbitraryWakeWord, RemovesItemRequestedForRemoval) {
+       const std::string arbitrary_wake_word{"Hi Tizen"};
+       const std::string arbitrary_language{"ar_LA"};
+       config.mas_config_add_custom_wake_word(
+               arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+       config.mas_config_remove_custom_wake_word(
+               preloaded_wake_word.c_str(), preloaded_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       bool exists = config.mas_config_has_custom_wake_word(
+               preloaded_wake_word.c_str(), preloaded_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+       ASSERT_EQ(exists, false);
+}
+
+TEST_F(StorageWithAnArbitraryWakeWord, PreservesItemNotRequestedForRemoval) {
+       const std::string arbitrary_wake_word{"Hi Tizen"};
+       const std::string arbitrary_language{"ar_LA"};
+       config.mas_config_add_custom_wake_word(
+               arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+       config.mas_config_remove_custom_wake_word(
+               preloaded_wake_word.c_str(), preloaded_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+
+       bool exists = config.mas_config_has_custom_wake_word(
+               arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
+               wakeup_word_storage,
+               wakeup_language_storage);
+       ASSERT_EQ(exists, true);
+}
+
+int main(int argc, char** argv) {
+       testing::InitGoogleTest(&argc, argv);
+       int ret = RUN_ALL_TESTS();
+       return ret;
+}
diff --git a/tests/utc/service/main.cpp b/tests/utc/service/main.cpp
deleted file mode 100644 (file)
index 1be2dc0..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2018 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 <gtest/gtest.h>
-
-#include "multi_assistant_config.h"
-
-#include <string>
-
-class ServiceWithEmptyWakeWord : public testing::Test {
-public:
-       ServiceWithEmptyWakeWord() {
-       }
-       virtual ~ServiceWithEmptyWakeWord() {
-       }
-       void SetUp() override {
-               memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage));
-               memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage));
-       }
-       void TearDown() override {
-       }
-       CConfig config;
-       char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
-       char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
-};
-
-class ServiceWithAnArbitraryWakeWord : public testing::Test {
-public:
-       ServiceWithAnArbitraryWakeWord() {
-       }
-       virtual ~ServiceWithAnArbitraryWakeWord() {
-       }
-       void SetUp() override {
-               memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage));
-               memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage));
-
-               strncpy(wakeup_word_storage[0], preloaded_wake_word.c_str(), sizeof(wakeup_word_storage[0]));
-               wakeup_word_storage[0][sizeof(wakeup_word_storage[0]) - 1] = '\0';
-       }
-       void TearDown() override {
-       }
-       const std::string preloaded_wake_word{"Hi Preloaded"};
-       const std::string preloaded_language{"pr_LD"};
-       CConfig config;
-       char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
-       char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
-};
-
-TEST_F(ServiceWithEmptyWakeWord, HasOneWakeWordAfterAdd) {
-       const std::string arbitrary_wake_word{"Hi Tizen"};
-       const std::string arbitrary_language{"ar_LA"};
-
-       config.mas_config_add_custom_wake_word(
-               arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
-               wakeup_word_storage,
-               wakeup_language_storage);
-
-       int wake_word_num = config.mas_config_get_custom_wake_word_num(
-               wakeup_word_storage, wakeup_language_storage);
-       ASSERT_EQ(wake_word_num, 1);
-}
-
-TEST_F(ServiceWithAnArbitraryWakeWord, HasTwoWakeWordsAfterAdd) {
-       const std::string arbitrary_wake_word{"Hi Tizen"};
-       const std::string arbitrary_language{"ar_LA"};
-
-       config.mas_config_add_custom_wake_word(
-               arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
-               wakeup_word_storage,
-               wakeup_language_storage);
-
-       int wake_word_num = config.mas_config_get_custom_wake_word_num(
-               wakeup_word_storage, wakeup_language_storage);
-       ASSERT_EQ(wake_word_num, 2);
-}
-
-int main(int argc, char** argv) {
-       testing::InitGoogleTest(&argc, argv);
-       int ret = RUN_ALL_TESTS();
-       return ret;
-}