Add test utility class
[platform/core/uifw/stt.git] / tests / src / test_util.h
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #ifndef __STT_TEST_UTIL_H__
19 #define __STT_TEST_UTIL_H__
20
21
22 #include <functional>
23
24 #include <stt.h>
25 #include <stt_internal.h>
26
27
28 class SttTestUtility {
29 public:
30         static void StateChangedCallback(stt_h stt, stt_state_e previous, stt_state_e current, void *user_data);
31         static void ErrorCallback(stt_h stt, stt_error_e reason, void *user_data);
32         static void RecognitionResultCallback(stt_h stt, stt_result_event_e event, const char** data, int data_count, const char* msg, void *user_data);
33
34         static void TerminateCurrentEngine();
35         static void WaitUntilEngineTerminated(int duration);
36         static bool IsFeatureSupported();
37
38 public:
39         SttTestUtility();
40         ~SttTestUtility();
41
42         void GetTestPCMData();
43
44         void CreateHandle();
45         void DestroyHandle();
46         void SetTestMode();
47         void UnsetTestMode();
48
49         bool Prepare();
50         bool Unprepare();
51
52         bool Start(const char* language, const char* type);
53         bool Stop();
54         bool StartAudioStreaming(const char* language, const char* type);
55         bool StopAudioStreaming();
56         bool Cancel();
57
58         bool IsStateChanged(stt_state_e targetState, int duration);
59         bool IsErrorOccurring(int duration);
60         bool IsResultReceived(int duration);
61
62 public:
63         stt_h mHandle;
64         stt_state_e mCurrentState;
65
66         bool mErrorOccured;
67         bool mResultReceived;
68         char *mErrorMessage;
69
70         char* mPCMData;
71         size_t mPCMSize;
72
73 private:
74         static bool WaitCondtion(std::function<bool(void)> checker, int duration);
75 };
76
77
78 #endif  /* __STT_TEST_UTIL_H__ */