• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <gtest/gtest.h>
16 #include <unistd.h>
17 #include <thread>
18 #include <mutex>
19 #include <condition_variable>
20 #include <cstdio>
21 
22 #include "iservice_registry.h"
23 #include "system_ability_definition.h"
24 #include "intell_voice_log.h"
25 #include "i_intell_voice_engine.h"
26 #include "i_intell_voice_service.h"
27 #include "intell_voice_service_proxy.h"
28 #include "intell_voice_engine_proxy.h"
29 #include "engine_callback_inner.h"
30 #include "engine_event_callback.h"
31 #include "wait_for_result.h"
32 
33 using namespace OHOS::IntellVoiceTests;
34 using namespace OHOS::IntellVoiceEngine;
35 using namespace OHOS;
36 using namespace testing::ext;
37 
38 static sptr<IIntellVoiceService> g_sProxy = nullptr;
39 #define LOG_TAG "ClientTest"
40 
41 class ClientTest : public testing::Test {
42 public:
43     static void SetUpTestCase(void);
44     static void TearDownTestCase(void);
45     void SetUp();
46     void TearDown();
47     std::shared_ptr<EngineEventCallback> cb_ = nullptr;
48 };
49 
SetUpTestCase(void)50 void ClientTest::SetUpTestCase(void)
51 {
52     INTELL_VOICE_LOG_INFO("hello harmony OS!\n");
53 }
54 
TearDownTestCase(void)55 void ClientTest::TearDownTestCase(void)
56 {
57 }
58 
SetUp(void)59 void ClientTest::SetUp(void)
60 {
61     auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
62     ASSERT_NE(samgr, nullptr);
63 
64     sptr<IRemoteObject> object = samgr->GetSystemAbility(INTELL_VOICE_SERVICE_ID);
65     ASSERT_NE(object, nullptr);
66 
67     g_sProxy = iface_cast<IIntellVoiceService>(object);
68     ASSERT_NE(g_sProxy, nullptr);
69 }
70 
TearDown(void)71 void ClientTest::TearDown(void)
72 {
73 }
74 
75 HWTEST_F(ClientTest, ClientUtils, TestSize.Level1)
76 {
77     WaitForResult waitForResult;
78 
79     sptr<IIntellVoiceEngine> engine;
80     g_sProxy->CreateIntellVoiceEngine(INTELL_VOICE_ENROLL, engine);
81     ASSERT_NE(engine, nullptr);
82 
83     sptr<EngineCallbackInner> callback = new(std::nothrow) EngineCallbackInner();
84     ASSERT_NE(callback, nullptr);
85     cb_ = std::make_shared<EngineEventCallback>(engine, &waitForResult);
86     ASSERT_NE(cb_, nullptr);
87 
88     callback->SetEngineEventCallback(cb_);
89     sptr<IRemoteObject> callbackObj = callback->AsObject();
90     ASSERT_NE(callbackObj, nullptr);
91 
92     engine->SetCallback(callbackObj);
93 
94     IntellVoiceEngineInfo info = {};
95     info.wakeupPhrase = "\xE5\xB0\x8F\xE8\x89\xBA\xE5\xB0\x8F\xE8\x89\xBA";
96     info.isPcmFromExternal = true;
97     info.minBufSize = 1280;
98     info.sampleChannels = 1;
99     info.bitsPerSample = 16;
100     info.sampleRate = 16000;
101 
102     engine->Attach(info);
103 
104     waitForResult.Wait();
105 
106     engine->Detach();
107 
108     INTELL_VOICE_LOG_INFO("end\n");
109 }
110