1 26 27 package net.sourceforge.groboutils.util.xml.v1; 28 29 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 30 import junit.framework.Test; 31 import junit.framework.TestCase; 32 import junit.framework.TestSuite; 33 34 35 42 public class XMLUtilUTest extends TestCase 43 { 44 private static final Class THIS_CLASS = XMLUtilUTest.class; 47 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 48 49 public XMLUtilUTest( String name ) 50 { 51 super( name ); 52 } 53 54 55 56 59 60 public void testConstruction() 61 { 62 assertNotNull( 63 "getInstance() must never return null.", 64 XMLUtil.getInstance() ); 65 } 66 67 68 public void testUTFConvert1() 69 { 70 assertNull( 72 "Null conversion didn't work right.", 73 XMLUtil.getInstance().utf2xml( null ) ); 74 } 75 76 77 public void testUTFConvert2() 78 { 79 String noescapes = 81 "abcdefghijklmnopqrstuvwxyz "+ 82 "ABCDEFGHIJKLMNOPQRSTUVWXYZ "+ 83 "()=+-_!@#$%^*{}[]\\|;:/?.,\n\t\r"; 84 String val = XMLUtil.getInstance().utf2xml( noescapes ); 85 DOC.getLog().debug( "expected '"+noescapes+"'" ); 86 DOC.getLog().debug( "received '"+val+"'" ); 87 assertEquals( 88 noescapes, 89 val ); 90 } 91 92 93 public void testUTFConvert2a() 94 { 95 String noescapes = "" + 99 ((char)0xD7FF) + ((char)0xE000) + ((char)0xFFFD); 100 String real = "퟿�"; 101 String val = XMLUtil.getInstance().utf2xml( noescapes ); 102 DOC.getLog().debug( "expected '"+noescapes+"'" ); 103 DOC.getLog().debug( "received '"+val+"'" ); 104 assertEquals( 105 real, 106 val ); 107 } 108 109 110 public void testUTFConvert3() 111 { 112 assertEquals( 113 "<", 114 XMLUtil.getInstance().utf2xml( "<" ) ); 115 } 116 117 118 public void testUTFConvert4() 119 { 120 assertEquals( 121 ">", 122 XMLUtil.getInstance().utf2xml( ">" ) ); 123 } 124 125 126 public void testUTFConvert5() 127 { 128 assertEquals( 129 "&", 130 XMLUtil.getInstance().utf2xml( "&" ) ); 131 } 132 133 134 public void testUTFConvert6() 135 { 136 assertEquals( 137 """, 138 XMLUtil.getInstance().utf2xml( "\"" ) ); 139 } 140 141 142 public void testUTFConvert7() 143 { 144 assertEquals( 145 "'", 146 XMLUtil.getInstance().utf2xml( "'" ) ); 147 } 148 149 150 public void testUTFConvert8() 151 { 152 assertEquals( 153 "", 154 XMLUtil.getInstance().utf2xml( ""+((char)2) ) ); 155 } 156 157 158 public void testUTFConvert9() 159 { 160 assertEquals( 161 "a<b", 162 XMLUtil.getInstance().utf2xml( "a<b" ) ); 163 } 164 165 166 public void testUTFConvert10() 167 { 168 assertEquals( 169 "a>b", 170 XMLUtil.getInstance().utf2xml( "a>b" ) ); 171 } 172 173 174 public void testUTFConvert11() 175 { 176 assertEquals( 177 "&a<", 178 XMLUtil.getInstance().utf2xml( "&a<" ) ); 179 } 180 181 182 public void testUTFConvert12() 183 { 184 assertEquals( 185 "a"b>c", 186 XMLUtil.getInstance().utf2xml( "a\"b>c" ) ); 187 } 188 189 190 public void testUTFConvert13() 191 { 192 assertEquals( 193 "'abc>d", 194 XMLUtil.getInstance().utf2xml( "'abc>d" ) ); 195 } 196 197 198 public void testUTFConvert14() 199 { 200 assertEquals( 201 "aaabcfed asdf;lkj qwepiouf &amp;f3df", 202 XMLUtil.getInstance().utf2xml( "aaa"+((char)2)+ 203 'b' + ((char)3) + "cfed asdf;lkj qwepiouf &f3df") ); 204 } 205 206 207 public void testUTFAppend1() 208 { 209 try 210 { 211 XMLUtil.getInstance().utf2xml( null, null ); 212 fail( "did not throw an IllegalArgumentException." ); 213 } 214 catch (IllegalArgumentException iae) 215 { 216 } 218 } 219 220 221 public void testUTFAppend2() 222 { 223 try 224 { 225 XMLUtil.getInstance().utf2xml( "abc", null ); 226 fail( "did not throw an IllegalArgumentException." ); 227 } 228 catch (IllegalArgumentException iae) 229 { 230 } 232 } 233 234 235 public void testUTFAppend3() 236 { 237 StringBuffer sb = new StringBuffer (); 239 XMLUtil.getInstance().utf2xml( null, sb ); 240 assertEquals( 241 "Null conversion did not work.", 242 "null", 243 sb.toString() ); 244 } 245 246 247 248 249 252 253 public static Test suite() 254 { 255 TestSuite suite = new TestSuite( THIS_CLASS ); 256 257 return suite; 258 } 259 260 public static void main( String [] args ) 261 { 262 String [] name = { THIS_CLASS.getName() }; 263 264 267 junit.textui.TestRunner.main( name ); 268 } 269 270 271 275 protected void setUp() throws Exception 276 { 277 super.setUp(); 278 279 } 281 282 283 287 protected void tearDown() throws Exception 288 { 289 291 292 super.tearDown(); 293 } 294 } 295 296 | Popular Tags |