• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.ide.eclipse.adt.internal.editors.layout.gre;
17 
18 import com.android.ide.common.api.IViewMetadata.FillPreference;
19 import com.android.ide.eclipse.adt.internal.editors.layout.gre.ViewMetadataRepository.RenderMode;
20 
21 import java.util.Arrays;
22 
23 import junit.framework.TestCase;
24 
25 public class ViewMetadataRepositoryTest extends TestCase {
testSingleton()26     public void testSingleton() throws Exception {
27         assertSame(ViewMetadataRepository.get(), ViewMetadataRepository.get());
28     }
29 
testBasic()30     public void testBasic() throws Exception {
31         ViewMetadataRepository repository = ViewMetadataRepository.get();
32 
33         assertEquals(FillPreference.WIDTH_IN_VERTICAL,
34                 repository.getFillPreference("android.widget.Spinner"));
35         assertEquals(FillPreference.NONE,
36                 repository.getFillPreference("foo.bar"));
37     }
38 
39     // Ensure that all basenames referenced in the metadata refer to other views in the file
40     // (e.g. no typos)
testRelatedTo()41     public void testRelatedTo() throws Exception {
42         // Make sure unit tests are run with assertions on
43         boolean assertionsEnabled = false;
44         assert assertionsEnabled = true; // Intentional assignment
45         assertTrue("This unit test must be run with assertions enabled (-ea)", assertionsEnabled);
46 
47         ViewMetadataRepository repository = ViewMetadataRepository.get();
48         for (String fqcn : repository.getAllFqcns()) {
49             repository.getRelatedTo(fqcn);
50         }
51     }
52 
testSkip()53     public void testSkip() throws Exception {
54         ViewMetadataRepository repository = ViewMetadataRepository.get();
55         assertTrue(repository.getSkip("merge"));
56         assertFalse(repository.getSkip("android.widget.Button"));
57     }
58 
testRenderMode()59     public void testRenderMode() throws Exception {
60         ViewMetadataRepository repository = ViewMetadataRepository.get();
61         assertEquals(RenderMode.NORMAL, repository.getRenderMode("android.widget.Button"));
62         assertEquals(RenderMode.SKIP, repository.getRenderMode("android.widget.LinearLayout"));
63         assertEquals(RenderMode.ALONE, repository.getRenderMode("android.widget.TabHost"));
64     }
65 
testGetTopAttributes()66     public void testGetTopAttributes() throws Exception {
67         ViewMetadataRepository repository = ViewMetadataRepository.get();
68         assertEquals(Arrays.asList("id", "text", "style"),
69                 repository.getTopAttributes("android.widget.RadioButton"));
70         assertEquals(Arrays.asList("id", "gravity", "paddingLeft", "paddingRight", "checkMark",
71                 "textAppearance"),
72                 repository.getTopAttributes("android.widget.CheckedTextView"));
73         assertEquals(Arrays.asList("id"),
74                 repository.getTopAttributes("android.widget.NonExistent"));
75     }
76 
77 }
78