⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stubtestbase.java

📁 java 调用windows的api
💻 JAVA
字号:
/*
 * StubTestBase.java -
 *
 * This file is part of the Jawin Project: http://jawinproject.sourceforge.net/
 * 
 * Please consult the LICENSE file in the project root directory,
 * or at the project site before using this software.
 */

/* $Id: StubTestBase.java,v 1.2 2004/07/18 15:12:35 arosii_moa Exp $ */

package org.jawin;

import java.util.Date;

import org.jawin.win32.COINIT;

/**
 * base testcase class for using the {@link test.DualTestItf} stub.
 * Compare this type-safe use with {@link test.DispatchTestBase}.
 * 
 * The used stub is a slightly modified version of the JTB generated code.
 *
 * @version     $Revision: 1.2 $
 * @author      Stuart Halloway, http://www.relevancellc.com/halloway/weblog/
 */
public abstract class StubTestBase extends COMTestBase {

	IDualTestItf idtc;

	protected abstract IDualTestItf initComReference() throws COMException;

	/**
	 * should be implemented by subclass to release the DispatchPtr used in the test.
	 */
	protected abstract void closeDisp(IDualTestItf itf) throws COMException;

	/**
	 * should be implemented by subclass and return the thread model for the test.
	 */
	protected abstract COINIT getThreadModel();
	
	protected void setUp() throws Exception {
		super.setUp(getThreadModel());
		idtc = initComReference();
	}

	protected void tearDown() throws Exception {
		closeDisp(idtc);
		super.tearDown();
	}
	
	public void testPropShort() throws Exception {
		short testValue = 117;
		idtc.setpropShort(testValue);
		assertEquals(testValue, idtc.getpropShort());
	}

	private void booleanTester(boolean testValue) throws Exception {
		idtc.setpropBool(testValue ? 1 : 0);
		assertEquals(testValue, idtc.getpropBool() == 1 ? true : false);
	}

	public void testPropBool() throws Exception {
		booleanTester(true);
		booleanTester(false);
	}

	public void testPropBSTR() throws Exception {
		String testValue = "some string";
		idtc.setpropBSTR(testValue);
		assertEquals(testValue, idtc.getpropBSTR());
	}

	public void testPropDate() throws Exception {
		Date testValue = new Date();
		idtc.setpropDate(testValue);
		assertEquals(testValue, idtc.getpropDate());
	}

	public void testPropFloat() throws Exception {
		float testValue = 11.7f;
		idtc.setpropFloat(testValue);
		assertEquals(testValue, idtc.getpropFloat(), 0.0f);
	}

	public void testPropDouble() throws Exception {
		double testValue = 671.7f;
		idtc.setpropDouble(testValue);
		assertEquals(testValue, idtc.getpropDouble(), 0.0f);
	}

	public void testConcat() throws Exception {
		String[] stringArgs = { "one", "two" };
		assertEquals("onetwo", idtc.concat(stringArgs));
	}
	
	public void testGreatExpectations() throws Exception {
		Object[] expectedArgs = { "one", new Integer(2),
				new Float(3.0f), new Short((short)4), Boolean.TRUE };
		idtc.greatExpectations(expectedArgs);
	}

	public void testSumInts() throws Exception {
		assertEquals(15, idtc.sumInts(intArgs));
	}

	public void testSumShorts() throws Exception {
		assertEquals(-15, idtc.sumShorts(shortArgs));
	}

	public void testCountTrues() throws Exception {
		assertEquals(3, idtc.countTrues(boolArgs));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -