Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 115716 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/core/tests/format/TestFormatProcessorXML.java (-47 / +37 lines)
Lines 61-78 Link Here
61
61
62
		IStructuredModel model = null;
62
		IStructuredModel model = null;
63
		try {
63
		try {
64
			IModelManager modelManager = StructuredModelManager
64
			IModelManager modelManager = StructuredModelManager.getModelManager();
65
					.getModelManager();
66
			InputStream inStream = getClass().getResourceAsStream(filename);
65
			InputStream inStream = getClass().getResourceAsStream(filename);
67
			if (inStream == null)
66
			if (inStream == null)
68
				throw new FileNotFoundException("Can't file resource stream "
67
				throw new FileNotFoundException("Can't file resource stream " + filename);
69
						+ filename);
70
			final String baseFile = getClass().getResource(filename).toString();
68
			final String baseFile = getClass().getResource(filename).toString();
71
			model = modelManager.getModelForEdit(baseFile, inStream, 
69
			model = modelManager.getModelForEdit(baseFile, inStream, new URIResolver() {
72
			new URIResolver() {
70
71
				String fBase = baseFile;
73
72
74
				String fBase = baseFile ;
75
				
76
				public String getFileBaseLocation() {
73
				public String getFileBaseLocation() {
77
					return fBase;
74
					return fBase;
78
				}
75
				}
Lines 88-99 Link Here
88
				public String getLocationByURI(String uri, String baseReference) {
85
				public String getLocationByURI(String uri, String baseReference) {
89
					int lastSlash = baseReference.lastIndexOf("/");
86
					int lastSlash = baseReference.lastIndexOf("/");
90
					if (lastSlash > 0)
87
					if (lastSlash > 0)
91
						return baseReference.substring(0, lastSlash+1) + uri;
88
						return baseReference.substring(0, lastSlash + 1) + uri;
92
					return baseReference;
89
					return baseReference;
93
				}
90
				}
94
91
95
				public String getLocationByURI(String uri, String baseReference, boolean resolveCrossProjectLinks) {
92
				public String getLocationByURI(String uri, String baseReference, boolean resolveCrossProjectLinks) {
96
					return getLocationByURI(uri, baseReference); 
93
					return getLocationByURI(uri, baseReference);
97
				}
94
				}
98
95
99
				public IProject getProject() {
96
				public IProject getProject() {
Lines 105-111 Link Here
105
				}
102
				}
106
103
107
				public InputStream getURIStream(String uri) {
104
				public InputStream getURIStream(String uri) {
108
					return  getClass().getResourceAsStream(getLocationByURI(uri));
105
					return getClass().getResourceAsStream(getLocationByURI(uri));
109
				}
106
				}
110
107
111
				public void setFileBaseLocation(String newLocation) {
108
				public void setFileBaseLocation(String newLocation) {
Lines 113-120 Link Here
113
				}
110
				}
114
111
115
				public void setProject(IProject newProject) {
112
				public void setProject(IProject newProject) {
116
				}});
113
				}
117
		} catch (IOException ex) {
114
			});
115
		}
116
		catch (IOException ex) {
118
			ex.printStackTrace();
117
			ex.printStackTrace();
119
		}
118
		}
120
		return model;
119
		return model;
Lines 129-172 Link Here
129
		return true;
128
		return true;
130
	}
129
	}
131
130
132
	protected void formatAndAssertEquals(String beforePath, String afterPath)
