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_bundle_manager_test.h"
17 
18 #define private public
19 #include "ringtone_bundle_manager.h"
20 #include "ringtone_data_command.h"
21 #undef private
22 
23 
24 using namespace std;
25 using namespace OHOS;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace Media {
30 shared_ptr<RingtoneBundleManager> g_bundleManager = nullptr;
31 
SetUpTestCase()32 void RingtoneBundleManagerTest::SetUpTestCase()
33 {
34     g_bundleManager = RingtoneBundleManager::GetInstance();
35     EXPECT_NE(g_bundleManager, nullptr);
36 }
TearDownTestCase()37 void RingtoneBundleManagerTest::TearDownTestCase() {}
38 
39 // SetUp:Execute before each test case
SetUp()40 void RingtoneBundleManagerTest::SetUp() {}
41 
TearDown(void)42 void RingtoneBundleManagerTest::TearDown(void) {}
43 
44 HWTEST_F(RingtoneBundleManagerTest, bundleManager_GetClientBundleName_test_001, TestSize.Level0)
45 {
46     auto ret = g_bundleManager->GetClientBundleName();
47     EXPECT_EQ(ret, "");
48     g_bundleManager->Clear();
49     g_bundleManager = RingtoneBundleManager::GetInstance();
50     EXPECT_NE(g_bundleManager, nullptr);
51 }
52 
53 HWTEST_F(RingtoneBundleManagerTest, dataCommand_GetBundleName_test_001, TestSize.Level0)
54 {
55     Uri uri(RINGTONE_PATH_URI);
56     RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::INSERT);
57     const string bundleName =  "dataCommand_GetBundleName_test_001";
58     cmd.SetBundleName(bundleName);
59     auto ret = cmd.GetBundleName();
60     EXPECT_EQ(ret, bundleName);
61 }
62 
63 HWTEST_F(RingtoneBundleManagerTest, dataCommand_GetResult_test_001, TestSize.Level0)
64 {
65     Uri uri(RINGTONE_PATH_URI);
66     RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::INSERT);
67     const string result =  "dataCommand_GetResult_test_001";
68     cmd.SetResult(result);
69     auto ret = cmd.GetResult();
70     EXPECT_EQ(ret, result);
71     auto type = cmd.GetOprnType();
72     EXPECT_EQ(type, RingtoneOperationType::INSERT);
73 }
74 } // namespace Media
75 } // namespace OHOS
76