//------------------------------------------------------------------------------
// 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/Model/ModelManagerTest.h"
#include "Graphics/System/LampGraphics.h"
#include "Graphics/Model/ModelManager.h"

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