1 /* 2 * Copyright (c) 2022 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 <map> 18 #include <thread> 19 20 #include "errorcode_convertor.h" 21 #include "event_report.h" 22 #include "net_manager_constants.h" 23 #include "netmanager_hitrace.h" 24 25 namespace OHOS { 26 namespace NetManagerStandard { 27 namespace { 28 using namespace testing::ext; 29 constexpr uint32_t TEST_DELAY_TIME = 1; 30 constexpr const char *TEST_VALUE = "TEST_VALUE"; 31 constexpr int32_t TEST_TASK_ID = 10054; 32 } // namespace 33 34 class ErrorCodeConvertorTest : public testing::Test { 35 public: 36 static void SetUpTestCase(); 37 static void TearDownTestCase(); 38 void SetUp(); 39 void TearDown(); 40 void AllTest001(); 41 }; 42 SetUpTestCase()43void ErrorCodeConvertorTest::SetUpTestCase() {} 44 TearDownTestCase()45void ErrorCodeConvertorTest::TearDownTestCase() {} 46 SetUp()47void ErrorCodeConvertorTest::SetUp() {} 48 TearDown()49void ErrorCodeConvertorTest::TearDown() {} 50 AllTest001()51void ErrorCodeConvertorTest::AllTest001() 52 { 53 NetmanagerHiTrace::NetmanagerStartSyncTrace(TEST_VALUE); 54 std::this_thread::sleep_for(std::chrono::seconds(TEST_DELAY_TIME)); 55 NetmanagerHiTrace::NetmanagerFinishSyncTrace(TEST_VALUE); 56 std::thread thread([this]() { 57 NetmanagerHiTrace::NetmanagerStartAsyncTrace(TEST_VALUE, TEST_TASK_ID); 58 std::this_thread::sleep_for(std::chrono::seconds(TEST_DELAY_TIME)); 59 NetmanagerHiTrace::NetmanagerFinishAsyncTrace(TEST_VALUE, TEST_TASK_ID); 60 }); 61 thread.join(); 62 } 63 64 HWTEST_F(ErrorCodeConvertorTest, ConvertErrorCodeTest001, TestSize.Level1) 65 { 66 EventInfo eventInfo; 67 EventReport::SendSupplierFaultEvent(eventInfo); 68 EventReport::SendSupplierBehaviorEvent(eventInfo); 69 EventReport::SendRequestFaultEvent(eventInfo); 70 EventReport::SendRequestBehaviorEvent(eventInfo); 71 EventReport::SendMonitorFaultEvent(eventInfo); 72 EventReport::SendMonitorBehaviorEvent(eventInfo); 73 74 AllTest001(); 75 76 int32_t testErrorCode = 5445645; 77 auto instance = std::make_unique<NetBaseErrorCodeConvertor>(); 78 int32_t errorCode = NETMANAGER_ERR_INTERNAL; 79 auto ret = instance->ConvertErrorCode(errorCode); 80 ASSERT_FALSE(ret.empty()); 81 ret = instance->ConvertErrorCode(testErrorCode); 82 ASSERT_TRUE(ret.empty()); 83 } 84 } // namespace NetManagerStandard 85 } // namespace OHOS