]> granicus.if.org Git - icu/commitdiff
ICU-12423 merge in coverage tests for several classes from branches/fabalbon/56-1...
authorMarkus Scherer <markus.icu@gmail.com>
Tue, 5 Apr 2016 20:43:46 +0000 (20:43 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Tue, 5 Apr 2016 20:43:46 +0000 (20:43 +0000)
X-SVN-Rev: 38601

15 files changed:
icu4j/main/classes/core/src/com/ibm/icu/impl/Norm2AllModes.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/ChineseTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/IndianTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/PersianTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPIC.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbols.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/MeasureUnitTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestMessageFormat.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeZoneFormatTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/normalizer/BasicTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java

index cc3ee5203f518dfbf45616233269b77ace0f1a55..d8bb77380bdf2071a0166c56687fd700771563e4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- *   Copyright (C) 2009-2014, International Business Machines
+ *   Copyright (C) 2009-2016, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *******************************************************************************
  */
@@ -155,9 +155,7 @@ public final class Norm2AllModes {
             return isNormalized(s) ? Normalizer.YES : Normalizer.NO;
         }
 
-        public int getQuickCheck(int c) {
-            return 1;
-        }
+        public abstract int getQuickCheck(int c);
 
         public final Normalizer2Impl impl;
     }
index 8ab5e6f0d305b085991d9f49aabd0b3d6dd8b9e9..39af99ff35167e03167fefdc30e5afe010798dca 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************************
- * Copyright (C) 2000-2015, International Business Machines Corporation and
+ * Copyright (C) 2000-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  *********************************************************************
  */
@@ -713,6 +713,10 @@ public class ChineseTest extends CalendarTest {
  
         // lunar to gregorian 
         chineseCalendar = new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6, 0, 0, 0); 
+        // coverage
+        assertEquals("equivalent ChineseCalendar() constructors", chineseCalendar,
+                new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6));
+
         gregorianCalendar = Calendar.getInstance(Locale.US); 
         gregorianCalendar.setTime(chineseCalendar.getTime()); 
  
index be508cd37ea7ba24366693564ead5d058767df3d..bd547fe71efd427fc5744d09004ab52ff88a3c28 100644 (file)
@@ -6,6 +6,7 @@
  */
 package com.ibm.icu.dev.test.calendar;
 
+import java.text.FieldPosition;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.Locale;
@@ -15,6 +16,7 @@ import com.ibm.icu.impl.CalendarAstronomer;
 import com.ibm.icu.impl.LocaleUtility;
 import com.ibm.icu.impl.ZoneMeta;
 import com.ibm.icu.text.DateFormat;
+import com.ibm.icu.text.DateFormatSymbols;
 import com.ibm.icu.text.SimpleDateFormat;
 import com.ibm.icu.util.BuddhistCalendar;
 import com.ibm.icu.util.Calendar;
@@ -934,9 +936,24 @@ public class IBMCalendarTest extends CalendarTest {
              * For serialization
              */
             private static final long serialVersionUID = -4558903444622684759L;
-            protected int handleGetLimit(int field, int limitType) {return 0;}
-            protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) {return 0;}
-            protected int handleGetExtendedYear() {return 0;}
+
+            protected int handleGetLimit(int field, int limitType) {
+                if (limitType == Calendar.LEAST_MAXIMUM) {
+                    return 1;
+                } else if (limitType == Calendar.GREATEST_MINIMUM) {
+                    return 7;
+                }
+               return -1;
+            }
+            protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) {
+                if (useMonth) {
+                    return eyear * 365 + month * 31;
+                } else {
+                    return eyear * 365;
+                }
+            }
+            protected int handleGetExtendedYear() {return 2017;}
+
             public void run(){
                 if (Calendar.gregorianPreviousMonthLength(2000,2) != 29){
                     errln("Year 2000 Feb should have 29 days.");
@@ -952,6 +969,37 @@ public class IBMCalendarTest extends CalendarTest {
                 if (!getType().equals("unknown")){
                     errln ("Calendar.getType() should be 'unknown'");
                 }
+
+                // Tests for complete coverage of Calendar functions.
+                int julianDay = Calendar.millisToJulianDay(millis - 1);
+                assertEquals("Julian max day -1", julianDay, Calendar.MAX_JULIAN - 1);
+                              
+                DateFormat df1 = handleGetDateFormat("GG yyyy-d:MM", "option=xyz", Locale.getDefault());
+                if (!df1.equals(handleGetDateFormat("GG yyyy-d:MM", "option=xyz", ULocale.getDefault()))){
+                    errln ("Calendar.handleGetDateFormat(String, Locale) should delegate to ( ,ULocale)");                  
+                }
+   
+                // Prove that the local overrides are used.
+                int leastMsInDay = handleGetLimit(Calendar.MILLISECONDS_IN_DAY, Calendar.LEAST_MAXIMUM);
+                assertEquals("getLimit test 1", leastMsInDay, 1);
+                int maxMsInDay = handleGetLimit(Calendar.WEEK_OF_MONTH, Calendar.GREATEST_MINIMUM);
+                assertEquals("getLimit test 2", 7, maxMsInDay);
+                
+                int febLeapLength = handleGetMonthLength(2020, Calendar.FEBRUARY);
+                assertEquals("handleMonthLength", 31, febLeapLength);
+                int exYear = handleGetExtendedYear();
+                assertEquals("handleGetExtendeYear", exYear, 2017);
+                int monthStart = handleComputeMonthStart(2016, 4, false);
+                assertEquals("handleComputeMonthStart false", 735840, monthStart);
+                monthStart = handleComputeMonthStart(2016, 4, true);
+                assertEquals("handleComputeMonthStart true", 735964, monthStart);
+
+                Calendar cal = Calendar.getInstance();
+                cal.set(1980, 5, 2);
+                this.setTime(cal.getTime());
+                assertEquals("handleComputeFields: year set", 1980, get(YEAR));
+                assertEquals("handleComputeFields: month set", 5, get(MONTH));
+                assertEquals("handleComputeFields: day set", 2, get(DAY_OF_MONTH));
             }
         }
         StubCalendar stub = new StubCalendar();
@@ -1882,4 +1930,51 @@ public class IBMCalendarTest extends CalendarTest {
             }
         }
     }
+    
+    public void TestSimpleDateFormatCoverage() {
+
+        class StubSimpleDateFormat extends SimpleDateFormat {
+            public StubSimpleDateFormat(String pattern, Locale loc) {
+                new SimpleDateFormat(pattern, loc);
+            }
+            
+            public void run(){
+                Calendar cal = Calendar.getInstance(Locale.US);
+                cal.clear();
+                cal.set(2000, Calendar.MARCH, 18, 15,  0, 1); // Sat 15:00
+
+                DateFormatSymbols theseSymbols = this.getSymbols();
+                String shouldBeMonday = theseSymbols.getWeekdays()[Calendar.MONDAY];
+                assertEquals("Should be Monday", "Monday", shouldBeMonday);
+                
+                String [] matchData = {"16", "2016", "2016AD", "Monday", "lunes"};
+                int matchIndex =  matchString("Monday March 28, 2016", 0, Calendar.DAY_OF_WEEK, matchData, cal);
+                assertEquals("matchData for Monday", 6, matchIndex); // Position of the pointer after the matched string.
+                matchIndex =  matchString("Monday March 28, 2016 AD", 17, Calendar.YEAR, matchData, cal);
+                assertEquals("matchData for 2016", 21, matchIndex); // Position of the pointer after the matched string.
+      
+                char ch = 'y';
+                int count = 4;
+                int beginOffset = 0;
+                cal.set(Calendar.YEAR, 2000);  // Reset this 
+                assertEquals("calendar year reset", 2000, cal.get(Calendar.YEAR));
+                FieldPosition pos = new FieldPosition(java.text.DateFormat.YEAR_FIELD);
+                String subFormatResult = subFormat(ch, count, beginOffset,
+                        pos, theseSymbols, cal);
+                assertEquals("subFormat result", "2000", subFormatResult);
+
+                String testParseString = "some text with a date 2017-03-15";
+                int start = 22;
+                boolean obeyCount = true;
+                boolean allowNegative = false;
+                boolean ambiguousYear[] = {true, false, true};
+                int subParseResult = subParse(testParseString, start, ch, count,
+                        obeyCount, allowNegative, ambiguousYear, cal);
+                assertEquals("subParseResult result", 26, subParseResult);
+                assertEquals("parsed year", 2017, cal.get(Calendar.YEAR));
+            }
+        }
+        StubSimpleDateFormat stub = new StubSimpleDateFormat("EEE MMM dd yyyy G HH:mm:ss.SSS", Locale.US);
+        stub.run();
+    }
 }
index d8633f94e5886c87d217da4ce87cc5ea8c74e3c5..c68a59eee4055e9a4a93d9bd6a79b1624fc2d742 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *******************************************************************************
- * Copyright (C) 2005-2011, International Business Machines Corporation and    *
- * others. All Rights Reserved.                                                *
+ * Copyright (C) 2005-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
  *******************************************************************************
  */
 package com.ibm.icu.dev.test.calendar;
@@ -273,4 +273,16 @@ public class IndianTest extends CalendarTest
             errln("Incorrect calendar value for year edge test");
         }
     }
+
+    public void TestCoverage12424() {
+        class StubCalendar extends IndianCalendar {   
+            private static final long serialVersionUID = 1L;
+            public StubCalendar() {
+                assertEquals("Indian month 0 length", 30, handleGetMonthLength(1000, 0));
+                assertEquals("Indian month 2 length", 31, handleGetMonthLength(1000, 2));
+             }
+        }
+        
+        new StubCalendar();
+    }
 }
index 70300c600905037c8c9aeb0fecf650d0562ad3f3..0e492c25a37c2b8da3e146702f92f355ce7fff73 100644 (file)
@@ -1,13 +1,14 @@
 /*
  *******************************************************************************
- * Copyright (C) 2012, International Business Machines Corporation and         *
- * others. All Rights Reserved.                                                *
+ * Copyright (C) 2012-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
  *******************************************************************************
  */
 package com.ibm.icu.dev.test.calendar;
 import java.util.Date;
 
 import com.ibm.icu.util.Calendar;
+import com.ibm.icu.util.PersianCalendar;
 import com.ibm.icu.util.ULocale;
 
 public class PersianTest extends CalendarTest {
@@ -123,4 +124,19 @@ public class PersianTest extends CalendarTest {
             }
         }
     }
+
+    public void TestCoverage12424() {
+        class StubCalendar extends PersianCalendar {   
+            private static final long serialVersionUID = 1L;
+            public StubCalendar() {
+                assertEquals("Persian month 0 length", 31, handleGetMonthLength(1000, 0));
+                assertEquals("Persian month 7 length", 30, handleGetMonthLength(1000, 7));
+                
+                int leastWeeks = handleGetLimit(Calendar.WEEK_OF_YEAR, Calendar.LEAST_MAXIMUM);
+                assertEquals("Persian Week of Year least maximum", 52, leastWeeks);             
+             }
+        }
+        
+        new StubCalendar();
+    }
 }
index bc28061e297481238c793c909caada4faefb3bde..8dee4abe5157dae0b9b7f3a45fb51059e485a4fe 100644 (file)
@@ -12,6 +12,7 @@ import java.text.FieldPosition;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
+import java.util.Locale;
 import java.util.Map;
 
 import com.ibm.icu.dev.test.TestFmwk;
@@ -324,8 +325,7 @@ public class CompactDecimalFormatTest extends TestFmwk {
             return;
         }
         NumberFormat cdf =
