commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r292567 - in /jakarta/commons/proper/configuration/trunk: ./ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/plist/
Date Thu, 29 Sep 2005 22:24:33 GMT
Author: ebourg
Date: Thu Sep 29 15:24:16 2005
New Revision: 292567

URL: http://svn.apache.org/viewcvs?rev=292567&view=rev
Log:
Improved the test coverage on the plist package

Added:
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListParser.java
Modified:
    jakarta/commons/proper/configuration/trunk/project.properties
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserTokenManager.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/SimpleCharStream.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java

Modified: jakarta/commons/proper/configuration/trunk/project.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/project.properties?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/project.properties (original)
+++ jakarta/commons/proper/configuration/trunk/project.properties Thu Sep 29 15:24:16 2005
@@ -35,6 +35,4 @@
 
 maven.compile.source = 1.3
 
-maven.clover.license.path=src/conf/clover.license
-
 maven.javacc.javacc.grammar=src/java/org/apache/commons/configuration/plist/PropertyListParser.jj

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListConfiguration.java
Thu Sep 29 15:24:16 2005
@@ -173,13 +173,14 @@
                 printNode(out, indentLevel + 1, child);
 
                 // add a semi colon for elements that are not dictionaries
-                if (child.getValue() != null)
+                Object value = child.getValue();
+                if (value != null && !(value instanceof Map) && !(value instanceof
Configuration))
                 {
                     out.println(";");
                 }
 
                 // skip a line after arrays and dictionaries
-                if (it.hasNext() && (child.getValue() == null || child.getValue()
instanceof List))
+                if (it.hasNext() && (value == null || value instanceof List))
                 {
                     out.println();
                 }
@@ -229,6 +230,7 @@
         else if (value instanceof Configuration)
         {
             // display a flat Configuration as a dictionary
+            out.println();
             out.println(padding + "{");
 
             Configuration config = (Configuration) value;
@@ -240,11 +242,7 @@
                 node.setValue(config.getProperty(key));
 
                 printNode(out, indentLevel + 1, node);
-
-                if (it.hasNext())
-                {
-                    out.println();
-                }
+                out.println(";");
             }
             out.println(padding + "}");
         }
@@ -281,7 +279,7 @@
      *   <li>foo;bar -> "foo;bar"</li>
      * </ul>
      */
