• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "intell_voice_manager_test.h"
16 
17 #include "intell_voice_manager.h"
18 #include "intell_voice_log.h"
19 #include "i_intell_voice_engine.h"
20 #include "i_intell_voice_engine_callback.h"
21 
22 #define LOG_TAG "TestIntellVoiceManager"
23 
24 constexpr int INTELL_VOICE_MANAGER_RANDOM_NUM = 11;
25 
26 using namespace std;
27 using namespace OHOS;
28 using namespace OHOS::IntellVoiceEngine;
29 using namespace OHOS::IntellVoice;
30 namespace OHOS {
31 namespace IntellVoiceFuzzTest {
32 
TestCreateEngine(const uint8_t * data,size_t sizeIn)33 static void TestCreateEngine(const uint8_t *data, size_t sizeIn)
34 {
35     IntellVoiceEngineType type = static_cast<const IntellVoiceEngineType>(data[0]);
36     sptr<IIntellVoiceEngine> engine;
37     auto manager = IntellVoiceManager::GetInstance();
38     manager->CreateIntellVoiceEngine(type, engine);
39 }
40 
TestReleaseEngine(const uint8_t * data,size_t sizeIn)41 static void TestReleaseEngine(const uint8_t *data, size_t sizeIn)
42 {
43     IntellVoiceEngineType type = static_cast<const IntellVoiceEngineType>(data[0]);
44     sptr<IIntellVoiceEngine> engine;
45     auto manager = IntellVoiceManager::GetInstance();
46     manager->ReleaseIntellVoiceEngine(type);
47 }
48 
TestCreateHeadsetEngine(const uint8_t * data,size_t sizeIn)49 static void TestCreateHeadsetEngine(const uint8_t *data, size_t sizeIn)
50 {
51     auto manager = IntellVoiceManager::GetInstance();
52     manager->CreateHeadsetWakeupEngine();
53 }
54 
TestRegisterRecipient(const uint8_t * data,size_t sizeIn)55 static void TestRegisterRecipient(const uint8_t *data, size_t sizeIn)
56 {
57     auto manager = IntellVoiceManager::GetInstance();
58     sptr<OHOS::IRemoteObject::DeathRecipient> callback;
59     manager->RegisterServiceDeathRecipient(callback);
60 }
61 
TestDeregisterRecipient(const uint8_t * data,size_t sizeIn)62 static void TestDeregisterRecipient(const uint8_t *data, size_t sizeIn)
63 {
64     auto manager = IntellVoiceManager::GetInstance();
65     sptr<OHOS::IRemoteObject::DeathRecipient> callback;
66     manager->DeregisterServiceDeathRecipient(callback);
67 }
68 
TestGetUploadFiles(const uint8_t * data,size_t sizeIn)69 static void TestGetUploadFiles(const uint8_t *data, size_t sizeIn)
70 {
71     auto manager = IntellVoiceManager::GetInstance();
72     std::vector<UploadFilesInfo> files;
73     manager->GetUploadFiles(sizeIn, files);
74 }
75 
TestSetParameter(const uint8_t * data,size_t sizeIn)76 static void TestSetParameter(const uint8_t *data, size_t sizeIn)
77 {
78     auto manager = IntellVoiceManager::GetInstance();
79     manager->SetParameter(to_string(data[0]), to_string(sizeIn));
80 }
81 
TestGetParameter(const uint8_t * data,size_t sizeIn)82 static void TestGetParameter(const uint8_t *data, size_t sizeIn)
83 {
84     auto manager = IntellVoiceManager::GetInstance();
85     manager->GetParameter(to_string(sizeIn));
86 }
87 
TestGetWakeupSourceFiles(const uint8_t * data,size_t sizeIn)88 static void TestGetWakeupSourceFiles(const uint8_t *data, size_t sizeIn)
89 {
90     auto manager = IntellVoiceManager::GetInstance();
91     std::vector<WakeupSourceFile> cloneFileInfo;
92     manager->GetWakeupSourceFiles(cloneFileInfo);
93 }
94 
TestEnrollWithWakeupFilesForResult(const uint8_t * data,size_t sizeIn)95 static void TestEnrollWithWakeupFilesForResult(const uint8_t *data, size_t sizeIn)
96 {
97     auto manager = IntellVoiceManager::GetInstance();
98     std::vector<WakeupSourceFile> cloneFileInfo;
99     WakeupSourceFile file = {"test", {1, 2, 3, 4, 5}};
100     cloneFileInfo.push_back(file);
101     std::string wakeupInfo = "test";
102     shared_ptr<IIntellVoiceUpdateCallback> callback;
103     manager->EnrollWithWakeupFilesForResult(cloneFileInfo, wakeupInfo, callback);
104 }
105 
TestClearUserData(const uint8_t * data,size_t sizeIn)106 static void TestClearUserData(const uint8_t *data, size_t sizeIn)
107 {
108     auto manager = IntellVoiceManager::GetInstance();
109     manager->ClearUserData();
110 }
111 
112 namespace {
113 void (*g_intellvoicemanagerFuncTable[INTELL_VOICE_MANAGER_RANDOM_NUM])(const uint8_t *, size_t) = {
114     TestCreateEngine,
115     TestReleaseEngine,
116     TestCreateHeadsetEngine,
117     TestRegisterRecipient,
118     TestDeregisterRecipient,
119     TestGetUploadFiles,
120     TestSetParameter,
121     TestGetParameter,
122     TestGetWakeupSourceFiles,
123     TestEnrollWithWakeupFilesForResult,
124     TestClearUserData
125 };
126 }
TestIntellVoiceRandomFuzzer(const uint8_t * data,size_t sizeIn)127 void TestIntellVoiceRandomFuzzer(const uint8_t *data, size_t sizeIn)
128 {
129     INTELL_VOICE_LOG_INFO("TestIntellVoiceRandomFuzzer in");
130     uint8_t type = data[0] % INTELL_VOICE_MANAGER_RANDOM_NUM;  // get the radom num to call the interface
131     INTELL_VOICE_LOG_INFO("intell voice manager type: %{public}d", type);
132     (*g_intellvoicemanagerFuncTable[type])(data, sizeIn);
133     return;
134 }
135 }  // namespace IntellVoiceFuzzTest
136 }  // namespace OHOS