1 /* 2 * Copyright (C) 2017 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 com.android.car; 18 19 import static org.junit.Assert.assertNotEquals; 20 21 import android.car.vms.VmsLayer; 22 import android.car.vms.VmsLayerDependency; 23 import android.car.vms.VmsLayersOffering; 24 import android.test.AndroidTestCase; 25 import android.test.suitebuilder.annotation.SmallTest; 26 import android.os.Parcel; 27 28 import java.util.Arrays; 29 import java.util.HashSet; 30 31 import android.util.Log; 32 33 /* 34 * A class to test the VmsLayersOffering parcelability. 35 */ 36 @SmallTest 37 public class VmsLayersOfferingTest extends AndroidTestCase { 38 private static final int PUBLISHER_ID = 1; 39 40 private static final int LAYER_ID = 112; 41 private static final int LAYER_VERSION = 134; 42 private static final int LAYER_SUBTYPE = 156; 43 44 private static final int DEPENDENT_LAYER_ID = 212; 45 private static final int DEPENDENT_LAYER_VERSION = 234; 46 private static final int DEPENDENT_LAYER_SUBTYPE = 256; 47 48 private static final int DIFFERENT_LAYER_ID = 99; 49 private static final int DIFFERENT_PUBLISHER_ID = 2; 50 51 private static final VmsLayer VMS_LAYER = new VmsLayer( 52 LAYER_ID, 53 LAYER_SUBTYPE, 54 LAYER_VERSION); 55 56 private static final VmsLayer DEPENDENT_VMS_LAYER = new VmsLayer( 57 DEPENDENT_LAYER_ID, 58 DEPENDENT_LAYER_SUBTYPE, 59 DEPENDENT_LAYER_VERSION); 60 61 private static final VmsLayer ANOTHER_DEPENDENT_VMS_LAYER = new VmsLayer( 62 DIFFERENT_LAYER_ID, 63 DEPENDENT_LAYER_SUBTYPE, 64 DEPENDENT_LAYER_VERSION); 65 66 private static final VmsLayerDependency VMS_LAYER_DEPENDENCY = 67 new VmsLayerDependency( 68 VMS_LAYER, 69 new HashSet<>(Arrays.asList(DEPENDENT_VMS_LAYER))); 70 71 private static final VmsLayerDependency ANOTHER_VMS_LAYER_DEPENDENCY = 72 new VmsLayerDependency( 73 VMS_LAYER, 74 new HashSet<>(Arrays.asList(ANOTHER_DEPENDENT_VMS_LAYER))); 75 76 public void testNoOfferingParcel() throws Exception { 77 VmsLayersOffering vmsLayersOffering = 78 new VmsLayersOffering(new HashSet<>(Arrays.asList()), PUBLISHER_ID); 79 80 Parcel parcel = Parcel.obtain(); 81 vmsLayersOffering.writeToParcel(parcel, vmsLayersOffering.describeContents()); 82 parcel.setDataPosition(0); 83 VmsLayersOffering createdFromParcel = VmsLayersOffering.CREATOR.createFromParcel(parcel); 84 assertEquals(vmsLayersOffering, createdFromParcel); 85 } 86 87 public void testMultipleOfferingParcel() throws Exception { 88 VmsLayersOffering vmsLayersOffering = 89 new VmsLayersOffering( 90 new HashSet<>(Arrays.asList( 91 VMS_LAYER_DEPENDENCY, 92 ANOTHER_VMS_LAYER_DEPENDENCY)), 93 PUBLISHER_ID); 94 95 Parcel parcel = Parcel.obtain(); 96 vmsLayersOffering.writeToParcel(parcel, vmsLayersOffering.describeContents()); 97 parcel.setDataPosition(0); 98 VmsLayersOffering createdFromParcel = VmsLayersOffering.CREATOR.createFromParcel(parcel); 99 100 assertEquals(vmsLayersOffering, createdFromParcel); 101 } 102 103 public void testNoOfferingEquality() throws Exception { 104 VmsLayersOffering original = 105 new VmsLayersOffering( 106 new HashSet<>(Arrays.asList()), PUBLISHER_ID); 107 108 VmsLayersOffering similar = 109 new VmsLayersOffering( 110 new HashSet<>(Arrays.asList()), PUBLISHER_ID); 111 112 assertEquals(original.getDependencies(), similar.getDependencies()); 113 assertEquals(original.getPublisherId(), similar.getPublisherId()); 114 assertEquals(original, similar); 115 } 116 117 public void testMultipleOfferingEquality() throws Exception { 118 VmsLayersOffering original = 119 new VmsLayersOffering( 120 new HashSet<>(Arrays.asList(VMS_LAYER_DEPENDENCY, ANOTHER_VMS_LAYER_DEPENDENCY)), PUBLISHER_ID); 121 122 VmsLayersOffering similar = 123 new VmsLayersOffering( 124 new HashSet<>(Arrays.asList(VMS_LAYER_DEPENDENCY, ANOTHER_VMS_LAYER_DEPENDENCY)), PUBLISHER_ID); 125 126 assertEquals(original.getDependencies(), similar.getDependencies()); 127 assertEquals(original.getPublisherId(), similar.getPublisherId()); 128 assertEquals(original, similar); 129 } 130 131 public void testVerifyNonEqualOnPublisherId() throws Exception { 132 VmsLayersOffering original = 133 new VmsLayersOffering( 134 new HashSet<>(Arrays.asList(VMS_LAYER_DEPENDENCY)), PUBLISHER_ID); 135 136 VmsLayersOffering similar = 137 new VmsLayersOffering( 138 new HashSet<>(Arrays.asList(VMS_LAYER_DEPENDENCY)), DIFFERENT_PUBLISHER_ID); 139 140 assertNotEquals(original, similar); 141 } 142 143 public void testVerifyNonEqualOnDependency() throws Exception { 144 VmsLayersOffering original = 145 new VmsLayersOffering( 146 new HashSet<>(Arrays.asList(VMS_LAYER_DEPENDENCY)), PUBLISHER_ID); 147 148 VmsLayersOffering similar = 149 new VmsLayersOffering( 150 new HashSet<>(Arrays.asList(ANOTHER_VMS_LAYER_DEPENDENCY)), PUBLISHER_ID); 151 152 assertNotEquals(original, similar); 153 } 154 } 155