Home | History | Annotate | Download | only in uploader
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "uploader/metrics_hashes.h"
     18 
     19 #include <base/format_macros.h>
     20 #include <base/macros.h>
     21 #include <base/strings/stringprintf.h>
     22 #include <gtest/gtest.h>
     23 
     24 namespace metrics {
     25 
     26 // Make sure our ID hashes are the same as what we see on the server side.
     27 TEST(MetricsUtilTest, HashMetricName) {
     28   static const struct {
     29     std::string input;
     30     std::string output;
     31   } cases[] = {
     32     {"Back", "0x0557fa923dcee4d0"},
     33     {"Forward", "0x67d2f6740a8eaebf"},
     34     {"NewTab", "0x290eb683f96572f1"},
     35   };
     36 
     37   for (size_t i = 0; i < arraysize(cases); ++i) {
     38     uint64_t hash = HashMetricName(cases[i].input);
     39     std::string hash_hex = base::StringPrintf("0x%016" PRIx64, hash);
     40     EXPECT_EQ(cases[i].output, hash_hex);
     41   }
     42 }
     43 
     44 }  // namespace metrics
     45