Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestDirstate.java @ 296:02f2963c70fa
Issue 13: Tests for mixed-cased filenames in case-insensitive FS
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 16 Sep 2011 21:00:29 +0200 |
parents | 9774f47d904d |
children | df5009d67be2 |
comparison
equal
deleted
inserted
replaced
295:981f9f50bb6c | 296:02f2963c70fa |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.test; | 17 package org.tmatesoft.hg.test; |
18 | 18 |
19 import static java.lang.Character.*; | |
20 import static org.junit.Assert.assertTrue; | |
21 import static org.junit.Assert.fail; | |
22 | |
23 import java.util.TreeSet; | |
24 | |
19 import org.junit.Assert; | 25 import org.junit.Assert; |
20 import org.junit.Test; | 26 import org.junit.Test; |
21 import org.tmatesoft.hg.core.Nodeid; | 27 import org.tmatesoft.hg.core.Nodeid; |
28 import org.tmatesoft.hg.repo.HgDirstate; | |
29 import org.tmatesoft.hg.repo.HgDirstate.EntryKind; | |
30 import org.tmatesoft.hg.repo.HgDirstate.Record; | |
31 import org.tmatesoft.hg.repo.HgInternals; | |
22 import org.tmatesoft.hg.repo.HgLookup; | 32 import org.tmatesoft.hg.repo.HgLookup; |
23 import org.tmatesoft.hg.repo.HgRepository; | 33 import org.tmatesoft.hg.repo.HgRepository; |
24 import org.tmatesoft.hg.util.Pair; | 34 import org.tmatesoft.hg.util.Pair; |
35 import org.tmatesoft.hg.util.Path; | |
25 | 36 |
26 /** | 37 /** |
27 * | 38 * |
28 * @author Artem Tikhomirov | 39 * @author Artem Tikhomirov |
29 * @author TMate Software Ltd. | 40 * @author TMate Software Ltd. |
56 Assert.assertEquals("test", repo.getWorkingCopyBranchName()); | 67 Assert.assertEquals("test", repo.getWorkingCopyBranchName()); |
57 repo = Configuration.get().own(); | 68 repo = Configuration.get().own(); |
58 Assert.assertEquals("default", repo.getWorkingCopyBranchName()); | 69 Assert.assertEquals("default", repo.getWorkingCopyBranchName()); |
59 } | 70 } |
60 | 71 |
61 public void testMixedNameCaseHandling() { | 72 @Test |
73 public void testMixedNameCaseHandling() throws Exception { | |
74 // General idea: to check cases like | |
62 // 1. dirstate: /a/b/c, FileIterator: /a/B/C | 75 // 1. dirstate: /a/b/c, FileIterator: /a/B/C |
63 // 2. dirstate: /a/B/C, FileIterator: /a/b/c | 76 // 2. dirstate: /a/B/C, FileIterator: /a/b/c |
64 // 2. dirstate: /a/B/C, FileIterator: /A/b/C | 77 // 2. dirstate: /a/B/C, FileIterator: /A/b/C |
78 repo = Configuration.get().find("mixed-case"); | |
79 // Windows, case-insensitive file system | |
80 final HgInternals testAccess = new HgInternals(repo); | |
81 HgDirstate dirstate = testAccess.createDirstate(false); | |
82 final TreeSet<Path> entries = new TreeSet<Path>(); | |
83 dirstate.walk(new HgDirstate.Inspector() { | |
84 | |
85 public boolean next(EntryKind kind, Record entry) { | |
86 entries.add(entry.name()); | |
87 return true; | |
88 } | |
89 }); | |
90 Path[] expected = new Path[] { | |
91 Path.create("a/low/low"), | |
92 Path.create("a/low/UP"), | |
93 Path.create("a/UP/low"), | |
94 Path.create("a/UP/UP"), | |
95 }; | |
96 Path[] allLower = new Path[expected.length]; | |
97 Path[] allUpper = new Path[expected.length]; | |
98 Path[] mixedNonMatching = new Path[expected.length]; | |
99 for (int i = 0; i < expected.length; i++) { | |
100 assertTrue("prereq", entries.contains(expected[i])); | |
101 final String s = expected[i].toString(); | |
102 allLower[i] = Path.create(s.toLowerCase()); | |
103 allUpper[i] = Path.create(s.toUpperCase()); | |
104 char[] ss = s.toCharArray(); | |
105 for (int j = 0; j < ss.length; j++) { | |
106 if (isLetter(ss[j])) { | |
107 ss[j] = isLowerCase(ss[j]) ? toUpperCase(ss[j]) : toLowerCase(ss[j]); | |
108 } | |
109 } | |
110 Path mixed = Path.create(new String(ss)); | |
111 mixedNonMatching[i] = mixed; | |
112 } | |
113 // prereq | |
114 checkKnownInDirstate(testAccess, dirstate, expected, expected); | |
115 // all upper | |
116 checkKnownInDirstate(testAccess, dirstate, allUpper, expected); | |
117 // all lower | |
118 checkKnownInDirstate(testAccess, dirstate, allLower, expected); | |
119 // mixed | |
120 checkKnownInDirstate(testAccess, dirstate, mixedNonMatching, expected); | |
121 // | |
122 // check that in case-sensitive file system mangled names do not match | |
123 dirstate = testAccess.createDirstate(true); | |
124 // ensure read | |
125 dirstate.walk(new HgDirstate.Inspector() { | |
126 public boolean next(EntryKind kind, Record entry) { | |
127 return false; | |
128 } | |
129 }); | |
130 Path[] known = testAccess.checkKnown(dirstate, mixedNonMatching); | |
131 for (int i = 0; i < known.length; i++) { | |
132 if (known[i] != null) { | |
133 fail(expected[i] + " in case-sensitive dirstate matched " + known[i]); | |
134 } | |
135 } | |
136 | |
137 } | |
138 | |
139 private static void checkKnownInDirstate(HgInternals testAccess, HgDirstate dirstate, Path[] toCheck, Path[] expected) { | |
140 Path[] known = testAccess.checkKnown(dirstate, toCheck); | |
141 for (int i = 0; i < expected.length; i++) { | |
142 assertTrue(expected[i].equals(known[i])); | |
143 } | |
65 } | 144 } |
66 } | 145 } |