Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestStorePath.java @ 411:464b4404e75d smartgit3
Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 20 Mar 2012 17:56:50 +0100 |
parents | 82bec80bb1a4 |
children | 63c5a9d7ca3f |
comparison
equal
deleted
inserted
replaced
410:df5009d67be2 | 411:464b4404e75d |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
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 java.util.HashMap; | |
20 import java.util.Map; | |
21 | |
19 import junit.framework.Assert; | 22 import junit.framework.Assert; |
20 | 23 |
21 import org.hamcrest.CoreMatchers; | 24 import org.hamcrest.CoreMatchers; |
25 import org.junit.Before; | |
22 import org.junit.Rule; | 26 import org.junit.Rule; |
23 import org.junit.Test; | 27 import org.junit.Test; |
24 import org.tmatesoft.hg.internal.BasicSessionContext; | 28 import org.tmatesoft.hg.internal.BasicSessionContext; |
25 import org.tmatesoft.hg.internal.Internals; | 29 import org.tmatesoft.hg.internal.Internals; |
26 import org.tmatesoft.hg.util.PathRewrite; | 30 import org.tmatesoft.hg.util.PathRewrite; |
34 | 38 |
35 @Rule | 39 @Rule |
36 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | 40 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); |
37 | 41 |
38 private PathRewrite storePathHelper; | 42 private PathRewrite storePathHelper; |
43 private final Map<String, Object> propertyOverrides = new HashMap<String, Object>(); | |
44 | |
45 private Internals internals; | |
39 | 46 |
40 public static void main(String[] args) throws Throwable { | 47 public static void main(String[] args) throws Throwable { |
41 final TestStorePath test = new TestStorePath(); | 48 final TestStorePath test = new TestStorePath(); |
42 test.testWindowsFilenames(); | 49 test.testWindowsFilenames(); |
43 test.testHashLongPath(); | 50 test.testHashLongPath(); |
51 test.testSuffixReplacement(); | |
44 test.errorCollector.verify(); | 52 test.errorCollector.verify(); |
45 } | 53 } |
46 | 54 |
47 public TestStorePath() { | 55 public TestStorePath() { |
48 final Internals i = new Internals(new BasicSessionContext(null, null)); | 56 propertyOverrides.put("hg.consolelog.debug", true); |
49 i.setStorageConfig(1, 0x7); | 57 internals = new Internals(new BasicSessionContext(propertyOverrides, null, null)); |
50 storePathHelper = i.buildDataFilesHelper(); | 58 internals.setStorageConfig(1, 0x7); |
59 storePathHelper = internals.buildDataFilesHelper(); | |
60 } | |
61 | |
62 @Before | |
63 public void setup() { | |
64 // just in case there are leftovers from #testNationalChars() and another test builds a helper | |
65 propertyOverrides.clear(); | |
66 propertyOverrides.put("hg.consolelog.debug", true); | |
51 } | 67 } |
52 | 68 |
53 @Test | 69 @Test |
54 public void testWindowsFilenames() { | 70 public void testWindowsFilenames() { |
55 // see http://mercurial.selenic.com/wiki/fncacheRepoFormat#Encoding_of_Windows_reserved_names | 71 // see http://mercurial.selenic.com/wiki/fncacheRepoFormat#Encoding_of_Windows_reserved_names |
86 String r3 = "store/data/src/jgit/main/org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/~2esettings/org.eclipse.core.resources.prefs.i"; | 102 String r3 = "store/data/src/jgit/main/org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/~2esettings/org.eclipse.core.resources.prefs.i"; |
87 errorCollector.checkThat(storePathHelper.rewrite(n1), CoreMatchers.<CharSequence>equalTo(r1)); | 103 errorCollector.checkThat(storePathHelper.rewrite(n1), CoreMatchers.<CharSequence>equalTo(r1)); |
88 errorCollector.checkThat(storePathHelper.rewrite(n2), CoreMatchers.<CharSequence>equalTo(r2)); | 104 errorCollector.checkThat(storePathHelper.rewrite(n2), CoreMatchers.<CharSequence>equalTo(r2)); |
89 errorCollector.checkThat(storePathHelper.rewrite(n3), CoreMatchers.<CharSequence>equalTo(r3)); | 105 errorCollector.checkThat(storePathHelper.rewrite(n3), CoreMatchers.<CharSequence>equalTo(r3)); |
90 } | 106 } |
107 | |
108 @Test | |
109 public void testSuffixReplacement() { | |
110 String s1 = "aaa/bbb.hg/ccc.i/ddd.hg/xx.i"; | |
111 String s2 = "bbb.d/aa.hg/bbb.hg/yy.d"; | |
112 String r1 = s1.replace(".hg/", ".hg.hg/").replace(".i/", ".i.hg/").replace(".d/", ".d.hg/"); | |
113 String r2 = s2.replace(".hg/", ".hg.hg/").replace(".i/", ".i.hg/").replace(".d/", ".d.hg/"); | |
114 errorCollector.checkThat(storePathHelper.rewrite(s1), CoreMatchers.<CharSequence>equalTo("store/data/" + r1 + ".i")); | |
115 errorCollector.checkThat(storePathHelper.rewrite(s2), CoreMatchers.<CharSequence>equalTo("store/data/" + r2 + ".i")); | |
116 } | |
117 | |
118 @Test | |
119 public void testNationalChars() { | |
120 String s = "Привет.txt"; | |
121 // | |
122 propertyOverrides.put(Internals.CFG_PROPERT_FS_FILENAME_ENCODING, "cp1251"); | |
123 PathRewrite sph = internals.buildDataFilesHelper(); | |
124 errorCollector.checkThat(sph.rewrite(s), CoreMatchers.<CharSequence>equalTo("store/data/~cf~f0~e8~e2~e5~f2.txt.i")); | |
125 // | |
126 propertyOverrides.put(Internals.CFG_PROPERT_FS_FILENAME_ENCODING, "UTF8"); | |
127 sph = internals.buildDataFilesHelper(); | |
128 errorCollector.checkThat(sph.rewrite(s), CoreMatchers.<CharSequence>equalTo("store/data/~d0~9f~d1~80~d0~b8~d0~b2~d0~b5~d1~82.txt.i")); | |
129 } | |
91 } | 130 } |