diff --git a/app/src/main/java/com/httrack/android/OptionsMapper.java b/app/src/main/java/com/httrack/android/OptionsMapper.java index 8abc1392..ceb67d03 100755 --- a/app/src/main/java/com/httrack/android/OptionsMapper.java +++ b/app/src/main/java/com/httrack/android/OptionsMapper.java @@ -88,7 +88,7 @@ public class OptionsMapper { new Pair(R.id.editRetries, "Retry"), new Pair(R.id.editMinTransferRate, "RateOut"), new Pair(R.id.checkRemoveHostIfSlow, "RemoveRateout"), - new Pair(R.id.editPause, "Pause"), + new Pair(R.id.editPause, "PauseFiles"), /* Links */ new Pair(R.id.checkDetectAllLinks, "ParseAll"), @@ -348,7 +348,7 @@ public class OptionsMapper { new Pair("Proxy", proxyHandler.getAddressMapper()), new Pair("Port", proxyHandler.getPortMapper()), new Pair("CookiesFile", new ArgumentOption("-%K")), - new Pair("Pause", new ArgumentOption("-%G")), + new Pair("PauseFiles", new ArgumentOption("-%G")), new Pair("StripQuery", new ArgumentOption("-%g")), new Pair("HostAlias", new RuleListOption( "--host-alias")), @@ -420,7 +420,7 @@ public static class ProfileFormat { // Spellings earlier builds wrote; accepted on read, never written back. private static final String LEGACY_NAMES[][] = { { "ProxyProtocol", "ProxyType" }, { "KeepWwwPrefix", "KeepWww" }, - { "KeepDoubleSlashes", "KeepSlashes" } }; + { "KeepDoubleSlashes", "KeepSlashes" }, { "Pause", "PauseFiles" } }; // WinHTTrack packs both name-mangling boxes in Dos; Iso9660 is ours alone. static final String DOS_KEY = "Dos"; diff --git a/app/src/test/java/com/httrack/android/WinProfileParityTest.java b/app/src/test/java/com/httrack/android/WinProfileParityTest.java index fc2ddd3b..1de53b4d 100644 --- a/app/src/test/java/com/httrack/android/WinProfileParityTest.java +++ b/app/src/test/java/com/httrack/android/WinProfileParityTest.java @@ -16,6 +16,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.Test; @@ -89,11 +90,12 @@ public void winHttrackProfileOpensWithBothBoxes() { public void olderProfileKeepsEveryRenamedSetting() { final Map values = ProfileFormat.resolve(file("Dos", "1", "Iso9660", "1", "ProxyProtocol", "1", "KeepWwwPrefix", "1", - "KeepDoubleSlashes", "1")); + "KeepDoubleSlashes", "1", "Pause", "2:5")); assertArrayEquals(new String[] { "1", "1" }, boxes(values)); assertEquals("1", values.get("ProxyType")); assertEquals("1", values.get("KeepWww")); assertEquals("1", values.get("KeepSlashes")); + assertEquals("2:5", values.get("PauseFiles")); assertFalse(values.containsKey("ProxyProtocol")); } @@ -159,6 +161,8 @@ public void renamedKeysMapBothWays() { assertEquals("KeepWww", ProfileFormat.canonicalName("KeepWwwPrefix")); assertEquals("KeepSlashes", ProfileFormat.canonicalName("KeepDoubleSlashes")); + assertEquals("PauseFiles", ProfileFormat.canonicalName("Pause")); + assertEquals("Pause", ProfileFormat.legacyName("PauseFiles")); assertEquals("Near", ProfileFormat.canonicalName("Near")); assertNull(ProfileFormat.legacyName("Near")); } @@ -168,25 +172,55 @@ private static String mapperTable() throws IOException { return TestSources.javaSource("OptionsMapper"); } - private static List serializerKeys() throws IOException { - final Matcher m = Pattern.compile( - "new Pair\\(R\\.id\\.\\w+,\\s*\"([^\"]+)\"\\)") - .matcher(mapperTable()); + private static int occurrences(final String source, final String text) { + int count = 0; + for (int at = source.indexOf(text); at != -1; at = source.indexOf(text, + at + 1)) { + count++; + } + return count; + } + + /* Counting the declarations separately keeps a regex that quietly stops + matching from passing every key test on a short list. */ + private static List keysOf(final String declaration, + final String pattern) throws IOException { + final String source = mapperTable(); + final Matcher m = Pattern.compile(pattern).matcher(source); final List keys = new ArrayList(); while (m.find()) { keys.add(m.group(1)); } - assertEquals("serializer keys parsed", 94, keys.size()); + assertEquals(declaration + " entries parsed", + occurrences(source, declaration), keys.size()); return keys; } + private static List serializerKeys() throws IOException { + return keysOf("new Pair(R.id.", + "new Pair\\(R\\.id\\.\\w+,\\s*\"([^\"]+)\"\\)"); + } + + private static List mapperKeys() throws IOException { + return keysOf("new Pair(", + "new Pair\\(\"([^\"]+)\""); + } + + /* The two tables are halves of one wiring: a key stored with no mapper never + reaches the engine, and a mapper under no stored key never runs. */ + @Test + public void everyStoredKeyHasAMapper() throws IOException { + assertEquals(new TreeSet(serializerKeys()), + new TreeSet(mapperKeys())); + } + @Test public void keysUseTheWinHttrackSpelling() throws IOException { final List keys = serializerKeys(); assertTrue(keys.containsAll(Arrays.asList("ProxyType", "KeepWww", - "KeepSlashes"))); + "KeepSlashes", "PauseFiles"))); for (final String legacy : new String[] { "ProxyProtocol", - "KeepWwwPrefix", "KeepDoubleSlashes" }) { + "KeepWwwPrefix", "KeepDoubleSlashes", "Pause" }) { assertFalse(legacy + " still written", keys.contains(legacy)); } } @@ -203,7 +237,7 @@ public void everyRenameTargetIsAStoredKey() throws IOException { } } for (final String legacy : new String[] { "ProxyProtocol", - "KeepWwwPrefix", "KeepDoubleSlashes" }) { + "KeepWwwPrefix", "KeepDoubleSlashes", "Pause" }) { assertTrue(legacy + " resolves to no stored key", keys.contains(ProfileFormat.canonicalName(legacy))); }