📄 fsclasstest.java
字号:
/*
* FSSetBackgroundColorTest.java
* Transform
*
* Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Flagstone Software Ltd. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.flagstone.transform.test;
import com.flagstone.transform.*;
public abstract class FSClassTest
{
public FSClassTest()
{
}
protected void checkType(int expected, int actual)
{
assert expected == actual : "Types are not identical.";
}
protected void checkIdentical(Object expected, Object actual)
{
assert expected == actual : "References are not to the same object.";
}
protected void checkNotIdentical(Object expected, Object actual)
{
assert expected != actual : "References are to the same object.";
}
protected void checkEqual(Object expected, Object actual)
{
if (expected == null && actual != null)
assert false : "Objects do not match.";
else if (expected != null && actual == null)
assert false : "Objects do not match.";
else if (expected != null && actual != null)
assert actual.equals(expected) : "Objects do not match.";
}
protected void checkNotEqual(Object expected, Object actual)
{
if (expected == null && actual == null)
assert false : "Objects should not match.";
else if (expected != null && actual != null)
assert actual.equals(expected) == false : "Objects should not match.";
}
protected void checkEncode(FSTransformObject obj, int[] bytes)
{
FSCoder coder = new FSCoder(FSCoder.LITTLE_ENDIAN, bytes.length);
checkEncode(coder, obj, bytes);
}
protected void checkEncode(FSCoder coder, FSTransformObject obj, int[] bytes)
{
int length = obj.length(coder);
if (obj instanceof FSMovieObject)
length += (length < 63) ? 2 : 6;
coder.setPointer(0);
obj.encode(coder);
assert (length == bytes.length) : "Calculated length does not match expected.";
compareData(coder.getData(), bytes);
}
protected void checkDecode(FSCoder coder, int length)
{
int delta = (coder.getPointer() >>> 3) - length;
if (delta < 0)
assert false : "Actual length is less than expected by "+(-delta)+" bytes.";
else if (delta > 0)
assert false : "Actual length is greater than expected by "+delta+" bytes.";
}
protected void compareData(byte[] actual, int[] expected)
{
int delta = actual.length - expected.length;
if (delta < 0)
assert false : "Actual length is less than expected by "+(-delta)+" bytes.";
else if (delta > 0)
assert false : "Actual length is greater than expected by "+delta+" bytes.";
for (int i=0; i<expected.length; i++) {
assert(actual[i] == (byte)expected[i]) : "Encoded byte does not match expected value";
}
}
protected byte[] compact(int[] ints)
{
byte[] bytes = new byte[ints.length];
for (int i=0; i<ints.length; i++)
bytes[i] = (byte)ints[i];
return bytes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -