Skip to content
Merged
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
6 changes: 3 additions & 3 deletions app/src/main/java/com/httrack/android/OptionsMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class OptionsMapper {
new Pair<Integer, String>(R.id.editRetries, "Retry"),
new Pair<Integer, String>(R.id.editMinTransferRate, "RateOut"),
new Pair<Integer, String>(R.id.checkRemoveHostIfSlow, "RemoveRateout"),
new Pair<Integer, String>(R.id.editPause, "Pause"),
new Pair<Integer, String>(R.id.editPause, "PauseFiles"),

/* Links */
new Pair<Integer, String>(R.id.checkDetectAllLinks, "ParseAll"),
Expand Down Expand Up @@ -348,7 +348,7 @@ public class OptionsMapper {
new Pair<String, OptionMapper>("Proxy", proxyHandler.getAddressMapper()),
new Pair<String, OptionMapper>("Port", proxyHandler.getPortMapper()),
new Pair<String, OptionMapper>("CookiesFile", new ArgumentOption("-%K")),
new Pair<String, OptionMapper>("Pause", new ArgumentOption("-%G")),
new Pair<String, OptionMapper>("PauseFiles", new ArgumentOption("-%G")),
new Pair<String, OptionMapper>("StripQuery", new ArgumentOption("-%g")),
new Pair<String, OptionMapper>("HostAlias", new RuleListOption(
"--host-alias")),
Expand Down Expand Up @@ -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";
Expand Down
52 changes: 43 additions & 9 deletions app/src/test/java/com/httrack/android/WinProfileParityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,11 +90,12 @@ public void winHttrackProfileOpensWithBothBoxes() {
public void olderProfileKeepsEveryRenamedSetting() {
final Map<String, String> 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"));
}

Expand Down Expand Up @@ -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"));
}
Expand All @@ -168,25 +172,55 @@ private static String mapperTable() throws IOException {
return TestSources.javaSource("OptionsMapper");
}

private static List<String> serializerKeys() throws IOException {
final Matcher m = Pattern.compile(
"new Pair<Integer, String>\\(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<String> keysOf(final String declaration,
final String pattern) throws IOException {
final String source = mapperTable();
final Matcher m = Pattern.compile(pattern).matcher(source);
final List<String> keys = new ArrayList<String>();
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<String> serializerKeys() throws IOException {
return keysOf("new Pair<Integer, String>(R.id.",
"new Pair<Integer, String>\\(R\\.id\\.\\w+,\\s*\"([^\"]+)\"\\)");
}

private static List<String> mapperKeys() throws IOException {
return keysOf("new Pair<String, OptionMapper>(",
"new Pair<String, OptionMapper>\\(\"([^\"]+)\"");
}

/* 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<String>(serializerKeys()),
new TreeSet<String>(mapperKeys()));
}

@Test
public void keysUseTheWinHttrackSpelling() throws IOException {
final List<String> 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));
}
}
Expand All @@ -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)));
}
Expand Down
Loading