Add new test cases to increse the coverage 58/295158/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 3 Jul 2023 07:55:00 +0000 (16:55 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 13 Jul 2023 02:59:13 +0000 (11:59 +0900)
- Contents:
This patch adds new test cases for uncovered line. Through this patch,
developers can check the behavior about specific situations.

Change-Id: I5e9175a9997ff26c58cd4b6ab31e05dd154b4408
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
tests/src/tts_unittests.cpp

index e3a1241..c929a88 100644 (file)
@@ -55,6 +55,10 @@ static void __tts_engine_changed_cb(tts_h tts, const char* engine_id, const char
 {
 }
 
+static void test_synthesized_pcm_cb(tts_h tts, int utt_id, tts_synthesized_pcm_event_e event, const char* pcm_data, int pcm_data_size, tts_audio_type_e audio_type, int sample_rate, void *user_data)
+{
+}
+
 
 namespace {
 
@@ -394,6 +398,23 @@ TEST_F(TTSPreparedTest, utc_tts_prepare_p2)
        EXPECT_EQ(mTestUtil->IsStateChanged(TTS_STATE_READY, STATE_CHECK_WAITING_TIME), true);
 }
 
+/**
+ * @testcase           utc_tts_prepare_p3
+ * @since_tizen                8.0
+ * @description                test whether tts daemon is prepared properly.
+ */
+TEST_F(TTSTest, utc_tts_prepare_p3)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_prepare(mHandle), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_prepare(mHandle), TTS_ERROR_NONE);
+       EXPECT_EQ(tts_prepare(mHandle), TTS_ERROR_NONE);
+       EXPECT_EQ(mTestUtil->IsStateChanged(TTS_STATE_READY, STATE_CHECK_WAITING_TIME), true);
+}
+
 TEST_F(TTSTest, utc_tts_prepare_n1)
 {
        if (false == mTestUtil->IsFeatureSupported()) {
@@ -474,6 +495,27 @@ TEST_F(TTSTest, utc_tts_prepare_n5)
 }
 
 /**
+ * @testcase           utc_tts_prepare_n6
+ * @since_tizen                8.0
+ * @description                Test if the function is failed when the invalid engine is set
+ */
+TEST_F(TTSTest, utc_tts_prepare_n6)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_prepare(mHandle), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       char* engine_id = vconf_get_str(VCONFKEY_TTS_ENGINE_DEFAULT);
+       EXPECT_EQ(vconf_set_str(VCONFKEY_TTS_ENGINE_DEFAULT, "test"), 0);
+
+       EXPECT_EQ(tts_prepare(mHandle), TTS_ERROR_NONE);
+       EXPECT_EQ(mTestUtil->IsErrorOccurring(30), true);
+
+       EXPECT_EQ(vconf_set_str(VCONFKEY_TTS_ENGINE_DEFAULT, engine_id), 0);
+}
+
+/**
  * @testcase           utc_tts_prepare_sync_p
  * @since_tizen                2.3
  * @description                test whether tts daemon is prepared properly.
@@ -559,6 +601,25 @@ TEST_F(TTSTest, utc_tts_prepare_sync_n3)
 }
 
 /**
+ * @testcase           utc_tts_prepare_sync_n4
+ * @since_tizen                8.0
+ * @description                Test if the function is failed when the invalid engine is set
+ */
+TEST_F(TTSTest, utc_tts_prepare_sync_n4)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_prepare_sync(mHandle), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       char* engine_id = vconf_get_str(VCONFKEY_TTS_ENGINE_DEFAULT);
+       EXPECT_EQ(vconf_set_str(VCONFKEY_TTS_ENGINE_DEFAULT, "test"), 0);
+
+       EXPECT_EQ(tts_prepare_sync(mHandle), TTS_ERROR_OPERATION_FAILED);
+       EXPECT_EQ(vconf_set_str(VCONFKEY_TTS_ENGINE_DEFAULT, engine_id), 0);
+}
+
+/**
  * @testcase           utc_tts_foreach_supported_voices_p
  * @since_tizen                2.3
  * @description                test whether each supported voices are gotten properly.
@@ -2281,6 +2342,8 @@ TEST_F(TTSTest, utc_tts_check_screen_reader_on_p2)
        EXPECT_EQ(is_on, true);
 
        EXPECT_EQ(vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, false), 0);
+       EXPECT_EQ(tts_check_screen_reader_on(mHandle, &is_on), TTS_ERROR_NONE);
+       EXPECT_EQ(is_on, false);
 }
 
 /**
@@ -2704,4 +2767,198 @@ TEST_F(TTSTest, utc_tts_stop_pcm_n2)
        EXPECT_EQ(tts_stop_pcm(mHandle), TTS_ERROR_INVALID_STATE);
 }
 
+/**
+ * @testcase           utc_tts_set_playing_mode_p1
+ * @since_tizen                8.0
+ * @description                Test if the function properly set the playing mode.
+ */
+TEST_F(TTSTest, utc_tts_set_playing_mode_p1)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_playing_mode(mHandle, TTS_PLAYING_MODE_BY_CLIENT), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_set_playing_mode(mHandle, TTS_PLAYING_MODE_BY_CLIENT), TTS_ERROR_NONE);
+}
+
+/**
+ * @testcase           utc_tts_set_playing_mode_n1
+ * @since_tizen                8.0
+ * @description                Test if the function returns the error with invalid parameters.
+ */
+TEST_F(TTSTest, utc_tts_set_playing_mode_n1)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_playing_mode(nullptr, TTS_PLAYING_MODE_BY_CLIENT), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_set_playing_mode(nullptr, TTS_PLAYING_MODE_BY_CLIENT), TTS_ERROR_INVALID_PARAMETER);
+       EXPECT_EQ(tts_set_playing_mode(mHandle, static_cast<tts_playing_mode_e>(-1)), TTS_ERROR_INVALID_PARAMETER);
+       EXPECT_EQ(tts_set_playing_mode(mHandle, static_cast<tts_playing_mode_e>(100)), TTS_ERROR_INVALID_PARAMETER);
+
+       mTestUtil->DestroyHandle();
+       EXPECT_EQ(tts_set_playing_mode(mHandle, TTS_PLAYING_MODE_BY_CLIENT), TTS_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase           utc_tts_set_playing_mode_n2
+ * @since_tizen                8.0
+ * @description                Test if the function returns the error when the state is not created.
+ */
+TEST_F(TTSPreparedTest, utc_tts_set_playing_mode_n2)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_playing_mode(mHandle, TTS_PLAYING_MODE_BY_CLIENT), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_set_playing_mode(mHandle, TTS_PLAYING_MODE_BY_CLIENT), TTS_ERROR_INVALID_STATE);
+}
+
+/**
+ * @testcase           utc_tts_set_synthesized_pcm_cb_p1
+ * @since_tizen                8.0
+ * @description                Test if the function properly set the synthesized pcm callback
+ */
+TEST_F(TTSTest, utc_tts_set_synthesized_pcm_cb_p1)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_synthesized_pcm_cb(mHandle, test_synthesized_pcm_cb, nullptr), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_set_synthesized_pcm_cb(mHandle, test_synthesized_pcm_cb, nullptr), TTS_ERROR_NONE);
+}
+
+/**
+ * @testcase           utc_tts_set_synthesized_pcm_cb_n1
+ * @since_tizen                8.0
+ * @description                Test if the function returns error with invalid parameters
+ */
+TEST_F(TTSTest, utc_tts_set_synthesized_pcm_cb_n1)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_synthesized_pcm_cb(nullptr, test_synthesized_pcm_cb, nullptr), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_set_synthesized_pcm_cb(nullptr, test_synthesized_pcm_cb, nullptr), TTS_ERROR_INVALID_PARAMETER);
+       EXPECT_EQ(tts_set_synthesized_pcm_cb(mHandle, nullptr, nullptr), TTS_ERROR_INVALID_PARAMETER);
+
+       mTestUtil->DestroyHandle();
+       EXPECT_EQ(tts_set_synthesized_pcm_cb(mHandle, test_synthesized_pcm_cb, nullptr), TTS_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase           utc_tts_set_synthesized_pcm_cb_n2
+ * @since_tizen                8.0
+ * @description                Test if the function returns error when the state is not created
+ */
+TEST_F(TTSPreparedTest, utc_tts_set_synthesized_pcm_cb_n2)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_synthesized_pcm_cb(mHandle, test_synthesized_pcm_cb, nullptr), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_set_synthesized_pcm_cb(mHandle, test_synthesized_pcm_cb, nullptr), TTS_ERROR_INVALID_STATE);
+}
+
+/**
+ * @testcase           utc_tts_unset_synthesized_pcm_cb_p
+ * @since_tizen                8.0
+ * @description                Positive UTC for unset current engine changed callback
+ */
+TEST_F(TTSTest, utc_tts_unset_synthesized_pcm_cb_p1)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_unset_synthesized_pcm_cb(mHandle), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_unset_synthesized_pcm_cb(mHandle), TTS_ERROR_NONE);
+}
+
+/**
+ * @testcase           utc_tts_unset_synthesized_pcm_cb_n1
+ * @since_tizen                8.0
+ * @description                Test if the function returns error with invalid parameters
+ */
+TEST_F(TTSTest, utc_tts_unset_synthesized_pcm_cb_n1)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_unset_synthesized_pcm_cb(nullptr), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_unset_synthesized_pcm_cb(nullptr), TTS_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase           utc_tts_unset_synthesized_pcm_cb_n2
+ * @since_tizen                8.0
+ * @description                Test if the function returns error when the state is not created
+ */
+TEST_F(TTSPreparedTest, utc_tts_unset_synthesized_pcm_cb_n2)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_unset_synthesized_pcm_cb(mHandle), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       EXPECT_EQ(tts_unset_synthesized_pcm_cb(mHandle), TTS_ERROR_INVALID_STATE);
+}
+
+/**
+ * @testcase           utc_reprepare_logic_p1
+ * @since_tizen                8.0
+ * @description                Test if the tts properly connects again after error occurring.
+ */
+TEST_F(TTSTest, utc_reprepare_logic_p1)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_error_cb(mHandle, mTestUtil->ErrorCallback, nullptr), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       auto localUtil = std::make_unique<TtsTestUtility>();
+
+       EXPECT_EQ(mTestUtil->Prepare(), true);
+       EXPECT_EQ(localUtil->Prepare(), true);
+
+       mTestUtil->TerminateCurrentEngine();
+       EXPECT_EQ(mTestUtil->IsErrorOccurring(STATE_CHECK_WAITING_TIME), true);
+       mTestUtil->mCurrentState = TTS_STATE_CREATED;
+
+       sleep(1);
+       EXPECT_EQ(mTestUtil->IsStateChanged(TTS_STATE_READY, STATE_CHECK_WAITING_TIME), true);
+}
+
+/**
+ * @testcase           utc_reprepare_logic_p2
+ * @since_tizen                8.0
+ * @description                Test if the tts properly connects again after error occurring.
+ */
+TEST_F(TTSTest, utc_reprepare_logic_p2)
+{
+       if (false == mTestUtil->IsFeatureSupported()) {
+               EXPECT_EQ(tts_set_error_cb(mHandle, mTestUtil->ErrorCallback, nullptr), TTS_ERROR_NOT_SUPPORTED);
+               return;
+       }
+
+       auto localUtil = std::make_unique<TtsTestUtility>();
+
+       EXPECT_EQ(localUtil->Prepare(), true);
+       EXPECT_EQ(mTestUtil->Prepare(), true);
+
+       mTestUtil->TerminateCurrentEngine();
+       EXPECT_EQ(mTestUtil->IsErrorOccurring(STATE_CHECK_WAITING_TIME), true);
+       sleep(2);
+
+       tts_service_state_e state = TTS_SERVICE_STATE_NONE;
+       EXPECT_EQ(tts_get_service_state(mHandle, &state), TTS_ERROR_NONE);
+}
+
 } // namespace