• 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 <cstdio>
18 
19 #include "intell_voice_log.h"
20 #include "trigger_manager.h"
21 #include "trigger_base_type.h"
22 #include "trigger_detector_callback.h"
23 
24 #define LOG_TAG "TriggerTest"
25 
26 using namespace OHOS::IntellVoiceTrigger;
27 using namespace OHOS;
28 using namespace testing::ext;
29 
30 static std::shared_ptr<TriggerManager> triggerManager = nullptr;
31 
32 class TriggerTest : public testing::Test {
33 public:
34     static void SetUpTestCase(void);
35     static void TearDownTestCase(void);
36     void SetUp();
37     void TearDown();
38 };
39 
SetUpTestCase(void)40 void TriggerTest::SetUpTestCase(void)
41 {}
42 
TearDownTestCase(void)43 void TriggerTest::TearDownTestCase(void)
44 {}
45 
SetUp(void)46 void TriggerTest::SetUp(void)
47 {
48     triggerManager = std::shared_ptr<TriggerManager>(new (std::nothrow) TriggerManager());
49     ASSERT_NE(triggerManager, nullptr);
50 }
51 
TearDown(void)52 void TriggerTest::TearDown(void)
53 {
54     triggerManager = nullptr;
55 }
56 
57 HWTEST_F(TriggerTest, trigger_db_helper_001, TestSize.Level1)
58 {
59     // insert model
60     int32_t uuid = 11;
61     uint8_t data[4] = {0, 1, 2, 3};
62     std::vector<uint8_t> expect(data, data + (sizeof(data) / sizeof(uint8_t)));
63 
64     triggerManager->UpdateModel(expect, uuid, TriggerModelType::VOICE_WAKEUP_TYPE);
65     auto result = triggerManager->GetModel(uuid);
66     EXPECT_EQ(expect, result->GetData());
67 
68     // update model
69     uint8_t newdata[4] = {0, 1, 2, 5};
70     std::vector<uint8_t>().swap(expect);
71     expect.insert(expect.begin(), newdata, newdata + (sizeof(newdata) / sizeof(uint8_t)));
72 
73     triggerManager->UpdateModel(expect, uuid, TriggerModelType::VOICE_WAKEUP_TYPE);
74     result = triggerManager->GetModel(uuid);
75     EXPECT_EQ(expect, result->GetData());
76 
77     // delete model
78     triggerManager->DeleteModel(uuid);
79     result = triggerManager->GetModel(uuid);
80     EXPECT_EQ(nullptr, result);
81 }
82