/**
 * LOGICAL-PARADOX.ORG variable record manager library
 * Copyright (C)2004 satoshi akabane(akabane@logical-paradox.org)
 *
 * Release 1.0
 * ・初期パージョン
 */
package org.logical_paradox.common.vrm;

import java.io.IOException;

import junit.framework.TestCase;

/**
 * VRMAvailableListのテストケース
 */
public class VRMAvailableListTest extends TestCase {
	// 利用可能レコード追加処理のテスト
	public void testAddRecord() throws IOException {
		VRMAvailableListMoc list = new VRMAvailableListMoc("foo");
		list.getCache().add(new AvailableRecord(1,100));
		list.getCache().add(new AvailableRecord(500,32));
		list.getCache().add(new AvailableRecord(2,51));
		list.getCache().add(new AvailableRecord(100,2));

		// ファイルへ反映
		list.flush();

		// 全部削除
		list.getCache().getOne();
		list.getCache().getOne();
		list.getCache().getOne();
		list.getCache().getOne();

		// リロード
		list.reload();

		// 確認
		assertEquals(4, list.getCache().size());

		AvailableRecord ar1 = (AvailableRecord)list.getCache().getOne();
		AvailableRecord ar2 = (AvailableRecord)list.getCache().getOne();
		AvailableRecord ar3 = (AvailableRecord)list.getCache().getOne();
		AvailableRecord ar4 = (AvailableRecord)list.getCache().getOne();

		assertEquals(500, ar1.getRecordSize());
		assertEquals(32, ar1.getNextPtr());
		assertEquals(100, ar2.getRecordSize());
		assertEquals(2, ar2.getNextPtr());
		assertEquals(2, ar3.getRecordSize());
		assertEquals(51, ar3.getNextPtr());
		assertEquals(1, ar4.getRecordSize());
		assertEquals(100, ar4.getNextPtr());
	}
}
