SAXParseExceptionTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package tests.api.org.xml.sax; 18 19import junit.framework.TestCase; 20 21import org.xml.sax.Locator; 22import org.xml.sax.SAXParseException; 23import org.xml.sax.helpers.LocatorImpl; 24 25import dalvik.annotation.TestLevel; 26import dalvik.annotation.TestTargetClass; 27import dalvik.annotation.TestTargetNew; 28import dalvik.annotation.TestTargets; 29 30@TestTargetClass(SAXParseException.class) 31public class SAXParseExceptionTest extends TestCase { 32 33 public static final String ERR = "Houston, we have a problem"; 34 35 public static final String SYS = "mySystemID"; 36 37 public static final String PUB = "myPublicID"; 38 39 public static final int ROW = 1; 40 41 public static final int COL = 2; 42 43 @TestTargets({ 44 @TestTargetNew( 45 level = TestLevel.COMPLETE, 46 method = "SAXParseException", 47 args = { String.class, Locator.class, Exception.class } 48 ), 49 @TestTargetNew( 50 level = TestLevel.COMPLETE, 51 method = "getMessage", 52 args = { } 53 ), 54 @TestTargetNew( 55 level = TestLevel.COMPLETE, 56 method = "getException", 57 args = { } 58 ), 59 @TestTargetNew( 60 level = TestLevel.COMPLETE, 61 method = "getPublicId", 62 args = { } 63 ), 64 @TestTargetNew( 65 level = TestLevel.COMPLETE, 66 method = "getSystemId", 67 args = { } 68 ), 69 @TestTargetNew( 70 level = TestLevel.COMPLETE, 71 method = "getLineNumber", 72 args = { } 73 ), 74 @TestTargetNew( 75 level = TestLevel.COMPLETE, 76 method = "getColumnNumber", 77 args = { } 78 ) 79 }) 80 public void testSAXParseException_String_Locator_Exception() { 81 LocatorImpl l = new LocatorImpl(); 82 l.setPublicId(PUB); 83 l.setSystemId(SYS); 84 l.setLineNumber(ROW); 85 l.setColumnNumber(COL); 86 87 Exception c = new Exception(); 88 89 // Ordinary case 90 SAXParseException e = new SAXParseException(ERR, l, c); 91 92 assertEquals(ERR, e.getMessage()); 93 assertEquals(c, e.getException()); 94 95 assertEquals(PUB, e.getPublicId()); 96 assertEquals(SYS, e.getSystemId()); 97 assertEquals(ROW, e.getLineNumber()); 98 assertEquals(COL, e.getColumnNumber()); 99 100 // No message 101 e = new SAXParseException(null, l, c); 102 103 assertNull(e.getMessage()); 104 assertEquals(c, e.getException()); 105 106 assertEquals(PUB, e.getPublicId()); 107 assertEquals(SYS, e.getSystemId()); 108 assertEquals(ROW, e.getLineNumber()); 109 assertEquals(COL, e.getColumnNumber()); 110 111 // No locator 112 e = new SAXParseException(ERR, null, c); 113 114 assertEquals(ERR, e.getMessage()); 115 assertEquals(c, e.getException()); 116 117 assertNull(e.getPublicId()); 118 assertNull(e.getSystemId()); 119 assertEquals(-1, e.getLineNumber()); 120 assertEquals(-1, e.getColumnNumber()); 121 122 // No cause 123 e = new SAXParseException(ERR, l, null); 124 125 assertEquals(ERR, e.getMessage()); 126 assertNull(e.getException()); 127 128 assertEquals(PUB, e.getPublicId()); 129 assertEquals(SYS, e.getSystemId()); 130 assertEquals(ROW, e.getLineNumber()); 131 assertEquals(COL, e.getColumnNumber()); 132 } 133 134 @TestTargetNew( 135 level = TestLevel.COMPLETE, 136 method = "SAXParseException", 137 args = { String.class, Locator.class } 138 ) 139 public void testSAXParseException_String_Locator() { 140 LocatorImpl l = new LocatorImpl(); 141 l.setPublicId(PUB); 142 l.setSystemId(SYS); 143 l.setLineNumber(ROW); 144 l.setColumnNumber(COL); 145 146 // Ordinary case 147 SAXParseException e = new SAXParseException(ERR, l); 148 149 assertEquals(ERR, e.getMessage()); 150 assertNull(e.getException()); 151 152 assertEquals(PUB, e.getPublicId()); 153 assertEquals(SYS, e.getSystemId()); 154 assertEquals(ROW, e.getLineNumber()); 155 assertEquals(COL, e.getColumnNumber()); 156 157 // No message 158 e = new SAXParseException(null, l); 159 160 assertNull(e.getMessage()); 161 assertNull(e.getException()); 162 163 assertEquals(PUB, e.getPublicId()); 164 assertEquals(SYS, e.getSystemId()); 165 assertEquals(ROW, e.getLineNumber()); 166 assertEquals(COL, e.getColumnNumber()); 167 168 // No locator 169 e = new SAXParseException(ERR, null); 170 171 assertEquals(ERR, e.getMessage()); 172 assertNull(e.getException()); 173 174 assertNull(e.getPublicId()); 175 assertNull(e.getSystemId()); 176 assertEquals(-1, e.getLineNumber()); 177 assertEquals(-1, e.getColumnNumber()); 178 179 } 180 181 @TestTargetNew( 182 level = TestLevel.COMPLETE, 183 method = "SAXParseException", 184 args = { String.class, String.class, String.class, int.class, int.class, 185 Exception.class } 186 ) 187 public void testSAXParseException_String_String_String_int_int_Exception() { 188 Exception c = new Exception(); 189 190 // Ordinary case 191 SAXParseException e = new SAXParseException(ERR, PUB, SYS, ROW, COL, c); 192 193 assertEquals(ERR, e.getMessage()); 194 assertEquals(c, e.getException()); 195 196 assertEquals(PUB, e.getPublicId()); 197 assertEquals(SYS, e.getSystemId()); 198 assertEquals(ROW, e.getLineNumber()); 199 assertEquals(COL, e.getColumnNumber()); 200 201 // No message 202 e = new SAXParseException(null, PUB, SYS, ROW, COL, c); 203 204 assertNull(e.getMessage()); 205 assertEquals(c, e.getException()); 206 207 assertEquals(PUB, e.getPublicId()); 208 assertEquals(SYS, e.getSystemId()); 209 assertEquals(ROW, e.getLineNumber()); 210 assertEquals(COL, e.getColumnNumber()); 211 212 // No locator 213 e = new SAXParseException(ERR, null, null, -1, -1, c); 214 215 assertEquals(ERR, e.getMessage()); 216 assertEquals(c, e.getException()); 217 218 assertNull(e.getPublicId()); 219 assertNull(e.getSystemId()); 220 assertEquals(-1, e.getLineNumber()); 221 assertEquals(-1, e.getColumnNumber()); 222 223 // No cause 224 e = new SAXParseException(ERR, PUB, SYS, ROW, COL, null); 225 226 assertEquals(ERR, e.getMessage()); 227 assertNull(e.getException()); 228 229 assertEquals(PUB, e.getPublicId()); 230 assertEquals(SYS, e.getSystemId()); 231 assertEquals(ROW, e.getLineNumber()); 232 assertEquals(COL, e.getColumnNumber()); 233 } 234 235 @TestTargetNew( 236 level = TestLevel.COMPLETE, 237 method = "SAXParseException", 238 args = { String.class, String.class, String.class, int.class, 239 int.class } 240 ) 241 public void testSAXParseException_String_String_String_int_int() { 242 // Ordinary case 243 SAXParseException e = new SAXParseException(ERR, PUB, SYS, ROW, COL); 244 245 assertEquals(ERR, e.getMessage()); 246 assertNull(e.getException()); 247 248 assertEquals(PUB, e.getPublicId()); 249 assertEquals(SYS, e.getSystemId()); 250 assertEquals(ROW, e.getLineNumber()); 251 assertEquals(COL, e.getColumnNumber()); 252 253 // No message 254 e = new SAXParseException(null, PUB, SYS, ROW, COL); 255 256 assertNull(e.getMessage()); 257 assertNull(e.getException()); 258 259 assertEquals(PUB, e.getPublicId()); 260 assertEquals(SYS, e.getSystemId()); 261 assertEquals(ROW, e.getLineNumber()); 262 assertEquals(COL, e.getColumnNumber()); 263 264 // No locator 265 e = new SAXParseException(ERR, null, null, -1, -1); 266 267 assertEquals(ERR, e.getMessage()); 268 assertNull(e.getException()); 269 270 assertNull(e.getPublicId()); 271 assertNull(e.getSystemId()); 272 assertEquals(-1, e.getLineNumber()); 273 assertEquals(-1, e.getColumnNumber()); 274 } 275 276}