| 1 |
/* |
| 2 |
* Copyright (C) 2013 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package com.android.ide.common.res2; |
| 18 |
|
| 19 |
import static org.junit.Assert.assertEquals; |
| 20 |
import static org.junit.Assert.assertTrue; |
| 21 |
|
| 22 |
import com.android.testutils.TestUtils; |
| 23 |
|
| 24 |
import org.junit.Test; |
| 25 |
|
| 26 |
import java.io.File; |
| 27 |
import java.io.IOException; |
| 28 |
|
| 29 |
public class AssetSetTest extends BaseTestCase { |
| 30 |
|
| 31 |
private static AssetSet sBaseResourceSet = null; |
| 32 |
|
| 33 |
@Test |
| 34 |
public void testBaseAssetSetByCount() throws Exception { |
| 35 |
AssetSet assetSet = getBaseAssetSet(); |
| 36 |
assertEquals(4, assetSet.size()); |
| 37 |
} |
| 38 |
|
| 39 |
@Test |
| 40 |
public void testBaseAssetSetByName() throws Exception { |
| 41 |
AssetSet assetSet = getBaseAssetSet(); |
| 42 |
|
| 43 |
verifyResourceExists(assetSet, |
| 44 |
"foo/foo.dat", |
| 45 |
"foo/icon.png", |
| 46 |
"main.xml", |
| 47 |
"values.xml" |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
@Test |
| 52 |
public void testDupAssetSet() throws Exception { |
| 53 |
File root = TestUtils.getRoot("assets", "dupSet"); |
| 54 |
|
| 55 |
AssetSet set = new AssetSet("main"); |
| 56 |
set.addSource(new File(root, "assets1")); |
| 57 |
set.addSource(new File(root, "assets2")); |
| 58 |
boolean gotException = false; |
| 59 |
RecordingLogger logger = new RecordingLogger(); |
| 60 |
try { |
| 61 |
set.loadFromFiles(logger); |
| 62 |
} catch (DuplicateDataException e) { |
| 63 |
gotException = true; |
| 64 |
} |
| 65 |
|
| 66 |
assertTrue(gotException); |
| 67 |
checkLogger(logger); |
| 68 |
} |
| 69 |
|
| 70 |
static AssetSet getBaseAssetSet() throws MergingException, IOException { |
| 71 |
if (sBaseResourceSet == null) { |
| 72 |
File root = TestUtils.getRoot("assets", "baseSet"); |
| 73 |
|
| 74 |
RecordingLogger logger = new RecordingLogger(); |
| 75 |
|
| 76 |
sBaseResourceSet = new AssetSet("main"); |
| 77 |
sBaseResourceSet.addSource(root); |
| 78 |
sBaseResourceSet.loadFromFiles(logger); |
| 79 |
checkLogger(logger); |
| 80 |
} |
| 81 |
|
| 82 |
return sBaseResourceSet; |
| 83 |
} |
| 84 |
} |