-                CompactDecimalFormat.getInstance(
-                        ULocale.forLanguageTag("ar"), CompactStyle.LONG);
+                CompactDecimalFormat.getInstance(new Locale("ar"), CompactStyle.LONG);
         assertEquals("Arabic Long", "\u200F-\u0665\u066B\u0663 \u0623\u0644\u0641", cdf.format(-5300));
     }
 
index 1f34ab1aff3fdea5a5f166a4d9373b8e5463f2e2..eb9f5f49ab75520b6d99df7a2f005b9e8dff3738 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *******************************************************************************
- * Copyright (C) 2001-2015, International Business Machines Corporation and    *
- * others. All Rights Reserved.                                                *
+ * Copyright (C) 2001-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
  *******************************************************************************
  */
 
@@ -21,9 +21,11 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
+import com.ibm.icu.text.CurrencyPluralInfo;
 import com.ibm.icu.text.DecimalFormat;
 import com.ibm.icu.text.DecimalFormatSymbols;
 import com.ibm.icu.text.NumberFormat;
+import com.ibm.icu.util.ULocale;
 
 // This is an API test, not a unit test.  It doesn't test very many cases, and doesn't
 // try to test the full functionality.  It just calls each function in the class and
@@ -48,6 +50,9 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
         DecimalFormat def = new DecimalFormat();
 
         final String pattern = new String("#,##0.# FF");
+        final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.FRENCH);
+        final CurrencyPluralInfo infoInput = new CurrencyPluralInfo(ULocale.FRENCH);
+        
         DecimalFormat pat = null;
         try {
             pat = new DecimalFormat(pattern);
@@ -55,9 +60,20 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
             errln("ERROR: Could not create DecimalFormat (pattern)");
         }
 
-        DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.FRENCH);
+        DecimalFormat cust1 = null;
+        try {
+            cust1 = new DecimalFormat(pattern, symbols);
+        } catch (IllegalArgumentException e) {
+            errln("ERROR: Could not create DecimalFormat (pattern, symbols)");
+        }
+        
+        DecimalFormat cust2 = null;
+        try {
+            cust2 = new DecimalFormat(pattern, symbols, infoInput, NumberFormat.PLURALCURRENCYSTYLE);
+        } catch (IllegalArgumentException e) {
+            errln("ERROR: Could not create DecimalFormat (pattern, symbols, infoInput, style)");
+        }
 
-        DecimalFormat cust1 = new DecimalFormat(pattern, symbols);
 
         // ======= Test clone(), assignment, and equality
 
@@ -187,6 +203,11 @@ public class IntlTestDecimalFormatAPIC extends com.ibm.icu.dev.test.TestFmwk {
         String locPat;
         locPat = pat.toLocalizedPattern();
         logln("Localized pattern is " + locPat);
+        
+        pat.setCurrencyPluralInfo(infoInput);
+        if(!infoInput.equals(pat.getCurrencyPluralInfo())) {
+            errln("ERROR: set/get CurrencyPluralInfo() failed");
+        }
 
         // ======= Test applyPattern()
 
index b7acc810eddd56a9db5b7192328d85f12d2e674c..ece92223e17945fc4ce42cc564398d124cddcdcb 100644 (file)
@@ -1,6 +1,6 @@
 /*****************************************************************************************
  *
- *   Copyright (C) 1996-2010, International Business Machines
+ *   Copyright (C) 1996-2016, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  **/
 
@@ -21,6 +21,7 @@ import java.util.Locale;
 
 import com.ibm.icu.text.DecimalFormatSymbols;
 import com.ibm.icu.util.Currency;
+import com.ibm.icu.util.ULocale;
 
 public class IntlTestDecimalFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
 {
@@ -40,6 +41,13 @@ public class IntlTestDecimalFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
         }
 
         // just do some VERY basic tests to make sure that get/set work
+        
+        if(!en.getLocale().equals(Locale.ENGLISH)) {
+            errln("ERROR: getLocale failed");
+        }
+        if(!en.getULocale().equals(ULocale.ENGLISH)) {
+            errln("ERROR: getULocale failed");
+        }
 
         char zero = en.getZeroDigit();
         fr.setZeroDigit(zero);
@@ -145,6 +153,12 @@ public class IntlTestDecimalFormatSymbols extends com.ibm.icu.dev.test.TestFmwk
             errln("ERROR: get/set Exponential failed");
         }
         
+        String exponentMultiplicationSign = en.getExponentMultiplicationSign();
+        fr.setExponentMultiplicationSign(exponentMultiplicationSign);
+        if(fr.getExponentMultiplicationSign() != en.getExponentMultiplicationSign()) {
+            errln("ERROR: get/set ExponentMultiplicationSign failed");
+        }
+        
         // Test CurrencySpacing.
         // In CLDR 1.7, only root.txt has CurrencySpacing data. This data might 
         // be different between en and fr in the future.
index e663199c447ff0ae9e83efaa089477ee71c282f7..469ee1c796b9437ff2bfe987f4c4a4b6f2bf5c53 100644 (file)
@@ -1599,6 +1599,16 @@ public class MeasureUnitTest extends TestFmwk {
         assertTrue("MeasureUnit: unexpectedly few currencies defined", MeasureUnit.getAvailable("currency").size() > 50);
     }
 
