mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-04 23:38:28 +07:00
Parameterized RiiabloTest dirs
Added D2_TEST environment variable and getTestDirs for InstallationFinder d2 home and d2 test home set by InstallationFinder for RiiabloTest
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.riiablo.util;
|
||||
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
@ -27,6 +28,12 @@ public abstract class InstallationFinder {
|
||||
return handle.child("d2data.mpq").exists();
|
||||
}
|
||||
|
||||
public static boolean isD2TestHome(FileHandle handle) {
|
||||
if (handle == null) return false;
|
||||
if (!handle.isDirectory()) return false;
|
||||
return handle.child("data").exists();
|
||||
}
|
||||
|
||||
public static boolean containsSaves(FileHandle handle) {
|
||||
if (handle == null) return false;
|
||||
final FileHandle[] children = handle.list();
|
||||
@ -59,6 +66,10 @@ public abstract class InstallationFinder {
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public Array<FileHandle> getTestDirs() {
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public static final class StubbedInstallationFinder extends InstallationFinder {
|
||||
}
|
||||
|
||||
@ -91,7 +102,7 @@ public abstract class InstallationFinder {
|
||||
homeDirs.add(ProgramFiles);
|
||||
homeDirs.add(ProgramFiles86);
|
||||
|
||||
log.traceEntry("resolve() paths: {}", homeDirs);
|
||||
log.trace("resolve() paths: {}", homeDirs);
|
||||
Array<FileHandle> result = null;
|
||||
for (String path : homeDirs) {
|
||||
FileHandle handle = new FileHandle(path);
|
||||
@ -113,6 +124,29 @@ public abstract class InstallationFinder {
|
||||
return result == null ? super.getHomeDirs() : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<FileHandle> getTestDirs() {
|
||||
final String d2test = SystemPropertyUtil.get("d2test", null);
|
||||
final String D2_TEST = SystemUtils.getEnvironmentVariable("D2_TEST", null);
|
||||
|
||||
final Array<String> testDirs = new Array<>();
|
||||
if (d2test != null) testDirs.add(d2test);
|
||||
if (D2_TEST != null) testDirs.add(D2_TEST);
|
||||
|
||||
log.trace("resolve() paths: {}", testDirs);
|
||||
Array<FileHandle> result = null;
|
||||
for (String path : testDirs) {
|
||||
FileHandle handle = new FileHandle(path);
|
||||
log.trace("Trying {}", handle);
|
||||
if (isD2TestHome(handle)) {
|
||||
if (result == null) result = new Array<>();
|
||||
result.add(handle);
|
||||
}
|
||||
}
|
||||
|
||||
return result == null ? super.getTestDirs() : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<FileHandle> getSaveDirs(FileHandle home) {
|
||||
final Array<FileHandle> saveDirs = new Array<>();
|
||||
@ -145,7 +179,7 @@ public abstract class InstallationFinder {
|
||||
homeDirs.add(SystemUtils.USER_HOME);
|
||||
homeDirs.add(SystemUtils.USER_DIR);
|
||||
|
||||
log.traceEntry("resolve() paths: {}", homeDirs);
|
||||
log.trace("resolve() paths: {}", homeDirs);
|
||||
Array<FileHandle> result = null;
|
||||
for (String path : homeDirs) {
|
||||
FileHandle handle = new FileHandle(path);
|
||||
@ -167,6 +201,29 @@ public abstract class InstallationFinder {
|
||||
return result == null ? super.getHomeDirs() : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<FileHandle> getTestDirs() {
|
||||
final String d2test = SystemPropertyUtil.get("d2test", null);
|
||||
final String D2_TEST = SystemUtils.getEnvironmentVariable("D2_TEST", null);
|
||||
|
||||
final Array<String> testDirs = new Array<>();
|
||||
if (d2test != null) testDirs.add(d2test);
|
||||
if (D2_TEST != null) testDirs.add(D2_TEST);
|
||||
|
||||
log.trace("resolve() paths: {}", testDirs);
|
||||
Array<FileHandle> result = null;
|
||||
for (String path : testDirs) {
|
||||
FileHandle handle = new FileHandle(path);
|
||||
log.trace("Trying {}", handle);
|
||||
if (isD2TestHome(handle)) {
|
||||
if (result == null) result = new Array<>();
|
||||
result.add(handle);
|
||||
}
|
||||
}
|
||||
|
||||
return result == null ? super.getTestDirs() : result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<FileHandle> getSaveDirs(FileHandle home) {
|
||||
final Array<FileHandle> saveDirs = new Array<>();
|
||||
|
@ -1,16 +1,19 @@
|
||||
package com.riiablo;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.headless.HeadlessApplication;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import com.riiablo.codec.StringTBLs;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.OutputStreamAppender;
|
||||
import com.riiablo.mpq.MPQFileHandleResolver;
|
||||
import com.riiablo.util.InstallationFinder;
|
||||
|
||||
public class RiiabloTest {
|
||||
protected static FileHandle testHome;
|
||||
@ -22,13 +25,32 @@ public class RiiabloTest {
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
Gdx.app = new HeadlessApplication(new ApplicationAdapter() {});
|
||||
Riiablo.home = Gdx.files.absolute("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Diablo II");
|
||||
final InstallationFinder finder = InstallationFinder.getInstance();
|
||||
Riiablo.home = getHomeDir(finder);
|
||||
Riiablo.mpqs = new MPQFileHandleResolver();
|
||||
Riiablo.string = new StringTBLs(Riiablo.mpqs);
|
||||
Riiablo.files = new Files();
|
||||
Riiablo.logs = new GdxLoggerManager(LogManager.getRegistry());
|
||||
Riiablo.logs.getRootLogger().addAppender(new OutputStreamAppender(System.out));
|
||||
testHome = Gdx.files.absolute("D:\\mpq");
|
||||
testHome = getTestDir(finder);
|
||||
}
|
||||
|
||||
static FileHandle getHomeDir(InstallationFinder finder) {
|
||||
Array<FileHandle> homeDirs = finder.getHomeDirs();
|
||||
if (homeDirs.size > 0) {
|
||||
return homeDirs.first();
|
||||
} else {
|
||||
return fail("Unable to locate D2 installation!");
|
||||
}
|
||||
}
|
||||
|
||||
static FileHandle getTestDir(InstallationFinder finder) {
|
||||
Array<FileHandle> testDirs = finder.getTestDirs();
|
||||
if (testDirs.size > 0) {
|
||||
return testDirs.first();
|
||||
} else {
|
||||
return fail("Unable to locate D2 test files!");
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
@ -46,6 +46,30 @@ public class InstallationFinderTest extends RiiabloTest {
|
||||
private void test_getHomeDirs_mac() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getTestDirs() {
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
test_getHomeDirs_windows();
|
||||
} else if (SystemUtils.IS_OS_LINUX) {
|
||||
test_getHomeDirs_linux();
|
||||
} else if (SystemUtils.IS_OS_MAC) {
|
||||
test_getHomeDirs_mac();
|
||||
}
|
||||
}
|
||||
|
||||
private void test_getTestDirs_windows() {
|
||||
final InstallationFinder instance = getInstance();
|
||||
final Array<FileHandle> handles = instance.getTestDirs();
|
||||
assertNotNull(handles);
|
||||
System.out.println("found: " + handles);
|
||||
}
|
||||
|
||||
private void test_getTestDirs_linux() {
|
||||
}
|
||||
|
||||
private void test_getTestDirs_mac() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getSaves() {
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
|
Reference in New Issue
Block a user