• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "perf_data_utils.h"
6 
7 #include "compat/string.h"
8 #include "compat/test.h"
9 
10 namespace quipper {
11 
TEST(PerfDataUtilsTest,GetUint64AlignedStringLength)12 TEST(PerfDataUtilsTest, GetUint64AlignedStringLength) {
13   EXPECT_EQ(8, GetUint64AlignedStringLength("012345"));
14   EXPECT_EQ(8, GetUint64AlignedStringLength("0123456"));
15   EXPECT_EQ(16, GetUint64AlignedStringLength("01234567"));  // Room for '\0'
16   EXPECT_EQ(16, GetUint64AlignedStringLength("012345678"));
17   EXPECT_EQ(16, GetUint64AlignedStringLength("0123456789abcde"));
18   EXPECT_EQ(24, GetUint64AlignedStringLength("0123456789abcdef"));
19 }
20 
TEST(PerfDataUtilsTest,PerfizeBuildID)21 TEST(PerfDataUtilsTest, PerfizeBuildID) {
22   string build_id_string = "f";
23   PerfizeBuildIDString(&build_id_string);
24   EXPECT_EQ("f000000000000000000000000000000000000000", build_id_string);
25   PerfizeBuildIDString(&build_id_string);
26   EXPECT_EQ("f000000000000000000000000000000000000000", build_id_string);
27 
28   build_id_string = "01234567890123456789012345678901234567890";
29   PerfizeBuildIDString(&build_id_string);
30   EXPECT_EQ("0123456789012345678901234567890123456789", build_id_string);
31   PerfizeBuildIDString(&build_id_string);
32   EXPECT_EQ("0123456789012345678901234567890123456789", build_id_string);
33 }
34 
TEST(PerfDataUtilsTest,UnperfizeBuildID)35 TEST(PerfDataUtilsTest, UnperfizeBuildID) {
36   string build_id_string = "f000000000000000000000000000000000000000";
37   TrimZeroesFromBuildIDString(&build_id_string);
38   EXPECT_EQ("f0000000", build_id_string);
39   TrimZeroesFromBuildIDString(&build_id_string);
40   EXPECT_EQ("f0000000", build_id_string);
41 
42   build_id_string = "0123456789012345678901234567890123456789";
43   TrimZeroesFromBuildIDString(&build_id_string);
44   EXPECT_EQ("0123456789012345678901234567890123456789", build_id_string);
45 
46   build_id_string = "0000000000000000000000000000001000000000";
47   TrimZeroesFromBuildIDString(&build_id_string);
48   EXPECT_EQ("00000000000000000000000000000010", build_id_string);
49   TrimZeroesFromBuildIDString(&build_id_string);
50   EXPECT_EQ("00000000000000000000000000000010", build_id_string);
51 
52   build_id_string = "0000000000000000000000000000000000000000";  // 40 zeroes
53   TrimZeroesFromBuildIDString(&build_id_string);
54   EXPECT_EQ("", build_id_string);
55 
56   build_id_string = "00000000000000000000000000000000";  // 32 zeroes
57   TrimZeroesFromBuildIDString(&build_id_string);
58   EXPECT_EQ("", build_id_string);
59 
60   build_id_string = "00000000";  // 8 zeroes
61   TrimZeroesFromBuildIDString(&build_id_string);
62   EXPECT_EQ("", build_id_string);
63 
64   build_id_string = "0000000";  // 7 zeroes
65   TrimZeroesFromBuildIDString(&build_id_string);
66   EXPECT_EQ("0000000", build_id_string);
67 
68   build_id_string = "";
69   TrimZeroesFromBuildIDString(&build_id_string);
70   EXPECT_EQ("", build_id_string);
71 }
72 
73 }  // namespace quipper
74