+    public void testParseObject() {
+        MeasureFormat mf = MeasureFormat.getInstance(Locale.GERMAN, FormatWidth.NARROW);
+        try {
+            mf.parseObject("3m", null);
+            fail("MeasureFormat.parseObject(String, ParsePosition) " +
+                    "should throw an UnsupportedOperationException");
+        } catch (UnsupportedOperationException expected) {
+        }
+    }
+
     // DO NOT DELETE THIS FUNCTION! It may appear as dead code, but we use this to generate code
     // for MeasureFormat during the release process.
     static Map<MeasureUnit, Pair<MeasureUnit, MeasureUnit>> getUnitsToPerParts() {
index aa98f19c2667819a84f791021346ccc9cd81dfff..6722eeed848f986fd3d466af12d465323b9ece2a 100644 (file)
@@ -33,6 +33,7 @@ import com.ibm.icu.impl.data.ResourceReader;
 import com.ibm.icu.impl.data.TokenIterator;
 import com.ibm.icu.math.BigDecimal;
 import com.ibm.icu.math.MathContext;
+import com.ibm.icu.text.CompactDecimalFormat;
 import com.ibm.icu.text.DecimalFormat;
 import com.ibm.icu.text.DecimalFormatSymbols;
 import com.ibm.icu.text.DisplayContext;
@@ -40,6 +41,8 @@ import com.ibm.icu.text.MeasureFormat;
 import com.ibm.icu.text.NumberFormat;
 import com.ibm.icu.text.NumberFormat.NumberFormatFactory;
 import com.ibm.icu.text.NumberFormat.SimpleNumberFormatFactory;
+import com.ibm.icu.text.NumberingSystem;
+import com.ibm.icu.text.RuleBasedNumberFormat;
 import com.ibm.icu.util.Currency;
 import com.ibm.icu.util.CurrencyAmount;
 import com.ibm.icu.util.ULocale;
@@ -1954,6 +1957,50 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
             }
         }
     }
+    
+    // Coverage tests for methods not being called otherwise.
+    public void TestNumberingSystemCoverage() {
+        // Test getAvaliableNames
+        String[] availableNames = NumberingSystem.getAvailableNames();
+        if (availableNames == null || availableNames.length <= 0) {
+            errln("ERROR: NumberingSystem.getAvailableNames() returned a null or empty array.");
+        } else {
+            boolean latnFound = false;
+            for (String name : availableNames){
+                if ("latn".equals(name)) {
+                    latnFound = true;
+                    break;
+                }
+            }
+            
+            if (!latnFound) {
+                errln("ERROR: 'latn' numbering system not found on NumberingSystem.getAvailableNames().");
+            }
+        }
+        
+        // Test NumberingSystem.getInstance()
+        NumberingSystem ns1 = NumberingSystem.getInstance();
+        if (ns1 == null || ns1.isAlgorithmic()) {
+            errln("ERROR: NumberingSystem.getInstance() returned a null or invalid NumberingSystem");
+        }
+        
+        // Test NumberingSystem.getInstance(int,boolean,String)
+        /* Parameters used: the ones used in the default constructor
+         * radix = 10;
+         * algorithmic = false;
+         * desc = "0123456789";
+         */
+        NumberingSystem ns2 = NumberingSystem.getInstance(10, false, "0123456789");
+        if (ns2 == null || ns2.isAlgorithmic()) {
+            errln("ERROR: NumberingSystem.getInstance(int,boolean,String) returned a null or invalid NumberingSystem");
+        }
+        
+        // Test NumberingSystem.getInstance(Locale)
+        NumberingSystem ns3 = NumberingSystem.getInstance(Locale.ENGLISH);
+        if (ns3 == null || ns3.isAlgorithmic()) {
+            errln("ERROR: NumberingSystem.getInstance(Locale) returned a null or invalid NumberingSystem");
+        }
+    }
 
     public void Test6816() {
         Currency cur1 = Currency.getInstance(new Locale("und", "PH"));
@@ -3243,6 +3290,36 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
         }
     }
 
+    /*
+     * Coverage tests for the implementation of abstract format methods not being called otherwise
+     */
+    public void TestFormatAbstractImplCoverage() {
+        NumberFormat df = DecimalFormat.getInstance(Locale.ENGLISH);
+        NumberFormat cdf = CompactDecimalFormat.getInstance(Locale.ENGLISH, CompactDecimalFormat.CompactStyle.SHORT);
+        NumberFormat rbf = new RuleBasedNumberFormat(ULocale.ENGLISH, RuleBasedNumberFormat.SPELLOUT);
+
+        /*
+         *  Test  NumberFormat.format(BigDecimal,StringBuffer,FieldPosition)
+         */
+        StringBuffer sb = new StringBuffer();
+        String result = df.format(new BigDecimal(2000.43), sb, new FieldPosition(0)).toString();
+        if (!"2,000.43".equals(result)) {
+            errln("DecimalFormat failed. Expected: 2,000.43 - Actual: " + result);
+        }
+
+        sb.delete(0, sb.length());
+        result = cdf.format(new BigDecimal(2000.43), sb, new FieldPosition(0)).toString();
+        if (!"2K".equals(result)) {
+            errln("DecimalFormat failed. Expected: 2K - Actual: " + result);
+        }
+
+        sb.delete(0, sb.length());
+        result = rbf.format(new BigDecimal(2000.43), sb, new FieldPosition(0)).toString();
+        if (!"two thousand point four three".equals(result)) {
+            errln("DecimalFormat failed. Expected: 'two thousand point four three' - Actual: '" + result + "'");
+        }  
+    }
+
     /*
      * Tests the method public final static NumberFormat getInstance(int style) public static NumberFormat
      * getInstance(Locale inLocale, int style) public static NumberFormat getInstance(ULocale desiredLocale, int choice)
@@ -3341,21 +3418,21 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
          * Tests the method public boolean visible()
          */
         if (tf.visible() != true) {
-            errln("NumberFormatFactor.visible() was suppose to return true.");
+            errln("NumberFormatFactory.visible() was suppose to return true.");
         }
 
         /*
          * Tests the method public NumberFormat createFormat(Locale loc, int formatType)
          */
         if (tf.createFormat(new Locale(""), 0) != null) {
-            errln("NumberFormatFactor.createFormat(Locale loc, int formatType) " + "was suppose to return null");
+            errln("NumberFormatFactory.createFormat(Locale loc, int formatType) " + "was suppose to return null");
         }
 
         /*
          * Tests the method public NumberFormat createFormat(ULocale loc, int formatType)
          */
         if (tf1.createFormat(new ULocale(""), 0) != null) {
-            errln("NumberFormatFactor.createFormat(ULocale loc, int formatType) " + "was suppose to return null");
+            errln("NumberFormatFactory.createFormat(ULocale loc, int formatType) " + "was suppose to return null");
         }
     }
 
