blob: 2c6787b8a6e759bb80351eaf782c997c6042e4b5 [file] [log] [blame]
Mathieu Chartier193bad92013-08-29 18:46:00 -07001/*
2 * Copyright (C) 2013 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 "common_test.h"
18#include "dedupe_set.h"
19
20namespace art {
21
Mathieu Chartier193bad92013-08-29 18:46:00 -070022class DedupeHashFunc {
23 public:
24 size_t operator()(const std::vector<uint8_t>& array) const {
25 size_t hash = 0;
26 for (uint8_t c : array) {
27 hash += c;
28 hash += hash << 10;
29 hash += hash >> 6;
30 }
31 return hash;
32 }
33};
Brian Carlstrom413e89f2013-10-21 23:53:49 -070034TEST(DedupeSetTest, Test) {
Mathieu Chartier193bad92013-08-29 18:46:00 -070035 Thread* self = Thread::Current();
36 typedef std::vector<uint8_t> ByteArray;
Ian Rogersd133b972013-09-05 11:01:30 -070037 DedupeSet<ByteArray, size_t, DedupeHashFunc> deduplicator("test");
Mathieu Chartier193bad92013-08-29 18:46:00 -070038 ByteArray* array1;
39 {
40 ByteArray test1;
41 test1.push_back(10);
42 test1.push_back(20);
43 test1.push_back(30);
44 test1.push_back(45);
45 array1 = deduplicator.Add(self, test1);
46 ASSERT_EQ(test1, *array1);
47 }
48
49 ByteArray* array2;
50 {
51 ByteArray test1;
52 test1.push_back(10);
53 test1.push_back(20);
54 test1.push_back(30);
55 test1.push_back(45);
56 array2 = deduplicator.Add(self, test1);
57 ASSERT_EQ(array2, array1);
58 ASSERT_EQ(test1, *array2);
59 }
60
61 ByteArray* array3;
62 {
63 ByteArray test1;
64 test1.push_back(10);
65 test1.push_back(22);
66 test1.push_back(30);
67 test1.push_back(47);
68 array3 = deduplicator.Add(self, test1);
69 ASSERT_NE(array3, &test1);
70 ASSERT_EQ(test1, *array3);
71 }
72}
73
74} // namespace art