//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * メッシュマネージャのテスト実装
 * @author Junpee
 */

#include "Test/stdafx.h"
#include "Graphics/Mesh/MeshManagerTest.h"
#include "Graphics/System/LampGraphics.h"
#include "Graphics/Mesh/MeshManager.h"

//------------------------------------------------------------------------------
// テストスィートの取得
Test* MeshManagerTest::suite(){
	TestSuite* suite = new TestSuite("MeshManagerTest");
	suite->addTest(new TestCaller(MeshManagerTest, testConstructor));
	suite->addTest(new TestCaller(MeshManagerTest, testDatabase));
	return suite;
}
//------------------------------------------------------------------------------
// コンストラクタテスト
void MeshManagerTest::testConstructor(){
	TestEquals(40, (int)sizeof(MeshManager));
	Scene* scene = LampGraphics::createScene("test");
	TestAssert(scene != NULL);
	MeshManager* manager = scene->getMeshManager();
	TestAssert(manager != NULL);
	// クリア
	TestEquals(0, scene->clear());
	LampGraphics::destroyScene(scene);
}
//------------------------------------------------------------------------------
// データベーステスト
void MeshManagerTest::testDatabase(){
	Scene* scene = LampGraphics::createScene("test");
	MeshManager* manager = scene->getMeshManager();
	// データベースの構築
	int meshCount = 257;
	String* names = new String[meshCount];
	Mesh** meshs = new Mesh*[meshCount];
	for(int i = 0; i < meshCount; i++){
		names[i].format("mesh%d", i);
	}
	for(int i = 0; i < meshCount; i++){
		meshs[i] = manager->createRigidMesh(names[i]);
	}
	// 配列アクセス
	TestEquals(meshCount, manager->getCount());
	for(int i = 0; i < meshCount; i++){
		TestEquals(names[i], manager->get(i)->getName());
		TestAssert(meshs[i] == manager->get(i));
	}
	// 検索アクセス
	for(int i = 0; i < meshCount; i++){
		Mesh* mesh = manager->search(names[i]);
		TestAssert(mesh == manager->get(i));
	}
	// 破棄
	int destroyCount = 64;
	for(int i = 0; i < destroyCount; i++){
		TestEquals(0, manager->destroy(meshs[i]));
	}
	// クリア
	TestEquals(meshCount - destroyCount, scene->clear());
	TestEquals(0, scene->clear());
	delete[] meshs;
	delete[] names;
	LampGraphics::destroyScene(scene);
}
//------------------------------------------------------------------------------
