public void testBufferWithLargeFile() throws Exception { final char[] chars = "0123456789abcdef".toCharArray(); final char[] manyChars = new char[10000]; for (int i = 0; i < manyChars.length; ++i) { manyChars[i] = chars[i % chars.length]; } final String s0 = new String(manyChars); final StringTextSource textSource = new StringTextSource(s0); assertSame(s0, textSource.getText()); final File file = new File(getDirectory(), "myfile.txt"); final Buffer buffer = new BufferImplementation(s_resources, textSource, file); assertEquals(Buffer.TEXT_BUFFER, buffer.getType()); assertTrue(!buffer.isDirty()); assertTrue(!buffer.isUpToDate()); assertEquals(file, buffer.getFile()); assertEquals(textSource, buffer.getTextSource()); buffer.save(); assertTrue(!buffer.isDirty()); assertTrue(buffer.isUpToDate()); assertSame(s0, textSource.getText()); buffer.load(); assertTrue(!buffer.isDirty()); assertTrue(buffer.isUpToDate()); assertEquals(canonicaliseLineEndings(s0), textSource.getText()); assertNotSame(s0, textSource.getText()); }
public void testBufferWithAssociatedFile() throws Exception { final String s0 = "A shield for your eyes\na beast in the well on your hand"; final String s1 = "Catch the mean beast\nin the well in the hell on the back\n" + "Watch out! You've got no shield\n" + "Break up! He's got no peace"; final StringTextSource textSource = new StringTextSource(s0); assertSame(s0, textSource.getText()); final File file = new File(getDirectory(), "myfile.txt"); final Buffer buffer = new BufferImplementation(s_resources, textSource, file); assertEquals(Buffer.TEXT_BUFFER, buffer.getType()); assertTrue(!buffer.isDirty()); assertTrue(!buffer.isUpToDate()); assertEquals(file, buffer.getFile()); assertEquals(textSource, buffer.getTextSource()); buffer.save(); assertTrue(!buffer.isDirty()); assertTrue(buffer.isUpToDate()); assertSame(s0, textSource.getText()); textSource.setText(s1); textSource.markDirty(); assertTrue(buffer.isDirty()); assertTrue(buffer.isUpToDate()); assertSame(s1, textSource.getText()); buffer.load(); assertTrue(!buffer.isDirty()); assertTrue(buffer.isUpToDate()); assertEquals(canonicaliseLineEndings(s0), textSource.getText()); assertNotSame(s0, textSource.getText()); // Add an error margin, as Linux does not support setting the modification // date with millisecond precision. assertTrue(file.setLastModified(System.currentTimeMillis() + 1000)); assertTrue(!buffer.isUpToDate()); buffer.load(); assertTrue(buffer.isUpToDate()); assertEquals(textSource, buffer.getTextSource()); }