Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 12490 Details for
Bug 66898
refactor-rename: encoding is not preserved
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Additional test added to EncodingTests
v01-tests-model.txt (text/plain), 8.36 KB, created by
Frederic Fusier
on 2004-06-18 11:49:03 EDT
(
hide
)
Description:
Additional test added to EncodingTests
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2004-06-18 11:49:03 EDT
Size:
8.36 KB
patch
obsolete
>Index: src/org/eclipse/jdt/core/tests/model/EncodingTests.java >=================================================================== >RCS file: /data/cvs/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/EncodingTests.java,v >retrieving revision 1.22 >diff -u -r1.22 EncodingTests.java >--- src/org/eclipse/jdt/core/tests/model/EncodingTests.java 16 Jun 2004 13:37:07 -0000 1.22 >+++ src/org/eclipse/jdt/core/tests/model/EncodingTests.java 18 Jun 2004 15:37:50 -0000 >@@ -16,8 +16,10 @@ > > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IWorkspaceRunnable; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.core.runtime.Preferences; > import org.eclipse.jdt.core.ICompilationUnit; >@@ -26,6 +28,7 @@ > import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.ISourceReference; >+import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.internal.core.util.Util; > >@@ -48,7 +51,7 @@ > // All specified tests which do not belong to the class are skipped... > static { > // Names of tests to run: can be "testBugXXXX" or "BugXXXX") >-// testsNames = new String[] { "testBug66898" }; >+// testsNames = new String[] { "testBug66898", "testBug66898b" }; > // Numbers of tests to run: "test<number>" will be run for each number of this array > // testsNumbers = new int[] { 2, 12 }; > // Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last } >@@ -587,29 +590,19 @@ > // Set file encoding > String encoding = "UTF-8".equals(vmEncoding) ? "Cp1252" : "UTF-8"; > this.utf8File.setCharset(encoding); >- >- // Move file > String fileName = this.utf8File.getName(); > ICompilationUnit cu = getCompilationUnit(this.utf8File.getFullPath().toString()); > createFolder("/Encoding/src/tmp"); > IPackageFragment packFrag = getPackageFragment("Encoding", "src", "tmp"); >+ >+ // Move file > cu.move(packFrag, null, null, false, null); > ICompilationUnit destSource = packFrag.getCompilationUnit(fileName); > IFile destFile = (IFile) destSource.getUnderlyingResource(); > assertEquals("Moved file should keep encoding", encoding, destFile.getCharset()); > > // Get source and compare with file contents >- String source = destSource.getSource(); >- String systemSource = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(source); >- String encodedContents = new String (Util.getResourceContentsAsCharArray(destFile)); >- encodedContents = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(encodedContents); >- assertEquals("Encoded UTF-8 source should have been decoded the same way!", encodedContents, systemSource); >- byte[] sourceBytes = source.getBytes(encoding); >- byte[] encodedBytes = Util.getResourceContentsAsByteArray(destFile); >- assertEquals("Wrong size of encoded string", encodedBytes.length, sourceBytes.length); >- for (int i = 0, max = sourceBytes.length; i < max; i++) { >- assertTrue("Wrong size of encoded character at " + i, sourceBytes[i] == encodedBytes[i]); >- } >+ compareContents(destSource, encoding); > > // Rename file > destSource.rename("TestUTF8.java", false, null); >@@ -618,20 +611,96 @@ > assertEquals("Moved file should keep encoding", encoding, renamedFile.getCharset()); > > // Compare contents again >- String sourceRenamed = renamedSource.getSource(); >- String systemSourceRenamed = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(sourceRenamed); >- String renamedContents = new String (Util.getResourceContentsAsCharArray(renamedFile)); >+ compareContents(renamedSource, encoding); >+ >+ // Move back >+ renamedFile.move(this.utf8File.getFullPath(), false, null); >+ assertEquals("Moved file should keep encoding", encoding, this.utf8File.getCharset()); >+ deleteFolder("/Encoding/src/tmp"); >+ } >+ public void testBug66898b() throws JavaModelException, CoreException { >+ >+ // Set file encoding >+ final String encoding = "UTF-8".equals(vmEncoding) ? "Cp1252" : "UTF-8"; >+ this.utf8File.setCharset(encoding); >+ final String fileName = utf8File.getName(); >+ final IPackageFragment srcFolder = getPackageFragment("Encoding", "src", "testUTF8"); >+ createFolder("/Encoding/src/tmp"); >+ final IPackageFragment tmpFolder = getPackageFragment("Encoding", "src", "tmp"); >+ >+ // Copy file >+ IWorkspaceRunnable copy = new IWorkspaceRunnable() { >+ public void run(IProgressMonitor monitor) throws CoreException { >+ ICompilationUnit cu = getCompilationUnit(utf8File.getFullPath().toString()); >+ cu.copy(tmpFolder, null, null, true, null); >+ cu.close(); // purge buffer contents from cache >+ ICompilationUnit dest = tmpFolder.getCompilationUnit(fileName); >+ IFile destFile = (IFile) dest.getUnderlyingResource(); >+ assertEquals("Copied file should keep encoding", encoding, destFile.getCharset()); >+ >+ // Get source and compare with file contents >+ compareContents(dest, encoding); >+ } >+ }; >+ JavaCore.run(copy, null); >+ >+ // Rename file >+ IWorkspaceRunnable rename = new IWorkspaceRunnable() { >+ public void run(IProgressMonitor monitor) throws CoreException { >+ ICompilationUnit cu = tmpFolder.getCompilationUnit(fileName); >+ cu.rename("Renamed.java", true, null); >+ cu.close(); // purge buffer contents from cache >+ ICompilationUnit ren = tmpFolder.getCompilationUnit("Renamed.java"); >+ IFile renFile = (IFile) ren.getUnderlyingResource(); >+ assertEquals("Renamed file should keep encoding", encoding, renFile.getCharset()); >+ >+ // Get source and compare with file contents >+ compareContents(ren, encoding); >+ } >+ }; >+ JavaCore.run(rename, null); >+ >+ // Move file >+ IWorkspaceRunnable move = new IWorkspaceRunnable() { >+ public void run(IProgressMonitor monitor) throws CoreException { >+ ICompilationUnit cu = tmpFolder.getCompilationUnit("Renamed.java"); >+ cu.move(srcFolder, null, null, true, null); >+ cu.close(); // purge buffer contents from cache >+ ICompilationUnit moved = srcFolder.getCompilationUnit("Renamed.java"); >+ IFile movedFile = (IFile) moved.getUnderlyingResource(); >+ assertEquals("Renamed file should keep encoding", encoding, movedFile.getCharset()); >+ >+ // Get source and compare with file contents >+ compareContents(moved, encoding); >+ } >+ }; >+ JavaCore.run(move, null); >+ >+ // Delete file >+ ICompilationUnit cu = srcFolder.getCompilationUnit("Renamed.java"); >+ cu.delete(true, null); >+ deleteFolder("/Encoding/src/tmp"); >+ } >+ void compareContents(ICompilationUnit cu, String encoding) throws JavaModelException { >+ // Compare source strings >+ String source = cu.getSource(); >+ String systemSourceRenamed = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(source); >+ IFile file = (IFile) cu.getUnderlyingResource(); >+ String renamedContents = new String (Util.getResourceContentsAsCharArray(file)); > renamedContents = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(renamedContents); > assertEquals("Encoded UTF-8 source should have been decoded the same way!", renamedContents, systemSourceRenamed); >- byte[] renamedSourceBytes = sourceRenamed.getBytes(encoding); >- byte[] renamedEncodedBytes = Util.getResourceContentsAsByteArray(renamedFile); >+ // Compare bytes array >+ byte[] renamedSourceBytes = null; >+ try { >+ renamedSourceBytes = source.getBytes(encoding); >+ } >+ catch (UnsupportedEncodingException uue) { >+ } >+ assertNotNull("Unsupported encoding: "+encoding, renamedSourceBytes); >+ byte[] renamedEncodedBytes = Util.getResourceContentsAsByteArray(file); > assertEquals("Wrong size of encoded string", renamedEncodedBytes.length, renamedSourceBytes.length); > for (int i = 0, max = renamedSourceBytes.length; i < max; i++) { > assertTrue("Wrong size of encoded character at " + i, renamedSourceBytes[i] == renamedEncodedBytes[i]); > } >- >- // Move back >- renamedFile.move(this.utf8File.getFullPath(), false, null); >- assertEquals("Moved file should keep encoding", encoding, this.utf8File.getCharset()); >- } >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 66898
:
12191
|
12488
| 12490