Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Win32 API mapping for Shlwapi PathIsUNC #767

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Release 4.3.1 (Next release)
Features
--------
* [#757](https://github.com/java-native-access/jna/issues/757): Build android archive (AAR) - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#767](https://github.com/java-native-access/jna/pull/767): Add Win32 API mapping for Shlwapi PathIsUNC - [@ivanwick](https://github.com/ivanwick).

Bug Fixes
---------
Expand Down
11 changes: 11 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Shlwapi.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@ public interface Shlwapi extends StdCallLibrary {
*/

HRESULT StrRetToStr(PointerByReference pstr, Pointer pidl, PointerByReference ppszName);

/**
* Determines if a path string is a valid Universal Naming Convention (UNC) path, as opposed to
* a path based on a drive letter.
*
* @param path
* A string containing the path to validate.
*
* @return TRUE if the string is a valid UNC path; otherwise, FALSE.
*/
boolean PathIsUNC(String path);
}
24 changes: 24 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/ShlwapiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sun.jna.platform.win32;

import junit.framework.TestCase;

public class ShlwapiTest extends TestCase {

public static void main(String[] args) {
junit.textui.TestRunner.run(ShlwapiTest.class);
}

public void testPathIsUNC() {
assertEquals(true, Shlwapi.INSTANCE.PathIsUNC("\\\\path1\\path2"));
assertEquals(true, Shlwapi.INSTANCE.PathIsUNC("\\\\path1"));
assertEquals(false, Shlwapi.INSTANCE.PathIsUNC("acme\\\\path4\\\\path5"));
assertEquals(true, Shlwapi.INSTANCE.PathIsUNC("\\\\"));
assertEquals(true, Shlwapi.INSTANCE.PathIsUNC("\\\\?\\UNC\\path1\\path2"));
assertEquals(true, Shlwapi.INSTANCE.PathIsUNC("\\\\?\\UNC\\path1"));
assertEquals(true, Shlwapi.INSTANCE.PathIsUNC("\\\\?\\UNC\\"));
assertEquals(false, Shlwapi.INSTANCE.PathIsUNC("\\path1"));
assertEquals(false, Shlwapi.INSTANCE.PathIsUNC("path1"));
assertEquals(false, Shlwapi.INSTANCE.PathIsUNC("c:\\path1"));
assertEquals(false, Shlwapi.INSTANCE.PathIsUNC("\\\\?\\c:\\path1"));
}
}