1 /* 2 * Copyright (C) 2022 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.permission.safetylabel 18 19 import android.os.PersistableBundle 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createInvalidSafetyLabelPersistableBundle 22 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createSafetyLabelPersistableBundle 23 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createSafetyLabelPersistableBundleWithEmptyDataCollected 24 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createSafetyLabelPersistableBundleWithEmptyDataShared 25 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createSafetyLabelPersistableBundleWithInvalidDataCollected 26 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createSafetyLabelPersistableBundleWithInvalidDataShared 27 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createSafetyLabelPersistableBundleWithNullDataCollected 28 import com.android.permission.safetylabel.SafetyLabelTestPersistableBundles.createSafetyLabelPersistableBundleWithNullDataShared 29 import com.google.common.truth.Truth.assertThat 30 import org.junit.Test 31 import org.junit.runner.RunWith 32 33 /** CTS tests for [DataLabel]. */ 34 @RunWith(AndroidJUnit4::class) 35 class DataLabelTest { 36 @Test getDataLabel_nullBundle_nullDataLabelnull37 fun getDataLabel_nullBundle_nullDataLabel() { 38 val dataLabel: DataLabel? = DataLabel.getDataLabel(null) 39 40 assertThat(dataLabel).isNull() 41 } 42 43 @Test getDataLabel_emptyBundle_nullDataLabelnull44 fun getDataLabel_emptyBundle_nullDataLabel() { 45 val dataLabel: DataLabel? = DataLabel.getDataLabel(PersistableBundle.EMPTY) 46 47 assertThat(dataLabel).isNull() 48 } 49 50 @Test getDataLabel_invalidBundle_nullDataLabelnull51 fun getDataLabel_invalidBundle_nullDataLabel() { 52 val dataLabel: DataLabel? = 53 DataLabel.getDataLabel(createInvalidSafetyLabelPersistableBundle()) 54 55 assertThat(dataLabel).isNull() 56 } 57 58 @Test getDataLabel_nullDataCollectedBundle_dataCollectedEmptynull59 fun getDataLabel_nullDataCollectedBundle_dataCollectedEmpty() { 60 val dataLabel: DataLabel? = 61 DataLabel.getDataLabel(createSafetyLabelPersistableBundleWithNullDataCollected()) 62 63 assertThat(dataLabel).isNotNull() 64 assertThat(dataLabel?.dataCollected).isEmpty() 65 assertThat(dataLabel?.dataShared).isNotEmpty() 66 } 67 68 @Test getDataLabel_nullDataSharedBundle_dataSharedEmptynull69 fun getDataLabel_nullDataSharedBundle_dataSharedEmpty() { 70 val dataLabel: DataLabel? = 71 DataLabel.getDataLabel(createSafetyLabelPersistableBundleWithNullDataShared()) 72 73 assertThat(dataLabel).isNotNull() 74 assertThat(dataLabel?.dataCollected).isNotEmpty() 75 assertThat(dataLabel?.dataShared).isEmpty() 76 } 77 78 @Test getDataLabel_emptyDataCollectedBundle_dataCollectedEmptynull79 fun getDataLabel_emptyDataCollectedBundle_dataCollectedEmpty() { 80 val dataLabel: DataLabel? = 81 DataLabel.getDataLabel(createSafetyLabelPersistableBundleWithEmptyDataCollected()) 82 83 assertThat(dataLabel).isNotNull() 84 assertThat(dataLabel?.dataCollected).isEmpty() 85 assertThat(dataLabel?.dataShared).isNotEmpty() 86 } 87 88 @Test getDataLabel_emptyDataSharedBundle_dataSharedEmptynull89 fun getDataLabel_emptyDataSharedBundle_dataSharedEmpty() { 90 val dataLabel: DataLabel? = 91 DataLabel.getDataLabel(createSafetyLabelPersistableBundleWithEmptyDataShared()) 92 93 assertThat(dataLabel).isNotNull() 94 assertThat(dataLabel?.dataCollected).isNotEmpty() 95 assertThat(dataLabel?.dataShared).isEmpty() 96 } 97 98 @Test getDataLabel_invalidDataCollectedBundle_dataCollectedEmptynull99 fun getDataLabel_invalidDataCollectedBundle_dataCollectedEmpty() { 100 val dataLabel: DataLabel? = 101 DataLabel.getDataLabel(createSafetyLabelPersistableBundleWithInvalidDataCollected()) 102 103 assertThat(dataLabel).isNotNull() 104 assertThat(dataLabel?.dataCollected).isEmpty() 105 assertThat(dataLabel?.dataShared).isNotEmpty() 106 } 107 108 @Test getDataLabel_invalidDataSharedBundle_dataSharedEmptynull109 fun getDataLabel_invalidDataSharedBundle_dataSharedEmpty() { 110 val dataLabel: DataLabel? = 111 DataLabel.getDataLabel(createSafetyLabelPersistableBundleWithInvalidDataShared()) 112 113 assertThat(dataLabel).isNotNull() 114 assertThat(dataLabel?.dataCollected).isNotEmpty() 115 assertThat(dataLabel?.dataShared).isEmpty() 116 } 117 118 @Test getDataLabel_validBundlenull119 fun getDataLabel_validBundle() { 120 val dataLabel: DataLabel? = DataLabel.getDataLabel(createSafetyLabelPersistableBundle()) 121 122 assertThat(dataLabel).isNotNull() 123 assertThat(dataLabel?.dataCollected).isNotEmpty() 124 assertThat(dataLabel?.dataShared).isNotEmpty() 125 } 126 } 127