1 /*
2  * Copyright (C) 2017 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 package com.android.compatibility.common.tradefed.util;
17 
18 import static org.junit.Assert.assertEquals;
19 
20 import com.android.compatibility.common.tradefed.testtype.IModuleDef;
21 import com.android.compatibility.common.tradefed.testtype.ModuleDef;
22 import com.android.compatibility.common.tradefed.testtype.TestStub;
23 import com.android.tradefed.config.ConfigurationDescriptor;
24 import com.android.tradefed.targetprep.ITargetPreparer;
25 import com.android.tradefed.testtype.Abi;
26 
27 import org.junit.Test;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 /**
33  * Unit tests for {@link UniqueModuleCountUtil}.
34  */
35 public class UniqueModuleCountUtilTest {
36 
37     @Test
testCountEmptyList()38     public void testCountEmptyList() {
39         List<IModuleDef> emptyList = new ArrayList<>();
40         assertEquals(0, UniqueModuleCountUtil.countUniqueModules(emptyList));
41     }
42 
43     @Test
testCount_2uniquesModules()44     public void testCount_2uniquesModules() {
45         List<IModuleDef> list = new ArrayList<>();
46         list.add(new ModuleDef("moduleA", new Abi("arm64", "64"), new TestStub(),
47                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
48         list.add(new ModuleDef("moduleA", new Abi("arm32", "32"), new TestStub(),
49                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
50         assertEquals(2, UniqueModuleCountUtil.countUniqueModules(list));
51     }
52 
53     @Test
testCount_2subModules()54     public void testCount_2subModules() {
55         List<IModuleDef> list = new ArrayList<>();
56         list.add(new ModuleDef("moduleA", new Abi("arm32", "32"), new TestStub(),
57                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
58         list.add(new ModuleDef("moduleA", new Abi("arm32", "32"), new TestStub(),
59                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
60         assertEquals(1, UniqueModuleCountUtil.countUniqueModules(list));
61     }
62 
63     @Test
testCount_mix()64     public void testCount_mix() {
65         List<IModuleDef> list = new ArrayList<>();
66         list.add(new ModuleDef("moduleA", new Abi("arm64", "64"), new TestStub(),
67                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
68         list.add(new ModuleDef("moduleA", new Abi("arm32", "32"), new TestStub(),
69                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
70         list.add(new ModuleDef("moduleC", new Abi("arm32", "32"), new TestStub(),
71                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
72         list.add(new ModuleDef("moduleB", new Abi("arm64", "64"), new TestStub(),
73                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
74         list.add(new ModuleDef("moduleB", new Abi("arm32", "32"), new TestStub(),
75                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
76         list.add(new ModuleDef("moduleC", new Abi("arm64", "64"), new TestStub(),
77                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
78         list.add(new ModuleDef("moduleA", new Abi("arm32", "32"), new TestStub(),
79                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
80         list.add(new ModuleDef("moduleC", new Abi("arm32", "32"), new TestStub(),
81                 new ArrayList<ITargetPreparer>(), new ConfigurationDescriptor()));
82         assertEquals(6, UniqueModuleCountUtil.countUniqueModules(list));
83     }
84 }
85