This source file includes following definitions.
- TEST
 
- TEST
 
- TEST
 
#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 = {
    16 ,
    4 ,
    PROBABILITY_75 ,
    PROBABILITY_50 ,
    PROBABILITY_75 ,
    PROBABILITY_50 };
const RapporParameters kTestStatsRapporParameters = {
    50 ,
    4 ,
    PROBABILITY_75 ,
    PROBABILITY_50 ,
    PROBABILITY_75 ,
    PROBABILITY_50 };
TEST(RapporMetricTest, BasicMetric) {
  RapporMetric testMetric("MyRappor", kTestRapporParameters, 0);
  testMetric.AddSample("Foo");
  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());
}
TEST(RapporMetricTest, GetReportStatistics) {
  RapporMetric metric("MyStatsRappor", kTestStatsRapporParameters, 0);
  for (char i = 0; i < 50; i++) {
    metric.AddSample(base::StringPrintf("%d", i));
  }
  const ByteVector real_bits = metric.bytes();
  const int real_bit_count = CountBits(real_bits);
  EXPECT_EQ(real_bit_count, 152);
  const std::string secret = HmacByteVectorGenerator::GenerateEntropyInput();
  const ByteVector report = metric.GetReport(secret);
  
  
  ByteVector from_true_reports = report;
  
  ByteVectorMerge(real_bits, real_bits, &from_true_reports);
  const int true_from_true_count = CountBits(from_true_reports);
  
  
  ByteVector from_false_reports = report;
  ByteVectorOr(real_bits, &from_false_reports);
  const int true_from_false_count =
      CountBits(from_false_reports) - real_bit_count;
  
  
  
  
  
  
  
  
  
  
  
  EXPECT_GT(true_from_true_count, 73);
  
  EXPECT_LE(true_from_true_count, 124);
  
  EXPECT_GT(true_from_false_count, 113);
  
  EXPECT_LE(true_from_false_count, 181);
}
}