📄 fsprotecttest.java
字号:
/*
* FSProtectTest.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 class FSProtectTest extends FSClassTest
{
private static String[] passwords = new String[] {
null,
"",
"5F4DCC3B5AA765D61D8327DEB882CF99", // "password"
};
private static int[][] encodedObjects = new int[][] {
{ 0x00, 0x06 },
{ 0x00, 0x06 },
{ 0x23, 0x06, 0x00, 0x00,
0x35, 0x46, 0x34, 0x44, 0x43, 0x43, 0x33, 0x42,
0x35, 0x41, 0x41, 0x37, 0x36, 0x35, 0x44, 0x36,
0x31, 0x44, 0x38, 0x33, 0x32, 0x37, 0x44, 0x45,
0x42, 0x38, 0x38, 0x32, 0x43, 0x46, 0x39, 0x39, 0x00},
};
/**
* @testng.test groups="setbackgroundcolor, constructors"
*/
public void checkConstructors()
{
for (int i=0; i<passwords.length; i++)
{
FSProtect background = new FSProtect(passwords[i]);
checkType(FSMovieObject.Protect, background.getType());
checkEqual(passwords[i], background.getPassword());
}
}
/**
* @testng.test groups="setbackgroundcolor, constructors"
*/
public void checkCopyConstructor()
{
for (int i=0; i<passwords.length; i++)
{
FSProtect original = new FSProtect(passwords[i]);
FSProtect copy = new FSProtect(original);
checkEqual(passwords[i], copy.getPassword());
checkNotIdentical(passwords[i], copy.getPassword());
}
}
/**
* @testng.test groups="setbackgroundcolor, constructors"
*/
public void checkClone()
{
for (int i=0; i<passwords.length; i++)
{
FSProtect original = new FSProtect(passwords[i]);
FSProtect clone = (FSProtect)original.clone();
checkEqual(original, clone);
checkNotIdentical(original, clone);
}
}
/**
* @testng.test groups="setbackgroundcolor, accessors"
*/
public void checkAccessors()
{
FSProtect original = new FSProtect("");
for (int i=0; i<passwords.length; i++)
{
original.setPassword(passwords[i]);
checkEqual(passwords[i], original.getPassword());
}
}
/**
* @testng.test groups="setbackgroundcolor, utilities"
*/
public void checkEquals()
{
for (int i=0; i<passwords.length; i++)
{
FSProtect a = new FSProtect(passwords[i]);
FSProtect b = new FSProtect(passwords[i]);
checkEqual(a, b);
}
}
/**
* @testng.test groups="setbackgroundcolor, encode"
*/
public void checkEncode()
{
FSCoder coder = new FSCoder(FSCoder.LITTLE_ENDIAN, 0);
coder.setContext(FSCoder.Version, 5);
for (int i=0; i<encodedObjects.length; i++) {
checkEncode(coder, new FSProtect(passwords[i]), encodedObjects[i]);
}
}
/**
* @testng.test groups="setbackgroundcolor, decode"
*/
public void checkDecode()
{
for (int i=0; i<encodedObjects.length; i++)
{
FSCoder coder = new FSCoder(FSCoder.LITTLE_ENDIAN, compact(encodedObjects[i]));
coder.setContext(FSCoder.Version, 5);
/*
* If a password is an empty string then the object is encoded as
* if the password was null. Therefore if the expected value is an
* empty string then it must be replaced by null for the test to
* pass.
*/
String expectedValue = passwords[i];
if (expectedValue != null && expectedValue.length() == 0)
expectedValue = null;
FSProtect obj = new FSProtect(coder);
checkDecode(coder, encodedObjects[i].length);
checkType(FSMovieObject.Protect, obj.getType());
checkEqual(expectedValue, obj.getPassword());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -