1 /* 2 * Copyright (C) 2020 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 #include <gtest/gtest.h> 17 18 #include "metadata_util.h" 19 #include "tests/statsd_test_util.h" 20 21 #ifdef __ANDROID__ 22 23 namespace android { 24 namespace os { 25 namespace statsd { 26 27 TEST(MetadataUtilTest, TestWriteAndReadMetricDimensionKey) { 28 HashableDimensionKey dim; 29 HashableDimensionKey dim2; 30 int pos1[] = {1, 1, 1}; 31 int pos2[] = {1, 1, 2}; 32 int pos3[] = {1, 1, 3}; 33 int pos4[] = {2, 0, 0}; 34 Field field1(10, pos1, 2); 35 Field field2(10, pos2, 2); 36 Field field3(10, pos3, 2); 37 Field field4(10, pos4, 0); 38 39 Value value1((int32_t)10025); 40 Value value2("tag"); 41 Value value3((int32_t)987654); 42 Value value4((int32_t)99999); 43 44 dim.addValue(FieldValue(field1, value1)); 45 dim.addValue(FieldValue(field2, value2)); 46 dim.addValue(FieldValue(field3, value3)); 47 dim.addValue(FieldValue(field4, value4)); 48 49 dim2.addValue(FieldValue(field1, value1)); 50 dim2.addValue(FieldValue(field2, value2)); 51 52 MetricDimensionKey dimKey(dim, dim2); 53 54 metadata::MetricDimensionKey metadataDimKey; 55 writeMetricDimensionKeyToMetadataDimensionKey(dimKey, &metadataDimKey); 56 57 MetricDimensionKey loadedDimKey = loadMetricDimensionKeyFromProto(metadataDimKey); 58 59 ASSERT_EQ(loadedDimKey, dimKey); 60 ASSERT_EQ(std::hash<MetricDimensionKey>{}(loadedDimKey), 61 std::hash<MetricDimensionKey>{}(dimKey)); 62 } 63 64 } // namespace statsd 65 } // namespace os 66 } // namespace android 67 #else 68 GTEST_LOG_(INFO) << "This test does nothing.\n"; 69 #endif 70