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_privacy_manager_test.h"
17 
18 #include "ringtone_errno.h"
19 #define private public
20 #include "ringtone_privacy_manager.h"
21 #undef private
22 
23 using namespace std;
24 using namespace OHOS;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Media {
29 const std::string STORAGE_MEDIA_DIR = "/storage/cloud/files/";
30 const string DEFAULT_STR = "";
31 
SetUpTestCase()32 void RingtonePrivacyManagerTest::SetUpTestCase() {}
33 
TearDownTestCase()34 void RingtonePrivacyManagerTest::TearDownTestCase() {}
35 
SetUp()36 void RingtonePrivacyManagerTest::SetUp() {}
37 
TearDown(void)38 void RingtonePrivacyManagerTest::TearDown(void) {}
39 
40 HWTEST_F(RingtonePrivacyManagerTest, ringtonePrivacyManager_Open_test_001, TestSize.Level0)
41 {
42     RingtonePrivacyManager ringtonePrivacyManager(DEFAULT_STR, DEFAULT_STR);
43     int32_t ret = ringtonePrivacyManager.Open();
44     EXPECT_EQ(ret, E_INVALID_PATH);
45 }
46 
47 HWTEST_F(RingtonePrivacyManagerTest, ringtonePrivacyManager_Open_test_002, TestSize.Level0)
48 {
49     const string path = ".Open";
50     const string mode = "Z";
51     RingtonePrivacyManager ringtonePrivacyManager(path, mode);
52     int32_t ret = ringtonePrivacyManager.Open();
53     EXPECT_EQ(ret, E_INVALID_PATH);
54 }
55 
56 HWTEST_F(RingtonePrivacyManagerTest, ringtonePrivacyManager_Open_test_003, TestSize.Level0)
57 {
58     const string path = ".ogg";
59     RingtonePrivacyManager ringtonePrivacyManager(path, DEFAULT_STR);
60     int32_t ret = ringtonePrivacyManager.Open();
61     EXPECT_EQ(ret, E_ERR);
62 }
63 
64 HWTEST_F(RingtonePrivacyManagerTest, ringtonePrivacyManager_Open_test_004, TestSize.Level0)
65 {
66     const string path = ".ogg";
67     const string mode = "w";
68     RingtonePrivacyManager ringtonePrivacyManager(path, mode);
69     int32_t ret = ringtonePrivacyManager.Open();
70     EXPECT_EQ(ret, E_ERR);
71 }
72 
73 HWTEST_F(RingtonePrivacyManagerTest, ringtonePrivacyManager_Open_test_005, TestSize.Level0)
74 {
75     const string path = "/storage/cloud/files/open.ogg";
76     const string mode = "w";
77     RingtonePrivacyManager ringtonePrivacyManager(path, mode);
78     int32_t ret = ringtonePrivacyManager.Open();
79     EXPECT_EQ(ret, E_ERR);
80 }
81 
82 HWTEST_F(RingtonePrivacyManagerTest, ringtonePrivacyManager_Open_test_006, TestSize.Level0)
83 {
84     const string mode = "w";
85     RingtonePrivacyManager ringtonePrivacyManager(DEFAULT_STR, mode);
86     int32_t ret = ringtonePrivacyManager.Open();
87     EXPECT_EQ(ret, E_INVALID_PATH);
88 }
89 
90 HWTEST_F(RingtonePrivacyManagerTest, ringtonePrivacyManager_Open_test_007, TestSize.Level0)
91 {
92     const string mode = "w";
93     RingtonePrivacyManager ringtonePrivacyManager(STORAGE_MEDIA_DIR, mode);
94     int32_t ret = ringtonePrivacyManager.Open();
95     EXPECT_EQ(ret, E_INVALID_PATH);
96 }
97 } // namespace Media
98 } // namespace OHOS
99