index 852218894a5a75acb16f59d71fcbb5e62f9cd0f8..26f1b95f3d8e163371c992e76471bcd9731abdc2 100644 (file)
@@ -1,12 +1,13 @@
 /*
  *******************************************************************************
- * Copyright (C) 2007-2015, International Business Machines Corporation and
+ * Copyright (C) 2007-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
 
 package com.ibm.icu.dev.test.format;
 
+import java.text.FieldPosition;
 import java.text.ParsePosition;
 import java.util.Collection;
 import java.util.LinkedHashMap;
@@ -70,15 +71,31 @@ public class PluralFormatUnitTest extends TestFmwk {
             }
         }
         // Test some bigger numbers.
+        // Coverage: Use the format(Object, ...) version.
+        StringBuffer sb = new StringBuffer();
+        FieldPosition ignore = new FieldPosition(-1);
         for (int n = 100; n < 113; n++) {
             String result = numberFmt.format(n*n);
             for (int k = 0; k < plFmts.length; ++k) {
-                this.assertEquals("PluralFormat's output is not as expected",
-                        result, plFmts[k].format(n*n));
+                sb.delete(0, sb.length());
+                String pfResult = plFmts[k].format(Long.valueOf(n*n), sb, ignore).toString();
+                this.assertEquals("PluralFormat's output is not as expected", result, pfResult);
             }
         }
     }
 
+    public void TestEquals() {
+        // There is neither clone() nor a copy constructor.
+        PluralFormat de_fee_1 = new PluralFormat(ULocale.GERMAN, PluralType.CARDINAL, "other{fee}");
+        PluralFormat de_fee_2 = new PluralFormat(ULocale.GERMAN, PluralType.CARDINAL, "other{fee}");
+        PluralFormat de_fi = new PluralFormat(ULocale.GERMAN, PluralType.CARDINAL, "other{fi}");
+        PluralFormat fr_fee = new PluralFormat(ULocale.FRENCH, PluralType.CARDINAL, "other{fee}");
+        assertTrue("different de_fee objects", de_fee_1 != de_fee_2);
+        assertTrue("equal de_fee objects", de_fee_1.equals(de_fee_2));
+        assertFalse("different pattern strings", de_fee_1.equals(de_fi));
+        assertFalse("different locales", de_fee_1.equals(fr_fee));
+    }
+
     public void TestApplyPatternAndFormat() {
         // Create rules for testing.
         PluralRules oddAndEven =  PluralRules.createRules("odd: n mod 2 is 1");
@@ -354,6 +371,12 @@ public class PluralFormatUnitTest extends TestFmwk {
         pf.applyPattern(pattern);
         assertEquals("PluralFormat.format(456)", "456th file", pf.format(456));
         assertEquals("PluralFormat.format(111)", "111th file", pf.format(111));
+
+        // Code coverage: Use Locale not ULocale.
+        pf = new PluralFormat(Locale.ENGLISH, PluralType.ORDINAL);
+        pf.applyPattern(pattern);
+        assertEquals("PluralFormat.format(456)", "456th file", pf.format(456));
+        assertEquals("PluralFormat.format(111)", "111th file", pf.format(111));
     }
 
     public void TestDecimals() {
index 44f5120b8a276c943e63c1fa1d7674a45d30f8c5..2b44f8dc3b1a508a449497a77053a430c41f4e0c 100644 (file)
@@ -1956,4 +1956,77 @@ public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk {
         MessageFormat mf3 = new MessageFormat("{aa} {aaa}", ULocale.ENGLISH);
         assertEquals("aa aaa", "AB ABC", mf3.format(args, new StringBuffer(), null).toString());
     }
+
+    public void TestMessagePatternAutoQuoteApostropheDeep() {
+        // Example input & output taken from API docs.
+        MessagePattern pattern = new MessagePattern(
+                "I don't '{know}' {gender,select,female{h''er}other{h'im}}.");
+        assertEquals("autoQuoteApostropheDeep()",
+                "I don''t '{know}' {gender,select,female{h''er}other{h''im}}.",
+                pattern.autoQuoteApostropheDeep());
+    }
+
+    public void TestMessagePatternFreezable() {
+        MessagePattern pattern = new MessagePattern();
+        assertFalse("just constructed, not yet frozen", pattern.isFrozen());
+        pattern.parse("fee");
+        assertTrue("parsed, not empty", pattern.countParts() > 0);
+        pattern.freeze();
+        assertTrue("just frozen", pattern.isFrozen());
+        try {
+            pattern.parse("fi");
+            fail("MessagePattern.freeze().parse() did not fail");
+        } catch (Exception expected) {
+        }
+        assertEquals("frozen+parse: no change", "fee", pattern.autoQuoteApostropheDeep());
+        MessagePattern thawed = pattern.cloneAsThawed();
+        assertFalse("thawed", thawed.isFrozen());
+        assertTrue("still frozen", pattern.isFrozen());
+        assertTrue("frozen!=thawed", pattern != thawed);
+        thawed.parse("fo");
+        assertEquals("thawed+parse", "fo", thawed.autoQuoteApostropheDeep());
+    }
+
+    public void TestMessagePatternNamedAndNumberedArguments() {
+        MessagePattern pattern = new MessagePattern();
+        pattern.parse("fee");
+        assertFalse("fee no named args", pattern.hasNamedArguments());
+        assertFalse("fee no numbered args", pattern.hasNumberedArguments());
+        pattern.parse("fi {0}");
+        assertFalse("fi {0} no named args", pattern.hasNamedArguments());
+        assertTrue("fi {0} has numbered args", pattern.hasNumberedArguments());
+        pattern.parse("fo {name}");
+        assertTrue("fo {name} has named args", pattern.hasNamedArguments());
+        assertFalse("fo {name} no numbered args", pattern.hasNumberedArguments());
+        pattern.parse("fum {0} {name}");
+        assertTrue("fum {0} {name} has named args", pattern.hasNamedArguments());
+        assertTrue("fum {0} {name} no numbered args", pattern.hasNumberedArguments());
+    }
+
+    public void TestMessagePatternPartCoverage() {
+        MessagePattern pattern = new MessagePattern("ab{17}c");
+        assertEquals("msg start { arg number } msg limit", 5, pattern.countParts());
+        MessagePattern.Part arg = pattern.getPart(2);
+        assertEquals("arg number", MessagePattern.Part.Type.ARG_NUMBER, arg.getType());
+        assertEquals("arg number start", 3, arg.getIndex());
+        assertEquals("arg number length", 2, arg.getLength());
+        assertEquals("arg number limit", 5, arg.getLimit());
+        assertEquals("arg number 17", 17, arg.getValue());
+    }
+
+    public void TestMessagePatternParseChoiceStyle() {
+        // This would be tested by ChoiceFormat if ICU4J had its own version of that,
+        // like ICU4C does.
+        // Instead, there is only java.text.ChoiceFormat.
+        // Most of the implementation gets covered by testing with a MessageFormat
+        // that contains a nested ChoiceFormat pattern,
+        // but that does not call this public API method.
+        MessagePattern pattern = new MessagePattern();
+        // Example string from java.text.ChoiceFormat class docs.
+        pattern.parseChoiceStyle(
+                "-1#is negative| 0#is zero or fraction | 1#is one |" +
+                "1.0<is 1+ |2#is two |2<is more than 2.");
+        // Only simple API coverage. The parser implementation is tested via MessageFormat.
+        assertTrue("many parts", pattern.countParts() > 10);
+    }
 }
index 77dada4fa1ba0b2f6664280228b582e391a08c47..f0e64ed356bb11b69bcf5251278e5734baf9cdbb 100644 (file)
@@ -1,12 +1,13 @@
 /*
  ********************************************************************************
- * Copyright (C) 2007-2015, Google, International Business Machines Corporation *
- * and others. All Rights Reserved.                                             *
+ * Copyright (C) 2007-2016, Google, International Business Machines Corporation
+ * and others. All Rights Reserved.
  ********************************************************************************
  */
 
 package com.ibm.icu.dev.test.format;
 
