/**
 * LOGICAL-PARADOX.ORG
 * Copyright (C)2004 satoshi akabane(akabane@logical-paradox.org)
 *
 */
package org.logical_paradox.common.util;

import org.logical_paradox.common.lang.StringByteStream;

import junit.framework.TestCase;

/**
 * ArrayListByteStreamのテストケース
 */
public class ArrayListByteStreamTest extends TestCase {

	/**
	 * Constructor for ArrayListByteStreamTest.
	 * @param arg0
	 */
	public ArrayListByteStreamTest(String arg0) {
		super(arg0);
	}

	/**
	 * オブジェクトの出し入れテスト
	 *
	 */
	public void testInOut() {
		ArrayListByteStream array = new ArrayListByteStreamTestImpl();
		array.add(new StringByteStream("あああ"));
		array.add(new StringByteStream("いいい"));
		array.add(new StringByteStream("ううう"));

		StringByteStream[] strings = (StringByteStream[])array.toArray(new StringByteStream[0]);
		assertEquals(3, strings.length);
		assertEquals("あああ",strings[0].getStringObject());
		assertEquals("いいい", strings[1].getStringObject());
		assertEquals("ううう", strings[2].getStringObject());
	}

	public void testSerializeUnSerialize() {
		ArrayListByteStream array = new ArrayListByteStreamTestImpl();
		array.add(new StringByteStream("あああ"));
		array.add(new StringByteStream("いいい"));
		array.add(new StringByteStream("ううう"));

		// 配列をバイト列に変換する
		byte[] bstream = array.byteStream();

		// 別のインスタンスで復元する
		ArrayListByteStream array2 = new ArrayListByteStreamTestImpl(bstream);

		// 復元チェック
		StringByteStream[] strings = (StringByteStream[])array2.toArray(new StringByteStream[0]);
		assertEquals(3, strings.length);
		assertEquals("あああ", strings[0].getStringObject());
		assertEquals("いいい", strings[1].getStringObject());
		assertEquals("ううう", strings[2].getStringObject());
	}
}
