1 /* 2 * Copyright (C) 2011 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.sdklib; 18 19 20 import com.android.sdklib.ISystemImage.LocationType; 21 import com.android.sdklib.SdkManager.LayoutlibVersion; 22 23 import java.util.Arrays; 24 import java.util.regex.Pattern; 25 26 public class SdkManagerTest extends SdkManagerTestCase { 27 28 @SuppressWarnings("deprecation") 29 public void testSdkManager_LayoutlibVersion() { 30 SdkManager sdkman = getSdkManager(); 31 IAndroidTarget t = sdkman.getTargets()[0]; 32 33 assertTrue(t instanceof PlatformTarget); 34 35 LayoutlibVersion lv = ((PlatformTarget) t).getLayoutlibVersion(); 36 assertNotNull(lv); 37 assertEquals(5, lv.getApi()); 38 assertEquals(2, lv.getRevision()); 39 40 assertSame(lv, sdkman.getMaxLayoutlibVersion()); 41 } 42 43 public void testSdkManager_SystemImage() throws Exception { 44 SdkManager sdkman = getSdkManager(); 45 assertEquals("[PlatformTarget API 0 rev 1]", Arrays.toString(sdkman.getTargets())); 46 IAndroidTarget t = sdkman.getTargets()[0]; 47 48 // By default SdkManagerTestCase creates an SDK with one platform containing 49 // a legacy armeabi system image. 50 assertEquals( 51 "[SystemImage ABI=armeabi, location in platform legacy='$SDK/platforms/v0_0/images']", 52 cleanPath(sdkman, Arrays.toString(t.getSystemImages()))); 53 54 // Now add a few "platform subfolders" system images and reload the SDK. 55 // This disables the "legacy" mode, which means that although the armeabi 56 // target from above is present, it is no longer visible. 57 58 makeSystemImageFolder(new SystemImage( 59 sdkman, t, LocationType.IN_PLATFORM_SUBFOLDER, SdkConstants.ABI_ARMEABI_V7A)); 60 makeSystemImageFolder(new SystemImage( 61 sdkman, t, LocationType.IN_PLATFORM_SUBFOLDER, SdkConstants.ABI_INTEL_ATOM)); 62 63 sdkman.reloadSdk(getLog()); 64 assertEquals("[PlatformTarget API 0 rev 1]", Arrays.toString(sdkman.getTargets())); 65 t = sdkman.getTargets()[0]; 66 67 assertEquals( 68 "[SystemImage ABI=armeabi-v7a, location in platform subfolder='$SDK/platforms/v0_0/images/armeabi-v7a', " + 69 "SystemImage ABI=x86, location in platform subfolder='$SDK/platforms/v0_0/images/x86']", 70 cleanPath(sdkman, Arrays.toString(t.getSystemImages()))); 71 72 // Now add arm + arm v7a images using the new SDK/system-images. 73 // The x86 one from the platform subfolder is still visible. 74 // The armeabi one from the legacy folder is overridden by the new one. 75 // The armeabi-v7a one from the platform subfolder is overridden by the new one. 76 77 makeSystemImageFolder(new SystemImage( 78 sdkman, t, LocationType.IN_SYSTEM_IMAGE, SdkConstants.ABI_ARMEABI)); 79 makeSystemImageFolder(new SystemImage( 80 sdkman, t, LocationType.IN_SYSTEM_IMAGE, SdkConstants.ABI_ARMEABI_V7A)); 81 82 sdkman.reloadSdk(getLog()); 83 assertEquals("[PlatformTarget API 0 rev 1]", Arrays.toString(sdkman.getTargets())); 84 t = sdkman.getTargets()[0]; 85 86 assertEquals( 87 "[SystemImage ABI=armeabi, location in system image='$SDK/system-images/android-0/armeabi', " + 88 "SystemImage ABI=armeabi-v7a, location in system image='$SDK/system-images/android-0/armeabi-v7a', " + 89 "SystemImage ABI=x86, location in platform subfolder='$SDK/platforms/v0_0/images/x86']", 90 cleanPath(sdkman, Arrays.toString(t.getSystemImages()))); 91 } 92 93 public void testSdkManager_SystemImage_LegacyOverride() throws Exception { 94 SdkManager sdkman = getSdkManager(); 95 assertEquals("[PlatformTarget API 0 rev 1]", Arrays.toString(sdkman.getTargets())); 96 IAndroidTarget t = sdkman.getTargets()[0]; 97 98 // By default SdkManagerTestCase creates an SDK with one platform containing 99 // a legacy armeabi system image. 100 assertEquals( 101 "[SystemImage ABI=armeabi, location in platform legacy='$SDK/platforms/v0_0/images']", 102 cleanPath(sdkman, Arrays.toString(t.getSystemImages()))); 103 104 // Now add a different ABI system image in the new system-images folder. 105 // This does not hide the legacy one as long as the ABI type is different 106 // (to contrast: having at least one sub-folder in the platform's legacy images folder 107 // will hide the legacy system image. Whereas this does not happen with the new type.) 108 109 makeSystemImageFolder(new SystemImage( 110 sdkman, t, LocationType.IN_SYSTEM_IMAGE, SdkConstants.ABI_INTEL_ATOM)); 111 112 sdkman.reloadSdk(getLog()); 113 assertEquals("[PlatformTarget API 0 rev 1]", Arrays.toString(sdkman.getTargets())); 114 t = sdkman.getTargets()[0]; 115 116 assertEquals( 117 "[SystemImage ABI=armeabi, location in platform legacy='$SDK/platforms/v0_0/images', " + 118 "SystemImage ABI=x86, location in system image='$SDK/system-images/android-0/x86']", 119 cleanPath(sdkman, Arrays.toString(t.getSystemImages()))); 120 121 // Now if we have one new system-image using the same ABI type, it will override the 122 // legacy one. This gives us a good path for updates. 123 124 makeSystemImageFolder(new SystemImage( 125 sdkman, t, LocationType.IN_SYSTEM_IMAGE, SdkConstants.ABI_ARMEABI)); 126 127 128 sdkman.reloadSdk(getLog()); 129 assertEquals("[PlatformTarget API 0 rev 1]", Arrays.toString(sdkman.getTargets())); 130 t = sdkman.getTargets()[0]; 131 132 assertEquals( 133 "[SystemImage ABI=armeabi, location in system image='$SDK/system-images/android-0/armeabi', " + 134 "SystemImage ABI=x86, location in system image='$SDK/system-images/android-0/x86']", 135 cleanPath(sdkman, Arrays.toString(t.getSystemImages()))); 136 } 137 138 /** 139 * Sanitizes the paths used when testing results. 140 * <p/> 141 * The system image text representation contains the absolute path to the SDK. 142 * However the SDK path is actually a randomized location. 143 * We clean it by replacing it by the constant '$SDK'. 144 * Also all the Windows path separators are converted to unix-like / separators. 145 */ 146 private String cleanPath(SdkManager sdkman, String string) { 147 return string 148 .replaceAll(Pattern.quote(sdkman.getLocation()), "\\$SDK") //$NON-NLS-1$ 149 .replace('\\', '/'); 150 } 151 } 152