KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > rasterizer > MainTest


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.apps.rasterizer;
19
20
21 import java.awt.Color JavaDoc;
22 import java.awt.geom.Rectangle2D JavaDoc;
23 import java.io.File JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import org.apache.batik.test.AbstractTest;
28 import org.apache.batik.test.DefaultTestSuite;
29 import org.apache.batik.test.Test;
30 import org.apache.batik.test.TestReport;
31
32 /**
33  * Validates the operation of the <tt>Main</tt> class.
34  *
35  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
36  * @version $Id: MainTest.java,v 1.14 2005/03/27 08:58:37 cam Exp $
37  */

38 public class MainTest extends DefaultTestSuite {
39     
40     public MainTest(){
41         Test t = new MainConfigTest("-d samples") {
42                 public TestReport validate(SVGConverter c){
43                     File JavaDoc dst = c.getDst();
44                     if(dst!= null && dst.equals(new File JavaDoc("samples"))){
45                         return reportSuccess();
46                     } else {
47                         return reportError("-d", "samples", "" + dst);
48                     }
49                 }
50                 
51             };
52         
53         addTest(t);
54         t.setId("MainConfigTest.output");
55         
56         t = new MainConfigTest("samples/anne.svg") {
57                 String JavaDoc ERROR_UNEXPECTED_SOURCES = "MainConfigTest.error.unexpected.sources";
58                 
59                 public TestReport validate(SVGConverter c){
60                     Vector JavaDoc sources = c.getSources();
61                     if(sources.size() == 1){
62                         String JavaDoc src = (String JavaDoc)sources.elementAt(0);
63                         if ("samples/anne.svg".equals(src)){
64                             return reportSuccess();
65                         }
66                     }
67                     
68                     return reportError(ERROR_UNEXPECTED_SOURCES);
69                 }
70                 
71             };
72     
73         addTest(t);
74         t.setId("MainConfigTest.source");
75     
76         t = new MainConfigTest("-m image/jpeg") {
77                 public TestReport validate(SVGConverter c){
78                     DestinationType type = c.getDestinationType();
79                     if(type.equals(DestinationType.JPEG)){
80                         return reportSuccess();
81                     } else {
82                         return reportError("-m", DestinationType.JPEG.toString(), "" + type);
83                     }
84                 }
85             
86             };
87     
88         addTest(t);
89         t.setId("MainConfigTest.mimeType.jpegA");
90
91         t = new MainConfigTest("-m image/jpg") {
92                 public TestReport validate(SVGConverter c){
93                     DestinationType type = c.getDestinationType();
94                     if(type.equals(DestinationType.JPEG)){
95                         return reportSuccess();
96                     } else {
97                         return reportError("-m", DestinationType.JPEG.toString(), "" + type);
98                     }
99                 }
100             
101             };
102     
103         addTest(t);
104         t.setId("MainConfigTest.mimeType.jpegB");
105
106         t = new MainConfigTest("-m image/jpe") {
107                 public TestReport validate(SVGConverter c){
108                     DestinationType type = c.getDestinationType();
109                     if(type.equals(DestinationType.JPEG)){
110                         return reportSuccess();
111                     } else {
112                         return reportError("-m", DestinationType.JPEG.toString(), "" + type);
113                     }
114                 }
115             
116             };
117     
118         addTest(t);
119         t.setId("MainConfigTest.mimeType.jpegC");
120
121         t = new MainConfigTest("-m image/png") {
122                 public TestReport validate(SVGConverter c){
123                     DestinationType type = c.getDestinationType();
124                     if(type.equals(DestinationType.PNG)){
125                         return reportSuccess();
126                     } else {
127                         return reportError("-m", DestinationType.PNG.toString(), "" + type);
128                     }
129                 }
130             
131             };
132     
133         addTest(t);
134         t.setId("MainConfigTest.mimeType.png");
135
136         t = new MainConfigTest("-m application/pdf") {
137                 public TestReport validate(SVGConverter c){
138                     DestinationType type = c.getDestinationType();
139                     if(type.equals(DestinationType.PDF)){
140                         return reportSuccess();
141                     } else {
142                         return reportError("-m", DestinationType.PDF.toString(), "" + type);
143                     }
144                 }
145             
146             };
147     
148         addTest(t);
149         t.setId("MainConfigTest.mimeType.pdf");
150
151         t = new MainConfigTest("-m image/tiff") {
152                 public TestReport validate(SVGConverter c){
153                     DestinationType type = c.getDestinationType();
154                     if(type.equals(DestinationType.TIFF)){
155                         return reportSuccess();
156                     } else {
157                         return reportError("-m", DestinationType.TIFF.toString(), "" + type);
158                     }
159                 }
160             
161             };
162     
163         addTest(t);
164         t.setId("MainConfigTest.mimeType.tiff");
165
166         t = new MainConfigTest("-w 467.69") {
167                 public TestReport validate(SVGConverter c){
168                     float width = c.getWidth();
169                     if(width == 467.69f){
170                         return reportSuccess();
171                     } else {
172                         return reportError("-w", "" + 467.69, "" + width);
173                     }
174                 }
175             
176             };
177     
178         addTest(t);
179         t.setId("MainConfigTest.width");
180
181         t = new MainConfigTest("-h 345.67") {
182                 public TestReport validate(SVGConverter c){
183                     float height = c.getHeight();
184                     if(height == 345.67f){
185                         return reportSuccess();
186                     } else {
187                         return reportError("-h", "" + 345.67, "" + height);
188                     }
189                 }
190             
191             };
192     
193         addTest(t);
194         t.setId("MainConfigTest.height");
195
196         t = new MainConfigTest("-maxw 467.69") {
197                 public TestReport validate(SVGConverter c){
198                     float maxWidth = c.getMaxWidth();
199                     if(maxWidth == 467.69f){
200                         return reportSuccess();
201                     } else {
202                         return reportError("-maxw", "" + 467.69, "" + maxWidth);
203                     }
204                 }
205             
206             };
207         addTest(t);
208         t.setId("MainConfigTest.maxWidth");
209
210         t = new MainConfigTest("-maxh 345.67") {
211                 public TestReport validate(SVGConverter c){
212                     float maxHeight = c.getMaxHeight();
213                     if(maxHeight == 345.67f){
214                         return reportSuccess();
215                     } else {
216                         return reportError("-maxh", "" + 345.67, "" + maxHeight);
217                     }
218                 }
219             };
220         addTest(t);
221         t.setId("MainConfigTest.maxHeight");
222
223         t = new MainConfigTest("-a 5,10,20,30") {
224                 public TestReport validate(SVGConverter c){
225                     Rectangle2D JavaDoc aoi = c.getArea();
226                     Rectangle2D.Float JavaDoc eAoi = new Rectangle2D.Float JavaDoc(5,10,20,30);
227                     if(eAoi.equals(aoi)){
228                         return reportSuccess();
229                     } else {
230                         return reportError("-a", toString(eAoi), toString(aoi));
231                     }
232                 }
233
234                 public String JavaDoc toString(Rectangle2D JavaDoc r){
235                     if (r == null){
236                         return "null";
237                     } else {
238                         return r.getX() + "," + r.getY() + "," + r.getWidth() + "," + r.getHeight();
239                     }
240                 }
241             
242             };
243     
244         addTest(t);
245         t.setId("MainConfigTest.aoi");
246
247     
248         t = new MainConfigTest("-bg 128.200.100.50") {
249                 public TestReport validate(SVGConverter c){
250                     Color JavaDoc bg = c.getBackgroundColor();
251                     Color JavaDoc eBg = new Color JavaDoc(200,100,50,128); // Alpha is last
252
if(eBg.equals(bg)){
253                         return reportSuccess();
254                     } else {
255                         return reportError("-bg", toString(eBg), toString(bg));
256                     }
257                 }
258
259                 public String JavaDoc toString(Color JavaDoc c){
260                     if (c==null){
261                         return "null";
262                     } else {
263                         return c.getAlpha() + "." + c.getRed() + "." + c.getGreen() + "." + c.getBlue();
264                     }
265                 }
266             
267             };
268     
269         addTest(t);
270         t.setId("MainConfigTest.backgroundColor");
271
272         t = new MainConfigTest("-cssMedia projection"){
273                 public TestReport validate(SVGConverter c){
274                     String JavaDoc cssMedia = c.getMediaType();
275                     String JavaDoc eCssMedia = "projection";
276                     if(eCssMedia.equals(cssMedia)){
277                         return reportSuccess();
278                     } else {
279                         return reportError("-cssMedia", eCssMedia, cssMedia);
280                     }
281                 }
282             };
283
284         addTest(t);
285         t.setId("MainConfigTest.cssMedia");
286
287
288         t = new MainConfigTest("-font-family Arial, Comic Sans MS"){
289                 public TestReport validate(SVGConverter c){
290                     String JavaDoc fontFamily = c.getDefaultFontFamily();
291                     String JavaDoc eFontFamily = "Arial, Comic Sans MS";
292                     if(eFontFamily.equals(fontFamily)){
293                         return reportSuccess();
294                     } else {
295                         return reportError("-font-family", eFontFamily, fontFamily);
296                     }
297                 }
298
299                 String JavaDoc[] makeArgsArray(String JavaDoc args) {
300                     return new String JavaDoc[] {"-font-family",
301                                         "Arial, Comic Sans MS"};
302                 }
303             };
304
305         addTest(t);
306         t.setId("MainConfigTest.fontFamily");
307
308
309
310
311         t = new MainConfigTest("-cssAlternate myAlternateStylesheet"){
312                 public TestReport validate(SVGConverter c){
313                     String JavaDoc alternate = c.getAlternateStylesheet();
314                     String JavaDoc eAlternate = "myAlternateStylesheet";
315                     if(eAlternate.equals(alternate)){
316                         return reportSuccess();
317                     } else {
318                         return reportError("-cssAlternate", eAlternate, alternate);
319                     }
320                 }
321             };
322         addTest(t);
323         t.setId("MainConfigTest.cssAlternate");
324
325         t = new MainConfigTest("-validate"){
326                 public TestReport validate(SVGConverter c){
327                     if(c.getValidate()){
328                         return reportSuccess();
329                     } else {
330                         return reportError("-validate", "true", "false");
331                     }
332                 }
333             };
334
335         addTest(t);
336         t.setId("MainConfigTest.validate");
337
338         t = new MainConfigTest("-onload"){
339                 public TestReport validate(SVGConverter c){
340                     if(c.getExecuteOnload()){
341                         return reportSuccess();
342                     } else {
343                         return reportError("-onload", "true", "false");
344                     }
345                 }
346             };
347
348         addTest(t);
349         t.setId("MainConfigTest.onload");
350
351         t = new MainConfigTest("-scripts text/jpython"){
352                 public TestReport validate(SVGConverter c){
353                     if("text/jpython".equals(c.getAllowedScriptTypes())){
354                         return reportSuccess();
355                     } else {
356                         return reportError("-scripts", "text/jpython", ">>" + c.getAllowedScriptTypes() + "<<");
357                     }
358                 }
359             };
360
361         addTest(t);
362         t.setId("MainConfigTest.scripts");
363
364         t = new MainConfigTest("-anyScriptOrigin"){
365                 public TestReport validate(SVGConverter c){
366                     if(!c.getConstrainScriptOrigin()){
367                         return reportSuccess();
368                     } else {
369                         return reportError("-anyScriptOrigin", "true", "false");
370                     }
371                 }
372             };
373
374         addTest(t);
375         t.setId("MainConfigTest.anyScriptOrigin");
376
377         t = new MainConfigTest("-scriptSecurityOff"){
378                 public TestReport validate(SVGConverter c){
379                     if(c.getSecurityOff()){
380                         return reportSuccess();
381                     } else {
382                         return reportError("-scriptSecurityOff", "true", "false");
383                     }
384                 }
385             };
386
387         addTest(t);
388         t.setId("MainConfigTest.scriptSecurityOff");
389
390         t = new MainConfigTest("-lang fr"){
391                 public TestReport validate(SVGConverter c){
392                     if("fr".equals(c.getLanguage())){
393                         return reportSuccess();
394                     } else {
395                         return reportError("-lang", "fr", c.getLanguage());
396                     }
397                 }
398             };
399         addTest(t);
400         t.setId("MainConfigTest.lang");
401
402         t = new MainConfigTest("-cssUser myStylesheet.css"){
403                 public TestReport validate(SVGConverter c){
404                     if("myStylesheet.css".equals(c.getUserStylesheet())){
405                         return reportSuccess();
406                     } else {
407                         return reportError("-cssUser", "myStylesheet.css", c.getUserStylesheet());
408                     }
409                 }
410             };
411         addTest(t);
412         t.setId("MainConfigTest.cssUser");
413
414         t = new MainConfigTest("-dpi 5.08"){
415                 public TestReport validate(SVGConverter c){
416                     if(c.getPixelUnitToMillimeter() == 5f){
417                         return reportSuccess();
418                     } else {
419                         return reportError("-dpi", "5f", "" + c.getPixelUnitToMillimeter());
420                     }
421                 }
422             };
423         addTest(t);
424         t.setId("MainConfigTest.dpi");
425
426         t = new MainConfigTest("-q .5"){
427                 public TestReport validate(SVGConverter c){
428                     if(c.getQuality() == .5f){
429                         return reportSuccess();
430                     } else {
431                         return reportError("-q", ".5f", "" + c.getQuality());
432                     }
433                 }
434             };
435         addTest(t);
436         t.setId("MainConfigTest.quality");
437
438         t = new MainConfigTest("-indexed 8"){
439                 public TestReport validate(SVGConverter c){
440                     if(c.getIndexed() == 8){
441                         return reportSuccess();
442                     } else {
443                         return reportError("-indexed", "8",
444                                            "" + c.getIndexed());
445                     }
446                 }
447             };
448         addTest(t);
449         t.setId("MainConfigTest.indexed");
450
451         t = new MainConfigErrorTest("-d", "hello.svg -d");
452         addTest(t);
453         t.setId("MainConfigErrorTest.output");
454
455         t = new MainConfigErrorTest("-m", "hello.svg -m");
456         addTest(t);
457         t.setId("MainConfigErrorTest.mimeType");
458
459         t = new MainConfigErrorTest("-w", "hello.svg -w");
460         addTest(t);
461         t.setId("MainConfigErrorTest.width");
462
463         t = new MainConfigErrorTest("-h", "hello.svg -h");
464         addTest(t);
465         t.setId("MainConfigErrorTest.height");
466
467         t = new MainConfigErrorTest("-maxw", "hello.svg -maxw");
468         addTest(t);
469         t.setId("MainConfigErrorTest.maxWidth");
470
471         t = new MainConfigErrorTest("-maxh", "hello.svg -maxh");
472         addTest(t);
473         t.setId("MainConfigErrorTest.maxHeight");
474
475         t = new MainConfigErrorTest("-a", "hello.svg -a");
476         addTest(t);
477         t.setId("MainConfigErrorTest.area");
478
479         t = new MainConfigErrorTest("-bg", "hello.svg -bg");
480         addTest(t);
481         t.setId("MainConfigErrorTest.backgroundColor");
482
483         t = new MainConfigErrorTest("-cssMedia", "hello.svg -cssMedia");
484         addTest(t);
485         t.setId("MainConfigErrorTest.mediaType");
486
487         t = new MainConfigErrorTest("-font-family", "hello.svg -font-family");
488         addTest(t);
489         t.setId("MainConfigErrorTest.font-family");
490
491         t = new MainConfigErrorTest("-cssAlternate", "hello.svg -cssAlternate");
492         addTest(t);
493         t.setId("MainConfigErrorTest.cssAlternate");
494
495         t = new MainConfigErrorTest("-lang", "hello.svg -lang");
496         addTest(t);
497         t.setId("MainConfigErrorTest.lang");
498
499         t = new MainConfigErrorTest("-cssUser", "hello.svg -cssUser");
500         addTest(t);
501         t.setId("MainConfigErrorTest.cssUser");
502
503         t = new MainConfigErrorTest("-dpi", "hello.svg -dpi");
504         addTest(t);
505         t.setId("MainConfigErrorTest.dpi");
506
507         t = new MainConfigErrorTest("-q", "hello.svg -q");
508         addTest(t);
509         t.setId("MainConfigErrorTest.quality");
510
511         t = new MainConfigErrorTest("-scripts", "hello.svg -scripts");
512         addTest(t);
513         t.setId("MainConfigErrorTest.allowedScriptTypes");
514
515         t = new MainIllegalArgTest("-m", "-m images/jpeq");
516         addTest(t);
517         t.setId("MainIllegalArgTest.mediaType");
518
519         t = new MainIllegalArgTest("-w", "-w abd");
520         addTest(t);
521         t.setId("MainIllegalArgTest.width");
522
523         t = new MainIllegalArgTest("-h", "-h abaa");
524         addTest(t);
525         t.setId("MainIllegalArgTest.height");
526
527         t = new MainIllegalArgTest("-maxw", "-maxw abd");
528         addTest(t);
529         t.setId("MainIllegalArgTest.maxWidth");
530
531         t = new MainIllegalArgTest("-maxh", "-maxh abaa");
532         addTest(t);
533         t.setId("MainIllegalArgTest.maxHeight");
534
535         t = new MainIllegalArgTest("a", "-a aaaaaa");
536         addTest(t);
537         t.setId("MainIllegalArgTest.aoi");
538
539         t = new MainIllegalArgTest("bg", "-bg a.b.c.d");
540         addTest(t);
541         t.setId("MainIllegalArgTest.bg");
542
543         t = new MainIllegalArgTest("dpi", "-dpi invalidDPI");
544         addTest(t);
545         t.setId("MainIllegalArgTest.dpi");
546
547         t = new MainIllegalArgTest("q", "-q illegalQuality");
548         addTest(t);
549         t.setId("MainIllegalArgTest.q");
550
551     }
552
553 }
554
555 class MainIllegalArgTest extends AbstractTest {
556     String JavaDoc badOption;
557     String JavaDoc args;
558     TestReport report;
559
560     public MainIllegalArgTest(String JavaDoc badOption, String JavaDoc args){
561         this.badOption = badOption;
562         this.args = args;
563     }
564
565     public String JavaDoc getName(){
566         return getId();
567     }
568
569     public static final String JavaDoc ERROR_NO_ERROR_REPORTED
570         = "MainIllegalArgTest.error.no.error.reported";
571
572     public static final String JavaDoc ERROR_UNEXPECTED_ERROR_CODE
573         = "MainIllegalArgTest.error.unexpected.error.code";
574
575     public static final String JavaDoc ENTRY_KEY_EXPECTED_ERROR_CODE
576         = "MainIllegalArgTest.entry.key.expected.error.code";
577
578     public static final String JavaDoc ENTRY_KEY_GOT_ERROR_CODE
579         = "MainIllegalArgTest.entry.key.got.error.code";
580
581     public TestReport runImpl() throws Exception JavaDoc {
582         String JavaDoc[] argsArray = makeArgsArray(args);
583         Main main = new Main(argsArray) {
584                 public void error(String JavaDoc errorCode,
585                                   Object JavaDoc[] errorArgs){
586                     if (Main.ERROR_ILLEGAL_ARGUMENT.equals(errorCode)){
587                         report = reportSuccess();
588                     } else {
589                         report = reportError(ERROR_UNEXPECTED_ERROR_CODE);
590                         report.addDescriptionEntry(ENTRY_KEY_EXPECTED_ERROR_CODE,
591                                                    Main.ERROR_ILLEGAL_ARGUMENT);
592                         report.addDescriptionEntry(ENTRY_KEY_GOT_ERROR_CODE,
593                                                    errorCode);
594                     }
595                 }
596                                   
597                 
598             };
599
600         main.execute();
601
602         if (report == null){
603             report = reportError(ERROR_NO_ERROR_REPORTED);
604         }
605
606         return report;
607     }
608
609     String JavaDoc[] makeArgsArray(String JavaDoc args){
610         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(args, " ");
611         String JavaDoc[] argsArray = new String JavaDoc[st.countTokens()];
612         for (int i=0; i<argsArray.length; i++){
613             argsArray[i] = st.nextToken();
614         }
615
616         return argsArray;
617     }
618
619 }
620
621 class MainConfigErrorTest extends AbstractTest {
622     String JavaDoc badOption;
623     String JavaDoc args;
624     TestReport report = null;
625
626     public static final String JavaDoc ERROR_UNEXPECTED_ERROR_ARGS_0
627         = "MainConfigErrorTest.error.unexpected.error.args.0";
628
629     public static final String JavaDoc ERROR_UNEXPECTED_ERROR_CODE
630         = "MainConfigErrorTest.error.unexpected.error.code";
631
632     public static final String JavaDoc ERROR_NO_ERROR_REPORTED
633         = "MainConfigErrorTest.error.no.error.reported";
634
635     public static final String JavaDoc ENTRY_KEY_EXPECTED_ERROR_ARGS_0
636         = "MainConfigErrorTest.entry.key.expected.error.args.0";
637
638     public static final String JavaDoc ENTRY_KEY_GOT_ERROR_ARGS_0
639         = "MainConfigErrorTest.entry.key.got.error.args.0";
640
641     public static final String JavaDoc ENTRY_KEY_EXPECTED_ERROR_CODE
642         = "MainConfigErrorTest.entry.key.expected.error.code";
643
644     public static final String JavaDoc ENTRY_KEY_GOT_ERROR_CODE
645         = "MainConfigErrorTest.entry.key.got.error.code";
646
647     public MainConfigErrorTest(String JavaDoc badOption, String JavaDoc args){
648         this.badOption = badOption;
649         this.args = args;
650     }
651
652     public String JavaDoc getName(){
653         return getId();
654     }
655
656     public TestReport runImpl() throws Exception JavaDoc {
657         String JavaDoc[] argsArray = makeArgsArray(args);
658         Main main = new Main(argsArray) {
659                 public void error(String JavaDoc errorCode,
660                                   Object JavaDoc[] errorArgs){
661                     if (Main.ERROR_NOT_ENOUGH_OPTION_VALUES.equals(errorCode)){
662                         if(errorArgs != null && errorArgs.length > 0 && badOption.equals(errorArgs[0])){
663                             report = reportSuccess();
664                         } else {
665                             report = reportError(ERROR_UNEXPECTED_ERROR_ARGS_0);
666                             report.addDescriptionEntry(ENTRY_KEY_EXPECTED_ERROR_ARGS_0,
667                                                        badOption);
668                             report.addDescriptionEntry(ENTRY_KEY_GOT_ERROR_ARGS_0,
669                                                        errorArgs!= null && errorArgs.length>0 ? errorArgs[0] : "none");
670                         }
671                     } else {
672                         report = reportError(ERROR_UNEXPECTED_ERROR_CODE);
673                         report.addDescriptionEntry(ENTRY_KEY_EXPECTED_ERROR_CODE,
674                                                    Main.ERROR_NOT_ENOUGH_OPTION_VALUES);
675                         report.addDescriptionEntry(ENTRY_KEY_GOT_ERROR_CODE,
676                                                    errorCode);
677                     }
678                 }
679                                   
680                 
681             };
682
683         main.execute();
684
685         if (report == null){
686             report = reportError(ERROR_NO_ERROR_REPORTED);
687         }
688
689         return report;
690     }
691
692     String JavaDoc[] makeArgsArray(String JavaDoc args){
693         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(args, " ");
694         String JavaDoc[] argsArray = new String JavaDoc[st.countTokens()];
695         for (int i=0; i<argsArray.length; i++){
696             argsArray[i] = st.nextToken();
697         }
698
699         return argsArray;
700     }
701 }
702
703 abstract class MainConfigTest extends AbstractTest {
704     String JavaDoc args;
705     TestReport report;
706
707     static final String JavaDoc ERROR_UNEXPECTED_OPTION_VALUE
708         = "MainConfigTest.error.unexpected.option.value";
709
710     static final String JavaDoc ENTRY_KEY_OPTION
711         = "MainConfigTest.entry.key.option";
712
713     static final String JavaDoc ENTRY_KEY_EXPECTED_VALUE
714         = "MainConfigTest.entry.key.expected.value";
715
716     static final String JavaDoc ENTRY_KEY_ACTUAL_VALUE
717         = "MainConfigTest.entry.key.actual.value";
718
719     public TestReport reportError(String JavaDoc option,
720                                   String JavaDoc expectedValue,
721                                   String JavaDoc actualValue){
722         TestReport report = reportError(ERROR_UNEXPECTED_OPTION_VALUE);
723         report.addDescriptionEntry(ENTRY_KEY_OPTION, option);
724         report.addDescriptionEntry(ENTRY_KEY_EXPECTED_VALUE, expectedValue);
725         report.addDescriptionEntry(ENTRY_KEY_ACTUAL_VALUE, actualValue);
726         return report;
727     }
728
729     public MainConfigTest(String JavaDoc args){
730         this.args = args;
731     }
732
733     public String JavaDoc getName(){
734         return getId();
735     }
736
737     public TestReport runImpl() throws Exception JavaDoc {
738         String JavaDoc[] argsArray = makeArgsArray(args);
739         Main main = new Main(argsArray) {
740                 public void validateConverterConfig(SVGConverter c){
741                     report = validate(c);
742                 }
743                 
744             };
745
746         main.execute();
747
748         return report;
749     }
750
751     public abstract TestReport validate(SVGConverter c);
752
753     String JavaDoc[] makeArgsArray(String JavaDoc args){
754         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(args, " ");
755         String JavaDoc[] argsArray = new String JavaDoc[st.countTokens()];
756         for (int i=0; i<argsArray.length; i++){
757             argsArray[i] = st.nextToken();
758         }
759
760         return argsArray;
761     }
762
763
764 }
765
766
Popular Tags