• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 #include <memory>
17 
18 #include "gtest/gtest.h"
19 #define private public
20 #include "batch_remove_box.h"
21 #include "distributed_service.h"
22 #include "distributed_publish_service.h"
23 #include "distributed_device_service.h"
24 #undef private
25 #include "analytics_util.h"
26 
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Notification {
31 
32 class DistributedAnalyticsUtilTest : public testing::Test {
33 public:
34     void SetUp() override;
35     void TearDown() override;
36 };
37 
SetUp()38 void DistributedAnalyticsUtilTest::SetUp() {}
39 
TearDown()40 void DistributedAnalyticsUtilTest::TearDown() {}
41 
42 static int32_t g_mockReportCallback = 0;
43 
MockSendReportCallback(int32_t messageType,int32_t errCode,std::string reason)44 void MockSendReportCallback(int32_t messageType, int32_t errCode, std::string reason)
45 {
46     g_mockReportCallback++;
47 }
48 
49 /**
50  * @tc.name      : DistributedAnalyticsUtilTest_00100
51  * @tc.number    : DistributedAnalyticsUtilTest_00100
52  * @tc.desc      : Test the ha callback is nullptr or not phone.
53  */
54 HWTEST_F(DistributedAnalyticsUtilTest, DistributedServiceTest_00100, Function | SmallTest | Level1)
55 {
56     AnalyticsUtil::GetInstance().SendEventReport(0, 0, "test reason.");
57     ASSERT_EQ(g_mockReportCallback, 0);
58     AnalyticsUtil::GetInstance().InitSendReportCallBack(&MockSendReportCallback);
59     DistributedDeviceService::GetInstance().InitLocalDevice("deviceId",
60         DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH);
61     AnalyticsUtil::GetInstance().SendEventReport(0, 0, "test reason.");
62     ASSERT_EQ(g_mockReportCallback, 0);
63     DistributedDeviceService::GetInstance().InitLocalDevice("deviceId",
64         DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE);
65     AnalyticsUtil::GetInstance().SendEventReport(0, 0, "test reason.");
66     ASSERT_EQ(g_mockReportCallback, 1);
67     g_mockReportCallback = 0;
68 }
69 } // namespace Notification
70 } // namespace OHOS
71