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 "PublicMethods.h" 18 19 namespace { 20 // 测试拷贝构造函数是否被删除 TEST(CppTimerTest,CopyConstructorDeletedTest)21 TEST(CppTimerTest, CopyConstructorDeletedTest) 22 { 23 EXPECT_TRUE(std::is_copy_constructible<PublicMethods>::value == false); 24 } 25 26 // 测试赋值运算符是否被删除 TEST(CppTimerTest,AssignmentOperatorDeletedTest)27 TEST(CppTimerTest, AssignmentOperatorDeletedTest) 28 { 29 EXPECT_TRUE(std::is_copy_assignable<PublicMethods>::value == false); 30 } 31 32 // 比较两个 int8_t 数组是否相等 CompareInt8Arrays(const int8_t * arr1,const int8_t * arr2,size_t size)33 bool CompareInt8Arrays(const int8_t* arr1, const int8_t* arr2, size_t size) 34 { 35 for (size_t i = 0; i < size; ++i) { 36 if (arr1[i] != arr2[i]) { 37 return false; 38 } 39 } 40 return true; 41 } 42 TEST(PublicMethodsTest,UlltoaTest)43 TEST(PublicMethodsTest, UlltoaTest) 44 { 45 const int testValue = 123456789; 46 const int8_t expectedOutput[] = "75bcd15"; 47 48 int8_t outputBuffer[PublicMethods::MAX_ITOA_BIT] = {0}; 49 uint32_t resultLength = PublicMethods::Ulltoa(testValue, outputBuffer); 50 // 验证返回值是否正确 51 ASSERT_EQ(std::size(expectedOutput) - 1, resultLength); // 减去 1,以排除空字符(‘\0’)的影响 52 // 验证结果字符串是否与预期相符 53 ASSERT_TRUE(CompareInt8Arrays(expectedOutput, outputBuffer, resultLength)); 54 } 55 }