Skip to main content
summaryrefslogtreecommitdiffstats
blob: a48ebbffaa9d0de379d9eb6c47d83c2d51e53b4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package org.eclipse.team.tests.ccvs.core.cvsresources;
/*
 * (c) Copyright IBM Corp. 2000, 2002.
 * All Rights Reserved.
 */
import java.io.BufferedInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

import junit.awtui.TestRunner;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.team.ccvs.core.*;
import org.eclipse.team.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
import org.eclipse.team.internal.ccvs.core.resources.LocalResource;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.team.tests.ccvs.core.JUnitTestCase;


public class LocalFileTest extends JUnitTestCase {
	
	ICVSFile file1;
	ICVSFile file1a;
	ICVSFile file2;
	ICVSFolder folder1;
	
	ResourceSyncInfo fileInfo1;
	
	File ioFile;
	
	
	public LocalFileTest(String arg) {
		super(arg);
	}
	
	public static void main(String[] args) {
		TestRunner.run(LocalFileTest.class);
	}


	public void setUp() throws CVSException {
		
		String tmpEntryLine1;


		String root = ":server:user:pwd@test:/home";
		String repo = "repository";		
		folder1 = getManagedFolder("proj1");
		folder1.mkdir();
		folder1.setFolderSyncInfo(new FolderSyncInfo(repo,root,null,false));
		
		file1 = folder1.getFile("file1.txt");
		file1a = folder1.getFile("file1.txt");
		file2 = folder1.getFile("file2.txt");
		
		tmpEntryLine1 = "/.vcm_meta/1.1/Thu Sep 27 18:00:16 2001/-kb/TmyTag";
		fileInfo1 = new ResourceSyncInfo(tmpEntryLine1,null,null);
		
		ioFile = getFile("proj1/file1.txt");
		
	}
	
	public void tearDown() throws CVSException {
		folder1.delete();
		CVSProviderPlugin.getSynchronizer().reload(((LocalResource)folder1).getLocalFile(), new NullProgressMonitor());
		assertSynchronizerEmpty();			
		assertTrue(!folder1.exists());
	}

	public static Test suite() {		
		TestSuite suite = new TestSuite(LocalFileTest.class);
    	return suite; 	
	}
	
	public void testFileInfo() throws CVSException {
		
		String entryLine1;
		String entryLine2;
		String entryLine3;
		boolean fail=false;
	
		entryLine1 = "/.vcm_meta/1.1/27 Sep 2001 18:00:16/-kb/TmyTag";
		entryLine2 = "/file1.txt/1.1/27 Sep 2001 18:00:16/-kb/TmyTag";
		entryLine3 = "/file1.txt/1.2/27 Sep 2001 18:00:16/-kb/TmyTag";

		ResourceSyncInfo fileInfo1 = new ResourceSyncInfo(entryLine1,null,null);
		ResourceSyncInfo fileInfo2 = new ResourceSyncInfo(entryLine2,null,null);
		ResourceSyncInfo fileInfo3 = new ResourceSyncInfo(entryLine3,null,null);

		file1.setSyncInfo(fileInfo2);
		
		assertEquals(file1a.getSyncInfo(),fileInfo2);
	
		file1a.setSyncInfo(fileInfo3);
		
		assertEquals(file1.getSyncInfo(),fileInfo3);
	}
	
//	public void testSendReceive() throws Exception {
//		
//		String sendTxt;
//		String expectTxt;
//		InputStream in;
//
//		sendTxt = "This is my text";
//		expectTxt = sendTxt.length() + "\n" + sendTxt;
//		
//		byte[] result = new byte[sendTxt.length()];
//		
//		PipedInputStream pIn;
//		PipedOutputStream pOut;
//		
//		pIn = new PipedInputStream();
//		pOut = new PipedOutputStream(pIn);
//		
//		in = new BufferedInputStream(pIn,sendTxt.length());
//		
//		pOut.write(sendTxt.getBytes());
//		file1.receiveFrom(in,sendTxt.length(),false,false, new NullProgressMonitor());
//		in.close();
//		pOut.close();
//		
//		result = new byte[expectTxt.length()];
//		pIn = new PipedInputStream();
//		pOut = new PipedOutputStream(pIn);
//		
//		in = new BufferedInputStream(pIn,sendTxt.length());
//		file1.sendTo(pOut,false, new NullProgressMonitor());
//		in.read(result);
//		in.close();
//		pOut.close();
//		
//		assertEquals(new String(result),expectTxt);	
//	}
	
	public void testTimestamp() throws Exception {
		
		String timeStamp;
		
		ioFile.createNewFile();
		timeStamp = "Tue Oct 30 14:38:16 2001";
		
		file1.setTimeStamp(timeStamp);
		assertEquals(timeStamp, file1a.getTimeStamp());
		
	}
	
	public void testIsDirty() throws Exception {
		
		String timeStamp;
		String entryLine;
		ResourceSyncInfo fileInfo;
		
		ioFile.createNewFile();
		timeStamp = "Tue Oct 30 14:38:16 2001";
		entryLine = "/file1.txt/1.1/Tue Oct 30 14:38:16 2001/-kb/TmyTag";
		
		file1.setTimeStamp(timeStamp);
		timeStamp = file1.getTimeStamp();
		
		fileInfo = new ResourceSyncInfo(entryLine,null,timeStamp);
		
		file1.setSyncInfo(fileInfo);
		
		assertEquals(false, file1.isDirty());
		
		// touch the file
		writeToFile(ioFile,readFromFile(ioFile));
		
		assertEquals(true, file1.isDirty());

		file1.setTimeStamp(timeStamp);

		assertEquals(false, file1.isDirty());	
	}
		
	// ---------------- Here the resource-tests start ---------------
	
	public void testExists() throws Exception {
		
		file1.delete();
		assertEquals(false, file1.exists());
		writeToFile(ioFile,new String[0]);
		assertEquals(true, file1.exists());
		
	}
	
	public void testGetName() {
		assertEquals("file1.txt", file1.getName());	
	}
	
	public void testGetParent() {
		assertEquals(folder1,file1.getParent());	
	}
	
	public void testGetRelativePath() throws CVSException {
		assertEquals("file1.txt", file1.getRelativePath(folder1));
	}
	
	public void testIsFolder() {
		assertEquals(false, file1.isFolder());
	}		

	public void testIsManaged() throws CVSException {
		
		ResourceSyncInfo fileInfo2 = new ResourceSyncInfo("/file1.txt/1.1/27 Sep 2001 18:00:16/-kb/TmyTag",null,null);
		
		assertEquals(false, file1.isManaged());
		file1.setSyncInfo(fileInfo2);
		assertEquals(true, file1.isManaged());
		
	}
}

Back to the top