From 3a9e2b2b7b2e695d60979ecb3b72e49ec97ca27b Mon Sep 17 00:00:00 2001 From: Bob Badour Date: Wed, 6 May 2020 16:12:09 -0700 Subject: Remove all non-Apache2 licensed files from sdk Remove MODULE_LICENSE_APACHE2 Repositories containing third-party code need a METADATA and a license_type. Repositories containing only first-party code no longer need a MODULE_LICENSE_* file. Remove EPL-licensed eclipse plugin and attribute_stats. Remove CC-BY-SA licensed typos files. Bug: 68860345 Bug: 69058154 Bug: 151953481 Test: treehugger Test: https://android-build.googleplex.com/builds/forrest/run/L63500000550775268 Exempt-From-Owner-Approval: janitorial work Change-Id: I5fafa76de21fb0b46c82a2c07ac048afbee3df25 --- .../com/android/ide/eclipse/adt/AdtPluginTest.java | 49 -- .../com/android/ide/eclipse/adt/AdtUtilsTest.java | 127 --- .../adt/internal/build/BaseBuilderTest.java | 37 - .../editors/AndroidDoubleClickStrategyTest.java | 71 -- .../editors/descriptors/DescriptorsUtilsTest.java | 297 ------- .../draw9patch/graphics/GraphicsUtilitiesTest.java | 313 ------- .../draw9patch/graphics/NinePatchedImageTest.java | 914 --------------------- .../AndroidXmlFormattingStrategyTest.java | 335 -------- .../editors/layout/ExplodeRenderingHelperTest.java | 256 ------ .../editors/layout/UiElementPullParserTest.java | 256 ------ .../layout/configuration/ConfigurationTest.java | 143 ---- .../layout/configuration/FlagManagerTest.java | 185 ----- .../editors/layout/configuration/LocaleTest.java | 99 --- .../editors/layout/gle2/CanvasViewInfoTest.java | 797 ------------------ .../editors/layout/gle2/ControlPointTest.java | 73 -- .../editors/layout/gle2/DomUtilitiesTest.java | 206 ----- .../editors/layout/gle2/ImageUtilsTest.java | 368 --------- .../editors/layout/gle2/IncludeFinderTest.java | 128 --- .../editors/layout/gle2/IncludeOverlayTest.java | 75 -- .../editors/layout/gle2/LayoutPointTest.java | 64 -- .../editors/layout/gle2/PointTestCases.java | 107 --- .../editors/layout/gle2/RenderLoggerTest.java | 82 -- .../editors/layout/gle2/SelectionManagerTest.java | 120 --- .../editors/layout/gle2/SimpleAttributeTest.java | 109 --- .../editors/layout/gle2/SimpleElementTest.java | 343 -------- .../internal/editors/layout/gle2/SwtUtilsTest.java | 343 -------- .../internal/editors/layout/gre/MockNodeProxy.java | 68 -- .../editors/layout/gre/NodeFactoryTest.java | 123 --- .../editors/layout/gre/RulesEngineTest.java | 37 - .../layout/gre/ViewMetadataRepositoryTest.java | 77 -- .../layout/properties/ValueCompleterTest.java | 151 ---- .../editors/manifest/model/UiElementNodeTest.java | 284 ------- .../internal/editors/mock/MockNamedNodeMap.java | 112 --- .../adt/internal/editors/mock/MockNodeList.java | 62 -- .../adt/internal/editors/mock/MockXmlNode.java | 319 ------- .../editors/resources/manager/ConfigMatchTest.java | 297 ------- .../adt/internal/project/ProjectHelperTest.java | 66 -- .../core/AndroidTypeMoveParticipantTest.java | 135 --- .../core/AndroidTypeRenameParticipantTest.java | 160 ---- .../core/RenameResourceXmlTextActionTest.java | 110 --- .../adt/internal/resources/ResourceHelperTest.java | 183 ----- .../resources/ResourceNameValidatorTest.java | 101 --- .../resources/manager/IdeScanningContextTest.java | 22 - .../adt/internal/sdk/AndroidJarLoaderTest.java | 166 ---- .../adt/internal/sdk/LayoutParamsParserTest.java | 182 ---- .../templates/FmActivityToLayoutMethodTest.java | 50 -- .../FmCamelCaseToUnderscoreMethodTest.java | 58 -- .../templates/FmClassNameToResourceMethodTest.java | 66 -- .../templates/FmEscapeXmlAttributeMethodTest.java | 50 -- .../templates/FmEscapeXmlStringMethodTest.java | 66 -- .../templates/FmEscapeXmlTextMethodTest.java | 46 -- .../templates/FmExtractLettersMethodTest.java | 46 -- .../templates/FmLayoutToActivityMethodTest.java | 54 -- .../templates/FmSlashedPackageNameMethodTest.java | 50 -- .../FmUnderscoreToCamelCaseMethodTest.java | 58 -- .../com/android/ide/eclipse/mock/Mocks.java | 189 ----- .../com/android/ide/eclipse/mock/TestLogger.java | 54 -- .../testdata/draw9patch/content-area-one-dot.9.png | Bin 206 -> 0 bytes .../draw9patch/content-area-two-dots.9.png | Bin 214 -> 0 bytes .../eclipse/testdata/draw9patch/content-area.9.png | Bin 210 -> 0 bytes .../testdata/draw9patch/invalid-patched1.9.png | Bin 2923 -> 0 bytes .../testdata/draw9patch/invalid-patched2.9.png | Bin 2913 -> 0 bytes .../testdata/draw9patch/invalid-patched3.9.png | Bin 2914 -> 0 bytes .../testdata/draw9patch/invalid-patched4.9.png | Bin 2914 -> 0 bytes .../testdata/draw9patch/invalid-patched5.9.png | Bin 2929 -> 0 bytes .../testdata/draw9patch/invalid-patched6.9.png | Bin 2920 -> 0 bytes .../testdata/draw9patch/invalid-patched7.9.png | Bin 2916 -> 0 bytes .../testdata/draw9patch/invalid-patched8.9.png | Bin 2923 -> 0 bytes .../testdata/draw9patch/layout-bounds-only.9.png | Bin 1466 -> 0 bytes .../testdata/draw9patch/no-patched-interlace.png | Bin 3138 -> 0 bytes .../ide/eclipse/testdata/draw9patch/no-patched.png | Bin 2906 -> 0 bytes .../draw9patch/patched-with-badpatches.9.png | Bin 214 -> 0 bytes .../ide/eclipse/testdata/draw9patch/patched1.9.png | Bin 210 -> 0 bytes .../ide/eclipse/testdata/draw9patch/patched2.9.png | Bin 217 -> 0 bytes .../ide/eclipse/testdata/draw9patch/patched3.9.png | Bin 214 -> 0 bytes .../android/ide/eclipse/testdata/jar_example.jar | Bin 1829 -> 0 bytes .../ide/eclipse/testdata/jar_example.jardesc | 16 - .../android/ide/eclipse/testdata/mock_attrs.xml | 340 -------- .../ide/eclipse/testdata/mock_manifest_attrs.xml | 180 ---- 79 files changed, 9875 deletions(-) delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtPluginTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/build/BaseBuilderTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/AndroidDoubleClickStrategyTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/GraphicsUtilitiesTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/NinePatchedImageTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/formatting/AndroidXmlFormattingStrategyTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/ExplodeRenderingHelperTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManagerTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/LocaleTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ControlPointTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilitiesTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/IncludeFinderTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/IncludeOverlayTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutPointTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PointTestCases.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderLoggerTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManagerTest.java delete mode 100755 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SimpleAttributeTest.java delete mode 100755 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SimpleElementTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SwtUtilsTest.java delete mode 100755 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/MockNodeProxy.java delete mode 100755 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/NodeFactoryTest.java delete mode 100755 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/RulesEngineTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/ViewMetadataRepositoryTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/properties/ValueCompleterTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiElementNodeTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNamedNodeMap.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNodeList.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockXmlNode.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/manager/ConfigMatchTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/project/ProjectHelperTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeMoveParticipantTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeRenameParticipantTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceHelperTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/ResourceNameValidatorTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/resources/manager/IdeScanningContextTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoaderTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/sdk/LayoutParamsParserTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmActivityToLayoutMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmCamelCaseToUnderscoreMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmClassNameToResourceMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmEscapeXmlAttributeMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmEscapeXmlStringMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmEscapeXmlTextMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmExtractLettersMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmLayoutToActivityMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmSlashedPackageNameMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/wizards/templates/FmUnderscoreToCamelCaseMethodTest.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/mock/Mocks.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/mock/TestLogger.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/content-area-one-dot.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/content-area-two-dots.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/content-area.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched1.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched2.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched3.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched4.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched5.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched6.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched7.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/invalid-patched8.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/layout-bounds-only.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/no-patched-interlace.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/no-patched.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/patched-with-badpatches.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/patched1.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/patched2.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/draw9patch/patched3.9.png delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/jar_example.jar delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/jar_example.jardesc delete mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/mock_attrs.xml delete mode 100755 eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/mock_manifest_attrs.xml (limited to 'eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse') diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtPluginTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtPluginTest.java deleted file mode 100644 index e198c6e4b..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtPluginTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.ide.eclipse.adt; - -import java.io.File; -import java.io.StringReader; - -import junit.framework.TestCase; - -public class AdtPluginTest extends TestCase { - public void testReaderContains() throws Exception { - String input = "this is a test"; - assertFalse(AdtPlugin.streamContains(new StringReader(input), "hello")); - assertTrue(AdtPlugin.streamContains(new StringReader(input), "this")); - assertFalse(AdtPlugin.streamContains(new StringReader(input), "thiss")); - assertTrue(AdtPlugin.streamContains(new StringReader(input), "is a")); - assertTrue(AdtPlugin.streamContains(new StringReader("ABC ABCDAB ABCDABCDABDE"), - "ABCDABD")); - assertFalse(AdtPlugin.streamContains(new StringReader("ABC ABCDAB ABCDABCDABDE"), - "ABCEABD")); - } - - public void testReadStream() throws Exception { - String input = "this is a test"; - String contents = AdtPlugin.readFile(new StringReader(input)); - assertEquals(input, contents); - } - - public void testReadWriteFile() throws Exception { - File temp = File.createTempFile("test", ".txt"); - String myContent = "this is\na test"; - AdtPlugin.writeFile(temp, myContent); - String readBack = AdtPlugin.readFile(temp); - assertEquals(myContent, readBack); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java deleted file mode 100644 index c1e94ac69..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.ide.eclipse.adt; - -import junit.framework.TestCase; - -import java.util.Locale; - -@SuppressWarnings("javadoc") -public class AdtUtilsTest extends TestCase { - public void testExtractClassName() { - assertEquals("Foo", AdtUtils.extractClassName("foo")); - assertEquals("Foobar", AdtUtils.extractClassName("foo bar")); - assertEquals("JavasTypeSystem", AdtUtils.extractClassName("Java's Type System")); - assertEquals("Foo", AdtUtils.extractClassName("1foo ")); - } - - public void testStripAllExtensions() { - assertEquals("", AdtUtils.stripAllExtensions("")); - assertEquals("foobar", AdtUtils.stripAllExtensions("foobar")); - assertEquals("foobar", AdtUtils.stripAllExtensions("foobar.png")); - assertEquals("foobar", AdtUtils.stripAllExtensions("foobar.9.png")); - assertEquals(".profile", AdtUtils.stripAllExtensions(".profile")); - } - - public void testStripLastExtension() { - assertEquals("", AdtUtils.stripLastExtension("")); - assertEquals("foobar", AdtUtils.stripLastExtension("foobar")); - assertEquals("foobar", AdtUtils.stripLastExtension("foobar.png")); - assertEquals("foobar.9", AdtUtils.stripLastExtension("foobar.9.png")); - assertEquals(".profile", AdtUtils.stripLastExtension(".profile")); - } - - public void testCapitalize() { - assertEquals("UPPER", AdtUtils.capitalize("UPPER")); - assertEquals("Lower", AdtUtils.capitalize("lower")); - assertEquals("Capital", AdtUtils.capitalize("Capital")); - assertEquals("CamelCase", AdtUtils.capitalize("camelCase")); - assertEquals("", AdtUtils.capitalize("")); - assertSame("Foo", AdtUtils.capitalize("Foo")); - assertNull(null, AdtUtils.capitalize(null)); - } - - public void testCamelCaseToUnderlines() { - assertEquals("", AdtUtils.camelCaseToUnderlines("")); - assertEquals("foo", AdtUtils.camelCaseToUnderlines("foo")); - assertEquals("foo", AdtUtils.camelCaseToUnderlines("Foo")); - assertEquals("foo_bar", AdtUtils.camelCaseToUnderlines("FooBar")); - assertEquals("test_xml", AdtUtils.camelCaseToUnderlines("testXML")); - assertEquals("test_foo", AdtUtils.camelCaseToUnderlines("testFoo")); - } - - public void testUnderlinesToCamelCase() { - assertEquals("", AdtUtils.underlinesToCamelCase("")); - assertEquals("", AdtUtils.underlinesToCamelCase("_")); - assertEquals("Foo", AdtUtils.underlinesToCamelCase("foo")); - assertEquals("FooBar", AdtUtils.underlinesToCamelCase("foo_bar")); - assertEquals("FooBar", AdtUtils.underlinesToCamelCase("foo__bar")); - assertEquals("Foo", AdtUtils.underlinesToCamelCase("foo_")); - } - - public void testStripSuffix() { - assertEquals("Foo", AdtUtils.stripSuffix("Foo", "")); - assertEquals("Fo", AdtUtils.stripSuffix("Foo", "o")); - assertEquals("F", AdtUtils.stripSuffix("Fo", "o")); - assertEquals("", AdtUtils.stripSuffix("Foo", "Foo")); - assertEquals("LinearLayout_Layout", - AdtUtils.stripSuffix("LinearLayout_LayoutParams", "Params")); - assertEquals("Foo", AdtUtils.stripSuffix("Foo", "Bar")); - } - - public void testFormatFloatValue() throws Exception { - assertEquals("1", AdtUtils.formatFloatAttribute(1.0f)); - assertEquals("2", AdtUtils.formatFloatAttribute(2.0f)); - assertEquals("1.50", AdtUtils.formatFloatAttribute(1.5f)); - assertEquals("1.50", AdtUtils.formatFloatAttribute(1.50f)); - assertEquals("1.51", AdtUtils.formatFloatAttribute(1.51f)); - assertEquals("1.51", AdtUtils.formatFloatAttribute(1.514542f)); - assertEquals("1.52", AdtUtils.formatFloatAttribute(1.516542f)); - assertEquals("-1.51", AdtUtils.formatFloatAttribute(-1.51f)); - assertEquals("-1", AdtUtils.formatFloatAttribute(-1f)); - } - - public void testFormatFloatValueLocale() throws Exception { - // Ensure that the layout float values aren't affected by - // locale settings, like using commas instead of of periods - Locale originalDefaultLocale = Locale.getDefault(); - - try { - Locale.setDefault(Locale.FRENCH); - - // Ensure that this is a locale which uses a comma instead of a period: - assertEquals("5,24", String.format("%.2f", 5.236f)); - - // Ensure that the formatFloatAttribute is immune - assertEquals("1.50", AdtUtils.formatFloatAttribute(1.5f)); - } finally { - Locale.setDefault(originalDefaultLocale); - } - } - - public void testEscapeUnicodeChars() throws Exception { - assertEquals("", AdtUtils.replaceUnicodeEscapes("")); - assertEquals("foo bar", AdtUtils.replaceUnicodeEscapes("foo bar")); - assertEquals("\u25C0", AdtUtils.replaceUnicodeEscapes("\\u25C0")); - assertEquals("!\u25C0\u25C1!", AdtUtils.replaceUnicodeEscapes("!\\u25C0\\u25C1!")); - assertEquals("\u1234\\", AdtUtils.replaceUnicodeEscapes("\\u1234\\")); - - assertEquals("\\U25C0", AdtUtils.replaceUnicodeEscapes("\\U25C0")); // no unicode expand - assertEquals("\\u25C", AdtUtils.replaceUnicodeEscapes("\\u25C")); // no unicode expand - assertEquals("\\\\u25C0", AdtUtils.replaceUnicodeEscapes("\\\\u25C0")); // escaped - assertEquals("\\u123\\", AdtUtils.replaceUnicodeEscapes("\\u123\\")); // broken - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/build/BaseBuilderTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/build/BaseBuilderTest.java deleted file mode 100644 index a1d658b97..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/build/BaseBuilderTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.ide.eclipse.adt.internal.build; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import junit.framework.TestCase; - -public class BaseBuilderTest extends TestCase { - - public void testParseAaptOutput() { - Pattern p = Pattern.compile( "^(.+):(\\d+):\\s(.+)$"); //$NON-NLS-1$ - String s = "C:\\java\\workspace-android\\AndroidApp\\res\\values\\strings.xml:11: WARNING: empty 'some warning text"; - - Matcher m = p.matcher(s); - assertEquals(true, m.matches()); - assertEquals("C:\\java\\workspace-android\\AndroidApp\\res\\values\\strings.xml", m.group(1)); - assertEquals("11", m.group(2)); - assertEquals("WARNING: empty 'some warning text", m.group(3)); - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/AndroidDoubleClickStrategyTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/AndroidDoubleClickStrategyTest.java deleted file mode 100644 index 3c0805a34..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/AndroidDoubleClickStrategyTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.ide.eclipse.adt.internal.editors; - -import org.eclipse.swt.graphics.Point; - -import junit.framework.TestCase; - -@SuppressWarnings("javadoc") -public class AndroidDoubleClickStrategyTest extends TestCase { - public void test_getWord_plain() throws Exception { - checkWord("^foo", "[foo]"); - checkWord("'fo^o'", "'[foo]'"); - checkWord("\"foo^\"", "\"[foo]\""); - } - - public void test_getWord_resources() throws Exception { - checkWord("'@and^roid:string/ok'", "'[@android:string/ok]'"); - checkWord("'@android^:string/ok'", "'[@android:string/ok]'"); - checkWord("'^@android:string/ok'", "'[@android:string/ok]'"); - checkWord("'@android:^string/ok'", "'[@android:string/ok]'"); - checkWord("'@android:string^/ok'", "'[@android:string/ok]'"); - checkWord("'@android:string/^ok'", "'@android:string/[ok]'"); - checkWord("'@android:string/o^k'", "'@android:string/[ok]'"); - checkWord("'@android:string/ok^'", "'@android:string/[ok]'"); - checkWord("'@string/ok^'", "'@string/[ok]'"); - checkWord("'@str^ing/ok'", "'[@string/ok]'"); - } - - public void test_getWord_classnames() throws Exception { - checkWord("\"co^m.example.templatetest1\"", "\"[com.example.templatetest1]\""); - checkWord("\"com.exam^ple.templatetest1\"", "\"[com.example.templatetest1]\""); - checkWord("\"com.example^.templatetest1\"", "\"[com.example.templatetest1]\""); - checkWord("\"com.example.templat^etest1\"", "\"com.example.[templatetest1]\""); - checkWord("\"com.example.^templatetest1\"", "\"com.example.[templatetest1]\""); - checkWord("\"com.example.templatetest1^\"", "\"com.example.[templatetest1]\""); - checkWord("\"...^\"", "\"[...]\""); - checkWord("\"..^.\"", "\"[...]\""); - } - - private void checkWord(String before, String expected) throws Exception { - AndroidDoubleClickStrategy strategy = new AndroidDoubleClickStrategy(); - int cursor = before.indexOf('^'); - assertTrue("Must set cursor position with ^ in " + before, cursor != -1); - before = before.substring(0, cursor) + before.substring(cursor + 1); - assertEquals(-1, before.indexOf('^')); - assertEquals(-1, before.indexOf('[')); - assertEquals(-1, before.indexOf(']')); - - Point positions = strategy.getWord(before, cursor); - assertNotNull(positions); - assertTrue(positions.y >= positions.x); - String after = before.substring(0, positions.x) + '[' + - before.substring(positions.x, positions.y) + ']' + - before.substring(positions.y); - assertEquals(expected, after); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java deleted file mode 100644 index 03db18956..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtilsTest.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.android.ide.eclipse.adt.internal.editors.descriptors; - -import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import junit.framework.TestCase; - -/** - * Unit tests for DescriptorsUtils in the editors plugin - */ -@SuppressWarnings("javadoc") -public class DescriptorsUtilsTest extends TestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testPrettyAttributeUiName() { - assertEquals("", DescriptorsUtils.prettyAttributeUiName("")); - - assertEquals("Max width for view", - DescriptorsUtils.prettyAttributeUiName("maxWidthForView")); - - assertEquals("Layout width", - DescriptorsUtils.prettyAttributeUiName("layout_width")); - - // X Y and Z are capitalized when used as single words (so "T" becomes "t") - assertEquals("Axis X", DescriptorsUtils.prettyAttributeUiName("axisX")); - assertEquals("Axis Y", DescriptorsUtils.prettyAttributeUiName("axisY")); - assertEquals("Axis Z", DescriptorsUtils.prettyAttributeUiName("axisZ")); - assertEquals("Axis t", DescriptorsUtils.prettyAttributeUiName("axisT")); - - assertEquals("The X axis", DescriptorsUtils.prettyAttributeUiName("theXAxis")); - assertEquals("The Y axis", DescriptorsUtils.prettyAttributeUiName("theYAxis")); - assertEquals("The Z axis", DescriptorsUtils.prettyAttributeUiName("theZAxis")); - assertEquals("The t axis", DescriptorsUtils.prettyAttributeUiName("theTAxis")); - - // Special cases for "uri" and "sdk" etc - assertEquals("Grant URI permission", - DescriptorsUtils.prettyAttributeUiName("grantUriPermission")); - assertEquals("URI permission", - DescriptorsUtils.prettyAttributeUiName("uriPermission")); - assertEquals("Min SDK version", DescriptorsUtils.prettyAttributeUiName("minSdkVersion")); - assertEquals("SDK version", DescriptorsUtils.prettyAttributeUiName("sdkVersion")); - assertEquals("IME action method", - DescriptorsUtils.prettyAttributeUiName("imeActionMethod")); - assertEquals("VM safe mode", DescriptorsUtils.prettyAttributeUiName("vmSafeMode")); - assertEquals("UI options", DescriptorsUtils.prettyAttributeUiName("uiOptions")); - } - - public void testCapitalize() { - assertEquals("", DescriptorsUtils.capitalize("")); - - assertEquals("Max Width For View", - DescriptorsUtils.capitalize("maxWidthForView")); - - assertEquals("Layout Width", - DescriptorsUtils.capitalize("layout_width")); - - assertEquals("Axis X", DescriptorsUtils.capitalize("axisX")); - assertEquals("Axis Y", DescriptorsUtils.capitalize("axisY")); - assertEquals("Axis Z", DescriptorsUtils.capitalize("axisZ")); - assertEquals("Axis T", DescriptorsUtils.capitalize("axisT")); - - assertEquals("The X Axis", DescriptorsUtils.capitalize("theXAxis")); - assertEquals("The Y Axis", DescriptorsUtils.capitalize("theYAxis")); - assertEquals("The Z Axis", DescriptorsUtils.capitalize("theZAxis")); - assertEquals("The T Axis", DescriptorsUtils.capitalize("theTAxis")); - - // Special cases for "uri" and "sdk" etc - assertEquals("Grant URI Permission", DescriptorsUtils.capitalize("grantUriPermission")); - assertEquals("Min SDK Version", DescriptorsUtils.capitalize("minSdkVersion")); - assertEquals("IME Action Method", DescriptorsUtils.capitalize("imeActionMethod")); - assertEquals("URI Permission", DescriptorsUtils.capitalize("uriPermission")); - assertEquals("SDK Version", DescriptorsUtils.capitalize("sdkVersion")); - assertEquals("Grant IME", DescriptorsUtils.capitalize("GrantIme")); - assertEquals("VM Safe Mode", DescriptorsUtils.capitalize("vmSafeMode")); - assertEquals("UI Options", DescriptorsUtils.capitalize("uiOptions")); - } - - public void testFormatTooltip() { - assertEquals("", DescriptorsUtils.formatTooltip("")); - - assertEquals("\"application\"", - DescriptorsUtils.formatTooltip( - "application")); - - assertEquals("android.content.Intent", - DescriptorsUtils.formatTooltip( - "{@link android.content.Intent}")); - - assertEquals("FLAG_ACTIVITY_SINGLE_TOP", - DescriptorsUtils.formatTooltip( - "{@link android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP}")); - - assertEquals("activity-alias", - DescriptorsUtils.formatTooltip( - "{@link \t #AndroidManifestActivityAlias \tactivity-alias }")); - - assertEquals("\"permission\"", - DescriptorsUtils.formatTooltip( - "{@link #AndroidManifestPermission <permission>}")); - - assertEquals("and etc.", - DescriptorsUtils.formatTooltip( - "{@link #IntentCategory and etc. }")); - - assertEquals("Activity.onNewIntent()", - DescriptorsUtils.formatTooltip( - "{@link android.app.Activity#onNewIntent Activity.onNewIntent()}")); - } - - public void testFormatFormText() { - ElementDescriptor desc = new ElementDescriptor("application"); - desc.setSdkUrl(DescriptorsUtils.MANIFEST_SDK_URL + "TagApplication"); - String docBaseUrl = "http://base"; - assertEquals("
  • ", DescriptorsUtils.formatFormText("", desc, docBaseUrl)); - - assertEquals("
  • application
  • ", - DescriptorsUtils.formatFormText( - "application", - desc, docBaseUrl)); - - assertEquals("
  • android.content.Intent
  • ", - DescriptorsUtils.formatFormText( - "{@link android.content.Intent}", - desc, docBaseUrl)); - - assertEquals("
  • AndroidManifestPermission
  • ", - DescriptorsUtils.formatFormText( - "{@link #AndroidManifestPermission}", - desc, docBaseUrl)); - - assertEquals("
  • \"permission\"
  • ", - DescriptorsUtils.formatFormText( - "{@link #AndroidManifestPermission <permission>}", - desc, docBaseUrl)); - } - - public void testGetFreeWidgetId() throws Exception { - DocumentDescriptor documentDescriptor = - new DocumentDescriptor("layout_doc", null); //$NON-NLS-1$ - UiDocumentNode model = new UiDocumentNode(documentDescriptor); - UiElementNode uiRoot = model.getUiRoot(); - - assertEquals("@+id/button1", DescriptorsUtils.getFreeWidgetId(uiRoot, "Button")); - assertEquals("@+id/linearLayout1", - DescriptorsUtils.getFreeWidgetId(uiRoot, "LinearLayout")); - } - - public void testNeedsDefaultId() throws Exception { - assertTrue(DescriptorsUtils.needsDefaultId(new ElementDescriptor("Button"))); - assertTrue(DescriptorsUtils.needsDefaultId(new ElementDescriptor("EditText"))); - assertTrue(DescriptorsUtils.needsDefaultId(new ElementDescriptor("TextView"))); - - assertFalse(DescriptorsUtils.needsDefaultId(new ElementDescriptor("LinearLayout"))); - assertFalse(DescriptorsUtils.needsDefaultId(new ElementDescriptor("GridLayout"))); - assertFalse(DescriptorsUtils.needsDefaultId(new ElementDescriptor("RelativeLayout"))); - assertFalse(DescriptorsUtils.needsDefaultId(new ElementDescriptor("include"))); - assertFalse(DescriptorsUtils.needsDefaultId(new ElementDescriptor("merge"))); - assertFalse(DescriptorsUtils.needsDefaultId(new ElementDescriptor("fragment"))); - assertFalse(DescriptorsUtils.needsDefaultId(new ElementDescriptor("Space"))); - } - - private static ViewElementDescriptor createDesc(String name, String fqn, boolean hasChildren) { - if (hasChildren) { - return new ViewElementDescriptor(name, name, fqn, "", "", new AttributeDescriptor[0], - new AttributeDescriptor[0], new ElementDescriptor[1], false); - } else { - return new ViewElementDescriptor(name, fqn); - } - } - - public void testCanInsertChildren() throws Exception { - assertFalse(DescriptorsUtils.canInsertChildren(createDesc("android:Button", - "android.widget.Button", false), null)); - assertTrue(DescriptorsUtils.canInsertChildren(createDesc("android:LinearLayout", - "android.view.LinearLayout", true), null)); - assertFalse(DescriptorsUtils.canInsertChildren(createDesc("android:ListView", - "android.widget.ListView", true), null)); - assertFalse(DescriptorsUtils.canInsertChildren(createDesc("android:ExpandableListView", - "android.widget.ExpandableListView", true), null)); - assertFalse(DescriptorsUtils.canInsertChildren(createDesc("android:Gallery", - "android.widget.Gallery", true), null)); - assertFalse(DescriptorsUtils.canInsertChildren(createDesc("android:GridView", - "android.widget.GridView", true), null)); - - // This isn't the Android one (missing android: namespace prefix): - // This test is disabled since I had to remove the namespace enforcement - // (see namespace-related comment in canInsertChildren) - //assertTrue(DescriptorsUtils.canInsertChildren(createDesc("mynamespace:ListView", - // "android.widget.ListView", true), null)); - - // Custom view without known view object - assertTrue(DescriptorsUtils.canInsertChildren(createDesc("MyView", - "foo.bar.MyView", true), null)); - - // Custom view with known view object that extends AdapterView - Object view = new MyClassLoader().findClass("foo.bar.MyView").newInstance(); - assertFalse(DescriptorsUtils.canInsertChildren(createDesc("MyView", - "foo.bar.MyView", true), view)); - } - - /** Test class loader which finds foo.bar.MyView extends android.widget.AdapterView */ - private static class MyClassLoader extends ClassLoader { - public MyClassLoader() { - super(null); - } - - @Override - protected Class findClass(String name) throws ClassNotFoundException { - if (name.equals("foo.bar.MyView")) { - // Simple class stub compiled by javac and dumped as bytes: - //package foo.bar; - //public class MyView extends android.widget.AdapterView { - // public MyView() { - // super(null); - // } - //} - byte[] classData = new byte[] { - -54,-2,-70,-66,0,0,0,49,0,17,10,0,3,0,13,7,0,14,7,0,15,1,0,6,60,105,110, - 105,116,62,1,0,3,40,41,86,1,0,4,67,111,100,101,1,0,15,76,105,110,101,78, - 117,109,98,101,114,84,97,98,108,101,1,0,18,76,111,99,97,108,86,97,114, - 105,97,98,108,101,84,97,98,108,101,1,0,4,116,104,105,115,1,0,16,76,102, - 111,111,47,98,97,114,47,77,121,86,105,101,119,59,1,0,10,83,111,117,114, - 99,101,70,105,108,101,1,0,11,77,121,86,105,101,119,46,106,97,118,97,12, - 0,4,0,16,1,0,14,102,111,111,47,98,97,114,47,77,121,86,105,101,119,1,0, - 26,97,110,100,114,111,105,100,47,119,105,100,103,101,116,47,65,100,97, - 112,116,101,114,86,105,101,119,1,0,28,40,76,97,110,100,114,111,105,100, - 47,99,111,110,116,101,110,116,47,67,111,110,116,101,120,116,59,41,86,0, - 33,0,2,0,3,0,0,0,0,0,1,0,1,0,4,0,5,0,1,0,6,0,0,0,52,0,2,0,1,0,0,0,6,42, - 1,-73,0,1,-79,0,0,0,2,0,7,0,0,0,10,0,2,0,0,0,9,0,5,0,10,0,8,0,0,0,12,0, - 1,0,0,0,6,0,9,0,10,0,0,0,1,0,11,0,0,0,2,0,12 - }; - return defineClass("foo.bar.MyView", classData, 0, classData.length); - } - if (name.equals("android.widget.AdapterView")) { - // Simple class stub compiled by javac and dumped as bytes: - //package android.widget; - //public class AdapterView { - // public AdapterView(android.content.Context context) { } - //} - byte[] classData = new byte[] { - -54,-2,-70,-66,0,0,0,49,0,19,10,0,3,0,15,7,0,16,7,0,17,1,0,6,60,105,110, - 105,116,62,1,0,28,40,76,97,110,100,114,111,105,100,47,99,111,110,116,101, - 110,116,47,67,111,110,116,101,120,116,59,41,86,1,0,4,67,111,100,101,1,0, - 15,76,105,110,101,78,117,109,98,101,114,84,97,98,108,101,1,0,18,76,111, - 99,97,108,86,97,114,105,97,98,108,101,84,97,98,108,101,1,0,4,116,104,105, - 115,1,0,28,76,97,110,100,114,111,105,100,47,119,105,100,103,101,116,47, - 65,100,97,112,116,101,114,86,105,101,119,59,1,0,7,99,111,110,116,101,120, - 116,1,0,25,76,97,110,100,114,111,105,100,47,99,111,110,116,101,110,116, - 47,67,111,110,116,101,120,116,59,1,0,10,83,111,117,114,99,101,70,105,108, - 101,1,0,16,65,100,97,112,116,101,114,86,105,101,119,46,106,97,118,97,12, - 0,4,0,18,1,0,26,97,110,100,114,111,105,100,47,119,105,100,103,101,116, - 47,65,100,97,112,116,101,114,86,105,101,119,1,0,16,106,97,118,97,47,108, - 97,110,103,47,79,98,106,101,99,116,1,0,3,40,41,86,0,33,0,2,0,3,0,0,0,0,0, - 1,0,1,0,4,0,5,0,1,0,6,0,0,0,57,0,1,0,2,0,0,0,5,42,-73,0,1,-79,0,0,0,2,0, - 7,0,0,0,6,0,1,0,0,0,8,0,8,0,0,0,22,0,2,0,0,0,5,0,9,0,10,0,0,0,0,0,5,0,11, - 0,12,0,1,0,1,0,13,0,0,0,2,0,14 - }; - return defineClass("android.widget.AdapterView", classData, 0, classData.length); - } - - return super.findClass(name); - } - } - - public void testGetBasename() { - assertEquals("Foo", DescriptorsUtils.getBasename("Foo")); - assertEquals("Foo", DescriptorsUtils.getBasename("foo.Foo")); - assertEquals("String", DescriptorsUtils.getBasename("java.util.String")); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/GraphicsUtilitiesTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/GraphicsUtilitiesTest.java deleted file mode 100644 index 4f00097bc..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/GraphicsUtilitiesTest.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.ide.eclipse.adt.internal.editors.draw9patch.graphics; - -import java.util.Arrays; - -import junit.framework.TestCase; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.widgets.Display; - -public class GraphicsUtilitiesTest extends TestCase { - private static final int MASK_ALPHA = 0xFF000000; - - private static final String DIR = "/com/android/ide/eclipse/testdata/draw9patch/"; - - public void testConvertToNinePatchNull() throws Exception { - ImageData result = GraphicsUtilities.convertToNinePatch(null); - assertNull(result); - } - - public void testConvertToNinePatch() throws Exception { - String fileName = DIR + "no-patched.png"; - Image image = new Image(Display.getDefault(), - getClass().getResourceAsStream(fileName)); - ImageData baseData = image.getImageData(); - - ImageData result = GraphicsUtilities.convertToNinePatch(baseData); - - assertEquals(baseData.width + 2, result.width); - assertEquals(baseData.height + 2, result.height); - - // horizontal - for (int x = 0; x < result.width; x++) { - - // top row - assertEquals(0x0, result.getPixel(x, 0) & MASK_ALPHA); - - // bottom row - assertEquals(0x0, result.getPixel(x, result.height - 1) & MASK_ALPHA); - } - - // vertical - for (int y = 0; y < result.height; y++) { - - // left column - assertEquals(0x0, result.getPixel(0, y) & MASK_ALPHA); - - // right column - assertEquals(0x0, result.getPixel(result.width - 1, y) & MASK_ALPHA); - } - } - - public void testClearImageDataNull() throws Exception { - try { - GraphicsUtilities.clearImageData(null); - fail(); - } catch (IllegalArgumentException e) { - } - } - - public void testClearImageData() throws Exception { - String fileName = DIR + "no-patched.png"; - Image image = new Image(Display.getDefault(), - getClass().getResourceAsStream(fileName)); - - ImageData baseData = image.getImageData(); - GraphicsUtilities.clearImageData(baseData); - for (int y = 0; y < baseData.height; y++) { - for (int x = 0; x < baseData.width; x++) { - assertEquals(0x000000, baseData.getPixel(x, y)); - assertEquals(0x00, baseData.getAlpha(x, y)); - } - } - - } - - public void testCopyNull() throws Exception { - ImageData result = GraphicsUtilities.copy(null); - assertNull(result); - } - - public void testCopy() throws Exception { - String fileName = DIR + "no-patched.png"; - Image image = new Image(Display.getDefault(), - getClass().getResourceAsStream(fileName)); - - ImageData baseData = image.getImageData(); - ImageData copiedData = GraphicsUtilities.copy(baseData); - - assertEquals(baseData.width, copiedData.width); - assertEquals(baseData.height, copiedData.height); - assertEquals(baseData.depth, copiedData.depth); - assertEquals(baseData.transparentPixel, copiedData.transparentPixel); - assertEquals(baseData.alpha, copiedData.alpha); - assertTrue(baseData.palette.equals(copiedData.palette)); - - final int[] baseColors = new int[baseData.width]; - final byte[] baseAlpha = new byte[baseData.width]; - - final int[] copiedColors = new int[copiedData.width]; - final byte[] copiedAlpha = new byte[copiedData.width]; - - for (int y = 0; y < baseData.height; y++) { - - baseData.getPixels(0, y, baseData.width, baseColors, 0); - baseData.getPixels(0, y, baseData.width, copiedColors, 0); - assertTrue(Arrays.equals(baseColors, copiedColors)); - - baseData.getAlphas(0, y, baseData.width, baseAlpha, 0); - baseData.getAlphas(0, y, baseData.width, copiedAlpha, 0); - assertTrue(Arrays.equals(baseAlpha, copiedAlpha)); - - } - } - - public void testGetVerticalPixelsIllegalArgument() throws Exception { - String fileName = DIR + "no-patched.png"; - Image image = new Image(Display.getDefault(), - getClass().getResourceAsStream(fileName)); - - ImageData baseData = image.getImageData(); - int[] temp = new int[baseData.width]; - - // data must not be null - try { - GraphicsUtilities.getVerticalPixels(null, 0, 0, 1, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // out must not be null - try { - GraphicsUtilities.getVerticalPixels(baseData, 0, 0, 1, null); - fail(); - } catch (IllegalArgumentException e) { - } - - // out length must be > height - try { - GraphicsUtilities.getVerticalPixels(baseData, 0, 0, 1, new int[0]); - fail(); - } catch (IllegalArgumentException e) { - } - - // x must be > 0 - try { - GraphicsUtilities.getVerticalPixels(baseData, -1, 0, 1, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // y must be > 0 - try { - GraphicsUtilities.getVerticalPixels(baseData, 0, -1, 1, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // height must be >= 0 - try { - GraphicsUtilities.getVerticalPixels(baseData, 0, 0, 0, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // argument x must be < data.width - try { - GraphicsUtilities.getVerticalPixels(baseData, baseData.width, 0, baseData.height, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // argument y must be < data.height - try { - GraphicsUtilities - .getVerticalPixels(baseData, 0, baseData.height, baseData.height, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // argument height must be > (y + data.height) - try { - GraphicsUtilities.getVerticalPixels(baseData, 0, 1, baseData.height, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - } - - public void testGetVerticalPixels() throws Exception { - String fileName = DIR + "no-patched.png"; - Image image = new Image(Display.getDefault(), - getClass().getResourceAsStream(fileName)); - - ImageData baseData = image.getImageData(); - int[] temp = new int[baseData.width]; - - GraphicsUtilities.getVerticalPixels(baseData, 0, 0, baseData.height, temp); - - int height = baseData.height; - for (int y = 0; y < height; y++) { - assertEquals(baseData.getPixel(0, y), temp[y]); - } - } - - public void testGetHorizontalPixelsIllegalArgument() throws Exception { - String fileName = DIR + "no-patched.png"; - Image image = new Image(Display.getDefault(), - getClass().getResourceAsStream(fileName)); - - ImageData baseData = image.getImageData(); - int[] temp = new int[baseData.width]; - - // data must not be null - try { - GraphicsUtilities.getHorizontalPixels(null, 0, 0, 1, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // out must not be null - try { - GraphicsUtilities.getHorizontalPixels(baseData, 0, 0, 1, null); - fail(); - } catch (IllegalArgumentException e) { - } - - // out length must be > width - try { - GraphicsUtilities.getHorizontalPixels(baseData, 0, 0, 1, new int[0]); - fail(); - } catch (IllegalArgumentException e) { - } - - // x must be > 0 - try { - GraphicsUtilities.getHorizontalPixels(baseData, -1, 0, 1, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // y must be > 0 - try { - GraphicsUtilities.getHorizontalPixels(baseData, 0, -1, 1, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // width must be >= 0 - try { - GraphicsUtilities.getHorizontalPixels(baseData, 0, 0, 0, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // argument x must be < data.width - try { - GraphicsUtilities - .getHorizontalPixels(baseData, baseData.width, 0, baseData.width, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // argument y must be < data.height - try { - GraphicsUtilities - .getHorizontalPixels(baseData, 0, baseData.height, baseData.width, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - // argument width must be > (x + data.width) - try { - GraphicsUtilities.getHorizontalPixels(baseData, 1, 0, baseData.width, temp); - fail(); - } catch (IllegalArgumentException e) { - } - - } - - public void testGetHorizontalPixels() throws Exception { - String fileName = DIR + "no-patched.png"; - Image image = new Image(Display.getDefault(), - getClass().getResourceAsStream(fileName)); - - ImageData baseData = image.getImageData(); - int[] temp = new int[baseData.width]; - - GraphicsUtilities.getHorizontalPixels(baseData, 0, 0, baseData.width, temp); - - int width = baseData.width; - for (int x = 0; x < width; x++) { - assertEquals(baseData.getPixel(x, 0), temp[x]); - } - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/NinePatchedImageTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/NinePatchedImageTest.java deleted file mode 100644 index 72c929618..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/draw9patch/graphics/NinePatchedImageTest.java +++ /dev/null @@ -1,914 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.ide.eclipse.adt.internal.editors.draw9patch.graphics; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; - -import com.android.ide.eclipse.adt.internal.editors.draw9patch.graphics.NinePatchedImage.Chunk; -import com.android.ide.eclipse.adt.internal.editors.draw9patch.graphics.NinePatchedImage.Projection; -import com.android.ide.eclipse.adt.internal.editors.draw9patch.graphics.NinePatchedImage.Tick; - -public class NinePatchedImageTest extends TestCase { - - private static final String DIR = "/com/android/ide/eclipse/testdata/draw9patch/"; - - public void testReadNoPatchedImage() throws Exception { - String fileName = DIR + "no-patched.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - ImageData data = image.getImageData(); - int width = data.width; - int height = data.height; - - assertEquals(72, width); - assertEquals(50, height); - - assertFalse(image.hasNinePatchExtension()); - } - - public void testReadNoPatchedInteraceImage() throws Exception { - String fileName = DIR + "no-patched-interlace.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - ImageData data = image.getImageData(); - int width = data.width; - int height = data.height; - - assertEquals(72, width); - assertEquals(50, height); - - assertFalse(image.hasNinePatchExtension()); - } - - public void testConvert9PatchedImage() throws Exception { - String fileName = DIR + "no-patched.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - ImageData data = image.getImageData(); - int width = data.width; - int height = data.height; - - assertEquals(72, width); - assertEquals(50, height); - - assertFalse(image.hasNinePatchExtension()); - - image.convertToNinePatch(); - - data = image.getImageData(); - width = data.width; - height = data.height; - - // increased patch size - assertEquals(72 + 2, width); - assertEquals(50 + 2, height); - - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.isDirty()); - - // initialized patches - List horizontalPatches = image.getHorizontalPatches(); - List verticalPatches = image.getVerticalPatches(); - assertEquals(1, horizontalPatches.size()); - assertEquals(1, verticalPatches.size()); - - // initialized contents area - List horizontalContentsArea = image.getHorizontalContents(); - List verticalContentsArea = image.getVerticalContents(); - assertEquals(1, horizontalContentsArea.size()); - assertEquals(1, verticalContentsArea.size()); - - // content area rectangle - Rectangle contentsArea = image.getContentArea(); - assertEquals(new Rectangle(1, 1, width - 2, height - 2), contentsArea); - } - - public void testReadInvalidPatchedImageCorners() throws Exception { - - // top-left - String fileName = DIR + "invalid-patched1.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - - // top-right - fileName = DIR + "invalid-patched2.9.png"; - image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - - // bottom-left - fileName = DIR + "invalid-patched3.9.png"; - image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - - // bottom-right - fileName = DIR + "invalid-patched4.9.png"; - image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - } - - public void testReadInvalidPatchedImageLine() throws Exception { - - // top - String fileName = DIR + "invalid-patched5.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - - // right - fileName = DIR + "invalid-patched6.9.png"; - image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - - // bottom - fileName = DIR + "invalid-patched7.9.png"; - image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - - // left - fileName = DIR + "invalid-patched8.9.png"; - image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - } - - public void testEnsure9PatchIgnoreInvalidPixels() throws Exception { - // top - String fileName = DIR + "invalid-patched5.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - // invalid pixel - int invalidPixel = image.getImageData().getPixel(33, 0); - assertTrue(0x0 != invalidPixel); - - assertTrue(image.hasNinePatchExtension()); - assertFalse(image.ensure9Patch()); - - // ensure9path() ignored invalid pixels - int invalidPixelAlpha = image.getImageData().getAlpha(33, 0); - assertEquals(0x00, invalidPixelAlpha); - } - - public void test9Patch1() throws Exception { - String fileName = DIR + "patched1.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - - // patches - List horizontalPatches = image.getHorizontalPatches(); - List verticalPatches = image.getVerticalPatches(); - assertEquals(3, horizontalPatches.size()); - assertEquals(3, verticalPatches.size()); - - Chunk[][] chunks = null; - chunks = image.getChunks(chunks); - - // vertical chunk size - assertEquals(3, chunks.length); - - // horizontal chunk size - for (int i = 0; i < chunks.length; i++) { - assertEquals(3, chunks[i].length); - } - - Chunk c = null; - Rectangle rect = null; - - // Row 1 - c = chunks[0][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(1, rect.x); - assertEquals(1, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - c = chunks[0][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(2, rect.x); - assertEquals(1, rect.y); - assertEquals(70, rect.width); - assertEquals(1, rect.height); - - c = chunks[0][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(72, rect.x); - assertEquals(1, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - // Row 2 - c = chunks[1][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(1, rect.x); - assertEquals(2, rect.y); - assertEquals(1, rect.width); - assertEquals(48, rect.height); - - c = chunks[1][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_FIXED, c.type); - assertEquals(2, rect.x); - assertEquals(2, rect.y); - assertEquals(70, rect.width); - assertEquals(48, rect.height); - - c = chunks[1][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(72, rect.x); - assertEquals(2, rect.y); - assertEquals(1, rect.width); - assertEquals(48, rect.height); - - // Row 3 - c = chunks[2][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(1, rect.x); - assertEquals(50, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - c = chunks[2][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(2, rect.x); - assertEquals(50, rect.y); - assertEquals(70, rect.width); - assertEquals(1, rect.height); - - c = chunks[2][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(72, rect.x); - assertEquals(50, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - } - - public void test9Patch2() throws Exception { - String fileName = DIR + "patched2.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - - // patches - List horizontalPatches = image.getHorizontalPatches(); - List verticalPatches = image.getVerticalPatches(); - assertEquals(5, horizontalPatches.size()); - assertEquals(7, verticalPatches.size()); - - NinePatchedImage.Chunk[][] chunks = null; - chunks = image.getChunks(chunks); - - // vertical chunk size - assertEquals(7, chunks.length); - - // horizontal chunk size - for (int i = 0; i < chunks.length; i++) { - assertEquals(5, chunks[i].length); - } - - NinePatchedImage.Chunk c = null; - Rectangle rect = null; - - // Row 1 - c = chunks[0][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(1, rect.x); - assertEquals(1, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - c = chunks[0][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(2, rect.x); - assertEquals(1, rect.y); - assertEquals(34, rect.width); - assertEquals(1, rect.height); - - c = chunks[0][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(36, rect.x); - assertEquals(1, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - c = chunks[0][3]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(37, rect.x); - assertEquals(1, rect.y); - assertEquals(35, rect.width); - assertEquals(1, rect.height); - - c = chunks[0][4]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(72, rect.x); - assertEquals(1, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - // Row 2 - c = chunks[1][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(1, rect.x); - assertEquals(2, rect.y); - assertEquals(1, rect.width); - assertEquals(7, rect.height); - - c = chunks[1][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_FIXED, c.type); - assertEquals(2, rect.x); - assertEquals(2, rect.y); - assertEquals(34, rect.width); - assertEquals(7, rect.height); - - c = chunks[1][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(36, rect.x); - assertEquals(2, rect.y); - assertEquals(1, rect.width); - assertEquals(7, rect.height); - - c = chunks[1][3]; - rect = c.rect; - assertEquals(Chunk.TYPE_FIXED, c.type); - assertEquals(37, rect.x); - assertEquals(2, rect.y); - assertEquals(35, rect.width); - assertEquals(7, rect.height); - - c = chunks[1][4]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(72, rect.x); - assertEquals(2, rect.y); - assertEquals(1, rect.width); - assertEquals(7, rect.height); - - // Row 3 - c = chunks[2][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(1, rect.x); - assertEquals(9, rect.y); - assertEquals(1, rect.width); - assertEquals(4, rect.height); - - c = chunks[2][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(2, rect.x); - assertEquals(9, rect.y); - assertEquals(34, rect.width); - assertEquals(4, rect.height); - - c = chunks[2][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(36, rect.x); - assertEquals(9, rect.y); - assertEquals(1, rect.width); - assertEquals(4, rect.height); - - c = chunks[2][3]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(37, rect.x); - assertEquals(9, rect.y); - assertEquals(35, rect.width); - assertEquals(4, rect.height); - - c = chunks[2][4]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(72, rect.x); - assertEquals(9, rect.y); - assertEquals(1, rect.width); - assertEquals(4, rect.height); - - // Row 4 - c = chunks[3][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(1, rect.x); - assertEquals(13, rect.y); - assertEquals(1, rect.width); - assertEquals(13, rect.height); - - c = chunks[3][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_FIXED, c.type); - assertEquals(2, rect.x); - assertEquals(13, rect.y); - assertEquals(34, rect.width); - assertEquals(13, rect.height); - - c = chunks[3][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(36, rect.x); - assertEquals(13, rect.y); - assertEquals(1, rect.width); - assertEquals(13, rect.height); - - c = chunks[3][3]; - rect = c.rect; - assertEquals(Chunk.TYPE_FIXED, c.type); - assertEquals(37, rect.x); - assertEquals(13, rect.y); - assertEquals(35, rect.width); - assertEquals(13, rect.height); - - c = chunks[3][4]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(72, rect.x); - assertEquals(13, rect.y); - assertEquals(1, rect.width); - assertEquals(13, rect.height); - - // Row 5 - c = chunks[4][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(1, rect.x); - assertEquals(26, rect.y); - assertEquals(1, rect.width); - assertEquals(12, rect.height); - - c = chunks[4][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(2, rect.x); - assertEquals(26, rect.y); - assertEquals(34, rect.width); - assertEquals(12, rect.height); - - c = chunks[4][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(36, rect.x); - assertEquals(26, rect.y); - assertEquals(1, rect.width); - assertEquals(12, rect.height); - - c = chunks[4][3]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(37, rect.x); - assertEquals(26, rect.y); - assertEquals(35, rect.width); - assertEquals(12, rect.height); - - c = chunks[4][4]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(72, rect.x); - assertEquals(26, rect.y); - assertEquals(1, rect.width); - assertEquals(12, rect.height); - - // Row 6 - c = chunks[5][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(1, rect.x); - assertEquals(38, rect.y); - assertEquals(1, rect.width); - assertEquals(12, rect.height); - - c = chunks[5][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_FIXED, c.type); - assertEquals(2, rect.x); - assertEquals(38, rect.y); - assertEquals(34, rect.width); - assertEquals(12, rect.height); - - c = chunks[5][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(36, rect.x); - assertEquals(38, rect.y); - assertEquals(1, rect.width); - assertEquals(12, rect.height); - - c = chunks[5][3]; - rect = c.rect; - assertEquals(Chunk.TYPE_FIXED, c.type); - assertEquals(37, rect.x); - assertEquals(38, rect.y); - assertEquals(35, rect.width); - assertEquals(12, rect.height); - - c = chunks[5][4]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL, c.type); - assertEquals(72, rect.x); - assertEquals(38, rect.y); - assertEquals(1, rect.width); - assertEquals(12, rect.height); - - // Row 7 - c = chunks[6][0]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(1, rect.x); - assertEquals(50, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - c = chunks[6][1]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(2, rect.x); - assertEquals(50, rect.y); - assertEquals(34, rect.width); - assertEquals(1, rect.height); - - c = chunks[6][2]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(36, rect.x); - assertEquals(50, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - - c = chunks[6][3]; - rect = c.rect; - assertEquals(Chunk.TYPE_VERTICAL, c.type); - assertEquals(37, rect.x); - assertEquals(50, rect.y); - assertEquals(35, rect.width); - assertEquals(1, rect.height); - - c = chunks[6][4]; - rect = c.rect; - assertEquals(Chunk.TYPE_HORIZONTAL | Chunk.TYPE_VERTICAL, c.type); - assertEquals(72, rect.x); - assertEquals(50, rect.y); - assertEquals(1, rect.width); - assertEquals(1, rect.height); - } - - public void testContentArea() throws Exception { - String fileName = DIR + "content-area.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - - // contents area - List horizontalContentsArea = image.getHorizontalContents(); - List verticalContentsArea = image.getVerticalContents(); - assertEquals(3, horizontalContentsArea.size()); - assertEquals(3, verticalContentsArea.size()); - - // content area rectangle - Rectangle contentsArea = image.getContentArea(); - assertEquals(new Rectangle(19, 13, 35, 25), contentsArea); - } - - public void testContentAreaOneDot() throws Exception { - String fileName = DIR + "content-area-one-dot.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - - // contents area - List horizontalContentsArea = image.getHorizontalContents(); - List verticalContentsArea = image.getVerticalContents(); - assertEquals(3, horizontalContentsArea.size()); - assertEquals(3, verticalContentsArea.size()); - - // content area rectangle - Rectangle contentsArea = image.getContentArea(); - assertEquals(new Rectangle(19, 13, 1, 1), contentsArea); - } - - public void testContentAreaTwoDots() throws Exception { - String fileName = DIR + "content-area-two-dots.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - - // contents area - List horizontalContentsArea = image.getHorizontalContents(); - List verticalContentsArea = image.getVerticalContents(); - assertEquals(5, horizontalContentsArea.size()); - assertEquals(5, verticalContentsArea.size()); - - // content area rectangle - Rectangle contentsArea = image.getContentArea(); - assertEquals(new Rectangle(19, 13, 35, 25), contentsArea); - - String fileName2 = DIR + "content-area.9.png"; - NinePatchedImage image2 = new NinePatchedImage(getClass() - .getResourceAsStream(fileName2), fileName2); - assertNotNull(image2); - - assertTrue(image2.hasNinePatchExtension()); - assertTrue(image2.ensure9Patch()); - - // content area rectangle - Rectangle contentsArea2 = image2.getContentArea(); - assertEquals(contentsArea2, contentsArea); - } - - public void testBadPatches() throws Exception { - String fileName = DIR + "patched-with-badpatches.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - - Chunk[][] chunks = null; - chunks = image.getChunks(chunks); - - // vertical chunk size - assertEquals(5, chunks.length); - - // horizontal chunk size - for (int i = 0; i < chunks.length; i++) { - assertEquals(7, chunks[i].length); - } - - chunks = image.getCorruptedChunks(chunks); - - Chunk c = null; - - // collect bad patches - List badPatches = new ArrayList(5 * 7); - for (int y = 0; y < chunks.length; y++) { - for (int x = 0; x < chunks[0].length; x++) { - c = chunks[y][x]; - if ((c.type & Chunk.TYPE_CORRUPT) != 0x0) { - badPatches.add(new Point(y, x)); - } - } - } - - assertEquals(15, badPatches.size()); - - assertTrue(badPatches.contains(new Point(0, 3))); - - assertTrue(badPatches.contains(new Point(1, 1))); - assertTrue(badPatches.contains(new Point(1, 2))); - assertTrue(badPatches.contains(new Point(1, 3))); - assertTrue(badPatches.contains(new Point(1, 4))); - assertTrue(badPatches.contains(new Point(1, 5))); - - assertTrue(badPatches.contains(new Point(2, 1))); - assertTrue(badPatches.contains(new Point(2, 5))); - - assertTrue(badPatches.contains(new Point(3, 0))); - assertTrue(badPatches.contains(new Point(3, 1))); - assertTrue(badPatches.contains(new Point(3, 5))); - assertTrue(badPatches.contains(new Point(3, 6))); - - assertTrue(badPatches.contains(new Point(4, 1))); - assertTrue(badPatches.contains(new Point(4, 3))); - assertTrue(badPatches.contains(new Point(4, 5))); - } - - public void testProjection() throws Exception { - // top - String fileName = DIR + "patched3.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - - ImageData data = image.getImageData(); - assertEquals(72 + 2, data.width); - assertEquals(50 + 2, data.height); - - int width = 72 * 2; - int height = 50 * 2; - - Chunk[][] chunks = null; - chunks = image.getChunks(chunks); - - Projection[][] projections = null; - projections = image.getProjections(width, height, projections); - - assertEquals(chunks.length, projections.length); - for (int i = 0; i < chunks.length; i++) { - assertEquals(chunks[i].length, projections[i].length); - } - - for (int y = 0; y < projections.length; y++) { - for (int x = 0; x < projections[y].length; x++) { - assertEquals(projections[y][x].src, chunks[y][x].rect); - - // If chunk type is FIXED. Same projection size as original - // chunk. - if (projections[y][x].chunk.type == Chunk.TYPE_FIXED) { - assertEquals(projections[y][x].dest.width, chunks[y][x].rect.width); - assertEquals(projections[y][x].dest.height, chunks[y][x].rect.height); - } - } - } - - Projection p = null; - Rectangle rect = null; - - // Check start position - p = projections[0][0]; - - // src position start from 1, 9-patch row and column included. - assertEquals(1, p.src.x); - assertEquals(1, p.src.y); - - // dest position start from 0, 9-patch row and column ignored. - assertEquals(0, p.dest.x); - assertEquals(0, p.dest.y); - - // row 1 - p = projections[0][0]; - rect = p.dest; - assertEquals(0, rect.x); - assertEquals(0, rect.y); - assertEquals(74, rect.width); - assertEquals(5, rect.height); - - p = projections[0][1]; - rect = p.dest; - assertEquals(74, rect.x); - assertEquals(0, rect.y); - assertEquals(62, rect.width); - assertEquals(5, rect.height); - - p = projections[0][2]; - rect = p.dest; - assertEquals(136, rect.x); - assertEquals(0, rect.y); - assertEquals(8, rect.width); - assertEquals(5, rect.height); - - // row 2 - p = projections[1][0]; - rect = p.dest; - assertEquals(0, rect.x); - assertEquals(5, rect.y); - assertEquals(74, rect.width); - assertEquals(24, rect.height); - - p = projections[1][1]; - rect = p.dest; - assertEquals(74, rect.x); - assertEquals(5, rect.y); - assertEquals(62, rect.width); - assertEquals(24, rect.height); - - p = projections[1][2]; - rect = p.dest; - assertEquals(136, rect.x); - assertEquals(5, rect.y); - assertEquals(8, rect.width); - assertEquals(24, rect.height); - - // row 3 - p = projections[2][0]; - rect = p.dest; - assertEquals(0, rect.x); - assertEquals(29, rect.y); - assertEquals(74, rect.width); - assertEquals(58, rect.height); - - p = projections[2][1]; - rect = p.dest; - assertEquals(74, rect.x); - assertEquals(29, rect.y); - assertEquals(62, rect.width); - assertEquals(58, rect.height); - - p = projections[2][2]; - rect = p.dest; - assertEquals(136, rect.x); - assertEquals(29, rect.y); - assertEquals(8, rect.width); - assertEquals(58, rect.height); - - // row 4 - p = projections[3][0]; - rect = p.dest; - assertEquals(0, rect.x); - assertEquals(87, rect.y); - assertEquals(74, rect.width); - assertEquals(13, rect.height); - - p = projections[3][1]; - rect = p.dest; - assertEquals(74, rect.x); - assertEquals(87, rect.y); - assertEquals(62, rect.width); - assertEquals(13, rect.height); - - p = projections[3][2]; - rect = p.dest; - assertEquals(136, rect.x); - assertEquals(87, rect.y); - assertEquals(8, rect.width); - assertEquals(13, rect.height); - } - - public void testReadLayoutBoundsOnlyImage() throws Exception { - String fileName = DIR + "layout-bounds-only.9.png"; - NinePatchedImage image = new NinePatchedImage(getClass() - .getResourceAsStream(fileName), fileName); - assertNotNull(image); - - ImageData data = image.getImageData(); - int width = data.width; - int height = data.height; - - assertEquals(74, width); - assertEquals(52, height); - - assertTrue(image.hasNinePatchExtension()); - assertTrue(image.ensure9Patch()); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/formatting/AndroidXmlFormattingStrategyTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/formatting/AndroidXmlFormattingStrategyTest.java deleted file mode 100644 index 9c7e25d4b..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/formatting/AndroidXmlFormattingStrategyTest.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.ide.eclipse.adt.internal.editors.formatting; - -import com.android.ide.common.xml.XmlFormatPreferences; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.ReplaceEdit; - -import junit.framework.TestCase; - -@SuppressWarnings("javadoc") -public class AndroidXmlFormattingStrategyTest extends TestCase { - // In the given before document, replace in the range replaceStart to replaceEnd - // the formatted string, and assert that it's identical to the given after string - private void check(String before, int replaceStart, int replaceEnd, String formatted, - String expected, XmlFormatPreferences prefs) - throws MalformedTreeException, BadLocationException { - Document document = new Document(); - document.set(before); - ReplaceEdit edit = AndroidXmlFormattingStrategy.createReplaceEdit(document, replaceStart, - replaceEnd, formatted, prefs); - assertNotNull(edit); - edit.apply(document); - String contents = document.get(); - // Ensure that we don't have any mangled CRLFs - char prev = 0; - boolean haveCrlf = false; - for (int i = 0, n = contents.length(); i < n; i++) { - char c = contents.charAt(i); - if (c == '\r') { - haveCrlf = true; - } - if (!(c != '\r' || prev != '\r')) { - fail("Mangled document: Found adjacent \\r's starting at " + i - + ": " + contents.substring(i - 1, Math.min(contents.length(), i + 10)) - + "..."); - } - if (haveCrlf && c == '\n' && prev != '\r') { - fail("Mangled document: In a CRLF document, found \\n without preceeding \\r"); - } - - prev = c; - } - - assertEquals(expected, contents); - } - - // In the given before document, replace the range indicated by [ and ] with the given - // formatted string, and assert that it's identical to the given after string - private void check( - String before, String insert, String expected, - XmlFormatPreferences prefs) - throws MalformedTreeException, BadLocationException { - int replaceStart = before.indexOf('['); - assertTrue(replaceStart != -1); - before = before.substring(0, replaceStart) + before.substring(replaceStart + 1); - - int replaceEnd = before.indexOf(']'); - assertTrue(replaceEnd != -1); - before = before.substring(0, replaceEnd) + before.substring(replaceEnd + 1); - - check(before, replaceStart, replaceEnd, insert, expected, prefs); - } - - public void test1() throws Exception { - check( - // Before - "\n" + - "[ \n" + - " \n" + - "]\n" + - "\n", - - // Insert - " \n" + - " \n", - - // After - "\n" + - " \n" + - " \n" + - "\n" + - "\n", - - XmlFormatPreferences.defaults()); - } - - public void test2() throws Exception { - XmlFormatPreferences prefs = XmlFormatPreferences.defaults(); - prefs.removeEmptyLines = true; - - check( - // Before - "\n" + - "\n" + - "\n" + - "[ \n" + - " \n" + - "]\n" + - "\n" + - "\n" + - "\n", - - // Insert - " \n" + - " \n", - - // After - "\n" + - " \n" + - " \n" + - "\n", - - prefs); - } - - public void test3() throws Exception { - XmlFormatPreferences prefs = XmlFormatPreferences.defaults(); - prefs.removeEmptyLines = true; - - check( - // Before - "\n" + - "\n" + - "\n" + - " [\n" + - " ]\n" + - "\n" + - "\n" + - "\n" + - "\n", - - // Insert - " \n" + - " ", - - // After - "\n" + - " \n" + - " \n" + - "\n", - - prefs); - } - - public void test4() throws Exception { - check( - "\n" + - "\n" + - " []\n" + - "\n" + - "\n", - - // Insert - "\n" + - " \n", - - // After - "\n" + - "\n" + - " \n" + - "\n" + - "\n", - - XmlFormatPreferences.defaults()); - } - - public void testCrLf1() throws Exception { - check( - // Before - "\r\n" + - "[ \r\n" + - " \r\n" + - "]\r\n" + - "\r\n", - - // Insert - " \r\n" + - " \r\n", - - // After - "\r\n" + - " \r\n" + - " \r\n" + - "\r\n" + - "\r\n", - - XmlFormatPreferences.defaults()); - } - - public void testCrLf2() throws Exception { - XmlFormatPreferences prefs = XmlFormatPreferences.defaults(); - prefs.removeEmptyLines = true; - - check( - // Before - "\r\n" + - "\r\n" + - "\r\n" + - "[ \r\n" + - " \r\n" + - "]\r\n" + - "\r\n" + - "\r\n" + - "\r\n", - - // Insert - " \r\n" + - " \r\n", - - // After - "\r\n" + - " \r\n" + - " \r\n" + - "\r\n", - - prefs); - } - - public void testCrLf3() throws Exception { - XmlFormatPreferences prefs = XmlFormatPreferences.defaults(); - prefs.removeEmptyLines = true; - - check( - // Before - "\r\n" + - "\r\n" + - "\r\n" + - " [\r\n" + - " ]\r\n" + - "\r\n" + - "\r\n" + - "\r\n" + - "\r\n", - - // Insert - " \r\n" + - " ", - - // After - "\r\n" + - " \r\n" + - " \r\n" + - "\r\n", - - prefs); - } - - - public void testCrlf4() throws Exception { - check( - "\r\n" + - "\r\n" + - " []\r\n" + - "\r\n" + - "\r\n", - - // Insert - "\r\n" + - " \r\n", - - // After - "\r\n" + - "\r\n" + - " \r\n" + - "\r\n" + - "\r\n", - - XmlFormatPreferences.defaults()); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/ExplodeRenderingHelperTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/ExplodeRenderingHelperTest.java deleted file mode 100644 index 0e528674a..000000000 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/ExplodeRenderingHelperTest.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.ide.eclipse.adt.internal.editors.layout; - -import com.android.SdkConstants; -import com.android.ide.eclipse.adt.internal.editors.mock.MockXmlNode; - -import org.w3c.dom.Node; - -import java.util.HashSet; - -import junit.framework.TestCase; - -public class ExplodeRenderingHelperTest extends TestCase { - - private final HashSet mLayoutNames = new HashSet(); - - @Override - protected void setUp() throws Exception { - super.setUp(); - - mLayoutNames.add("LinearLayout"); - mLayoutNames.add("RelativeLayout"); - } - - public void testSingleHorizontalLinearLayout() { - // Single layout, horizontal, 2 buttons. - MockXmlNode layout = createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton()} ); - - ExplodedRenderingHelper helper = new ExplodedRenderingHelper(layout, mLayoutNames); - assertEquals(1, helper.getHeightPadding()); - assertEquals(1, helper.getWidthPadding()); - } - - public void testSingleVerticalLinearLayout() { - // Single layout, horizontal, with 2 buttons. - // LinearLayout(H:[Button Button]) - MockXmlNode layout = createLinearLayout(false /*horizontal*/, - new MockXmlNode[] { createButton(), createButton()} ); - - ExplodedRenderingHelper helper = new ExplodedRenderingHelper(layout, mLayoutNames); - assertEquals(1, helper.getWidthPadding()); - assertEquals(1, helper.getHeightPadding()); - } - - public void testEmbeddedLinearLayouts() { - /* - * LinearLayout(vertical): - * LinearLayout(H:[Button Button]) - * LinearLayout(H:[Button Button Button]) - * - * Result should be 2 in x, 3 in y - */ - MockXmlNode layout = createLinearLayout(false /*horizontal*/, - new MockXmlNode[] { - createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton()}), - createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton(), createButton()}), - } ); - - ExplodedRenderingHelper helper = new ExplodedRenderingHelper(layout, mLayoutNames); - assertEquals(2, helper.getWidthPadding()); - assertEquals(3, helper.getHeightPadding()); - } - - public void testSimpleRelativeLayoutWithOneLinearLayouts() { - /* - * RelativeLayout: - * LinearLayout(H:[Button Button]) - * - * Result should be 2 in x, 2 in y - */ - MockXmlNode layout = createRelativeLayout( - new MockXmlNode[] { - createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton()}), - } ); - - ExplodedRenderingHelper helper = new ExplodedRenderingHelper(layout, mLayoutNames); - assertEquals(2, helper.getWidthPadding()); - assertEquals(2, helper.getHeightPadding()); - } - - public void /*test*/RelativeLayoutWithVerticalLinearLayouts() { - //FIXME: Reenable once the relative layout are properly supported. - /* - * Children of the relative layouts, one below the other. - * Each with only buttons in them. - * RelativeLayout: - * LinearLayout(H:[Button Button]) - * ^ - * LinearLayout(H:[Button Button]) - * - * Result should be 2 in x, 3 in y - */ - - // create the linearlayouts. - MockXmlNode linear1 = createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton()}); - linear1.addAttributes(SdkConstants.NS_RESOURCES, "id", "@+id/linear1"); - - MockXmlNode linear2 = createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton()}); - linear2.addAttributes(SdkConstants.NS_RESOURCES, "id", "@+id/linear2"); - - // position linear2 below linear1 - linear2.addAttributes(SdkConstants.NS_RESOURCES, "layout_below", "@+id/linear1"); - - - MockXmlNode layout = createRelativeLayout(new MockXmlNode[] { linear1, linear2 } ); - - ExplodedRenderingHelper helper = new ExplodedRenderingHelper(layout, mLayoutNames); - assertEquals(2, helper.getWidthPadding()); - assertEquals(3, helper.getHeightPadding()); - } - - public void /*test*/RelativeLayoutWithVerticalLinearLayouts2() { - //FIXME: Reenable once the relative layout are properly supported. - /* - * Children of the relative layouts, one above the other. - * Each with only buttons in them. - * RelativeLayout: - * LinearLayout(H:[Button Button]) - * v - * LinearLayout(H:[Button Button]) - * - * Result should be 2 in x, 3 in y - */ - - // create the linearlayouts. - MockXmlNode linear1 = createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton() } ); - linear1.addAttributes(SdkConstants.NS_RESOURCES, "id", "@+id/linear1"); - - MockXmlNode linear2 = createLinearLayout(true /*horizontal*/, - new MockXmlNode[] { createButton(), createButton() } ); - linear2.addAttributes(SdkConstants.NS_RESOURCES, "id", "@+id/linear2"); - - // position linear2 below linear1 - linear2.addAttributes(SdkConstants.NS_RESOURCES, "layout_above", "@+id/linear1"); - - - MockXmlNode layout = createRelativeLayout(new MockXmlNode[] { linear1, linear2 } ); - - ExplodedRenderingHelper helper = new ExplodedRenderingHelper(layout, mLayoutNames); - assertEquals(2, helper.getWidthPadding()); - assertEquals(3, helper.getHeightPadding()); - } - - public void /*test*/ComplexRelativeLayout() { - //FIXME: Reenable once the relative layout are properly supported. - /* - * RelativeLayout: - * - * < LinearLayout1(V: [button]) > LinearLayout2(V: [button]) - * v - * Button1 > LinearLayout3(V: [button]) < Button2 - * v - * < LinearLayout4(V: [button]) - * ^ - * button1Map; - private HashMap button2Map; - private HashMap textMap; - - private TextAttributeDescriptor createTextAttrDesc(String xmlName) { - return new TextAttributeDescriptor( - xmlName, // xmlLocalName - SdkConstants.NS_RESOURCES, - new AttributeInfo(xmlName, Format.STRING_SET) - ); - } - - @Override - protected void setUp() throws Exception { - // set up some basic descriptors. - // We have button, textview, linear layout, relative layout. - // only the layouts have children (all 4 descriptors possible) - // Also add some dummy attributes. - ElementDescriptor buttonDescriptor = new ElementDescriptor("Button", "Button", "", "", - new AttributeDescriptor[] { - createTextAttrDesc("name"), - createTextAttrDesc("text"), - }, - new ElementDescriptor[] {}, false); - - ElementDescriptor textDescriptor = new ElementDescriptor("TextView", "TextView", "", "", - new AttributeDescriptor[] { - createTextAttrDesc("name"), - createTextAttrDesc("text"), - }, - new ElementDescriptor[] {}, false); - - ElementDescriptor linearDescriptor = new ElementDescriptor("LinearLayout", "Linear Layout", - "", "", - new AttributeDescriptor[] { - createTextAttrDesc("orientation"), - }, - new ElementDescriptor[] { }, false); - - ElementDescriptor relativeDescriptor = new ElementDescriptor("RelativeLayout", - "Relative Layout", "", "", - new AttributeDescriptor[] { - createTextAttrDesc("orientation"), - }, - new ElementDescriptor[] { }, false); - - ElementDescriptor[] a = new ElementDescriptor[] { - buttonDescriptor, textDescriptor, linearDescriptor, relativeDescriptor - }; - - linearDescriptor.setChildren(a); - relativeDescriptor.setChildren(a); - - // document descriptor - ElementDescriptor rootDescriptor = new ElementDescriptor("root", "", "", "", - new AttributeDescriptor[] { }, a, false); - - - ui = new UiElementNode(rootDescriptor); - - /* create a dummy XML file. - * - *