Add linux compatibility & Finalize Config Loader

This commit is contained in:
2023-02-19 15:51:50 +01:00
parent f69fbedee0
commit ce9a2fc805
29 changed files with 212 additions and 71 deletions

View File

@@ -0,0 +1,30 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.nio.file.Path;
class ConfigTest {
private static final File TEST_MKVTOOLNIX_DIR = Path.of("src/test/resources/mkvtoolnix").toFile();
private static final File TEST_MKVTOOLNIX_EXE_DIR = Path.of("src/test/resources/mkvtoolnix_exe").toFile();
@Test
void getPathForWindows() {
Config.getInstance().setWindows(true);
Config.getInstance().setMkvToolNix(TEST_MKVTOOLNIX_EXE_DIR);
assert Config.getInstance().getPathFor(MkvToolNix.MKV_MERGER).endsWith(MkvToolNix.MKV_MERGER + ".exe");
assert Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT).endsWith(MkvToolNix.MKV_PROP_EDIT + ".exe");
}
@Test
void getPathForUnix() {
Config.getInstance().setWindows(false);
Config.getInstance().setMkvToolNix(TEST_MKVTOOLNIX_DIR);
assert Config.getInstance().getPathFor(MkvToolNix.MKV_MERGER).endsWith(MkvToolNix.MKV_MERGER.toString());
assert Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT).endsWith(MkvToolNix.MKV_PROP_EDIT.toString());
}
}

View File

@@ -32,7 +32,7 @@ class AttributeConfigValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(ATTRIBUTE_CONFIG, ATTRIBUTE_CONFIG.abrv(), true));
options.addOption(optionOf(ATTRIBUTE_CONFIG, ATTRIBUTE_CONFIG.abrv(), ATTRIBUTE_CONFIG.args()));
}
@BeforeEach

View File

@@ -29,7 +29,7 @@ class BooleanValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(SAFE_MODE, SAFE_MODE.abrv(), false));
options.addOption(optionOf(SAFE_MODE, SAFE_MODE.abrv(), SAFE_MODE.args()));
}
private static Stream<Arguments> provideTestCases() {

View File

@@ -35,7 +35,7 @@ class ConfigPathValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(CONFIG_PATH, CONFIG_PATH.abrv(), true));
options.addOption(optionOf(CONFIG_PATH, CONFIG_PATH.abrv(), CONFIG_PATH.args()));
}
private static Stream<Arguments> provideTestCases() {

View File

@@ -24,6 +24,10 @@ import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsU
import static org.junit.jupiter.api.Assertions.*;
class MkvToolNixPathValidatorTest {
private static final String TEST_INVALID_DIR = "src/test/resources/test-dir";
private static final String TEST_MKVTOOLNIX_DIR = "src/test/resources/mkvtoolnix";
private static final String TEST_MKVTOOLNIX_EXE_DIR = "src/test/resources/mkvtoolnix_exe";
private static CommandLineParser parser;
private static Options options;
@@ -31,19 +35,19 @@ class MkvToolNixPathValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(MKV_TOOL_NIX, MKV_TOOL_NIX.abrv(), true));
options.addOption(optionOf(MKV_TOOL_NIX, MKV_TOOL_NIX.abrv(), MKV_TOOL_NIX.args()));
}
private static Stream<Arguments> provideTestCases() {
return Stream.of(
Arguments.of(MKV_TOOL_NIX, false, null, "", new String[]{"-m", "\"C:\\Program Files\\MKVToolNix\""}, VALID),
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", "\"C:\\Program Files\\MKVToolNix\""}, VALID),
Arguments.of(MKV_TOOL_NIX, false, null, "mkvtoolnix: C:\\Program Files\\MKVToolNix", new String[]{}, VALID),
Arguments.of(MKV_TOOL_NIX, true, null, "mkvtoolnix: C:\\Program Files\\MKVToolNix", new String[]{}, VALID),
Arguments.of(MKV_TOOL_NIX, false, Path.of("C:\\Program Files\\MKVToolNix").toFile(), "", new String[]{}, DEFAULT),
Arguments.of(MKV_TOOL_NIX, false, null, "", new String[]{"-m", TEST_MKVTOOLNIX_DIR}, VALID),
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", TEST_MKVTOOLNIX_EXE_DIR}, VALID),
Arguments.of(MKV_TOOL_NIX, false, null, "mkvtoolnix: " + TEST_MKVTOOLNIX_EXE_DIR, new String[]{}, VALID),
Arguments.of(MKV_TOOL_NIX, true, null, "mkvtoolnix: " + TEST_MKVTOOLNIX_DIR, new String[]{}, VALID),
Arguments.of(MKV_TOOL_NIX, false, Path.of(TEST_MKVTOOLNIX_EXE_DIR).toFile(), "", new String[]{}, DEFAULT),
Arguments.of(MKV_TOOL_NIX, false, null, "", new String[]{}, NOT_PRESENT),
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{}, MISSING),
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", "\"C:\\Program Files\\MKVTool\""}, INVALID)
Arguments.of(MKV_TOOL_NIX, true, null, "", new String[]{"-m", TEST_INVALID_DIR}, INVALID)
);
}

View File

@@ -34,7 +34,7 @@ class PathValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(LIBRARY, LIBRARY.abrv(), true));
options.addOption(optionOf(LIBRARY, LIBRARY.abrv(), LIBRARY.args()));
}
private static Stream<Arguments> provideTestCases() {

View File

@@ -31,7 +31,7 @@ class PatternValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(INCLUDE_PATTERN, INCLUDE_PATTERN.abrv(), true));
options.addOption(optionOf(INCLUDE_PATTERN, INCLUDE_PATTERN.abrv(), INCLUDE_PATTERN.args()));
}
private static Stream<Arguments> provideTestCases() {

View File

@@ -32,7 +32,7 @@ class SetValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(COMMENTARY_KEYWORDS, COMMENTARY_KEYWORDS.abrv(), true));
options.addOption(optionOf(COMMENTARY_KEYWORDS, COMMENTARY_KEYWORDS.abrv(), COMMENTARY_KEYWORDS.args()));
}
@BeforeEach
@@ -46,7 +46,6 @@ class SetValidatorTest {
argumentsOf(COMMENTARY_KEYWORDS, true, false, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 1),
argumentsOf(COMMENTARY_KEYWORDS, false, true, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 3),
argumentsOf(COMMENTARY_KEYWORDS, false, false, "", new String[]{"-ck", "test"}, VALID, 1),
argumentsOf(COMMENTARY_KEYWORDS, true, true, COMMENTARY_KEYWORDS.prop() + ": [commentary]", new String[]{}, VALID, 2),
argumentsOf(COMMENTARY_KEYWORDS, true, true, "", new String[]{}, MISSING, 2),

View File

@@ -30,7 +30,7 @@ class ThreadValidatorTest {
static void before() {
parser = new DefaultParser();
options = new Options();
options.addOption(optionOf(THREADS, "t", true));
options.addOption(optionOf(THREADS, "t", THREADS.args()));
}
private static Stream<Arguments> provideTestCases() {