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