kitaev@213: /* kitaev@213: * Copyright (c) 2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.test; kitaev@213: kitaev@213: import static org.hamcrest.CoreMatchers.equalTo; kitaev@213: import junit.framework.Assert; kitaev@213: kitaev@213: import org.junit.Rule; kitaev@213: import org.junit.Test; kitaev@213: import org.tmatesoft.hg.internal.Internals; kitaev@213: import org.tmatesoft.hg.util.PathRewrite; kitaev@213: kitaev@213: /** kitaev@213: * kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: */ kitaev@213: public class TestStorePath { kitaev@213: kitaev@213: @Rule kitaev@213: public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); kitaev@213: kitaev@213: private PathRewrite storePathHelper; kitaev@213: kitaev@213: public static void main(String[] args) throws Throwable { kitaev@213: final TestStorePath test = new TestStorePath(); kitaev@213: test.testWindowsFilenames(); kitaev@213: test.testHashLongPath(); kitaev@213: test.errorCollector.verify(); kitaev@213: } kitaev@213: kitaev@213: public TestStorePath() { kitaev@213: final Internals i = new Internals(); kitaev@213: i.setStorageConfig(1, 0x7); kitaev@213: storePathHelper = i.buildDataFilesHelper(); kitaev@213: } kitaev@213: kitaev@213: @Test kitaev@213: public void testWindowsFilenames() { kitaev@213: // see http://mercurial.selenic.com/wiki/fncacheRepoFormat#Encoding_of_Windows_reserved_names kitaev@213: String n1 = "aux.bla/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c"; kitaev@213: String r1 = "store/data/au~78.bla/bla.aux/pr~6e/_p_r_n/lpt/co~6d3/nu~6c/coma/foo._n_u_l/normal.c.i"; kitaev@213: Assert.assertEquals("Windows filenames are ", r1, storePathHelper.rewrite(n1)); kitaev@213: } kitaev@213: kitaev@213: @Test kitaev@213: public void testHashLongPath() { kitaev@213: String n1 = "AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT"; kitaev@213: String r1 = "store/dh/au~78/second/x.prn/fourth/fi~3afth/sixth/seventh/eighth/nineth/tenth/loremia20419e358ddff1bf8751e38288aff1d7c32ec05.i"; kitaev@213: String n2 = "enterprise/openesbaddons/contrib-imola/corba-bc/netbeansplugin/wsdlExtension/src/main/java/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider"; kitaev@213: String r2 = "store/dh/enterpri/openesba/contrib-/corba-bc/netbeans/wsdlexte/src/main/java/org.net7018f27961fdf338a598a40c4683429e7ffb9743.i"; kitaev@213: String n3 = "AUX.THE-QUICK-BROWN-FOX-JU:MPS-OVER-THE-LAZY-DOG-THE-QUICK-BROWN-FOX-JUMPS-OVER-THE-LAZY-DOG.TXT"; kitaev@213: String r3 = "store/dh/au~78.the-quick-brown-fox-ju~3amps-over-the-lazy-dog-the-quick-brown-fox-jud4dcadd033000ab2b26eb66bae1906bcb15d4a70.i"; kitaev@213: // TODO segment[8] == [. ], segment[8] in the middle of windows reserved name or character (to see if ~xx is broken) kitaev@213: errorCollector.checkThat(storePathHelper.rewrite(n1), equalTo(r1)); kitaev@213: errorCollector.checkThat(storePathHelper.rewrite(n2), equalTo(r2)); kitaev@213: errorCollector.checkThat(storePathHelper.rewrite(n3), equalTo(r3)); kitaev@213: } kitaev@213: }