1 /* 2 * Copyright (C) 2018 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 @file:Suppress("ALL") 18 19 package com.android.tools.metalava 20 21 import com.android.tools.metalava.lint.DefaultLintErrorMessage 22 import com.android.tools.metalava.testing.java 23 import org.junit.Test 24 25 class SdkFileWriterTest : DriverTest() { 26 @Test Test generating broadcast actionsnull27 fun `Test generating broadcast actions`() { 28 check( 29 expectedFail = DefaultLintErrorMessage, 30 expectedIssues = 31 """ 32 src/android/telephony/SubscriptionManager.java:11: error: Field 'ACTION_DEFAULT_SUBSCRIPTION_CHANGED' is missing @BroadcastBehavior [BroadcastBehavior] 33 """, 34 sourceFiles = 35 arrayOf( 36 java( 37 """ 38 package android.telephony; 39 40 import android.annotation.SdkConstant; 41 import android.annotation.SdkConstant.SdkConstantType; 42 43 public class SubscriptionManager { 44 /** 45 * Broadcast Action: The default subscription has changed. 46 */ 47 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 48 public static final String ACTION_DEFAULT_SUBSCRIPTION_CHANGED 49 = "android.telephony.action.DEFAULT_SUBSCRIPTION_CHANGED"; 50 } 51 """ 52 ), 53 sdkConstantSource 54 ), 55 sdkBroadcastActions = 56 """ 57 android.telephony.action.DEFAULT_SUBSCRIPTION_CHANGED 58 """ 59 ) 60 } 61 62 @Test Test generating activity actionsnull63 fun `Test generating activity actions`() { 64 check( 65 sourceFiles = 66 arrayOf( 67 java( 68 """ 69 package android.content; 70 71 import android.annotation.SdkConstant; 72 import android.annotation.SdkConstant.SdkConstantType; 73 74 public class Intent { 75 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 76 public static final String ACTION_MAIN = "android.intent.action.MAIN"; 77 } 78 """ 79 ), 80 sdkConstantSource 81 ), 82 sdkActivityActions = """ 83 android.intent.action.MAIN 84 """ 85 ) 86 } 87 88 @Test Test generating widgetsnull89 fun `Test generating widgets`() { 90 check( 91 sourceFiles = 92 arrayOf( 93 java( 94 """ 95 package android.widget; 96 97 import android.content.Context; 98 import android.annotation.Widget; 99 100 @Widget 101 public class MyButton extends android.view.View { 102 public MyButton(Context context) { 103 super(context, null); 104 } 105 } 106 """ 107 ), 108 widgetSource 109 ), 110 sdkWidgets = 111 """ 112 Wandroid.view.View java.lang.Object 113 Wandroid.widget.MyButton android.view.View java.lang.Object 114 """ 115 ) 116 } 117 } 118