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.IAnalysisModule; 39 40 41 48 public class AnalysisModuleIOUTest extends TestCase 49 { 50 53 private static final Class THIS_CLASS = AnalysisModuleIOUTest.class; 54 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 55 56 public AnalysisModuleIOUTest( String name ) 57 { 58 super( name ); 59 } 60 61 62 65 public void testWriteAnalysisModule1() throws Exception 66 { 67 AnalysisModuleIO amio = new AnalysisModuleIO(); 68 StringWriter sw = new StringWriter (); 69 IAnalysisModule am = createIAnalysisModule( 70 "n", "u", "m" ); 71 72 amio.writeAnalysisModule( am, sw ); 73 74 String res = sw.toString(); 75 DOC.getLog().info( "Wrote module ["+res+"]" ); 76 assertEquals( 77 "Incorrect result format.", 78 "1:n,1:u,1:m", 79 res ); 80 } 81 82 public void testWriteAnalysisModule2() throws Exception 83 { 84 AnalysisModuleIO amio = new AnalysisModuleIO(); 85 StringWriter sw = new StringWriter (); 86 IAnalysisModule am = createIAnalysisModule( 87 "", "", "" ); 88 89 amio.writeAnalysisModule( am, sw ); 90 91 String res = sw.toString(); 92 DOC.getLog().info( "Wrote module ["+res+"]" ); 93 assertEquals( 94 "Incorrect result format.", 95 "0:,0:,0:", 96 res ); 97 } 98 99 public void testWriteAnalysisModule3() throws Exception 100 { 101 AnalysisModuleIO amio = new AnalysisModuleIO(); 102 StringWriter sw = new StringWriter (); 103 IAnalysisModule am = createIAnalysisModule( 104 "aaaa", "bbbb", "1234" ); 105 106 amio.writeAnalysisModule( am, sw ); 107 108 String res = sw.toString(); 109 DOC.getLog().info( "Wrote module ["+res+"]" ); 110 assertEquals( 111 "Incorrect result format.", 112 "4:aaaa,4:bbbb,4:1234", 113 res ); 114 } 115 116 117 public void testReadAnalysisModule1() throws Exception 118 { 119 AnalysisModuleIO amio = new AnalysisModuleIO(); 120 StringReader sr = new StringReader ( "1:n,1:u,1:m" ); 121 IAnalysisModule am = amio.readAnalysisModule( sr ); 122 assertNotNull( 123 "Returned null data.", 124 am ); 125 assertEquals( 126 "name incorrect.", 127 "n", 128 am.getMeasureName() ); 129 assertEquals( 130 "unit incorrect.", 131 "u", 132 am.getMeasureUnit() ); 133 assertEquals( 134 "instruction weight incorrect.", 135 "m", 136 am.getMimeEncoding() ); 137 } 138 139 140 public void testReadAnalysisMetaData2() throws Exception 141 { 142 AnalysisModuleIO amio = new AnalysisModuleIO(); 143 StringReader sr = new StringReader ( "0: ,0:,0:asdf," ); 144 IAnalysisModule am = amio.readAnalysisModule( sr ); 145 assertNotNull( 146 "Returned null data.", 147 am ); 148 assertEquals( 149 "name incorrect.", 150 "", 151 am.getMeasureName() ); 152 assertEquals( 153 "unit incorrect.", 154 "", 155 am.getMeasureUnit() ); 156 assertEquals( 157 "instruction weight incorrect.", 158 "", 159 am.getMimeEncoding() ); 160 } 161 162 163 public void testReadAnalysisMetaData3() throws Exception 164 { 165 AnalysisModuleIO amio = new AnalysisModuleIO(); 166 StringReader sr = new StringReader ( "" ); 167 try 168 { 169 amio.readAnalysisModule( sr ); 170 fail( "Did not throw IOException." ); 171 } 172 catch (IOException ioe) 173 { 174 } 176 } 177 178 179 public void testReadAnalysisMetaData4() throws Exception 180 { 181 AnalysisModuleIO amio = new AnalysisModuleIO(); 182 StringReader sr = new StringReader ( "1" ); 183 try 184 { 185 amio.readAnalysisModule( sr ); 186 fail( "Did not throw IOException." ); 187 } 188 catch (IOException ioe) 189 { 190 } 192 } 193 194 195 public void testReadAnalysisMetaData5() throws Exception 196 { 197 AnalysisModuleIO amio = new AnalysisModuleIO(); 198 StringReader sr = new StringReader ( "a:a,1:1,1:1" ); 199 try 200 { 201 amio.readAnalysisModule( sr ); 202 fail( "Did not throw IOException." ); 203 } 204 catch (IOException ioe) 205 { 206 } 208 } 209 210 211 214 protected IAnalysisModule createIAnalysisModule( String name, String unit, 215 String mime ) 216 { 217 return CCCreatorUtil.createIAnalysisModule( name, unit, mime ); 218 } 219 220 221 224 225 public static Test suite() 226 { 227 TestSuite suite = new TestSuite( THIS_CLASS ); 228 229 return suite; 230 } 231 232 public static void main( String [] args ) 233 { 234 String [] name = { THIS_CLASS.getName() }; 235 236 239 junit.textui.TestRunner.main( name ); 240 } 241 242 243 247 protected void setUp() throws Exception 248 { 249 super.setUp(); 250 251 } 253 254 255 259 protected void tearDown() throws Exception 260 { 261 263 264 super.tearDown(); 265 } 266 } 267 268 | Popular Tags |