• 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 "vibrate_asset_test.h"
17 #include "vibrate_asset.h"
18 #include "ringtone_errno.h"
19 
20 using namespace std;
21 using namespace OHOS;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Media {
26 shared_ptr<VibrateAsset> g_vibrateAsset;
27 
SetUpTestCase()28 void VibrateAssetTest::SetUpTestCase()
29 {
30     g_vibrateAsset = std::make_shared<VibrateAsset>();
31     EXPECT_NE(g_vibrateAsset, nullptr);
32 }
33 
TearDownTestCase()34 void VibrateAssetTest::TearDownTestCase() {}
35 
36 // SetUp:Execute before each test case
SetUp()37 void VibrateAssetTest::SetUp() {}
38 
TearDown(void)39 void VibrateAssetTest::TearDown(void) {}
40 
41 HWTEST_F(VibrateAssetTest, vibrateAsset_GetId_test_001, TestSize.Level0)
42 {
43     auto assetId = g_vibrateAsset->GetId();
44     EXPECT_EQ(assetId, 0);
45     const int32_t id = 1;
46     g_vibrateAsset->SetId(id);
47     assetId = g_vibrateAsset->GetId();
48     EXPECT_EQ(assetId, id);
49 }
50 
51 HWTEST_F(VibrateAssetTest, vibrateAsset_GetSize_test_001, TestSize.Level0)
52 {
53     auto assetSize = g_vibrateAsset->GetSize();
54     EXPECT_EQ(assetSize, 0);
55     const int64_t size = 3267; // 3267 is vibrate column size
56     g_vibrateAsset->SetSize(size);
57     assetSize = g_vibrateAsset->GetSize();
58     EXPECT_EQ(assetSize, size);
59 }
60 
61 HWTEST_F(VibrateAssetTest, vibrateAsset_GetPath_test_001, TestSize.Level0)
62 {
63     auto assetPath = g_vibrateAsset->GetPath();
64     EXPECT_EQ(assetPath, "");
65     const string path = "data/tmp";
66     g_vibrateAsset->SetPath(path);
67     assetPath = g_vibrateAsset->GetPath();
68     EXPECT_EQ(assetPath, path);
69 }
70 
71 HWTEST_F(VibrateAssetTest, vibrateAsset_GetDisplayName_test_001, TestSize.Level0)
72 {
73     auto assetdisplayName = g_vibrateAsset->GetDisplayName();
74     EXPECT_EQ(assetdisplayName, "");
75     const string displayName = "vibrateAsset_GetDisplayName_test_001.ogg";
76     g_vibrateAsset->SetDisplayName(displayName);
77     assetdisplayName = g_vibrateAsset->GetDisplayName();
78     EXPECT_EQ(assetdisplayName, displayName);
79 }
80 
81 HWTEST_F(VibrateAssetTest, vibrateAsset_GetTitle_test_001, TestSize.Level0)
82 {
83     const string title = "vibrateAsset_GetTitle_test_001";
84     g_vibrateAsset->SetTitle(title);
85     auto assetTitle = g_vibrateAsset->GetTitle();
86     EXPECT_EQ(assetTitle, title);
87 }
88 
89 HWTEST_F(VibrateAssetTest, vibrateAsset_GetDisplayLanguage_test_001, TestSize.Level0)
90 {
91     const string displayLanguage = "ch-zn";
92     g_vibrateAsset->SetDisplayLanguage(displayLanguage);
93     auto assetLanguage = g_vibrateAsset->GetDisplayLanguage();
94     EXPECT_EQ(assetLanguage, displayLanguage);
95 }
96 
97 HWTEST_F(VibrateAssetTest, vibrateAsset_GetVibrateType_test_001, TestSize.Level0)
98 {
99     const int32_t type = 1;
100     g_vibrateAsset->SetVibrateType(type);
101     auto assetType = g_vibrateAsset->GetVibrateType();
102     EXPECT_EQ(assetType, type);
103 }
104 
105 HWTEST_F(VibrateAssetTest, vibrateAsset_GetSourceType_test_001, TestSize.Level0)
106 {
107     int32_t sourceType = 1;
108     g_vibrateAsset->SetSourceType(sourceType);
109     auto assetSourceType = g_vibrateAsset->GetSourceType();
110     EXPECT_EQ(assetSourceType, sourceType);
111 }
112 
113 HWTEST_F(VibrateAssetTest, vibrateAsset_GetDateAdded_test_001, TestSize.Level0)
114 {
115     const int64_t dateAdded = 1559276457;
116     g_vibrateAsset->SetDateAdded(dateAdded);
117     auto assetDateAdded = g_vibrateAsset->GetDateAdded();
118     EXPECT_EQ(assetDateAdded, dateAdded);
119 }
120 
121 HWTEST_F(VibrateAssetTest, vibrateAsset_GetDateModified_test_001, TestSize.Level0)
122 {
123     const int64_t dateModified = 1559276475;
124     g_vibrateAsset->SetDateModified(dateModified);
125     auto assetDateModified = g_vibrateAsset->GetDateModified();
126     EXPECT_EQ(assetDateModified, dateModified);
127 }
128 
129 HWTEST_F(VibrateAssetTest, vibrateAsset_GetDateTaken_test_001, TestSize.Level0)
130 {
131     const int64_t dataTaken = 1559277457;
132     g_vibrateAsset->SetDateTaken(dataTaken);
133     auto assetDataTaken = g_vibrateAsset->GetDateTaken();
134     EXPECT_EQ(assetDataTaken, dataTaken);
135 }
136 
137 HWTEST_F(VibrateAssetTest, vibrateAsset_GetMemberValue_test_001, TestSize.Level0)
138 {
139     variant<int32_t, int64_t, string, double> memberValue;
140     const string name = "vibrateAsset_GetMemberValue_test_001";
141     auto assetMemberValue = g_vibrateAsset->GetMemberValue(name);
142     EXPECT_EQ(assetMemberValue, memberValue);
143 }
144 } // namespace Media
145 } // namespace OHOS
146