001 package javancss.test; 002 003 import java.io.File; 004 005 import ccl.util.FileUtil; 006 import ccl.util.Test; 007 import ccl.util.Util; 008 import ccl.xml.XMLUtil; 009 010 import javancss.Javancss; 011 import javancss.XmlFormatter; 012 013 /** 014 * This test class checks that the xml output feature is 015 * working properly. 016 * 017 * @version $Id: XmlFormatterTest.java 121 2009-01-17 22:19:45Z hboutemy $ 018 * @author Chr. Clemens Lee 019 */ 020 public class XmlFormatterTest extends AbstractTest { 021 /** 022 * Is it at least possible to properly parse generated xml code? 023 */ 024 public void testParsing() 025 throws Exception 026 { 027 Javancss pJavancss = new Javancss( getTestFile( 57 ) ); 028 pJavancss.setXML( true ); 029 030 String sXML = XmlFormatter.printStart() 031 + pJavancss.printPackageNcss() 032 + pJavancss.printObjectNcss() 033 + pJavancss.printFunctionNcss() 034 + pJavancss.printJavaNcss() 035 + XmlFormatter.printEnd(); 036 037 try 038 { 039 String sText = XMLUtil.getXML( sXML, getXslFile( "xmltest.xsl" ) ); 040 Assert( sText.equals( "79" ), sText ); 041 } 042 catch( NoClassDefFoundError error ) 043 { 044 Util.print( "skipped: 'xalan.jar' and or 'xerces.jar' library missing." ); 045 } 046 047 pJavancss = new Javancss( getTestFile( 117 ) ); 048 pJavancss.setXML( true ); 049 050 sXML = XmlFormatter.printStart() 051 + pJavancss.printPackageNcss() 052 + pJavancss.printObjectNcss() 053 + pJavancss.printFunctionNcss() 054 + pJavancss.printJavaNcss() 055 + XmlFormatter.printEnd(); 056 Assert( Util.isEmpty( sXML ) == false ); 057 058 pJavancss = new Javancss( getTestFile( 118 ) ); 059 pJavancss.setXML( true ); 060 061 sXML = XmlFormatter.printStart() 062 + pJavancss.printPackageNcss() 063 + pJavancss.printObjectNcss() 064 + pJavancss.printFunctionNcss() 065 + pJavancss.printJavaNcss() 066 + XmlFormatter.printEnd(); 067 Assert( Util.isEmpty( sXML ) == false ); 068 } 069 070 /** 071 * Is the transformed XML output identical to the standard ASCI output? 072 */ 073 public void testXML2Text() 074 throws Exception 075 { 076 Javancss pJavancss = new Javancss( getTestFile( 32 ) ); 077 pJavancss.setXML( true ); 078 079 String sXML = XmlFormatter.printStart() 080 + pJavancss.printPackageNcss() 081 + pJavancss.printObjectNcss() 082 + pJavancss.printFunctionNcss() 083 + pJavancss.printJavaNcss() 084 + XmlFormatter.printEnd(); 085 086 try 087 { 088 String sText = XMLUtil.getXML( sXML, getXslFile( "javancss2text.xsl" ) ); 089 FileUtil.writeFile( "/tmp/t", sText ); 090 String sCompare = FileUtil.readFile( getTestFile( "Output32.txt" ).getAbsolutePath() ); 091 Assert( sText.equals( sCompare ), sText ); 092 } 093 catch( NoClassDefFoundError error ) 094 { 095 Util.print( "skipped: 'xalan.jar' and or 'xerces.jar' library missing." ); 096 } 097 } 098 099 public XmlFormatterTest() 100 { 101 super(); 102 } 103 104 public XmlFormatterTest( Test pTest_ ) 105 { 106 super( pTest_ ); 107 } 108 109 private File getXslFile( String filename ) 110 { 111 return new File( getTestDir(), ".." + File.separator + "xslt" + File.separator + filename ); 112 } 113 114 /** 115 * Test code goes here. 116 */ 117 protected void _doIt() 118 throws Exception 119 { 120 testParsing (); 121 testXML2Text(); 122 } 123 124 public static void main( String[] asArg_ ) 125 { 126 new XmlFormatterTest().main(); 127 } 128 }