+import java.text.FieldPosition;
 import java.text.ParseException;
 import java.text.ParsePosition;
 import java.util.ArrayList;
@@ -23,8 +24,10 @@ import java.util.regex.Pattern;
 import com.ibm.icu.impl.TZDBTimeZoneNames;
 import com.ibm.icu.impl.ZoneMeta;
 import com.ibm.icu.lang.UCharacter;
+import com.ibm.icu.text.DateFormat;
 import com.ibm.icu.text.SimpleDateFormat;
 import com.ibm.icu.text.TimeZoneFormat;
+import com.ibm.icu.text.TimeZoneFormat.GMTOffsetPatternType;
 import com.ibm.icu.text.TimeZoneFormat.ParseOption;
 import com.ibm.icu.text.TimeZoneFormat.Style;
 import com.ibm.icu.text.TimeZoneFormat.TimeType;
@@ -656,6 +659,48 @@ public class TimeZoneFormatTest extends com.ibm.icu.dev.test.TestFmwk {
             }
         }
     }
+    
+    // Coverage tests for other versions of the parse() method. All of them end up
+    // calling the full parse() method tested on the TestParse() test.
+    public void TestParseCoverage() {
+        TimeZone expectedTZ = TimeZone.getTimeZone("America/Los_Angeles");       
+        TimeZoneFormat fmt = TimeZoneFormat.getInstance(ULocale.ENGLISH);
+        
+        // Test parse(String)
+        try {
+            TimeZone tz1 = fmt.parse("America/Los_Angeles");
+            if (tz1 == null) {
+                errln("Parse failure using parse(String) - expected: " + expectedTZ.getID());
+            } else if (!expectedTZ.equals(tz1)) {
+                errln("Parsed TimeZone: '" + tz1.getID()  + "' using parse(String) - expected: "
+                        + expectedTZ.getID());
+            } 
+        } catch (ParseException e) {
+            errln("Parse failure using parse(String) - expected: " + expectedTZ.getID()
+                    + " exception: " + e.getMessage());
+        }
+        
+        // Test parse(String, ParsePosition)
+        TimeZone tz2 = fmt.parse("++America/Los_Angeles", new ParsePosition(2));
+        if (tz2 == null) {
+            errln("Parse failure using parse(String, ParsePosition) - expected: " 
+                    + expectedTZ.getID());
+        } else if (!expectedTZ.equals(tz2)) {
+            errln("Parsed TimeZone: '" + tz2.getID()  + "' using parse(String, ParsePosition) - expected: "
+                    + expectedTZ.getID());
+        }
+        
+        // Test parseObject(String, ParsePosition)
+        Object tz3 = fmt.parseObject("++America/Los_Angeles", new ParsePosition(2));
+        if (tz3 == null) {
+            errln("Parse failure using parseObject(String, ParsePosition) - expected: " 
+                    + expectedTZ.getID());
+        } else if (!expectedTZ.equals(tz3)) {
+            errln("Parsed TimeZone: '" + ((TimeZone)tz3).getID()
+                    + "' using parseObject(String, ParsePosition) - expected: "
+                    + expectedTZ.getID());
+        }
+    }
 
     public void TestISOFormat() {
         final int[] OFFSET = {
@@ -984,6 +1029,41 @@ public class TimeZoneFormatTest extends com.ibm.icu.dev.test.TestFmwk {
         }
     }
 
+    // Tests format(Object, StringBuffer, FieldPosition):StringBuffer method
+    // inherited from Format class
+    public void TestInheritedFormat() {
+        TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
+        Calendar cal = Calendar.getInstance(tz);
+        cal.setTimeInMillis(1459187377690L); // Mar 28, 2016
+        
+        StringBuffer sb = new StringBuffer();
+        FieldPosition fp = new FieldPosition(DateFormat.Field.TIME_ZONE);
+        
+        TimeZoneFormat fmt = TimeZoneFormat.getInstance(ULocale.ENGLISH);
+        
+        // Test formatting a non-timezone related object
+        try {
+            fmt.format(new Object(), sb, fp);
+            errln("ERROR: format non-timezone related object failed");
+        } catch (IllegalArgumentException e) { /* Expected */ }
+        
+        // Test formatting a TimeZone object
+        sb = new StringBuffer();
+        fmt.format(tz, sb, fp);
+        // When formatting a TimeZone object the formatter uses the current date.
+        String fmtOutput = tz.inDaylightTime(new Date()) ? "GMT-07:00" : "GMT-08:00";
+        if (!sb.toString().equals(fmtOutput)) {
+            errln("ERROR: format TimerZone object failed. Expected: " + fmtOutput + ", actual: " + sb);
+        }
+        
+        // Test formatting a Calendar object
+        sb = new StringBuffer();
+        fmt.format(cal, sb, fp);
+        if (!sb.toString().equals("GMT-07:00")) {
+            errln("ERROR: format Calendar object failed. Expected: GMT-07:00, actual: " + sb);
+        }
+    }
+    
     // This is a test case of Ticket#11487.
     // Because the problem is reproduced for the very first time,
     // the reported problem cannot be reproduced with regular test
@@ -1021,4 +1101,28 @@ public class TimeZoneFormatTest extends com.ibm.icu.dev.test.TestFmwk {
             errln("Incorrect count: " + found.toString() + ", expected: " + numIteration);
         }
     }
+    
+    // Basic get/set test for methods not being called otherwise.
+    public void TestAPI() {
+        TimeZoneFormat tzfmtEn = TimeZoneFormat.getInstance(ULocale.ENGLISH);
+        TimeZoneFormat tzfmtAr = TimeZoneFormat.getInstance(new ULocale("ar")).cloneAsThawed();
+        
+        String digits = tzfmtEn.getGMTOffsetDigits();
+        tzfmtAr.setGMTOffsetDigits(digits);
+        if (!digits.equals(tzfmtAr.getGMTOffsetDigits())) {
+            errln("ERROR: get/set GMTOffsetDigits failed");
+        }
+        
+        String pattern = tzfmtEn.getGMTOffsetPattern(GMTOffsetPatternType.POSITIVE_H);
+        tzfmtAr.setGMTOffsetPattern(GMTOffsetPatternType.POSITIVE_H, pattern);
+        if (!pattern.equals(tzfmtAr.getGMTOffsetPattern(GMTOffsetPatternType.POSITIVE_H))) {
+            errln("ERROR: get/set GMTOffsetPattern failed");
+        }
+        
+        String zeroFmt = tzfmtEn.getGMTZeroFormat();
+        tzfmtAr.setGMTZeroFormat(zeroFmt);
+        if (!zeroFmt.equals(tzfmtAr.getGMTZeroFormat())) {
+            errln("ERROR: get/set GMTZeroFormat failed");
+        }
+    }
 }
\ No newline at end of file
index fa300046d027dd52695b12f585f107b36c41a3fb..23f1887f4f692ef216e0cf8dd6768dd6dd9ed4f8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 1996-2012, International Business Machines Corporation and
+ * Copyright (C) 1996-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
@@ -1720,7 +1720,12 @@ public class BasicTest extends TestFmwk {
             options|=Normalizer.INPUT_IS_FCD;
         }
 
-        return Normalizer.compare(s1, s2, options);
+        int cmpStrings = Normalizer.compare(s1, s2, options);
+        int cmpArrays = Normalizer.compare(
+                s1.toCharArray(), 0, s1.length(),
+                s2.toCharArray(), 0, s2.length(), options);
+        assertEquals("compare strings == compare char arrays", cmpStrings, cmpArrays);
+        return cmpStrings;
     }
 
     // reference implementation of UnicodeString::caseCompare
@@ -2649,6 +2654,13 @@ public class BasicTest extends TestFmwk {
                     ")==filtered NFC.getCC()",
                     expectedCC, cc);
         }
+
+        // More coverage.
+        StringBuilder sb=new StringBuilder();
+        assertEquals("filtered normalize()", "ää\u0304",
+                fn2.normalize("a\u0308ä\u0304", (Appendable)sb).toString());
+        assertTrue("filtered hasBoundaryAfter()", fn2.hasBoundaryAfter('ä'));
+        assertTrue("filtered isInert()", fn2.isInert(0x0313));
     }
 
     public void TestFilteredAppend() {
@@ -2711,4 +2723,50 @@ public class BasicTest extends TestFmwk {
                 "(normalizes to " + prettify(out) + ')',
                 " \u1E09", out);
     }
