svn commit: r19890 - trunk/tools/test-i18n-properties: . src/org/argouml/i18n

[email protected] Sat, 23 Jun 2012 13:55:42 -0700 (PDT)
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: linus
Date: 2012-06-23 13:55:42-0700
New Revision: 19890

Modified:
   trunk/tools/test-i18n-properties/   (props changed)
   trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java

Log:
Added the option of not testing everything. Remove the char test case. Added MessageFormat arguments test case.

Modified: trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java?view=diff&pathrev=19890&r1=19889&r2=19890
==============================================================================
--- trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java	(original)
+++ trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java	2012-06-23 13:55:42-0700
@@ -30,13 +30,23 @@
  * This is a test case for property files. 
  */
 public abstract class CheckKey {
+    public interface IgnoredKey {
+	public abstract boolean ignore(String theKey,
+				       Locale theLocale,
+				       ResourceBundle theLabels,
+				       ResourceBundle theRootLabels);
+    }
+
     /**
      * Create the list of objects to test.
      *
      * @param currentLocale the Locale to test.
+     * @param predicate an IgnoredKey that returns true for keys to ignore
      * @return a Collection of arrays of Objects.
      */
-    public static Collection<Object[]> getKeysFor(Locale currentLocale) {
+    public static Collection<Object[]> getKeysFor(
+            Locale currentLocale,
+	    IgnoredKey predicate) {
 	Collection<Object[]> retval = new ArrayList();
 	for (String bundleName : Arrays.asList(
 					       "aboutbox",
@@ -70,7 +80,19 @@
 		    ResourceBundle.getBundle("org.argouml.i18n." + bundleName,
 					     Locale.ROOT);
 		for (String key : labels.keySet()) {
-		    retval.add(new Object[] { key, currentLocale, labels, rootLabels });
+		    if (predicate.ignore(key,
+					 currentLocale,
+					 labels,
+					 rootLabels)) {
+			continue;
+		    }
+
+		    retval.add(new Object[] {
+				   key,
+				   currentLocale,
+				   labels,
+				   rootLabels
+			       });
 		}
 	    } catch (MissingResourceException e) {
 		// There is no such file.
@@ -80,6 +102,26 @@
 	return retval;
     }
 
+    /**
+     * Create the list of objects to test.
+     *
+     * @param currentLocale the Locale to test.
+     * @return a Collection of arrays of Objects.
+     */
+    public static Collection<Object[]> getKeysFor(
+            Locale locale) {
+	return getKeysFor(locale,
+			  new IgnoredKey() {
+			      public boolean ignore(String theKey,
+						    Locale theLocale,
+						    ResourceBundle theLabels,
+						    ResourceBundle theRootLabels) {
+				  return false;
+			      };
+			  }
+			  );
+    }
+
     private String key;
     private Locale currentLocale;
     private ResourceBundle labels;
@@ -110,27 +152,40 @@
      * Check that the key is localized.
      */
     @Test public void keyIsLocalized() {
-	assertTrue("Key " + key + " localized for " + currentLocale + ".",
-		   labels.getString(key) != rootLabels.getString(key));
+	try {
+	    assertTrue("Key " + key + " localized for " + currentLocale + ".",
+		       labels.getString(key) != rootLabels.getString(key));
+	} catch (MissingResourceException e) {};
     }
 
     /**
-     * Check the validity of the localized contents.
+     * Check that the strings has the same formatted values.
      */
-    @Test public void valueValid() {
-	String str = labels.getString(key);
+    @Test public void checkMessageFormatValues() {
+	String i18nString = labels.getString(key);
+	String rootString;
+	try {
+	    rootString = rootLabels.getString(key);
+	} catch (MissingResourceException e) {
+	    return;
+	};
 
-	for (int i = 0; i < str.length(); i++) {
-	    if (str.charAt(i) == '\n') {
-		continue;
-	    }
-	    if (str.charAt(i) >= 32 && str.charAt(i) < 128) {
-		continue;
+	if (i18nString.equals(rootString)) {
+	    return;
+	}
+
+	for (int i = 0; ; i++) {
+	    String match = ".*[{]" + i + "[},].*";
+	    boolean i18nFound = i18nString.matches(match);
+	    boolean rootFound = rootString.matches(match);
+
+	    assertTrue("Key " + key + " use value " + i
+		       + " to the same extent",
+		       i18nFound == rootFound);
+
+	    if (!i18nFound && !rootFound) {
+		break;
 	    }
-	    fail("Char " + i + " of key " + key + " is " 
-		 + str.charAt(i)
-		 + " outside of allowed range in locale "
-		 + currentLocale + ".");
 	}
     }
 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2972809

To unsubscribe from this discussion, e-mail: [[email protected]].