-    private String quoteString(String s)
+    String quoteString(String s)
     {
         if (s == null)
         {

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.java
Thu Sep 29 15:24:16 2005
@@ -22,7 +22,7 @@
     /**
      * Remove the quotes at the beginning and at the end of the specified String.
      */
-    private String removeQuotes(String s)
+    protected String removeQuotes(String s)
     {
         if (s == null)
         {
@@ -37,7 +37,7 @@
         return s;
     }
 
-    private String unescapeQuotes(String s)
+    protected String unescapeQuotes(String s)
     {
         return StringUtils.replace(s, "\\\"", "\"");
     }
@@ -46,7 +46,7 @@
      * Remove the white spaces and the data delimiters from the specified
      * string and parse it as a byte array.
      */
-    private byte[] filterData(String s) throws ParseException
+    protected byte[] filterData(String s) throws ParseException
     {
         if (s == null)
         {
@@ -84,10 +84,8 @@
         PropertyListConfiguration configuration = null;
         configuration = Dictionary();
         jj_consume_token(0);
-        {
-            if (true) return configuration;
-        }
-        throw new Error("Missing return statement in function");
+
+        return configuration;
     }
 
     final public PropertyListConfiguration Dictionary() throws ParseException
@@ -130,21 +128,16 @@
             configuration.getRoot().addChild(child);
         }
 
-        {
-            if (true) return configuration;
-        }
-        throw new Error("Missing return statement in function");
+        return configuration;
     }
 
     final public Node Property() throws ParseException
     {
-        String key = null;
-        Object value = null;
         Node node = new Node();
-        key = String();
+        String key = String();
         node.setName(key);
         jj_consume_token(EQUAL);
-        value = Element();
+        Object value = Element();
         node.setValue(value);
         switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
         {
@@ -155,48 +148,32 @@
                 jj_la1[1] = jj_gen;
                 ;
         }
-        {
-            if (true) return node;
-        }
-        throw new Error("Missing return statement in function");
+
+        return node;
     }
 
     final public Object Element() throws ParseException
     {
-        Object value = null;
         switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
         {
             case ARRAY_BEGIN:
-                value = Array();
-                {
-                    if (true) return value;
-                }
-                break;
+                return Array();
+
             case DICT_BEGIN:
-                value = Dictionary();
-                {
-                    if (true) return value;
-                }
-                break;
+                return Dictionary();
+
             case STRING:
             case QUOTED_STRING:
-                value = String();
-                {
-                    if (true) return value;
-                }
-                break;
+                return String();
+
             case DATA:
-                value = Data();
-                {
-                    if (true) return value;
-                }
-                break;
+                return Data();
+
             default:
                 jj_la1[2] = jj_gen;
                 jj_consume_token(-1);
                 throw new ParseException();
         }
-        throw new Error("Missing return statement in function");
     }
 
     final public List Array() throws ParseException
@@ -235,46 +212,36 @@
                 ;
         }
         jj_consume_token(ARRAY_END);
-        {
-            if (true) return list;
-        }
-        throw new Error("Missing return statement in function");
+
+        return list;
     }
 
     final public String String() throws ParseException
     {
         Token token = null;
-        String value = null;
         switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
         {
             case QUOTED_STRING:
                 token = jj_consume_token(QUOTED_STRING);
-                {
-                    if (true) return unescapeQuotes(removeQuotes(token.image));
-                }
-                break;
+                return unescapeQuotes(removeQuotes(token.image));
+
             case STRING:
                 token = jj_consume_token(STRING);
-                {
-                    if (true) return token.image;
-                }
-                break;
+                return token.image;
+
             default:
                 jj_la1[5] = jj_gen;
                 jj_consume_token(-1);
                 throw new ParseException();
         }
-        throw new Error("Missing return statement in function");
     }
 
     final public byte[] Data() throws ParseException
     {
         Token token;
         token = jj_consume_token(DATA);
-        {
-            if (true) return filterData(token.image);
-        }
-        throw new Error("Missing return statement in function");
+
+        return filterData(token.image);
     }
 
     public PropertyListParserTokenManager token_source;
@@ -305,16 +272,6 @@
         for (int i = 0; i < 6; i++) jj_la1[i] = -1;
     }
 
-    public void ReInit(java.io.InputStream stream)
-    {
-        jj_input_stream.ReInit(stream, 1, 1);
-        token_source.ReInit(jj_input_stream);
-        token = new Token();
-        jj_ntk = -1;
-        jj_gen = 0;
-        for (int i = 0; i < 6; i++) jj_la1[i] = -1;
-    }
-
     public PropertyListParser(java.io.Reader stream)
     {
         jj_input_stream = new SimpleCharStream(stream, 1, 1);
@@ -325,34 +282,6 @@
         for (int i = 0; i < 6; i++) jj_la1[i] = -1;
     }
 
-    public void ReInit(java.io.Reader stream)
-    {
-        jj_input_stream.ReInit(stream, 1, 1);
-        token_source.ReInit(jj_input_stream);
-        token = new Token();
-        jj_ntk = -1;
-        jj_gen = 0;
-        for (int i = 0; i < 6; i++) jj_la1[i] = -1;
-    }
-
-    public PropertyListParser(PropertyListParserTokenManager tm)
-    {
-        token_source = tm;
-        token = new Token();
-        jj_ntk = -1;
-        jj_gen = 0;
-        for (int i = 0; i < 6; i++) jj_la1[i] = -1;
-    }
-
-    public void ReInit(PropertyListParserTokenManager tm)
-    {
-        token_source = tm;
-        token = new Token();
-        jj_ntk = -1;
-        jj_gen = 0;
-        for (int i = 0; i < 6; i++) jj_la1[i] = -1;
-    }
-
     final private Token jj_consume_token(int kind) throws ParseException
     {
         Token oldToken;
@@ -371,30 +300,6 @@
         throw generateParseException();
     }
 
-    final public Token getNextToken()
-    {
-        if (token.next != null)
-            token = token.next;
-        else
-            token = token.next = token_source.getNextToken();
-        jj_ntk = -1;
-        jj_gen++;
-        return token;
-    }
-
-    final public Token getToken(int index)
-    {
-        Token t = token;
-        for (int i = 0; i < index; i++)
-        {
-            if (t.next != null)
-                t = t.next;
-            else
-                t = t.next = token_source.getNextToken();
-        }
-        return t;
-    }
-
     final private int jj_ntk()
     {
         if ((jj_nt = token.next) == null)
@@ -448,14 +353,6 @@
             exptokseq[i] = (int[]) jj_expentries.elementAt(i);
         }
         return new ParseException(token, exptokseq, tokenImage);
