1 /* 2 * Copyright (c) 2023 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 "hisysevent_mock.h" 17 #include "softbus_hisysevent_matcher.h" 18 #include "gtest/gtest.h" 19 20 using namespace std; 21 using namespace testing; 22 using namespace testing::ext; 23 24 namespace OHOS { 25 class SoftbusEventTest : public testing::Test { }; 26 27 /** 28 * @tc.name: SoftbusEventTest001 29 * @tc.desc: Test event names 30 * @tc.type: FUNC 31 * @tc.require: I8HA59 32 */ 33 HWTEST_F(SoftbusEventTest, SoftbusEventTest001, TestSize.Level0) 34 { 35 EXPECT_STREQ(CONN_EVENT_NAME, "CONNECTION_BEHAVIOR"); 36 EXPECT_STREQ(DISC_EVENT_NAME, "DISCOVER_BEHAVIOR"); 37 EXPECT_STREQ(LNN_EVENT_NAME, "BUSCENTER_BEHAVIOR"); 38 EXPECT_STREQ(TRANS_EVENT_NAME, "TRANSPORT_BEHAVIOR"); 39 } 40 41 /** 42 * @tc.name: SoftbusEventTest002 43 * @tc.desc: Test softbus event form 44 * @tc.type: FUNC 45 * @tc.require: I8HA59 46 */ 47 HWTEST_F(SoftbusEventTest, SoftbusEventTest002, TestSize.Level0) 48 { 49 SoftbusEventForm form = { 50 .scene = EVENT_SCENE_OPEN_CHANNEL, 51 .stage = EVENT_STAGE_START_CONNECT, 52 .line = 233, 53 .func = "TestFunc", 54 }; 55 constexpr int32_t VALID_FORM_SIZE = SOFTBUS_ASSIGNER_SIZE; 56 57 HiSysEventMock mock; 58 EXPECT_CALL(mock, 59 HiSysEvent_Write(StrEq(form.func), Eq(form.line), StrEq(SOFTBUS_EVENT_DOMAIN), _, 60 Eq(SOFTBUS_EVENT_TYPE_BEHAVIOR), SoftbusParamArrayMatcher(form, VALID_FORM_SIZE), _)) 61 .Times(1); 62 SoftbusEventInner(EVENT_MODULE_CONN, &form); 63 } 64 65 } // namespace OHOS