1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #include <gtest/gtest.h>
29 
30 #include "OgreRoot.h"
31 #include "OgreTerrain.h"
32 #include "OgreFileSystemLayer.h"
33 
34 #include "OgreBuildSettings.h"
35 #include "OgreStaticPluginLoader.h"
36 #include "OgreConfigFile.h"
37 #include "OgreResourceGroupManager.h"
38 #include "OgreLogManager.h"
39 
40 using namespace Ogre;
41 
42 class TerrainTests : public ::testing::Test
43 {
44 public:
45 #ifdef OGRE_STATIC_LIB
46     OgreBites::StaticPluginLoader mStaticPluginLoader;
47 #endif
48 
49     Root* mRoot;
50     SceneManager* mSceneMgr;
51     TerrainGlobalOptions* mTerrainOpts;
52     FileSystemLayer* mFSLayer;
53 
54     void SetUp();
55     void TearDown();
56 };
57 
58 //--------------------------------------------------------------------------
SetUp()59 void TerrainTests::SetUp()
60 {
61     mFSLayer = OGRE_NEW_T(Ogre::FileSystemLayer, Ogre::MEMCATEGORY_GENERAL)(OGRE_VERSION_NAME);
62 
63 #ifdef OGRE_STATIC_LIB
64     mRoot = OGRE_NEW Root(BLANKSTRING);
65     mStaticPluginLoader.load();
66 #else
67     String pluginsPath = mFSLayer->getConfigFilePath("plugins.cfg");
68     mRoot = OGRE_NEW Root(pluginsPath);
69     Ogre::LogManager::getSingletonPtr()->getDefaultLog()->setDebugOutputEnabled(false);
70 #endif
71 
72     mTerrainOpts = OGRE_NEW TerrainGlobalOptions();
73 
74     // Load resource paths from config file
75     ConfigFile cf;
76     String resourcesPath = mFSLayer->getConfigFilePath("resources.cfg");
77     cf.load(resourcesPath);
78 
79     // Go through all sections & settings in the file
80     String secName, typeName, archName;
81     ConfigFile::SettingsBySection_::const_iterator seci;
82     for(seci = cf.getSettingsBySection().begin(); seci != cf.getSettingsBySection().end(); ++seci) {
83         secName = seci->first;
84         const ConfigFile::SettingsMultiMap& settings = seci->second;
85         ConfigFile::SettingsMultiMap::const_iterator i;
86         for (i = settings.begin(); i != settings.end(); ++i)
87         {
88             typeName = i->first;
89             archName = i->second;
90             ResourceGroupManager::getSingleton().addResourceLocation(
91                 archName, typeName, secName);
92         }
93     }
94 
95     mSceneMgr = mRoot->createSceneManager();
96 }
97 //--------------------------------------------------------------------------
TearDown()98 void TerrainTests::TearDown()
99 {
100     OGRE_DELETE mTerrainOpts;
101     OGRE_DELETE mRoot;
102     OGRE_DELETE_T(mFSLayer, FileSystemLayer, Ogre::MEMCATEGORY_GENERAL);
103 }
104 //--------------------------------------------------------------------------
TEST_F(TerrainTests,create)105 TEST_F(TerrainTests, create)
106 {
107     Terrain* t = OGRE_NEW Terrain(mSceneMgr);
108     Image img;
109     img.load("terrain.png", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
110 
111     Terrain::ImportData imp;
112     imp.inputImage = &img;
113     imp.terrainSize = 513;
114     imp.worldSize = 1000;
115     imp.minBatchSize = 33;
116     imp.maxBatchSize = 65;
117     ASSERT_TRUE(t->prepare(imp));
118 
119     // Note: Do not load as this would require GPU access!
120     //t->load();
121 
122     OGRE_DELETE t;
123 }
124 //--------------------------------------------------------------------------
125