1 /* 2 * Copyright (C) 2014 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 package android.hardware.cts.helpers; 18 19 import junit.framework.TestCase; 20 21 import java.util.Map; 22 23 /** 24 * Unit tests for the {@link SensorStats} class. 25 */ 26 public class SensorStatsTest extends TestCase { 27 28 /** 29 * Test that {@link SensorStats#flatten()} works correctly. 30 */ testFlatten()31 public void testFlatten() { 32 SensorStats stats = new SensorStats(); 33 stats.addValue("value0", 0); 34 stats.addValue("value1", 1); 35 36 SensorStats subStats = new SensorStats(); 37 subStats.addValue("value2", 2); 38 subStats.addValue("value3", 3); 39 40 SensorStats subSubStats = new SensorStats(); 41 subSubStats.addValue("value4", 4); 42 subSubStats.addValue("value5", 5); 43 44 subStats.addSensorStats("stats1", subSubStats); 45 stats.addSensorStats("stats0", subStats); 46 47 // Add empty stats, expect no value in flattened map 48 stats.addSensorStats("stats2", new SensorStats()); 49 50 // Add null values, expect no value in flattened map 51 stats.addSensorStats("stats3", null); 52 stats.addValue("value6", null); 53 54 Map<String, Object> flattened = stats.flatten(); 55 56 assertEquals(6, flattened.size()); 57 assertEquals(0, (int) (Integer) flattened.get("value0")); 58 assertEquals(1, (int) (Integer) flattened.get("value1")); 59 assertEquals(2, (int) (Integer) flattened.get("stats0__value2")); 60 assertEquals(3, (int) (Integer) flattened.get("stats0__value3")); 61 assertEquals(4, (int) (Integer) flattened.get("stats0__stats1__value4")); 62 assertEquals(5, (int) (Integer) flattened.get("stats0__stats1__value5")); 63 } 64 } 65