+
+    public void TestNFC() {
+        // Coverage tests.
+        Normalizer2 nfc = Normalizer2.getNFCInstance();
+        assertTrue("nfc.hasBoundaryAfter(space)", nfc.hasBoundaryAfter(' '));
+        assertFalse("nfc.hasBoundaryAfter(ä)", nfc.hasBoundaryAfter('ä'));
+    }
+
+    public void TestNFD() {
+        // Coverage tests.
+        Normalizer2 nfd = Normalizer2.getNFDInstance();
+        assertTrue("nfd.hasBoundaryAfter(space)", nfd.hasBoundaryAfter(' '));
+        assertFalse("nfd.hasBoundaryAfter(ä)", nfd.hasBoundaryAfter('ä'));
+    }
+
+    public void TestFCD() {
+        // Coverage tests.
+        Normalizer2 fcd = Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.FCD);
+        assertTrue("fcd.hasBoundaryAfter(space)", fcd.hasBoundaryAfter(' '));
+        assertFalse("fcd.hasBoundaryAfter(ä)", fcd.hasBoundaryAfter('ä'));
+        assertTrue("fcd.isInert(space)", fcd.isInert(' '));
+        assertFalse("fcd.isInert(ä)", fcd.isInert('ä'));
+
+        // This implementation method is unreachable via public API.
+        Norm2AllModes.FCDNormalizer2 impl = (Norm2AllModes.FCDNormalizer2)fcd;
+        assertEquals("fcd impl.getQuickCheck(space)", 1, impl.getQuickCheck(' '));
+        assertEquals("fcd impl.getQuickCheck(ä)", 0, impl.getQuickCheck('ä'));
+    }
+
+    public void TestNoneNormalizer() {
+        // Use the deprecated Mode Normalizer.NONE for coverage of the internal NoopNormalizer2
+        // as far as its methods are reachable that way.
+        assertEquals("NONE.concatenate()", "ä\u0327",
+                Normalizer.concatenate("ä", "\u0327", Normalizer.NONE, 0));
+        assertTrue("NONE.isNormalized()", Normalizer.isNormalized("ä\u0327", Normalizer.NONE, 0));
+    }
+
+    public void TestNoopNormalizer2() {
+        // Use the internal class directly for coverage of methods that are not publicly reachable.
+        Normalizer2 noop = Norm2AllModes.NOOP_NORMALIZER2;
+        assertEquals("noop.normalizeSecondAndAppend()", "ä\u0327",
+                noop.normalizeSecondAndAppend(new StringBuilder("ä"), "\u0327").toString());
+        assertEquals("noop.getDecomposition()", null, noop.getDecomposition('ä'));
+        assertTrue("noop.hasBoundaryAfter()", noop.hasBoundaryAfter(0x0308));
+        assertTrue("noop.isInert()", noop.isInert(0x0308));
+    }
 }
index cb3fd812deb029d68ea38387f9b989fb737a3ceb..5cbc64e550d23a9fcfb61e39a60f3349a7090f28 100644 (file)
@@ -1115,6 +1115,9 @@ public class ULocaleTest extends TestFmwk {
                 ULocale locale = new ULocale(item.displayLocale);
                 LocaleDisplayNames ldn = LocaleDisplayNames.getInstance(locale, item.dialectHandling, item.capitalization, item.nameLength);
                 DisplayContext dialectHandling = ldn.getContext(DisplayContext.Type.DIALECT_HANDLING);
+                assertEquals("consistent dialect handling",
+                        dialectHandling == DisplayContext.DIALECT_NAMES,
+                        ldn.getDialectHandling() == LocaleDisplayNames.DialectHandling.DIALECT_NAMES);
                 DisplayContext capitalization = ldn.getContext(DisplayContext.Type.CAPITALIZATION);
                 DisplayContext nameLength = ldn.getContext(DisplayContext.Type.DISPLAY_LENGTH);
                 if (dialectHandling != item.dialectHandling || capitalization != item.capitalization || nameLength != item.nameLength) {
@@ -1133,6 +1136,43 @@ public class ULocaleTest extends TestFmwk {
         }
     }
 
+    public void TestDisplayLanguageWithDialectCoverage() {
+        // Coverage test. Implementation is in class LocaleDisplayNames.
+        assertFalse("en in system default locale: anything but empty",
+                ULocale.ENGLISH.getDisplayLanguageWithDialect().isEmpty());
+        assertEquals("en in de", "Englisch",
+                ULocale.ENGLISH.getDisplayLanguageWithDialect(ULocale.GERMAN));
+        assertEquals("en (string) in de", "Englisch",
+                ULocale.getDisplayLanguageWithDialect("en", ULocale.GERMAN));
+        assertEquals("en (string) in de (string)", "Englisch",
+                ULocale.getDisplayLanguageWithDialect("en", "de"));
+    }
+
+    public void TestDisplayNameWithDialectCoverage() {
+        // Coverage test. Implementation is in class LocaleDisplayNames.
+        assertFalse("en-GB in system default locale: anything but empty",
+                ULocale.UK.getDisplayNameWithDialect().isEmpty());
+        assertEquals("en-GB in de", "Britisches Englisch",
+                ULocale.UK.getDisplayNameWithDialect(ULocale.GERMAN));
+        assertEquals("en-GB (string) in de", "Britisches Englisch",
+                ULocale.getDisplayNameWithDialect("en-GB", ULocale.GERMAN));
+        assertEquals("en-GB (string) in de (string)", "Britisches Englisch",
+                ULocale.getDisplayNameWithDialect("en-GB", "de"));
+    }
+
+    public void TestDisplayScriptCoverage() {
+        // Coverage test. Implementation is in class LocaleDisplayNames.
+        assertFalse("zh-Hans in system default locale: anything but empty",
+                ULocale.SIMPLIFIED_CHINESE.getDisplayScript().isEmpty());
+        // Stand-alone script name, so not just "Vereinfacht".
+        assertEquals("zh-Hans in de", "Vereinfachtes Chinesisch",
+                ULocale.SIMPLIFIED_CHINESE.getDisplayScript(ULocale.GERMAN));
+        assertEquals("zh-Hans (string) in de", "Vereinfachtes Chinesisch",
+                ULocale.getDisplayScript("zh-Hans", ULocale.GERMAN));
+        assertEquals("zh-Hans (string) in de (string)", "Vereinfachtes Chinesisch",
+                ULocale.getDisplayScript("zh-Hans", "de"));
+    }
+
     private boolean checkName(String name, String language, String script, String country, String variant, ULocale dl) {
         if (!checkInclusion(dl, name, language, "language")) {
             return false;