-    }
-
-    final public void enable_tracing()
-    {
-    }
-
-    final public void disable_tracing()
-    {
     }
 
 }

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParser.jj
Thu Sep 29 15:24:16 2005
@@ -43,7 +43,7 @@
     /**
      * Remove the quotes at the beginning and at the end of the specified String.
      */
-    private String removeQuotes(String s)
+    protected String removeQuotes(String s)
     {
         if (s == null)
         {
@@ -58,7 +58,7 @@
         return s;
     }
 
-    private String unescapeQuotes(String s)
+    protected String unescapeQuotes(String s)
     {
         return StringUtils.replace(s, "\\\"", "\"");
     }
@@ -67,7 +67,7 @@
      * Remove the white spaces and the data delimiters from the specified
      * string and parse it as a byte array.
      */
-    private byte[] filterData(String s) throws ParseException
+    protected byte[] filterData(String s) throws ParseException
     {
         if (s == null)
         {

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserTokenManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserTokenManager.java?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserTokenManager.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/PropertyListParserTokenManager.java
Thu Sep 29 15:24:16 2005
@@ -1,14 +1,12 @@
 /* Generated By:JavaCC: Do not edit this line. PropertyListParserTokenManager.java */
 package org.apache.commons.configuration.plist;
 
+import java.io.IOException;
+import java.io.PrintStream;
+
 class PropertyListParserTokenManager implements PropertyListParserConstants
 {
-    public java.io.PrintStream debugStream = System.out;
-
-    public void setDebugStream(java.io.PrintStream ds)
-    {
-        debugStream = ds;
-    }
+    public PrintStream debugStream = System.out;
 
     private final int jjStopStringLiteralDfa_0(int pos, long active0)
     {
@@ -52,7 +50,7 @@
         {
             curChar = input_stream.readChar();
         }
-        catch (java.io.IOException e)
+        catch (IOException e)
         {
             return pos + 1;
         }
@@ -96,7 +94,7 @@
         {
             curChar = input_stream.readChar();
         }
-        catch (java.io.IOException e)
+        catch (IOException e)
         {
             jjStopStringLiteralDfa_0(0, active0);
             return 1;
@@ -122,15 +120,6 @@
         }
     }
 
-    private final void jjAddStates(int start, int end)
-    {
-        do
-        {
-            jjstateSet[jjnewStateCnt++] = jjnextStates[start];
-        }
-        while (start++ != end);
-    }
-
     private final void jjCheckNAddTwoStates(int state1, int state2)
     {
         jjCheckNAdd(state1);
@@ -146,24 +135,17 @@
         while (start++ != end);
     }
 
-    private final void jjCheckNAddStates(int start)
-    {
-        jjCheckNAdd(jjnextStates[start]);
-        jjCheckNAdd(jjnextStates[start + 1]);
-    }
-
     static final long[] jjbitVec0 = {
         0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
     };
 
     private final int jjMoveNfa_0(int startState, int curPos)
     {
-        int[] nextStates;
         int startsAt = 0;
         jjnewStateCnt = 9;
         int i = 1;
         jjstateSet[0] = startState;
-        int j, kind = 0x7fffffff;
+        int kind = 0x7fffffff;
         for (; ;)
         {
             if (++jjround == 0x7fffffff)
@@ -339,7 +321,7 @@
             {
                 curChar = input_stream.readChar();
             }
-            catch (java.io.IOException e)
+            catch (IOException e)
             {
                 return curPos;
             }
@@ -373,12 +355,6 @@
         input_stream = stream;
     }
 
-    public PropertyListParserTokenManager(SimpleCharStream stream, int lexState)
-    {
-        this(stream);
-        SwitchTo(lexState);
-    }
-
     public void ReInit(SimpleCharStream stream)
     {
         jjmatchedPos = jjnewStateCnt = 0;
@@ -395,20 +371,6 @@
             jjrounds[i] = 0x80000000;
     }
 
-    public void ReInit(SimpleCharStream stream, int lexState)
-    {
-        ReInit(stream);
-        SwitchTo(lexState);
-    }
-
-    public void SwitchTo(int lexState)
-    {
-        if (lexState >= 1 || lexState < 0)
-            throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState
+ ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
-        else
-            curLexState = lexState;
-    }
-
     protected Token jjFillToken()
     {
         Token t = Token.newToken(jjmatchedKind);
@@ -431,8 +393,6 @@
 
     public Token getNextToken()
     {
-        int kind;
-        Token specialToken = null;
         Token matchedToken;
         int curPos = 0;
 
@@ -443,7 +403,7 @@
             {
                 curChar = input_stream.BeginToken();
             }
-            catch (java.io.IOException e)
+            catch (IOException e)
             {
                 jjmatchedKind = 0;
                 matchedToken = jjFillToken();
@@ -456,7 +416,7 @@
                 while (curChar <= 32 && (0x100002600L & (1L << curChar))
!= 0L)
                     curChar = input_stream.BeginToken();
             }
-            catch (java.io.IOException e1)
+            catch (IOException e1)
             {
                 continue EOFLoop;
             }
@@ -486,7 +446,7 @@
                 input_stream.readChar();
                 input_stream.backup(1);
             }
-            catch (java.io.IOException e1)
+            catch (IOException e1)
             {
                 EOFSeen = true;
                 error_after = curPos <= 1 ? "" : input_stream.GetImage();

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/SimpleCharStream.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/SimpleCharStream.java?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/SimpleCharStream.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/SimpleCharStream.java
Thu Sep 29 15:24:16 2005
@@ -276,16 +276,6 @@
     bufpos = -1;
   }
 
-  public void ReInit(java.io.Reader dstream, int startline,
-                                                           int startcolumn)
-  {
-     ReInit(dstream, startline, startcolumn, 4096);
-  }
-
-  public void ReInit(java.io.Reader dstream)
-  {
-     ReInit(dstream, 1, 1, 4096);
-  }
   public SimpleCharStream(java.io.InputStream dstream, int startline,
   int startcolumn, int buffersize)
   {
@@ -303,21 +293,6 @@
      this(dstream, 1, 1, 4096);
   }
 
-  public void ReInit(java.io.InputStream dstream, int startline,
-                          int startcolumn, int buffersize)
-  {
-     ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
-  }
-
-  public void ReInit(java.io.InputStream dstream)
-  {
-     ReInit(dstream, 1, 1, 4096);
-  }
-  public void ReInit(java.io.InputStream dstream, int startline,
-                                                           int startcolumn)
-  {
-     ReInit(dstream, startline, startcolumn, 4096);
-  }
   public String GetImage()
   {
      if (bufpos >= tokenBegin)
@@ -327,75 +302,11 @@
                               new String(buffer, 0, bufpos + 1);
   }
 
-  public char[] GetSuffix(int len)
-  {
-     char[] ret = new char[len];
-
-     if ((bufpos + 1) >= len)
-        System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
-     else
-     {
-        System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
-                                                          len - bufpos - 1);
-        System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
-     }
-
-     return ret;
-  }
-
   public void Done()
   {
      buffer = null;
      bufline = null;
      bufcolumn = null;
-  }
-
-  /**
-   * Method to adjust line and column numbers for the start of a token.
-   */
-  public void adjustBeginLineColumn(int newLine, int newCol)
-  {
-     int start = tokenBegin;
-     int len;
-
-     if (bufpos >= tokenBegin)
-     {
-        len = bufpos - tokenBegin + inBuf + 1;
-     }
-     else
-     {
-        len = bufsize - tokenBegin + bufpos + 1 + inBuf;
-     }
-
-     int i = 0, j = 0, k = 0;
-     int nextColDiff = 0, columnDiff = 0;
-
-     while (i < len &&
-            bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
-     {
-        bufline[j] = newLine;
-        nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
-        bufcolumn[j] = newCol + columnDiff;
-        columnDiff = nextColDiff;
-        i++;
-     } 
-
-     if (i < len)
-     {
-        bufline[j] = newLine++;
-        bufcolumn[j] = newCol + columnDiff;
-
-        while (i++ < len)
-        {
-           if (bufline[j = start % bufsize] != bufline[++start % bufsize])
-              bufline[j] = newLine++;
-           else
-              bufline[j] = newLine;
-        }
-     }
-
-     line = bufline[j];
-     column = bufcolumn[j];
   }
 
 }

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
Thu Sep 29 15:24:16 2005
@@ -257,11 +257,6 @@
             super(methodName);
         }
 
-        public SetNextAndPopRule(String methodName, String paramType)
-        {
-            super(methodName, paramType);
-        }
-
         public void end(String namespace, String name) throws Exception
         {
             super.end(namespace, name);

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListConfiguration.java
Thu Sep 29 15:24:16 2005
@@ -17,16 +17,18 @@
 package org.apache.commons.configuration.plist;
 
 import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
+import java.io.StringReader;
 import java.util.Iterator;
+import java.util.List;
 
 import junit.framework.TestCase;
-import junitx.framework.ObjectAssert;
 import junitx.framework.ArrayAssert;
 import junitx.framework.ListAssert;
+import junitx.framework.ObjectAssert;
 import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationComparator;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.StrictConfigurationComparator;
 
 /**
  * @author Emmanuel Bourg
@@ -50,6 +52,18 @@
         assertFalse("the configuration is empty", config.isEmpty());
     }
 
+    public void testLoadWithError()
+    {
+        config = new PropertyListConfiguration();
+        try {
+            config.load(new StringReader(""));
+            fail("No exception thrown on loading an empty file");
+        } catch (ConfigurationException e) {
+            // expected
+            assertNotNull(e.getMessage());
+        }
+    }
+
     public void testString()
     {
         assertEquals("simple-string", "string1", config.getProperty("simple-string"));
@@ -160,7 +174,7 @@
     }
 
 
-    public void invalidtestSave() throws Exception
+    public void testSave() throws Exception
     {
         File savedFile = new File("target/testsave.plist");
 
@@ -177,10 +191,12 @@
         assertTrue("The saved file doesn't exist", savedFile.exists());
 
         // read the configuration and compare the properties
-        Configuration checkConfig = new PropertyListConfiguration(filename);
-        for (Iterator i = config.getKeys(); i.hasNext();)
+        Configuration checkConfig = new PropertyListConfiguration(new File(filename));
+
+        Iterator it = config.getKeys();
+        while (it.hasNext())
         {
-            String key = (String) i.next();
+            String key = (String) it.next();
             assertTrue("The saved configuration doesn't contain the key '" + key + "'", checkConfig.containsKey(key));
 
             Object value = checkConfig.getProperty(key);
@@ -191,7 +207,27 @@
             }
             else if (value instanceof List)
             {
-                List list1 = (List) value;
+                List list1 = (List) config.getProperty(key);
+                List list2 = (List) value;
+
+                assertEquals("The size of the list for the key '" + key + "' doesn't match",
list1.size(), list2.size());
+
+                for (int i = 0; i < list2.size(); i++)
+                {
+                    Object value1 = list1.get(i);
+                    Object value2 = list2.get(i);
+
+                    if (value1 instanceof Configuration)
+                    {
+                        ConfigurationComparator comparator = new StrictConfigurationComparator();
+                        assertTrue("The dictionnary at index " + i + " for the key '" + key
+ "' doesn't match", comparator.compare((Configuration) value1, (Configuration) value2));
+                    }
+                    else
+                    {
+                        assertEquals("Element at index " + i + " for the key '" + key + "'",
value1, value2);
+                    }
+                }
+
                 ListAssert.assertEquals("Value of the '" + key + "' property", (List) config.getProperty(key),
list1);
             }
             else
@@ -200,5 +236,14 @@
             }
 
         }
+    }
+
+    public void testQuoteString()
+    {
+        assertEquals("null string", null, config.quoteString(null));
+        assertEquals("simple string", "abcd", config.quoteString("abcd"));
+        assertEquals("string with a space", "\"ab cd\"", config.quoteString("ab cd"));
+        assertEquals("string with a quote", "\"foo\\\"bar\"", config.quoteString("foo\"bar"));
+        assertEquals("string with a special char", "\"foo;bar\"", config.quoteString("foo;bar"));
     }
 }

Added: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListParser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListParser.java?rev=292567&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListParser.java
(added)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestPropertyListParser.java
Thu Sep 29 15:24:16 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.configuration.plist;
+
+import java.io.Reader;
+
+import junit.framework.TestCase;
+import junitx.framework.ArrayAssert;
+
+/**
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ */
+public class TestPropertyListParser extends TestCase
+{
+    private PropertyListParser parser = new PropertyListParser((Reader) null);
+
+    public void testRemoveQuotes()
+    {
+        assertEquals("unquoted string", "abc", parser.removeQuotes("abc"));
+        assertEquals("quoted string", "abc", parser.removeQuotes("\"abc\""));
+        assertEquals("empty quotes", "", parser.removeQuotes("\"\""));
+        assertEquals("empty string", "", parser.removeQuotes(""));
+        assertEquals("null string", null, parser.removeQuotes(null));
+    }
+
+    public void testUnescapeQuotes()
+    {
+        assertEquals("non escaped quotes", "aaa\"bbb\"ccc", parser.unescapeQuotes("aaa\"bbb\"ccc"));
+        assertEquals("escaped quotes", "aaa\"bbb\"ccc", parser.unescapeQuotes("aaa\\\"bbb\\\"ccc"));
+    }
+
+    public void testFilterData() throws Exception
+    {
+        byte[] expected = new byte[] {0x20, 0x20};
+        ArrayAssert.assertEquals("null string", null, parser.filterData(null));
+        ArrayAssert.assertEquals("data with < >", expected, parser.filterData("<2020>"));
+        ArrayAssert.assertEquals("data without < >", expected, parser.filterData("2020"));
+        ArrayAssert.assertEquals("data with space", expected, parser.filterData("20 20"));
+        ArrayAssert.assertEquals("odd length", new byte[]{9, 0x20}, parser.filterData("920"));
+    }
+}

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java?rev=292567&r1=292566&r2=292567&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/plist/TestXMLPropertyListConfiguration.java
Thu Sep 29 15:24:16 2005
@@ -17,11 +17,7 @@
 package org.apache.commons.configuration.plist;
 
 import java.io.File;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
+import java.util.*;
 
 import junit.framework.TestCase;
 import junitx.framework.ObjectAssert;
@@ -29,6 +25,8 @@
 import junitx.framework.ListAssert;
 import org.apache.commons.configuration.FileConfiguration;
 import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.StrictConfigurationComparator;
+import org.apache.commons.configuration.ConfigurationComparator;
 
 /**
  * @author Emmanuel Bourg
@@ -171,7 +169,7 @@
         assertEquals("nested property", "value", config.getString("nested.node1.node2.node3"));
     }
 
-    public void invalidtestSave() throws Exception
+    public void testSave() throws Exception
     {
         File savedFile = new File("target/testsave.plist.xml");
 
@@ -208,10 +206,12 @@
         assertTrue("The saved file doesn't exist", savedFile.exists());
 
         // read the configuration and compare the properties
-        Configuration checkConfig = new XMLPropertyListConfiguration(filename);
-        for (Iterator i = config.getKeys(); i.hasNext();)
+        Configuration checkConfig = new XMLPropertyListConfiguration(new File(filename));
+
+        Iterator it = config.getKeys();
+        while (it.hasNext())
         {
-            String key = (String) i.next();
+            String key = (String) it.next();
             assertTrue("The saved configuration doesn't contain the key '" + key + "'", checkConfig.containsKey(key));
 
             Object value = checkConfig.getProperty(key);
@@ -222,7 +222,27 @@
             }
             else if (value instanceof List)
             {
-                List list1 = (List) value;
+                List list1 = (List) config.getProperty(key);
+                List list2 = (List) value;
+
+                assertEquals("The size of the list for the key '" + key + "' doesn't match",
list1.size(), list2.size());
+
+                for (int i = 0; i < list2.size(); i++)
+                {
+                    Object value1 = list1.get(i);
+                    Object value2 = list2.get(i);
+
+                    if (value1 instanceof Configuration)
+                    {
+                        ConfigurationComparator comparator = new StrictConfigurationComparator();
+                        assertTrue("The dictionnary at index " + i + " for the key '" + key
+ "' doesn't match", comparator.compare((Configuration) value1, (Configuration) value2));
+                    }
+                    else
+                    {
+                        assertEquals("Element at index " + i + " for the key '" + key + "'",
value1, value2);
+                    }
+                }
+
                 ListAssert.assertEquals("Value of the '" + key + "' property", (List) config.getProperty(key),
list1);
             }
             else



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message