|
1 | 1 | package tests.wurstscript.tests; |
2 | 2 |
|
3 | 3 | import org.wurstscript.projectconfig.WurstProjectConfigData; |
| 4 | +import org.wurstscript.projectconfig.WurstProjectBuildMapData; |
4 | 5 | import de.peeeq.wurstio.languageserver.WFile; |
5 | 6 | import de.peeeq.wurstio.languageserver.ProjectConfigBuilder; |
6 | 7 | import de.peeeq.wurstio.languageserver.WurstBuildConfig; |
7 | 8 | import de.peeeq.wurstio.languageserver.WurstCommands; |
8 | 9 | import de.peeeq.wurstio.utils.W3InstallationData; |
| 10 | +import net.moonlightflower.wc3libs.bin.app.MapHeader; |
9 | 11 | import net.moonlightflower.wc3libs.port.GameVersion; |
10 | 12 | import org.testng.annotations.Test; |
11 | 13 |
|
@@ -223,6 +225,57 @@ public void configInjectionPrefersPinnedPatchOverDetectedInstallVersion() throws |
223 | 225 | ); |
224 | 226 | } |
225 | 227 |
|
| 228 | + @Test |
| 229 | + public void mapHeaderConfigAcceptsAnArchiveWithoutAnHm3wPrefix() throws Exception { |
| 230 | + Path mapWithoutHeader = Files.createTempFile("wurst-map-without-header", ".w3x"); |
| 231 | + byte[] original = new byte[1024]; |
| 232 | + original[0] = 'M'; |
| 233 | + original[1] = 'P'; |
| 234 | + original[2] = 'Q'; |
| 235 | + original[3] = 0x1a; |
| 236 | + Files.write(mapWithoutHeader, original); |
| 237 | + |
| 238 | + Method applyMapHeader = ProjectConfigBuilder.class.getDeclaredMethod( |
| 239 | + "applyMapHeader", WurstProjectConfigData.class, File.class |
| 240 | + ); |
| 241 | + applyMapHeader.setAccessible(true); |
| 242 | + |
| 243 | + applyMapHeader.invoke( |
| 244 | + null, |
| 245 | + new WurstProjectConfigData( |
| 246 | + "Test", |
| 247 | + List.of(), |
| 248 | + new WurstProjectBuildMapData("Configured map", null, null, null, null, List.of(), List.of()), |
| 249 | + null, |
| 250 | + null |
| 251 | + ), |
| 252 | + mapWithoutHeader.toFile() |
| 253 | + ); |
| 254 | + |
| 255 | + assertEquals(Files.readAllBytes(mapWithoutHeader)[0], (byte) 'H'); |
| 256 | + assertEquals(MapHeader.ofFile(mapWithoutHeader.toFile()).getMaxPlayersCount(), 0); |
| 257 | + assertEquals(Files.size(mapWithoutHeader), original.length + 512); |
| 258 | + } |
| 259 | + |
| 260 | + @Test |
| 261 | + public void mapHeaderConfigDoesNotReadAnArchiveWhenNothingNeedsChanging() throws Exception { |
| 262 | + Path mapWithoutHeader = Files.createTempFile("wurst-map-without-header-noop", ".w3x"); |
| 263 | + byte[] original = new byte[1024]; |
| 264 | + original[0] = 'M'; |
| 265 | + original[1] = 'P'; |
| 266 | + original[2] = 'Q'; |
| 267 | + original[3] = 0x1a; |
| 268 | + Files.write(mapWithoutHeader, original); |
| 269 | + |
| 270 | + Method applyMapHeader = ProjectConfigBuilder.class.getDeclaredMethod( |
| 271 | + "applyMapHeader", WurstProjectConfigData.class, File.class |
| 272 | + ); |
| 273 | + applyMapHeader.setAccessible(true); |
| 274 | + applyMapHeader.invoke(null, WurstProjectConfigData.empty(), mapWithoutHeader.toFile()); |
| 275 | + |
| 276 | + assertEquals(Files.readAllBytes(mapWithoutHeader), original); |
| 277 | + } |
| 278 | + |
226 | 279 | private static String calculateProjectConfigHash(File buildDir) throws Exception { |
227 | 280 | Method method = ProjectConfigBuilder.class.getDeclaredMethod( |
228 | 281 | "calculateProjectConfigHash", |
|
0 commit comments