1/* 2 * Copyright (c) 2022-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#include <securec.h> 16#include "gtest/gtest.h" 17 18#include "softbus_adapter_timer.h" 19#include "softbus_def.h" 20#include "softbus_errcode.h" 21 22using namespace std; 23using namespace testing::ext; 24 25namespace OHOS { 26const int32_t TIMER_TIMEOUT = 1000; 27 28class SoftbusTimeTest : public testing::Test { 29protected: 30 static void SetUpTestCase(void); 31 static void TearDownTestCase(void); 32 void SetUp(); 33 void TearDown(); 34}; 35 36void SoftbusTimeTest::SetUpTestCase(void) 37{ 38} 39 40void SoftbusTimeTest::TearDownTestCase(void) 41{ 42} 43 44void SoftbusTimeTest::SetUp() 45{ 46} 47 48void SoftbusTimeTest::TearDown() 49{ 50} 51 52/* 53 * @tc.name: SoftBusTimerTest001 54 * @tc.desc: soft bus timer test 55 * @tc.type: FUNC 56 * @tc.require: 57 */ 58HWTEST_F(SoftbusTimeTest, SoftBusTimerTest001, TestSize.Level1) 59{ 60 void *timerId = NULL; 61 SoftBusSysTime times = {0}; 62 int32_t ret; 63 64 ret = SoftBusStartTimer(NULL, TIMER_TIMEOUT); 65 EXPECT_EQ(SOFTBUS_ERR, ret); 66 SoftBusCreateTimer(NULL, TIMER_TYPE_ONCE); 67 SoftBusCreateTimer(&timerId, TIMER_TYPE_ONCE); 68 ret = SoftBusStartTimer(timerId, TIMER_TIMEOUT); 69 EXPECT_NE(SOFTBUS_ERR, ret); 70 ret = SoftBusDeleteTimer(NULL); 71 EXPECT_EQ(SOFTBUS_ERR, ret); 72 ret = SoftBusDeleteTimer(timerId); 73 EXPECT_EQ(SOFTBUS_OK, ret); 74 ret = SoftBusGetTime(NULL); 75 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret); 76 ret = SoftBusGetTime(×); 77 EXPECT_EQ(SOFTBUS_OK, ret); 78} 79 80/* 81 * @tc.name: SoftBusTimerTest002 82 * @tc.desc: test SoftBusFormatTimestamp 83 * @tc.type: FUNC 84 * @tc.require: 85 */ 86HWTEST_F(SoftbusTimeTest, SoftBusTimerTest002, TestSize.Level1) 87{ 88 uint64_t timestamp1 = 946656000000; 89 const char *formated1 = SoftBusFormatTimestamp(timestamp1); 90 EXPECT_STREQ(formated1, "2000-01-01 00:00:00.000"); 91 92 uint64_t timestamp2 = 1705984496789; 93 const char *formated2 = SoftBusFormatTimestamp(timestamp2); 94 EXPECT_STREQ(formated2, "2024-01-23 12:34:56.789"); 95} 96} // namespace OHOS 97