| 31 | |
| 32 | |
| 33 | public class BadIonTest |
| 34 | extends IonTestCase |
| 35 | { |
| 36 | @Inject("testFile") |
| 37 | public static final File[] FILES = |
| 38 | testdataFiles(GLOBAL_SKIP_LIST, BAD_IONTESTS_FILES); |
| 39 | |
| 40 | |
| 41 | private File myTestFile; |
| 42 | private boolean myFileIsBinary; |
| 43 | |
| 44 | public void setTestFile(File file) |
| 45 | { |
| 46 | myTestFile = file; |
| 47 | |
| 48 | String fileName = file.getName(); |
| 49 | myFileIsBinary = fileName.endsWith(".10n"); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | @Test |
| 54 | public void testLoadFile() |
| 55 | throws Exception |
| 56 | { |
| 57 | try |
| 58 | { |
| 59 | load(myTestFile); |
| 60 | fail("Expected exception"); |
| 61 | } |
| 62 | catch (IonException e) { /* good */ } |
| 63 | catch (IOException e) { /* good? (e.g. EOF error) */ } |
| 64 | } |
| 65 | |
| 66 | |
| 67 | @Test |
| 68 | public void testLoadString() |
| 69 | throws Exception |
| 70 | { |
| 71 | if (! myFileIsBinary) |
| 72 | { |
| 73 | String ionText; |
| 74 | try |
| 75 | { |
| 76 | // This will fail if the file has bad UTF-8 data. |
| 77 | // That's OK, the other test will still do the right thing. |
| 78 | ionText = _Private_Utils.utf8FileToString(myTestFile); |
| 79 | } |
| 80 | catch (IonException e) |
| 81 | { |
| 82 | // checks that test failed because of bad UTF-8 data |
| 83 | final CharBuffer buffer = CharBuffer.allocate(1024); |
| 84 | final CharsetEncoder utf8Encoder = Charset.forName("UTF-8").newEncoder(); |
| 85 | |
| 86 | final FileReader fileReader = new FileReader(myTestFile); |
| 87 | while(fileReader.read(buffer) != -1){ |
| 88 | assert utf8Encoder.canEncode(buffer); |
| 89 | } |
| 90 |
nothing calls this directly
no test coverage detected
searching dependent graphs…