comparison test/org/tmatesoft/hg/test/TestByteChannel.java @ 388:b015f3918120

Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 15 Feb 2012 22:57:56 +0100
parents d5268ca7715b
children 12f668401613
comparison
equal deleted inserted replaced
387:cdea37239b01 388:b015f3918120
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 static org.junit.Assert.assertArrayEquals; 19 import static org.junit.Assert.*;
20
21 import java.io.File;
22 import java.io.FileWriter;
23 import java.io.IOException;
24 import java.util.Collections;
25 import java.util.Map;
20 26
21 import org.junit.Assert; 27 import org.junit.Assert;
22 import org.junit.Test; 28 import org.junit.Test;
29 import org.tmatesoft.hg.internal.BasicSessionContext;
23 import org.tmatesoft.hg.internal.ByteArrayChannel; 30 import org.tmatesoft.hg.internal.ByteArrayChannel;
31 import org.tmatesoft.hg.internal.Internals;
24 import org.tmatesoft.hg.repo.HgDataFile; 32 import org.tmatesoft.hg.repo.HgDataFile;
33 import org.tmatesoft.hg.repo.HgLookup;
25 import org.tmatesoft.hg.repo.HgRepository; 34 import org.tmatesoft.hg.repo.HgRepository;
26 35
27 /** 36 /**
28 * 37 *
29 * @author Artem Tikhomirov 38 * @author Artem Tikhomirov
82 // 91 //
83 // try once again to make sure metadata records/extracts correct offsets 92 // try once again to make sure metadata records/extracts correct offsets
84 dir_b.content(0, ch = new ByteArrayChannel()); 93 dir_b.content(0, ch = new ByteArrayChannel());
85 assertArrayEquals("a \r\n".getBytes(), ch.toArray()); 94 assertArrayEquals("a \r\n".getBytes(), ch.toArray());
86 } 95 }
96
97 @Test
98 public void testWorkingCopyFileAccess() throws Exception {
99 final File repoDir = TestIncoming.initEmptyTempRepo("testWorkingCopyFileAccess");
100 final Map<String, ?> props = Collections.singletonMap(Internals.CFG_PROPERTY_REVLOG_STREAM_CACHE, false);
101 repo = new HgLookup(new BasicSessionContext(props, null, null)).detect(repoDir);
102 File f1 = new File(repoDir, "file1");
103 final String c1 = "First", c2 = "Second", c3 = "Third";
104 ByteArrayChannel ch;
105 ExecHelper exec = new ExecHelper(new OutputParser.Stub(), repoDir);
106 // commit cset 0
107 write(f1, c1);
108 exec.run("hg", "add");
109 Assert.assertEquals(0, exec.getExitValue());
110 exec.run("hg", "commit", "-m", "c0");
111 Assert.assertEquals(0, exec.getExitValue());
112 // commit cset 1
113 write(f1, c2);
114 exec.run("hg", "commit", "-m", "c1");
115 assertEquals(0, exec.getExitValue());
116 //
117 // modify working copy
118 write(f1, c3);
119 //
120 HgDataFile df = repo.getFileNode(f1.getName());
121 // 1. Shall take content of the file from the dir
122 df.workingCopy(ch = new ByteArrayChannel());
123 assertArrayEquals(c3.getBytes(), ch.toArray());
124 // 2. Shall supply working copy even if no local file is there
125 f1.delete();
126 assertFalse(f1.exists());
127 df = repo.getFileNode(f1.getName());
128 df.workingCopy(ch = new ByteArrayChannel());
129 assertArrayEquals(c2.getBytes(), ch.toArray());
130 //
131 // 3. Shall extract revision of the file that corresponds actual parents (from dirstate) not the TIP as it was
132 exec.run("hg", "update", "-r", "0");
133 assertEquals(0, exec.getExitValue());
134 f1.delete();
135 assertFalse(f1.exists());
136 // there's no file and workingCopy shall do some extra work to find out actual revision to check out
137 df = repo.getFileNode(f1.getName());
138 df.workingCopy(ch = new ByteArrayChannel());
139 assertArrayEquals(c1.getBytes(), ch.toArray());
140 }
141
142 private static void write(File f, String content) throws IOException {
143 FileWriter fw = new FileWriter(f);
144 fw.write(content);
145 fw.close();
146 }
87 } 147 }