Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: components/rappor/byte_vector_utils_unittest.cc

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RapporMetric Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium 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 "components/rappor/byte_vector_utils.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace rappor {
10
11 TEST(ByteVectorTest, TestOr) {
12 ByteVector lhs(2);
13 lhs[1] = 0x12;
14 ByteVector rhs(2);
15 rhs[1] = 0x03;
16
17 ASSERT_EQ(0x13, (*ByteVectorOr(&lhs, rhs))[1]);
18 }
19
20 TEST(ByteVectorTest, TestAnd) {
21 ByteVector lhs(2);
22 lhs[1] = 0x12;
23 ByteVector rhs(2);
24 rhs[1] = 0x03;
25
26 ASSERT_EQ(0x02, (*ByteVectorAnd(&lhs, rhs))[1]);
27 }
28
29 TEST(ByteVectorTest, TestMerge) {
30 ByteVector lhs(2);
31 lhs[1] = 0x33;
32 ByteVector rhs(2);
33 rhs[1] = 0x55;
34 ByteVector mask(2);
35 mask[1] = 0x0f;
36
37 ASSERT_EQ(0x35, (*ByteVectorMerge(&lhs, rhs, mask))[1]);
38 }
39
40 TEST(ByteVectorTest, TestGenerator) {
41 ByteVectorGenerator generator(2);
42 ByteVector random_50 = generator.GetWeightedRandomByteVector(PROBABILITY_50);
43 ASSERT_EQ(random_50.size(), 2u);
44 ByteVector random_75 = generator.GetWeightedRandomByteVector(PROBABILITY_75);
45 ASSERT_EQ(random_75.size(), 2u);
46 }
47
48 TEST(ByteVectorTest, TestHmacGenerator) {
49 HmacByteVectorGenerator generator(2, "MySecret");
50 ByteVector random_50 = generator.GetWeightedRandomByteVector(PROBABILITY_50);
51 ASSERT_EQ(random_50.size(), 2u);
52 ASSERT_EQ(random_50[0], 0x16);
53 ByteVector random_75 = generator.GetWeightedRandomByteVector(PROBABILITY_75);
54 ASSERT_EQ(random_75.size(), 2u);
55 ASSERT_EQ(random_75[0], 0xef);
56 }
57
58 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698