1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.IOException ; 30 import java.io.StringReader ; 31 import java.io.StringWriter ; 32 33 import junit.framework.Test; 34 import junit.framework.TestCase; 35 import junit.framework.TestSuite; 36 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 37 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil; 38 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData; 39 40 41 48 public class AnalysisMetaDataIOUTest extends TestCase 49 { 50 53 private static final Class THIS_CLASS = AnalysisMetaDataIOUTest.class; 54 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 55 56 public AnalysisMetaDataIOUTest( String name ) 57 { 58 super( name ); 59 } 60 61 62 65 public void testWriteAnalysisMetaData1() throws Exception 66 { 67 AnalysisMetaDataIO amdio = new AnalysisMetaDataIO(); 68 StringWriter sw = new StringWriter (); 69 IAnalysisMetaData amd = createIAnalysisMetaData( 70 "c", "n", (byte)-1 ); 71 72 amdio.writeAnalysisMetaData( amd, sw ); 73 74 String res = sw.toString(); 75 DOC.getLog().info( "Wrote meta-data ["+res+"]" ); 76 assertEquals( 77 "Incorrect result format.", 78 "1:c,1:n,-1,", 79 res ); 80 } 81 82 public void testWriteAnalysisMetaData2() throws Exception 83 { 84 AnalysisMetaDataIO amdio = new AnalysisMetaDataIO(); 85 StringWriter sw = new StringWriter (); 86 IAnalysisMetaData amd = createIAnalysisMetaData( 87 "123", "12345", (byte)100 ); 88 89 amdio.writeAnalysisMetaData( amd, sw ); 90 91 String res = sw.toString(); 92 DOC.getLog().info( "Wrote meta-data ["+res+"]" ); 93 assertEquals( 94 "Incorrect result format.", 95 "3:123,5:12345,100,", 96 res ); 97 } 98 99 100 public void testReadAnalysisMetaData1() throws Exception 101 { 102 AnalysisMetaDataIO amdio = new AnalysisMetaDataIO(); 103 StringReader sr = new StringReader ( "1:c,1:n,-1," ); 104 IAnalysisMetaData amd = amdio.readAnalysisMetaData( sr ); 105 assertNotNull( 106 "Returned null data.", 107 amd ); 108 assertEquals( 109 "Covered formatted text incorrect.", 110 "c", 111 amd.getCoveredFormattedText() ); 112 assertEquals( 113 "Not covered formatted text incorrect.", 114 "n", 115 amd.getNotCoveredFormattedText() ); 116 assertEquals( 117 "instruction weight incorrect.", 118 (byte)-1, 119 amd.getInstructionWeight() ); 120 } 121 122 123 public void testReadAnalysisMetaData2() throws Exception 124 { 125 AnalysisMetaDataIO amdio = new AnalysisMetaDataIO(); 126 StringReader sr = new StringReader ( "3:123,5:12345,100," ); 127 IAnalysisMetaData amd = amdio.readAnalysisMetaData( sr ); 128 assertNotNull( 129 "Returned null data.", 130 amd ); 131 assertEquals( 132 "Covered formatted text incorrect.", 133 "123", 134 amd.getCoveredFormattedText() ); 135 assertEquals( 136 "Not covered formatted text incorrect.", 137 "12345", 138 amd.getNotCoveredFormattedText() ); 139 assertEquals( 140 "instruction weight incorrect.", 141 (byte)100, 142 amd.getInstructionWeight() ); 143 } 144 145 146 public void testReadAnalysisMetaData3() throws Exception 147 { 148 AnalysisMetaDataIO amdio = new AnalysisMetaDataIO(); 149 StringReader sr = new StringReader ( "" ); 150 try 151 { 152 amdio.readAnalysisMetaData( sr ); 153 fail( "Did not throw IOException." ); 154 } 155 catch (IOException ioe) 156 { 157 } 159 } 160 161 162 public void testReadAnalysisMetaData4() throws Exception 163 { 164 AnalysisMetaDataIO amdio = new AnalysisMetaDataIO(); 165 StringReader sr = new StringReader ( "1" ); 166 try 167 { 168 amdio.readAnalysisMetaData( sr ); 169 fail( "Did not throw IOException." ); 170 } 171 catch (IOException ioe) 172 { 173 } 175 } 176 177 178 public void testReadAnalysisMetaData5() throws Exception 179 { 180 AnalysisMetaDataIO amdio = new AnalysisMetaDataIO(); 181 StringReader sr = new StringReader ( "a:a" ); 182 try 183 { 184 amdio.readAnalysisMetaData( sr ); 185 fail( "Did not throw IOException." ); 186 } 187 catch (IOException ioe) 188 { 189 } 191 } 192 193 194 197 protected IAnalysisMetaData createIAnalysisMetaData( String c, String nc, 198 byte w ) 199 { 200 return CCCreatorUtil.createIAnalysisMetaData( c, nc, w ); 201 } 202 203 204 207 208 public static Test suite() 209 { 210 TestSuite suite = new TestSuite( THIS_CLASS ); 211 212 return suite; 213 } 214 215 public static void main( String [] args ) 216 { 217 String [] name = { THIS_CLASS.getName() }; 218 219 222 junit.textui.TestRunner.main( name ); 223 } 224 225 226 230 protected void setUp() throws Exception 231 { 232 super.setUp(); 233 234 } 236 237 238 242 protected void tearDown() throws Exception 243 { 244 246 247 super.tearDown(); 248 } 249 } 250 251 | Popular Tags |