Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
44   112   16   44
26   61   0.36   1
1     16  
1    
 
 
  RFC2253Test       Line # 41 44 16 88.7% 0.8873239
 
No Tests
 
1    /*
2    * Copyright (c) 2000-2005, University of Salford
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * Neither the name of the University of Salford nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    * POSSIBILITY OF SUCH DAMAGE.
30    */
31   
32    package issrg.test;
33   
34    import issrg.utils.RFC2253NameParser;
35    import issrg.utils.RFC2253ParsingException;
36   
37    /*
38    * This is a test application to see if the RFC2253NameParser works fine
39    */
40   
 
41    public class RFC2253Test{
42    public final static String HELP_SCREEN = "This application test how the RFC2253NameParser works.\n(c) 2001, by Sassa\n\nusage: RFC2253test <testfile> [<logfile> [<input/output charset name>]]\n\n\ttestfile is the file where each line is a DN to parse\n\tlogfile is a file where to output the result of parsing\n\t\tThe console is used by default.\n";
43   
 
44  1 toggle public static void main(String [] a){
45  1 System.setProperty("line.separator", "\r\n");
46  1 java.io.PrintWriter out=new java.io.PrintWriter(System.out);
47  1 if (a.length<1 || a.length>3){
48  0 out.println(HELP_SCREEN);
49  0 System.exit(0);
50    }
51   
52  1 java.io.BufferedReader br=null;
53   
54  1 try{
55  1 String charset = "UTF-8";
56  1 if (a.length>1){
57  1 if (a.length>2){
58  1 charset = a[2];
59    }
60  1 out=new java.io.PrintWriter(a[1], charset);
61    }
62   
63  1 br = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(a[0]), charset));
64   
65  36 while(br.ready()){
66  35 String s = br.readLine();
67  35 if(s.length() <= 2)
68  2 continue;
69   
70  33 out.println(s+":");
71  33 try{
72  33 String [][][] dn = (String [][][])RFC2253NameParser.distinguishedName(s);
73   
74  23 StringBuffer newDN = new StringBuffer();
75   
76  56 for (int i=0; i<dn.length; i++){
77  33 if (i!=0) newDN.append(RFC2253NameParser.COMMA_CHAR);
78   
79  33 out.println("\tRDN:");
80  68 for (int j=0; j<dn[i].length; j++){
81  35 if (j!=0) newDN.append(RFC2253NameParser.PLUS_CHAR);
82  35 newDN.append(dn[i][j][0]);
83  35 newDN.append(RFC2253NameParser.ASSIGN_CHAR);
84  35 newDN.append(dn[i][j][1]==null?dn[i][j][2]:RFC2253NameParser.escapeString(dn[i][j][1]));
85   
86  35 out.println("\t\tAVA: "+dn[i][j][0]+" = "+(dn[i][j][1]==null?dn[i][j][2]:dn[i][j][1]));
87    }
88  33 out.println();
89    }
90   
91   
92  23 out.println("\nCompiled into: "+newDN);
93  23 out.println("\n\n");
94    }catch(RFC2253ParsingException ex){
95  115 for (int i=ex.getErrorPos(); i-->0; ) out.print(" ");
96   
97  10 out.println("^\n"+ex.getMessage()+". "+ex.getEmbedded().getMessage()+"\n");
98    //ex.getNestedException().printStackTrace();
99    }
100    }
101  1 out.close();
102    }catch (Exception e){
103  0 out.println(e.getMessage());
104  0 e.printStackTrace();
105    }finally{
106  1 try{
107  1 if (br!=null) br.close();
108    }catch (java.io.IOException ioe){
109    }
110    }
111    }
112    }