• 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 
16 #include "ringtone_dfx_test.h"
17 
18 #include <fcntl.h>
19 #include <iostream>
20 #include <string>
21 
22 #include "ability_context_impl.h"
23 #include "dfx_const.h"
24 #include "dfx_manager.h"
25 #include "dfx_worker.h"
26 #include "preferences.h"
27 #include "preferences_helper.h"
28 #include "ringtone_errno.h"
29 #include "ringtone_log.h"
30 #include "ringtone_rdbstore.h"
31 
32 using namespace std;
33 using namespace OHOS;
34 using namespace testing::ext;
35 
36 namespace OHOS {
37 namespace Media {
38 shared_ptr<OHOS::AbilityRuntime::AbilityContextImpl> abilityContextImpl;
SetUpTestCase()39 void RingtoneDfxTest::SetUpTestCase()
40 {
41     auto stageContext = std::make_shared<AbilityRuntime::ContextImpl>();
42     abilityContextImpl = std::make_shared<OHOS::AbilityRuntime::AbilityContextImpl>();
43     abilityContextImpl->SetStageContext(stageContext);
44 }
TearDownTestCase()45 void RingtoneDfxTest::TearDownTestCase()
46 {
47 }
48 
49 // SetUp:Execute before each test case
SetUp()50 void RingtoneDfxTest::SetUp() {}
51 
TearDown(void)52 void RingtoneDfxTest::TearDown(void) {}
53 
54 HWTEST_F(RingtoneDfxTest, ringtonelib_dfx_manager_test_0001, TestSize.Level0)
55 {
56     RINGTONE_INFO_LOG("ringtonelib_dfx_manager_test_0001 start");
57     auto dfxMgr = DfxManager::GetInstance();
58     EXPECT_NE(dfxMgr, nullptr);
59     int32_t ret = dfxMgr->Init(nullptr);
60     EXPECT_NE(ret, E_OK);
61     int64_t res = dfxMgr->HandleReportXml();
62     EXPECT_NE(res, 0);
63     ret = dfxMgr->Init(abilityContextImpl);
64     EXPECT_EQ(ret, E_OK);
65     sleep(1);
66     auto dfxMgrTwo = DfxManager::GetInstance();
67     EXPECT_NE(dfxMgrTwo, nullptr);
68     ret = dfxMgrTwo->Init(abilityContextImpl);
69     EXPECT_EQ(ret, E_OK);
70     RINGTONE_INFO_LOG("ringtonelib_dfx_manager_test_0001 end");
71 }
72 
73 HWTEST_F(RingtoneDfxTest, ringtonelib_dfx_manager_test_0002, TestSize.Level0)
74 {
75     RINGTONE_INFO_LOG("ringtonelib_dfx_manager_test_0002 start");
76     auto dfxMgr = DfxManager::GetInstance();
77     EXPECT_NE(dfxMgr, nullptr);
78     auto result = dfxMgr->Init(abilityContextImpl);
79     EXPECT_EQ(result, E_OK);;
80     auto dfxWorker = DfxWorker::GetInstance();
81     EXPECT_NE(dfxWorker, nullptr);
82     int64_t ret = dfxMgr->HandleReportXml();
83     EXPECT_EQ((ret > 0), true);
84     std::string bundleName = "test";
85     ret = dfxMgr->RequestTonesCount(SourceType::SOURCE_TYPE_INVALID);
86     EXPECT_EQ(ret, 0);
87     ret = dfxMgr->RequestTonesCount(SourceType::SOURCE_TYPE_PRESET);
88     EXPECT_EQ(ret, 0);
89     ret = dfxMgr->RequestTonesCount(SourceType::SOURCE_TYPE_MAX);
90     EXPECT_EQ(ret, 0);
91     auto dfxStore = RingtoneRdbStore::GetInstance(abilityContextImpl);
92     dfxStore->Stop();
93     ret = dfxMgr->RequestTonesCount(SourceType::SOURCE_TYPE_PRESET);
94     EXPECT_EQ(ret, 0);
95     RINGTONE_INFO_LOG("ringtonelib_dfx_manager_test_0002 end");
96 }
97 } // namespace Media
98 } // namespace OHOS