--- /dev/null
+/*
+ * 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;
+}
+++ /dev/null
-/*
- * 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;
-}