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 18 #include "edm_utils.h" 19 20 using namespace testing::ext; 21 22 namespace OHOS { 23 namespace EDM { 24 namespace TEST { 25 class EdmUtilsTest : public testing::Test {}; 26 /** 27 * @tc.name: Test_ParseStringToInt_SUC 28 * @tc.desc: Test ParseStringToInt function when input data is available. 29 * @tc.type: FUNC 30 */ 31 HWTEST_F(EdmUtilsTest, Test_ParseStringToInt_SUC, TestSize.Level1) 32 { 33 int32_t retNum = 0; 34 ErrCode ret = EdmUtils::ParseStringToInt("1", retNum); 35 ASSERT_EQ(ret, 0); 36 ASSERT_EQ(retNum, 1); 37 } 38 39 /** 40 * @tc.name: Test_ParseStringToInt_FAIL 41 * @tc.desc: Test ParseStringToInt function when input data is unavailable. 42 * @tc.type: FUNC 43 */ 44 HWTEST_F(EdmUtilsTest, Test_ParseStringToInt_FAIL, TestSize.Level1) 45 { 46 int32_t retNum = 0; 47 ErrCode ret = EdmUtils::ParseStringToInt("", retNum); 48 ASSERT_EQ(ret, EdmReturnErrCode::PARAM_ERROR); 49 ASSERT_EQ(retNum, 0); 50 } 51 52 /** 53 * @tc.name: Test_ParseStringToLong_SUC 54 * @tc.desc: Test ParseStringToLong function when input data is available. 55 * @tc.type: FUNC 56 */ 57 HWTEST_F(EdmUtilsTest, Test_ParseStringToLong_SUC, TestSize.Level1) 58 { 59 int64_t retNum = 0; 60 ErrCode ret = EdmUtils::ParseStringToLong("2147483647", retNum); 61 ASSERT_EQ(ret, 0); 62 ASSERT_EQ(retNum, 2147483647); 63 } 64 65 66 /** 67 * @tc.name: Test_ParseStringToLong_FAIL 68 * @tc.desc: Test Test ParseStringToLong function when input data is unavailable. 69 * @tc.type: FUNC 70 */ 71 HWTEST_F(EdmUtilsTest, Test_ParseStringToLong_FAIL, TestSize.Level1) 72 { 73 int64_t retNum = 0; 74 ErrCode ret = EdmUtils::ParseStringToLong("abc", retNum); 75 ASSERT_EQ(ret, EdmReturnErrCode::PARAM_ERROR); 76 ASSERT_EQ(retNum, 0); 77 } 78 } // namespace TEST 79 } // namespace EDM 80 } // namespace OHOS 81