131
	protected void formatAndAssertEquals(String beforePath, String afterPath) throws UnsupportedEncodingException, IOException, CoreException {
133
			throws UnsupportedEncodingException, IOException, CoreException {
134
		IStructuredModel beforeModel = null, afterModel = null;
132
		IStructuredModel beforeModel = null, afterModel = null;
135
		try {
133
		try {
136
			beforeModel = getModelForEdit(beforePath);
134
			beforeModel = getModelForEdit(beforePath);
137
			assertNotNull("could not retrieve structured model for : "
135
			assertNotNull("could not retrieve structured model for : " + beforePath, beforeModel);
138
					+ beforePath, beforeModel);
139
136
140
			afterModel = getModelForEdit(afterPath);
137
			afterModel = getModelForEdit(afterPath);
141
			assertNotNull("could not retrieve structured model for : "
138
			assertNotNull("could not retrieve structured model for : " + afterPath, afterModel);
142
					+ afterPath, afterModel);
143
139
144
			IStructuredFormatPreferences formatPreferences = formatProcessor
140
			IStructuredFormatPreferences formatPreferences = formatProcessor.getFormatPreferences();
145
					.getFormatPreferences();
146
			formatPreferences.setLineWidth(MAX_LINE_WIDTH);
141
			formatPreferences.setLineWidth(MAX_LINE_WIDTH);
147
			formatPreferences.setClearAllBlankLines(CLEAR_ALL_BLANK_LINES);
142
			formatPreferences.setClearAllBlankLines(CLEAR_ALL_BLANK_LINES);
148
			formatPreferences.setIndent(INDENT);
143
			formatPreferences.setIndent(INDENT);
149
			((IStructuredFormatPreferencesXML) formatPreferences)
144
			((IStructuredFormatPreferencesXML) formatPreferences).setSplitMultiAttrs(SPLIT_MULTI_ATTRS);
150
					.setSplitMultiAttrs(SPLIT_MULTI_ATTRS);
151
145
152
			formatProcessor.formatModel(beforeModel);
146
			formatProcessor.formatModel(beforeModel);
153
147
154
			ByteArrayOutputStream formattedBytes = new ByteArrayOutputStream();
148
			ByteArrayOutputStream formattedBytes = new ByteArrayOutputStream();
155
			beforeModel.save(formattedBytes); // "beforeModel" should now be
149
			beforeModel.save(formattedBytes); // "beforeModel" should now be
156
												// after the formatter
150
			// after the formatter
157
151
158
			ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
152
			ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
159
			afterModel.save(afterBytes);
153
			afterModel.save(afterBytes);
160
154
161
			assertEquals("Formatted document differs from the expected",
155
			assertEquals("Formatted document differs from the expected", new String(afterBytes.toByteArray(), UTF_8), new String(formattedBytes.toByteArray(), UTF_8));
162
					new String(afterBytes.toByteArray(), UTF_8), new String(
163
							formattedBytes.toByteArray(), UTF_8));
164
156
165
			// Do the same check in binary for kicks
157
			// Do the same check in binary for kicks
166
			assertTrue("Formatted document differs fromto the expected",
158
			assertTrue("Formatted document differs fromto the expected", isByteArrayIdentical(formattedBytes.toByteArray(), afterBytes.toByteArray()));
167
					isByteArrayIdentical(formattedBytes.toByteArray(),
159
		}
168
							afterBytes.toByteArray()));
160
		finally {
169
		} finally {
170
			if (beforeModel != null)
161
			if (beforeModel != null)
171
				beforeModel.releaseFromEdit();
162
				beforeModel.releaseFromEdit();
172
			if (afterModel != null)
163
			if (afterModel != null)
Lines 174-195 Link Here
174
		}
165
		}
175
	}
166
	}
176
167
177
	public void testSimpleXml() throws UnsupportedEncodingException,
168
	public void testSimpleXml() throws UnsupportedEncodingException, IOException, CoreException {
178
			IOException, CoreException {
169
		formatAndAssertEquals("testfiles/xml/simple-standalone.xml", "testfiles/xml/simple-standalone-fmt.xml");
179
		formatAndAssertEquals("testfiles/xml/simple-standalone.xml",
170
	}
180
				"testfiles/xml/simple-standalone-fmt.xml");
171
181
	}
172
	public void testPreserveFormat() throws UnsupportedEncodingException, IOException, CoreException {
182
173
		formatAndAssertEquals("testfiles/xml/xml-space-preserve-standalone.xml", "testfiles/xml/xml-space-preserve-standalone-fmt.xml");
183
	public void testPreserveFormat() throws UnsupportedEncodingException,
174
	}
184
		IOException, CoreException {
175
185
		formatAndAssertEquals("testfiles/xml/xml-space-preserve-standalone.xml",
176
	public void testPreserveFormatDTD() throws UnsupportedEncodingException, IOException, CoreException {
186
		"testfiles/xml/xml-space-preserve-standalone-fmt.xml");
177
		formatAndAssertEquals("testfiles/xml/xml-space-preserve-dtd.xml", "testfiles/xml/xml-space-preserve-dtd-fmt.xml");
187
	}
178
	}
188
179
189
	public void testPreserveFormatDTD() throws UnsupportedEncodingException,
180
	public void testOneLineFormat() throws UnsupportedEncodingException, IOException, CoreException {
190
		IOException, CoreException {
181
		// BUG115716
191
		formatAndAssertEquals("testfiles/xml/xml-space-preserve-dtd.xml",
182
		formatAndAssertEquals("testfiles/xml/oneline.xml", "testfiles/xml/oneline-fmt.xml");
192
		"testfiles/xml/xml-space-preserve-dtd-fmt.xml");
193
	}
183
	}
194
184
195
}
185
}
(-)src/org/eclipse/wst/xml/core/tests/format/testfiles/xml/oneline.xml (+1 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?><one><two></two><three><four></four></three></one>
(-)src/org/eclipse/wst/xml/core/tests/format/testfiles/xml/oneline-fmt.xml (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<one>
3
	<two></two>
4
	<three>
5
		<four></four>
6
	</three>
7
</one>

Return to bug 115716