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