summaryrefslogtreecommitdiffstats
path: root/components/rappor/rappor_metric_unittest.cc
blob: 44c918b098d586fe55a75564c30322314ef759dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/rappor/rappor_metric.h"

#include <stdlib.h>

#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace rappor {

const RapporParameters kTestRapporParameters = {
    1 /* Num cohorts */,
    16 /* Bloom filter size bytes */,
    4 /* Bloom filter hash count */,
    NORMAL_NOISE /* Noise level */,
    UMA_RAPPOR_GROUP /* Recording group (not used) */,
};

// Check for basic syntax and use.
TEST(RapporMetricTest, BasicMetric) {
  RapporMetric testMetric("MyRappor", kTestRapporParameters, 0);
  testMetric.AddSample("Bar");
  EXPECT_EQ(0x80, testMetric.bytes()[1]);
}

TEST(RapporMetricTest, GetReport) {
  RapporMetric metric("MyRappor", kTestRapporParameters, 0);

  const ByteVector report = metric.GetReport(
      HmacByteVectorGenerator::GenerateEntropyInput());
  EXPECT_EQ(16u, report.size());
}

}  // namespace rappor