OSDN Git Service

original
[gb-231r1-is01/GB_2.3_IS01.git] / sdk / sdkmanager / libs / sdklib / tests / com / android / sdklib / internal / repository / MockPlatformPackage.java
diff --git a/sdk/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockPlatformPackage.java b/sdk/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockPlatformPackage.java
new file mode 100644 (file)
index 0000000..0a58487
--- /dev/null
@@ -0,0 +1,184 @@
+/*\r
+ * Copyright (C) 2009 The Android Open Source Project\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package com.android.sdklib.internal.repository;\r
+\r
+import com.android.sdklib.AndroidVersion;\r
+import com.android.sdklib.IAndroidTarget;\r
+\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+/**\r
+ * A mock {@link PlatformPackage} for testing.\r
+ *\r
+ * By design, this package contains one and only one archive.\r
+ */\r
+public class MockPlatformPackage extends PlatformPackage {\r
+\r
+    private final IAndroidTarget mTarget;\r
+\r
+    /**\r
+     * Creates a {@link MockPlatformTarget} with the requested API and revision\r
+     * and then a {@link MockPlatformPackage} wrapping it.\r
+     *\r
+     * By design, this package contains one and only one archive.\r
+     */\r
+    public MockPlatformPackage(int apiLevel, int revision) {\r
+        this(new MockPlatformTarget(apiLevel, revision), null /*props*/);\r
+    }\r
+\r
+    /**\r
+     * Creates a {@link MockPlatformTarget} with the requested API and revision\r
+     * and then a {@link MockPlatformPackage} wrapping it.\r
+     *\r
+     * Also sets the min-tools-rev of the platform.\r
+     *\r
+     * By design, this package contains one and only one archive.\r
+     */\r
+    public MockPlatformPackage(int apiLevel, int revision, int min_tools_rev) {\r
+        this(new MockPlatformTarget(apiLevel, revision), createProps(min_tools_rev));\r
+    }\r
+\r
+    /** A little trick to be able to capture the target new after passing it to the super. */\r
+    private MockPlatformPackage(IAndroidTarget target, Properties props) {\r
+        super(target, props);\r
+        mTarget = target;\r
+    }\r
+\r
+    private static Properties createProps(int min_tools_rev) {\r
+        Properties props = new Properties();\r
+        props.setProperty(PlatformPackage.PROP_MIN_TOOLS_REV, Integer.toString((min_tools_rev)));\r
+        return props;\r
+    }\r
+\r
+    public IAndroidTarget getTarget() {\r
+        return mTarget;\r
+    }\r
+\r
+    /**\r
+     * A mock PlatformTarget.\r
+     * This reimplements the minimum needed from the interface for our limited testing needs.\r
+     */\r
+    static class MockPlatformTarget implements IAndroidTarget {\r
+\r
+        private final int mApiLevel;\r
+        private final int mRevision;\r
+\r
+        public MockPlatformTarget(int apiLevel, int revision) {\r
+            mApiLevel = apiLevel;\r
+            mRevision = revision;\r
+\r
+        }\r
+\r
+        public String getClasspathName() {\r
+            return null;\r
+        }\r
+\r
+        public String getDefaultSkin() {\r
+            return null;\r
+        }\r
+\r
+        public String getDescription() {\r
+            return "mock platform target";\r
+        }\r
+\r
+        public String getFullName() {\r
+            return "mock platform target";\r
+        }\r
+\r
+        public String getLocation() {\r
+            return "";\r
+        }\r
+\r
+        public String getName() {\r
+            return "mock platform target";\r
+        }\r
+\r
+        public IOptionalLibrary[] getOptionalLibraries() {\r
+            return null;\r
+        }\r
+\r
+        public IAndroidTarget getParent() {\r
+            return null;\r
+        }\r
+\r
+        public String getPath(int pathId) {\r
+            return null;\r
+        }\r
+\r
+        public String[] getPlatformLibraries() {\r
+            return null;\r
+        }\r
+\r
+        public String getProperty(String name) {\r
+            return null;\r
+        }\r
+\r
+        public Integer getProperty(String name, Integer defaultValue) {\r
+            return defaultValue;\r
+        }\r
+\r
+        public Boolean getProperty(String name, Boolean defaultValue) {\r
+            return defaultValue;\r
+        }\r
+\r
+        public Map<String, String> getProperties() {\r
+            return null;\r
+        }\r
+\r
+        public int getRevision() {\r
+            return mRevision;\r
+        }\r
+\r
+        public String[] getSkins() {\r
+            return null;\r
+        }\r
+\r
+        public int getUsbVendorId() {\r
+            return 0;\r
+        }\r
+\r
+        public String getVendor() {\r
+            return null;\r
+        }\r
+\r
+        public AndroidVersion getVersion() {\r
+            return new AndroidVersion(mApiLevel, null /*codename*/);\r
+        }\r
+\r
+        public String getVersionName() {\r
+            return String.format("android-%1$d", mApiLevel);\r
+        }\r
+\r
+        public String hashString() {\r
+            return getVersionName();\r
+        }\r
+\r
+        /** Returns true for a platform. */\r
+        public boolean isPlatform() {\r
+            return true;\r
+        }\r
+\r
+        public boolean canRunOn(IAndroidTarget target) {\r
+            throw new UnsupportedOperationException("Implement this as needed for tests");\r
+        }\r
+\r
+        public int compareTo(IAndroidTarget o) {\r
+            throw new UnsupportedOperationException("Implement this as needed for tests");\r
+        }\r
+    }\r
+}\r