1 /*
2  * Copyright (C) 2018 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 android.icu.extratest;
17 
18 import org.junit.Before;
19 import org.junit.runner.RunWith;
20 import org.junit.runners.JUnit4;
21 import org.junit.Test;
22 
23 import android.icu.dev.data.TestDataElements_testtypes;
24 import android.icu.dev.test.TestFmwk;
25 import android.icu.testsharding.MainTestShard;
26 import android.icu.util.VersionInfo;
27 
28 import libcore.icu.ICU;
29 
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.util.Properties;
33 
34 @MainTestShard
35 @RunWith(JUnit4.class)
36 public class AndroidICUVersionTest extends TestFmwk {
37 
38     private static final String PROP_FILE = "android_icu_version.properties";
39     private static final String VERSION_PROP_NAME = "version";
40 
41     private VersionInfo expectedIcuVersion;
42 
43     @Before
setUp()44     public void setUp() throws IOException {
45         try (InputStream in = AndroidICUVersionTest.class.getResourceAsStream(PROP_FILE)) {
46             Properties prop = new Properties();
47             prop.load(in);
48             String propValue = prop.getProperty(VERSION_PROP_NAME);
49             assertNotNull("Expected ICU version can't be null", propValue);
50             expectedIcuVersion = VersionInfo.getInstance(propValue);
51         }
52     }
53 
54     @Test
testAndroidIcuVersion()55     public void testAndroidIcuVersion() {
56         // Check ICU4J.
57         VersionInfo actualIcu4jVersion = VersionInfo.ICU_VERSION;
58         assertEquals("The ICU4J major version is not expected.",
59                 expectedIcuVersion.getMajor(), actualIcu4jVersion.getMajor());
60         assertTrue("ICU4J minor version can't be smaller than the expected.",
61                 expectedIcuVersion.getMinor() <= actualIcu4jVersion.getMinor());
62 
63         // Check ICU4C.
64         VersionInfo actualIcu4cVersion = VersionInfo.getInstance(ICU.getIcuVersion());
65         assertEquals("The ICU4C major version is not expected.",
66                 expectedIcuVersion.getMajor(), actualIcu4cVersion.getMajor());
67         assertTrue("ICU4C minor version can't be smaller than the expected.",
68                 expectedIcuVersion.getMinor() <= actualIcu4cVersion.getMinor());
69     }
70 
71 }
72