📄 wc.java
字号:
{
// clear the touched flag of all items
Iterator it = items.values().iterator();
while (it.hasNext())
{
Item item = (Item) it.next();
item.touched = false;
}
// normalize directory path
if (basePath != null && basePath.length() > 0)
{
basePath = basePath + "/";
}
else
{
basePath = "";
}
// check all returned DirEntry's
for (int i = 0; i < tested.length; i++)
{
String name = basePath + tested[i].getPath();
Item item = (Item) items.get(name);
Assert.assertNotNull("not found in working copy", item);
if (item.myContent != null)
{
Assert.assertEquals("state says file, working copy not",
tested[i].getNodeKind(),
item.nodeKind == -1 ? NodeKind.file : item.nodeKind);
}
else
{
Assert.assertEquals("state says dir, working copy not",
tested[i].getNodeKind(),
item.nodeKind == -1 ? NodeKind.dir : item.nodeKind);
}
item.touched = true;
}
// all items should have been in items, should had their touched flag
// set
it = items.values().iterator();
while (it.hasNext())
{
Item item = (Item) it.next();
if(!item.touched)
{
if(item.myPath.startsWith(basePath) &&
!item.myPath.equals(basePath))
{
Assert.assertFalse("not found in dir entries", recursive);
boolean found = false;
for(int i = 0; i < tested.length; i++)
{
if(tested[i].getNodeKind() == NodeKind.dir)
{
if(item.myPath.
startsWith(basePath+tested[i].getPath()))
{
found = true;
break;
}
}
}
Assert.assertTrue("not found in dir entries", found);
}
}
}
}
/**
* Check the result of a SVNClient.status versus the expected state
* @param tested the result to be tested
* @param workingCopyPath the path of the working copy
* @throws Exception
*/
void check(Status[] tested, String workingCopyPath) throws Exception
{
// clear the touched flag of all items
Iterator it = items.values().iterator();
while (it.hasNext())
{
Item item = (Item) it.next();
item.touched = false;
}
String normalizeWCPath =
workingCopyPath.replace(File.separatorChar, '/');
// check all result Staus object
for (int i = 0; i < tested.length; i++)
{
String path = tested[i].getPath();
Assert.assertTrue("status path starts not with working copy path",
path.startsWith(normalizeWCPath));
// we calculate the relative path to the working copy root
if (path.length() > workingCopyPath.length() + 1)
{
Assert.assertEquals("missing '/' in status path",
path.charAt(workingCopyPath.length()), '/');
path = path.substring(workingCopyPath.length() + 1);
}
else
// this is the working copy root itself
path = "";
Item item = (Item) items.get(path);
Assert.assertNotNull("status not found in working copy", item);
Assert.assertEquals("wrong text status in working copy",
item.textStatus, tested[i].getTextStatus());
if (item.workingCopyRev != -1)
Assert.assertEquals("wrong revision number in working copy",
item.workingCopyRev, tested[i].getRevisionNumber());
Assert.assertEquals("lock status wrong",
item.isLocked, tested[i].isLocked());
Assert.assertEquals("switch status wrong",
item.isSwitched, tested[i].isSwitched());
Assert.assertEquals("wrong prop status in working copy",
item.propStatus, tested[i].getPropStatus());
if (item.myContent != null)
{
Assert.assertEquals("state says file, working copy not",
tested[i].getNodeKind(),
item.nodeKind == -1 ? NodeKind.file : item.nodeKind);
if (tested[i].getTextStatus() == Status.Kind.normal ||
item.checkContent)
{
File input = new File(workingCopyPath, item.myPath);
Reader rd =
new InputStreamReader(new FileInputStream(input));
StringBuffer buffer = new StringBuffer();
int ch;
while ((ch = rd.read()) != -1)
{
buffer.append((char) ch);
}
rd.close();
Assert.assertEquals("content mismatch", buffer.toString(),
item.myContent);
}
}
else
{
Assert.assertEquals("state says dir, working copy not",
tested[i].getNodeKind(),
item.nodeKind == -1 ? NodeKind.dir : item.nodeKind);
}
item.touched = true;
}
// all items which have the touched flag not set, are missing in the
// result array
it = items.values().iterator();
while (it.hasNext())
{
Item item = (Item) it.next();
Assert.assertTrue("item in working copy not found in status",
item.touched);
}
}
/**
* internal class to discribe a single working copy item
*/
public class Item
{
/**
* the content of a file. A directory has a null content
*/
String myContent;
/**
* the relative path of the item
*/
String myPath;
/**
* the text (content) status of the item
*/
int textStatus = Status.Kind.normal;
/**
* the property status of the item.
*/
int propStatus = Status.Kind.none;
/**
* the expected revision number. -1 means do not check.
*/
long workingCopyRev = -1;
/**
* flag if item has been touched. To detect missing items.
*/
boolean touched;
/**
* flag if the content will be checked
*/
boolean checkContent;
/**
* expected node kind. -1 means do not check.
*/
int nodeKind = -1;
/**
* expected locked status
*/
boolean isLocked;
/**
* expected switched status
*/
boolean isSwitched;
/**
* create a new item
* @param path the path of the item.
* @param content the content of the item. A null signals a directory.
*/
private Item(String path, String content)
{
myPath = path;
myContent = content;
items.put(path, this);
}
/**
* copy constructor
* @param source the copy source.
* @param owner the WC of the copy
*/
private Item(Item source, WC owner)
{
myPath = source.myPath;
myContent = source.myContent;
textStatus = source.textStatus;
propStatus = source.propStatus;
owner.items.put(myPath, this);
}
/**
* copy this item
* @param owner the new WC
* @return the copied item
*/
private Item copy(WC owner)
{
return new Item(this, owner);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -