OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / tools / layoutlib / create / tests / com / android / tools / layoutlib / create / AsmGeneratorTest.java
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 package com.android.tools.layoutlib.create;
19
20
21 import static org.junit.Assert.assertArrayEquals;
22
23 import com.android.tools.layoutlib.create.LogTest.MockLog;
24
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import java.io.File;
30 import java.io.IOException;
31 import java.net.URL;
32 import java.util.ArrayList;
33 import java.util.Set;
34
35 /**
36  * Unit tests for some methods of {@link AsmGenerator}.
37  */
38 public class AsmGeneratorTest {
39
40     private MockLog mLog;
41     private ArrayList<String> mOsJarPath;
42     private String mOsDestJar;
43     private File mTempFile;
44
45     @Before
46     public void setUp() throws Exception {
47         mLog = new LogTest.MockLog();
48         URL url = this.getClass().getClassLoader().getResource("data/mock_android.jar");
49         
50         mOsJarPath = new ArrayList<String>();
51         mOsJarPath.add(url.getFile());
52
53         mTempFile = File.createTempFile("mock", "jar");
54         mOsDestJar = mTempFile.getAbsolutePath();
55         mTempFile.deleteOnExit();
56     }
57
58     @After
59     public void tearDown() throws Exception {
60         if (mTempFile != null) {
61             mTempFile.delete();
62             mTempFile = null;
63         }
64     }
65
66     @Test
67     public void testClassRenaming() throws IOException, LogAbortException {
68         
69         AsmGenerator agen = new AsmGenerator(mLog, mOsDestJar,
70             null, // classes to inject in the final JAR
71             null,  // methods to force override
72             new String[] {  // classes to rename (so that we can replace them)
73                 "mock_android.view.View", "mock_android.view._Original_View",
74                 "not.an.actual.ClassName", "anoter.fake.NewClassName",
75             },
76             null // methods deleted from their return type.
77             );
78
79         AsmAnalyzer aa = new AsmAnalyzer(mLog, mOsJarPath, agen,
80                 null,                 // derived from
81                 new String[] {        // include classes
82                     "**"
83                 });
84         aa.analyze();
85         agen.generate();
86         
87         Set<String> notRenamed = agen.getClassesNotRenamed();
88         assertArrayEquals(new String[] { "not/an/actual/ClassName" }, notRenamed.toArray());
89     }
90 }