Skip to content

Commit

Permalink
Prepared fix for issue #1118.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Oct 24, 2024
1 parent 6702be0 commit 6936558
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
43 changes: 43 additions & 0 deletions src/org/nschmidt/ldparteditor/text/Win32LnkParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* MIT - License
Copyright (c) 2012 - this year, Nils Schmidt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
package org.nschmidt.ldparteditor.text;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.nschmidt.ldparteditor.logger.NLogger;

public enum Win32LnkParser {
INSTANCE;

/**
* Parses and resolves Windows *.lnk shortcut files
* @param lnkFile the shortcut file.
* @return the actual file.
*/
public static File resolveLnkShortcut(File lnkFile) {
try (DataInputStream is = new DataInputStream(new FileInputStream(lnkFile))) {
// FIXME Needs implementation!

} catch (IOException ex) {
NLogger.debug(Win32LnkParser.class, ex);
}

return lnkFile;
}
}
16 changes: 8 additions & 8 deletions test/org/nschmidt/ldparteditor/StlToDatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,42 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

@SuppressWarnings("java:S5960")
public class StlToDatTest {

@Test
public void testStlImportOfAsciiFile() {
UserSettingState userSettings = createTestUserSettings();
String resPath = resourcePath("stl2dat_ascii.stl"); //$NON-NLS-1$
String result = Stl2Dat.convertStlToDatFile(resPath, userSettings);
assertEquals(EXPECTED_ASCII.replace("\r", "").replace("\n", "\r\n"), result); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}

@Test
public void testStlImportOfBinaryFile() {
UserSettingState userSettings = createTestUserSettings();
String resPath = resourcePath("stl2dat_binary.stl"); //$NON-NLS-1$
String result = Stl2Dat.convertStlToDatFile(resPath, userSettings);
assertEquals(EXPECTED_BINARY.replace("\r", "").replace("\n", "\r\n"), result); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}

private UserSettingState createTestUserSettings() {
UserSettingState userSettings = new UserSettingState();
userSettings.setLdrawUserName("BlackBrick89"); //$NON-NLS-1$
userSettings.setRealUserName("Nils Schmidt"); //$NON-NLS-1$
return userSettings;
}
private String resourcePath(String fileName) {

public static String resourcePath(String fileName) {
URL stlToTest = Thread.currentThread().getContextClassLoader().getResource(fileName);
String resPath = "(none)"; //$NON-NLS-1$
try {
resPath = java.nio.file.Paths.get(stlToTest.toURI()).toString();
} catch (URISyntaxException e) {
fail("Resource " + fileName + " was not found."); //$NON-NLS-1$ //$NON-NLS-2$
}

return resPath;
}

private static final String EXPECTED_ASCII = """
0 STL-Import
0 Name: stl.dat
Expand Down Expand Up @@ -193,7 +193,7 @@ private String resourcePath(String fileName) {
3 16 -1000 0 0 0 -995 -105 0 -999 -52
3 16 -1000 0 0 0 -999 -52 0 -1000 0
"""; //$NON-NLS-1$

private static final String EXPECTED_BINARY = """
0 STL-Import
0 Name: stl.dat
Expand Down
32 changes: 32 additions & 0 deletions test/org/nschmidt/ldparteditor/Win32LnkParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.nschmidt.ldparteditor;

import static org.junit.Assert.assertTrue;
import static org.nschmidt.ldparteditor.StlToDatTest.resourcePath;

import java.io.File;

import org.junit.Test;
import org.nschmidt.ldparteditor.text.Win32LnkParser;

public class Win32LnkParserTest {

// FIXME Needs implementation!

@Test
public void testLinkToFileOnHarddisk() {
String resPath = resourcePath("3782.jpg-Shortcut.lnk"); //$NON-NLS-1$

File result = Win32LnkParser.resolveLnkShortcut(new File(resPath));

assertTrue(result.getName().contains("3782.jpg")); //$NON-NLS-1$
}

@Test
public void testLinkToFileOnNetwork() {
String resPath = resourcePath("3782.jpg-NetworkShortcut.lnk"); //$NON-NLS-1$

File result = Win32LnkParser.resolveLnkShortcut(new File(resPath));

assertTrue(result.getName().contains("3782.jpg")); //$NON-NLS-1$
}
}

0 comments on commit 6936558

Please # to comment.