OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
TerrainTest.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using NUnit.Framework;
30 using OpenSim.Framework;
31 using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes;
32 using OpenSim.Region.Framework.Scenes;
33 using OpenSim.Tests.Common;
34 
35 namespace OpenSim.Region.CoreModules.World.Terrain.Tests
36 {
37  [TestFixture]
39  {
40  [Test]
41  public void BrushTest()
42  {
43  int midRegion = (int)Constants.RegionSize / 2;
44 
45  // Create a mask that covers only the left half of the region
46  bool[,] allowMask = new bool[(int)Constants.RegionSize, 256];
47  int x;
48  int y;
49  for (x = 0; x < midRegion; x++)
50  {
51  for (y = 0; y < (int)Constants.RegionSize; y++)
52  {
53  allowMask[x,y] = true;
54  }
55  }
56 
57  //
58  // Test RaiseSphere
59  //
61  ITerrainPaintableEffect effect = new RaiseSphere();
62 
63  effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
64  0, midRegion - 1,0, (int)Constants.RegionSize -1);
65  Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128).");
66  Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128).");
67  Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128).");
68  Assert.That(map[128, midRegion] == 0.0, "Raise brush should not change value at this point (128,128).");
69 // Assert.That(map[0, midRegion] == 0.0, "Raise brush should not change value at this point (0,128).");
70  //
71  // Test LowerSphere
72  //
74  for (x=0; x<map.Width; x++)
75  {
76  for (y=0; y<map.Height; y++)
77  {
78  map[x,y] = 1.0;
79  }
80  }
81  effect = new LowerSphere();
82 
83  effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
84  0, (int)Constants.RegionSize -1,0, (int)Constants.RegionSize -1);
85  Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
86  Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
87  Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128).");
88  Assert.That(map[120, midRegion] == 1.0, "Lower brush should not change value at this point (120,128).");
89  Assert.That(map[128, midRegion] == 1.0, "Lower brush should not change value at this point (128,128).");
90 // Assert.That(map[0, midRegion] == 1.0, "Lower brush should not change value at this point (0,128).");
91  }
92 
93  [Test]
94  public void TerrainChannelTest()
95  {
97  Assert.That(x[0, 0] == 0.0, "Terrain not initialising correctly.");
98 
99  x[0, 0] = 1.0;
100  Assert.That(x[0, 0] == 1.0, "Terrain not setting values correctly.");
101 
102  x[0, 0] = 0;
103  x[0, 0] += 5.0;
104  x[0, 0] -= 1.0;
105  Assert.That(x[0, 0] == 4.0, "Terrain addition/subtraction error.");
106 
107  x[0, 0] = 1.0;
108  float[] floatsExport = x.GetFloatsSerialised();
109  Assert.That(floatsExport[0] == 1.0f, "Export to float[] not working correctly.");
110 
111  x[0, 0] = 1.0;
112  Assert.That(x.Tainted(0, 0), "Terrain channel tainting not working correctly.");
113  Assert.That(!x.Tainted(0, 0), "Terrain channel tainting not working correctly.");
114 
115  TerrainChannel y = x.Copy();
116  Assert.That(!ReferenceEquals(x, y), "Terrain copy not duplicating correctly.");
117  Assert.That(!ReferenceEquals(x.GetDoubles(), y.GetDoubles()), "Terrain array not duplicating correctly.");
118  }
119  }
120 }
Interactive OpenSim region server
Definition: OpenSim.cs:55
A new version of the old Channel class, simplified