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 "gtest/gtest.h"
17 #include "iremote_object.h"
18 #define private public
19 #define protected public
20 #include "sms_send_short_message_proxy.h"
21 #include "sms_delivery_short_message_proxy.h"
22 #include "mock/mock_remote_object.h"
23 #include "sms_persist_helper.h"
24 namespace OHOS {
25 namespace Telephony {
26 using namespace testing::ext;
27
28 class SmsServiceProxyTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp();
33 void TearDown();
34 };
SetUpTestCase()35 void SmsServiceProxyTest::SetUpTestCase() {}
36
37 constexpr uint32_t EVENT_RELEASE_DATA_SHARE_HELPER = 10000;
TearDownTestCase()38 void SmsServiceProxyTest::TearDownTestCase()
39 {
40 DelayedSingleton<SmsPersistHelper>::GetInstance()->RemoveEvent(EVENT_RELEASE_DATA_SHARE_HELPER);
41 }
42
SetUp()43 void SmsServiceProxyTest::SetUp() {}
44
TearDown()45 void SmsServiceProxyTest::TearDown() {}
46
47 /**
48 * @tc.number Telephony_SmsMmsGtest_smsServiceProxyTest_001
49 * @tc.name smsServiceProxyTest_001
50 * @tc.desc Function test
51 */
52 HWTEST_F(SmsServiceProxyTest, smsServiceProxyTest_001, Function | MediumTest | Level1)
53 {
54 sptr<IRemoteObject> sptrRemoteObject = nullptr;
55 ISendShortMessageCallback::SmsSendResult sendResult =
56 ISendShortMessageCallback::SmsSendResult::SEND_SMS_FAILURE_UNKNOWN;
57
58 SmsSendShortMessageProxy sendShortMessageProxy(sptrRemoteObject);
59 EXPECT_EQ(sendShortMessageProxy.Remote().GetRefPtr(), nullptr);
60 sendShortMessageProxy.OnSmsSendResult(sendResult);
61 }
62 /**
63 * @tc.number Telephony_SmsMmsGtest_smsServiceProxyTest_002
64 * @tc.name smsServiceProxyTest_001
65 * @tc.desc Function test
66 */
67 HWTEST_F(SmsServiceProxyTest, smsServiceProxyTest_002, Function | MediumTest | Level1)
68 {
69 sptr<MockRemoteObject> sptrRemoteObject = new MockRemoteObject();
70 sptrRemoteObject->retGetObjectRefCount = 1;
71 sptrRemoteObject->retSendRequest = 0;
72
73 ISendShortMessageCallback::SmsSendResult sendResult =
74 ISendShortMessageCallback::SmsSendResult::SEND_SMS_FAILURE_UNKNOWN;
75 SmsSendShortMessageProxy sendShortMessageProxy(sptrRemoteObject);
76 EXPECT_EQ(sendShortMessageProxy.Remote().GetRefPtr(), sptrRemoteObject);
77 sendShortMessageProxy.OnSmsSendResult(sendResult);
78 }
79 /**
80 * @tc.number Telephony_SmsMmsGtest_smsServiceProxyTest_003
81 * @tc.name smsServiceProxyTest_001
82 * @tc.desc Function test
83 */
84 HWTEST_F(SmsServiceProxyTest, smsServiceProxyTest_003, Function | MediumTest | Level1)
85 {
86 sptr<IRemoteObject> sptrRemoteObject = nullptr;
87 std::u16string strPdu = u"";
88 SmsDeliveryShortMessageProxy sendShortMessageProxy(sptrRemoteObject);
89 EXPECT_EQ(sendShortMessageProxy.Remote().GetRefPtr(), nullptr);
90 sendShortMessageProxy.OnSmsDeliveryResult(strPdu);
91 }
92 /**
93 * @tc.number Telephony_SmsMmsGtest_smsServiceProxyTest_004
94 * @tc.name smsServiceProxyTest_001
95 * @tc.desc Function test
96 */
97 HWTEST_F(SmsServiceProxyTest, smsServiceProxyTest_004, Function | MediumTest | Level1)
98 {
99 sptr<MockRemoteObject> sptrRemoteObject = new MockRemoteObject();
100 sptrRemoteObject->retGetObjectRefCount = 1;
101 sptrRemoteObject->retSendRequest = 0;
102
103 std::u16string strPdu = u"";
104 SmsDeliveryShortMessageProxy sendShortMessageProxy(sptrRemoteObject);
105 EXPECT_EQ(sendShortMessageProxy.Remote().GetRefPtr(), sptrRemoteObject);
106 sendShortMessageProxy.OnSmsDeliveryResult(strPdu);
107 }
108 }
109 }