diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/Tests/AssetTests.cs | 221 | ||||
-rw-r--r-- | OpenSim/Data/Tests/BasicAssetTest.cs | 166 | ||||
-rw-r--r-- | OpenSim/Data/Tests/BasicDataServiceTest.cs | 234 | ||||
-rw-r--r-- | OpenSim/Data/Tests/DefaultTestConns.cs | 63 | ||||
-rw-r--r-- | OpenSim/Data/Tests/EstateTests.cs (renamed from OpenSim/Data/Tests/BasicEstateTest.cs) | 98 | ||||
-rw-r--r-- | OpenSim/Data/Tests/InventoryTests.cs (renamed from OpenSim/Data/Tests/BasicInventoryTest.cs) | 127 | ||||
-rw-r--r-- | OpenSim/Data/Tests/RegionTests.cs (renamed from OpenSim/Data/Tests/BasicRegionTest.cs) | 221 | ||||
-rw-r--r-- | OpenSim/Data/Tests/Resources/TestDataConnections.ini | 24 |
8 files changed, 837 insertions, 317 deletions
diff --git a/OpenSim/Data/Tests/AssetTests.cs b/OpenSim/Data/Tests/AssetTests.cs new file mode 100644 index 0000000..800b9bf --- /dev/null +++ b/OpenSim/Data/Tests/AssetTests.cs | |||
@@ -0,0 +1,221 @@ | |||
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 System.Collections.Generic; | ||
30 | using log4net.Config; | ||
31 | using NUnit.Framework; | ||
32 | using NUnit.Framework.Constraints; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using System.Data.Common; | ||
36 | using log4net; | ||
37 | |||
38 | #if !NUNIT25 | ||
39 | using NUnit.Framework.SyntaxHelpers; | ||
40 | #endif | ||
41 | |||
42 | // DBMS-specific: | ||
43 | using MySql.Data.MySqlClient; | ||
44 | using OpenSim.Data.MySQL; | ||
45 | |||
46 | using System.Data.SqlClient; | ||
47 | using OpenSim.Data.MSSQL; | ||
48 | |||
49 | using Mono.Data.Sqlite; | ||
50 | using OpenSim.Data.SQLite; | ||
51 | |||
52 | namespace OpenSim.Data.Tests | ||
53 | { | ||
54 | |||
55 | #if NUNIT25 | ||
56 | |||
57 | [TestFixture(typeof(MySqlConnection), typeof(MySQLAssetData), Description="Basic Asset store tests (MySQL)")] | ||
58 | [TestFixture(typeof(SqlConnection), typeof(MSSQLAssetData), Description = "Basic Asset store tests (MS SQL Server)")] | ||
59 | [TestFixture(typeof(SqliteConnection), typeof(SQLiteAssetData), Description = "Basic Asset store tests (SQLite)")] | ||
60 | |||
61 | #else | ||
62 | |||
63 | [TestFixture(Description = "Asset store tests (SQLite)")] | ||
64 | public class SQLiteAssetTests : AssetTests<SqliteConnection, SQLiteAssetData> | ||
65 | { | ||
66 | } | ||
67 | |||
68 | [TestFixture(Description = "Asset store tests (MySQL)")] | ||
69 | public class MySqlAssetTests : AssetTests<MySqlConnection, MySQLAssetData> | ||
70 | { | ||
71 | } | ||
72 | |||
73 | [TestFixture(Description = "Asset store tests (MS SQL Server)")] | ||
74 | public class MSSQLAssetTests : AssetTests<SqlConnection, MSSQLAssetData> | ||
75 | { | ||
76 | } | ||
77 | |||
78 | #endif | ||
79 | |||
80 | |||
81 | public class AssetTests<TConn, TAssetData> : BasicDataServiceTest<TConn, TAssetData> | ||
82 | where TConn : DbConnection, new() | ||
83 | where TAssetData : AssetDataBase, new() | ||
84 | { | ||
85 | TAssetData m_db; | ||
86 | |||
87 | public UUID uuid1 = UUID.Random(); | ||
88 | public UUID uuid2 = UUID.Random(); | ||
89 | public UUID uuid3 = UUID.Random(); | ||
90 | |||
91 | public string critter1 = UUID.Random().ToString(); | ||
92 | public string critter2 = UUID.Random().ToString(); | ||
93 | public string critter3 = UUID.Random().ToString(); | ||
94 | |||
95 | public byte[] data1 = new byte[100]; | ||
96 | |||
97 | PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>() | ||
98 | .DontScramble(x => x.ID) | ||
99 | .DontScramble(x => x.Type) | ||
100 | .DontScramble(x => x.FullID) | ||
101 | .DontScramble(x => x.Metadata.ID) | ||
102 | .DontScramble(x => x.Metadata.CreatorID) | ||
103 | .DontScramble(x => x.Metadata.ContentType) | ||
104 | .DontScramble(x => x.Metadata.FullID) | ||
105 | .DontScramble(x => x.Data); | ||
106 | |||
107 | protected override void InitService(object service) | ||
108 | { | ||
109 | ClearDB(); | ||
110 | m_db = (TAssetData)service; | ||
111 | m_db.Initialise(m_connStr); | ||
112 | } | ||
113 | |||
114 | private void ClearDB() | ||
115 | { | ||
116 | DropTables("assets"); | ||
117 | ResetMigrations("AssetStore"); | ||
118 | } | ||
119 | |||
120 | |||
121 | [Test] | ||
122 | public void T001_LoadEmpty() | ||
123 | { | ||
124 | Assert.That(m_db.ExistsAsset(uuid1), Is.False); | ||
125 | Assert.That(m_db.ExistsAsset(uuid2), Is.False); | ||
126 | Assert.That(m_db.ExistsAsset(uuid3), Is.False); | ||
127 | } | ||
128 | |||
129 | [Test] | ||
130 | public void T010_StoreReadVerifyAssets() | ||
131 | { | ||
132 | AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1.ToString()); | ||
133 | AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2.ToString()); | ||
134 | AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3.ToString()); | ||
135 | a1.Data = data1; | ||
136 | a2.Data = data1; | ||
137 | a3.Data = data1; | ||
138 | |||
139 | scrambler.Scramble(a1); | ||
140 | scrambler.Scramble(a2); | ||
141 | scrambler.Scramble(a3); | ||
142 | |||
143 | m_db.StoreAsset(a1); | ||
144 | m_db.StoreAsset(a2); | ||
145 | m_db.StoreAsset(a3); | ||
146 | |||
147 | AssetBase a1a = m_db.GetAsset(uuid1); | ||
148 | Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); | ||
149 | |||
150 | AssetBase a2a = m_db.GetAsset(uuid2); | ||
151 | Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); | ||
152 | |||
153 | AssetBase a3a = m_db.GetAsset(uuid3); | ||
154 | Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); | ||
155 | |||
156 | scrambler.Scramble(a1a); | ||
157 | scrambler.Scramble(a2a); | ||
158 | scrambler.Scramble(a3a); | ||
159 | |||
160 | m_db.StoreAsset(a1a); | ||
161 | m_db.StoreAsset(a2a); | ||
162 | m_db.StoreAsset(a3a); | ||
163 | |||
164 | AssetBase a1b = m_db.GetAsset(uuid1); | ||
165 | Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); | ||
166 | |||
167 | AssetBase a2b = m_db.GetAsset(uuid2); | ||
168 | Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); | ||
169 | |||
170 | AssetBase a3b = m_db.GetAsset(uuid3); | ||
171 | Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); | ||
172 | |||
173 | Assert.That(m_db.ExistsAsset(uuid1), Is.True); | ||
174 | Assert.That(m_db.ExistsAsset(uuid2), Is.True); | ||
175 | Assert.That(m_db.ExistsAsset(uuid3), Is.True); | ||
176 | |||
177 | List<AssetMetadata> metadatas = m_db.FetchAssetMetadataSet(0, 1000); | ||
178 | |||
179 | Assert.That(metadatas.Count >= 3, "FetchAssetMetadataSet() should have returned at least 3 assets!"); | ||
180 | |||
181 | // It is possible that the Asset table is filled with data, in which case we don't try to find "our" | ||
182 | // assets there: | ||
183 | if (metadatas.Count < 1000) | ||
184 | { | ||
185 | AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1); | ||
186 | Assert.That(metadata.Name, Is.EqualTo(a1b.Name)); | ||
187 | Assert.That(metadata.Description, Is.EqualTo(a1b.Description)); | ||
188 | Assert.That(metadata.Type, Is.EqualTo(a1b.Type)); | ||
189 | Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary)); | ||
190 | Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID)); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | [Test] | ||
195 | public void T020_CheckForWeirdCreatorID() | ||
196 | { | ||
197 | // It is expected that eventually the CreatorID might be an arbitrary string (an URI) | ||
198 | // rather than a valid UUID (?). This test is to make sure that the database layer does not | ||
199 | // attempt to convert CreatorID to GUID, but just passes it both ways as a string. | ||
200 | AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1); | ||
201 | AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, "This is not a GUID!"); | ||
202 | AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, ""); | ||
203 | a1.Data = data1; | ||
204 | a2.Data = data1; | ||
205 | a3.Data = data1; | ||
206 | |||
207 | m_db.StoreAsset(a1); | ||
208 | m_db.StoreAsset(a2); | ||
209 | m_db.StoreAsset(a3); | ||
210 | |||
211 | AssetBase a1a = m_db.GetAsset(uuid1); | ||
212 | Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); | ||
213 | |||
214 | AssetBase a2a = m_db.GetAsset(uuid2); | ||
215 | Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); | ||
216 | |||
217 | AssetBase a3a = m_db.GetAsset(uuid3); | ||
218 | Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); | ||
219 | } | ||
220 | } | ||
221 | } | ||
diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs deleted file mode 100644 index 71d6314..0000000 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
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 System.Collections.Generic; | ||
30 | using log4net.Config; | ||
31 | using NUnit.Framework; | ||
32 | using NUnit.Framework.SyntaxHelpers; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using log4net; | ||
36 | |||
37 | namespace OpenSim.Data.Tests | ||
38 | { | ||
39 | public class BasicAssetTest | ||
40 | { | ||
41 | public IAssetDataPlugin db; | ||
42 | public UUID uuid1; | ||
43 | public UUID uuid2; | ||
44 | public UUID uuid3; | ||
45 | public string critter1 = UUID.Random().ToString(); | ||
46 | public string critter2 = UUID.Random().ToString(); | ||
47 | public string critter3 = UUID.Random().ToString(); | ||
48 | public byte[] asset1; | ||
49 | PropertyScrambler<AssetBase> scrambler; | ||
50 | |||
51 | public void SuperInit() | ||
52 | { | ||
53 | OpenSim.Tests.Common.TestLogging.LogToConsole(); | ||
54 | |||
55 | uuid1 = UUID.Random(); | ||
56 | uuid2 = UUID.Random(); | ||
57 | uuid3 = UUID.Random(); | ||
58 | asset1 = new byte[100]; | ||
59 | asset1.Initialize(); | ||
60 | |||
61 | |||
62 | scrambler = new PropertyScrambler<AssetBase>() | ||
63 | .DontScramble(x => x.ID) | ||
64 | .DontScramble(x => x.FullID) | ||
65 | .DontScramble(x => x.Metadata.ID) | ||
66 | .DontScramble(x => x.Metadata.Type) | ||
67 | .DontScramble(x => x.Metadata.CreatorID) | ||
68 | .DontScramble(x => x.Metadata.ContentType) | ||
69 | .DontScramble(x => x.Metadata.FullID); | ||
70 | } | ||
71 | |||
72 | [Test] | ||
73 | public void T001_LoadEmpty() | ||
74 | { | ||
75 | Assert.That(db.ExistsAsset(uuid1), Is.False); | ||
76 | Assert.That(db.ExistsAsset(uuid2), Is.False); | ||
77 | Assert.That(db.ExistsAsset(uuid3), Is.False); | ||
78 | } | ||
79 | |||
80 | [Test] | ||
81 | public void T010_StoreSimpleAsset() | ||
82 | { | ||
83 | AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1); | ||
84 | AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2); | ||
85 | AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3); | ||
86 | a1.Data = asset1; | ||
87 | a2.Data = asset1; | ||
88 | a3.Data = asset1; | ||
89 | |||
90 | scrambler.Scramble(a1); | ||
91 | scrambler.Scramble(a2); | ||
92 | scrambler.Scramble(a3); | ||
93 | |||
94 | db.StoreAsset(a1); | ||
95 | db.StoreAsset(a2); | ||
96 | db.StoreAsset(a3); | ||
97 | |||
98 | AssetBase a1a = db.GetAsset(uuid1); | ||
99 | Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); | ||
100 | |||
101 | AssetBase a2a = db.GetAsset(uuid2); | ||
102 | Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); | ||
103 | |||
104 | AssetBase a3a = db.GetAsset(uuid3); | ||
105 | Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); | ||
106 | |||
107 | scrambler.Scramble(a1a); | ||
108 | scrambler.Scramble(a2a); | ||
109 | scrambler.Scramble(a3a); | ||
110 | |||
111 | db.StoreAsset(a1a); | ||
112 | db.StoreAsset(a2a); | ||
113 | db.StoreAsset(a3a); | ||
114 | |||
115 | AssetBase a1b = db.GetAsset(uuid1); | ||
116 | Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); | ||
117 | |||
118 | AssetBase a2b = db.GetAsset(uuid2); | ||
119 | Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); | ||
120 | |||
121 | AssetBase a3b = db.GetAsset(uuid3); | ||
122 | Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); | ||
123 | |||
124 | Assert.That(db.ExistsAsset(uuid1), Is.True); | ||
125 | Assert.That(db.ExistsAsset(uuid2), Is.True); | ||
126 | Assert.That(db.ExistsAsset(uuid3), Is.True); | ||
127 | |||
128 | List<AssetMetadata> metadatas = db.FetchAssetMetadataSet(0, 1000); | ||
129 | |||
130 | AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1); | ||
131 | Assert.That(metadata.Name, Is.EqualTo(a1b.Name)); | ||
132 | Assert.That(metadata.Description, Is.EqualTo(a1b.Description)); | ||
133 | Assert.That(metadata.Type, Is.EqualTo(a1b.Type)); | ||
134 | Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary)); | ||
135 | Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID)); | ||
136 | } | ||
137 | |||
138 | |||
139 | [Test] | ||
140 | public void T020_CheckForWeirdCreatorID() | ||
141 | { | ||
142 | // It is expected that eventually the CreatorID might be an arbitrary string (an URI) | ||
143 | // rather than a valid UUID (?). This test is to make sure that the database layer does not | ||
144 | // attempt to convert CreatorID to GUID, but just passes it both ways as a string. | ||
145 | AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1); | ||
146 | AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, "This is not a GUID!"); | ||
147 | AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, ""); | ||
148 | a1.Data = asset1; | ||
149 | a2.Data = asset1; | ||
150 | a3.Data = asset1; | ||
151 | |||
152 | db.StoreAsset(a1); | ||
153 | db.StoreAsset(a2); | ||
154 | db.StoreAsset(a3); | ||
155 | |||
156 | AssetBase a1a = db.GetAsset(uuid1); | ||
157 | Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); | ||
158 | |||
159 | AssetBase a2a = db.GetAsset(uuid2); | ||
160 | Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); | ||
161 | |||
162 | AssetBase a3a = db.GetAsset(uuid3); | ||
163 | Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); | ||
164 | } | ||
165 | } | ||
166 | } | ||
diff --git a/OpenSim/Data/Tests/BasicDataServiceTest.cs b/OpenSim/Data/Tests/BasicDataServiceTest.cs new file mode 100644 index 0000000..c261126 --- /dev/null +++ b/OpenSim/Data/Tests/BasicDataServiceTest.cs | |||
@@ -0,0 +1,234 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Collections.Generic; | ||
4 | using log4net.Config; | ||
5 | using NUnit.Framework; | ||
6 | using NUnit.Framework.Constraints; | ||
7 | using OpenMetaverse; | ||
8 | using OpenSim.Framework; | ||
9 | using log4net; | ||
10 | using System.Data; | ||
11 | using System.Data.Common; | ||
12 | using System.Reflection; | ||
13 | |||
14 | namespace OpenSim.Data.Tests | ||
15 | { | ||
16 | /// <summary>This is a base class for testing any Data service for any DBMS. | ||
17 | /// Requires NUnit 2.5 or better (to support the generics). | ||
18 | /// </summary> | ||
19 | /// <typeparam name="TConn"></typeparam> | ||
20 | /// <typeparam name="TService"></typeparam> | ||
21 | public class BasicDataServiceTest<TConn, TService> | ||
22 | where TConn : DbConnection, new() | ||
23 | where TService : class, new() | ||
24 | { | ||
25 | protected string m_connStr; | ||
26 | private TService m_service; | ||
27 | private string m_file; | ||
28 | |||
29 | // TODO: Is this in the right place here? | ||
30 | // Later: apparently it's not, but does it matter here? | ||
31 | // protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
32 | |||
33 | protected ILog m_log; // doesn't matter here that it's not static, init to correct type in instance .ctor | ||
34 | |||
35 | public BasicDataServiceTest() | ||
36 | : this("") | ||
37 | { | ||
38 | } | ||
39 | |||
40 | public BasicDataServiceTest(string conn) | ||
41 | { | ||
42 | m_connStr = !String.IsNullOrEmpty(conn) ? conn : DefaultTestConns.Get(typeof(TConn)); | ||
43 | |||
44 | m_log = LogManager.GetLogger(this.GetType()); | ||
45 | OpenSim.Tests.Common.TestLogging.LogToConsole(); // TODO: Is that right? | ||
46 | } | ||
47 | |||
48 | /// <summary> | ||
49 | /// To be overridden in derived classes. Do whatever init with the m_service, like setting the conn string to it. | ||
50 | /// You'd probably want to to cast the 'service' to a more specific type and store it in a member var. | ||
51 | /// This framework takes care of disposing it, if it's disposable. | ||
52 | /// </summary> | ||
53 | /// <param name="service">The service being tested</param> | ||
54 | protected virtual void InitService(object service) | ||
55 | { | ||
56 | } | ||
57 | |||
58 | [TestFixtureSetUp] | ||
59 | public void Init() | ||
60 | { | ||
61 | // Sorry, some SQLite-specific stuff goes here (not a big deal, as its just some file ops) | ||
62 | if (typeof(TConn).Name.StartsWith("Sqlite")) | ||
63 | { | ||
64 | // SQLite doesn't work on power or z linux | ||
65 | if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd")) | ||
66 | Assert.Ignore(); | ||
67 | |||
68 | // for SQLite, if no explicit conn string is specified, use a temp file | ||
69 | if (String.IsNullOrEmpty(m_connStr)) | ||
70 | { | ||
71 | m_file = Path.GetTempFileName() + ".db"; | ||
72 | m_connStr = "URI=file:" + m_file + ",version=3"; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | if (String.IsNullOrEmpty(m_connStr)) | ||
77 | { | ||
78 | string msg = String.Format("Connection string for {0} is not defined, ignoring tests", typeof(TConn).Name); | ||
79 | m_log.Warn(msg); | ||
80 | Assert.Ignore(msg); | ||
81 | } | ||
82 | |||
83 | // Try the connection, ignore tests if Open() fails | ||
84 | using (TConn conn = new TConn()) | ||
85 | { | ||
86 | conn.ConnectionString = m_connStr; | ||
87 | try | ||
88 | { | ||
89 | conn.Open(); | ||
90 | conn.Close(); | ||
91 | } | ||
92 | catch | ||
93 | { | ||
94 | string msg = String.Format("{0} is unable to connect to the database, ignoring tests", typeof(TConn).Name); | ||
95 | m_log.Warn(msg); | ||
96 | Assert.Ignore(msg); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | // If we manage to connect to the database with the user | ||
101 | // and password above it is our test database, and run | ||
102 | // these tests. If anything goes wrong, ignore these | ||
103 | // tests. | ||
104 | try | ||
105 | { | ||
106 | m_service = new TService(); | ||
107 | InitService(m_service); | ||
108 | } | ||
109 | catch (Exception e) | ||
110 | { | ||
111 | m_log.Error(e.ToString()); | ||
112 | Assert.Ignore(); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | [TestFixtureTearDown] | ||
117 | public void Cleanup() | ||
118 | { | ||
119 | if (m_service != null) | ||
120 | { | ||
121 | if( m_service is IDisposable) | ||
122 | ((IDisposable)m_service).Dispose(); | ||
123 | m_service = null; | ||
124 | } | ||
125 | |||
126 | if( !String.IsNullOrEmpty(m_file) && File.Exists(m_file) ) | ||
127 | File.Delete(m_file); | ||
128 | } | ||
129 | |||
130 | protected virtual DbConnection Connect() | ||
131 | { | ||
132 | DbConnection cnn = new TConn(); | ||
133 | cnn.ConnectionString = m_connStr; | ||
134 | cnn.Open(); | ||
135 | return cnn; | ||
136 | } | ||
137 | |||
138 | protected virtual void ExecuteSql(string sql) | ||
139 | { | ||
140 | using (DbConnection dbcon = Connect()) | ||
141 | { | ||
142 | using (DbCommand cmd = dbcon.CreateCommand()) | ||
143 | { | ||
144 | cmd.CommandText = sql; | ||
145 | cmd.ExecuteNonQuery(); | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | |||
150 | protected delegate bool ProcessRow(IDataReader reader); | ||
151 | |||
152 | protected virtual int ExecQuery(string sql, bool bSingleRow, ProcessRow action) | ||
153 | { | ||
154 | int nRecs = 0; | ||
155 | using (DbConnection dbcon = Connect()) | ||
156 | { | ||
157 | using (DbCommand cmd = dbcon.CreateCommand()) | ||
158 | { | ||
159 | cmd.CommandText = sql; | ||
160 | CommandBehavior cb = bSingleRow ? CommandBehavior.SingleRow : CommandBehavior.Default; | ||
161 | using (DbDataReader rdr = cmd.ExecuteReader(cb)) | ||
162 | { | ||
163 | while (rdr.Read()) | ||
164 | { | ||
165 | nRecs++; | ||
166 | if (!action(rdr)) | ||
167 | break; | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | return nRecs; | ||
173 | } | ||
174 | |||
175 | /// <summary>Drop tables (listed as parameters). There is no "DROP IF EXISTS" syntax common for all | ||
176 | /// databases, so we just DROP and ignore an exception. | ||
177 | /// </summary> | ||
178 | /// <param name="tables"></param> | ||
179 | protected virtual void DropTables(params string[] tables) | ||
180 | { | ||
181 | foreach (string tbl in tables) | ||
182 | { | ||
183 | try | ||
184 | { | ||
185 | ExecuteSql("DROP TABLE " + tbl + ";"); | ||
186 | }catch | ||
187 | { | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | |||
192 | /// <summary>Clear tables listed as parameters (without dropping them). | ||
193 | /// </summary> | ||
194 | /// <param name="tables"></param> | ||
195 | protected virtual void ResetMigrations(params string[] stores) | ||
196 | { | ||
197 | string lst = ""; | ||
198 | foreach (string store in stores) | ||
199 | { | ||
200 | string s = "'" + store + "'"; | ||
201 | if (lst == "") | ||
202 | lst = s; | ||
203 | else | ||
204 | lst += ", " + s; | ||
205 | } | ||
206 | |||
207 | string sCond = stores.Length > 1 ? ("in (" + lst + ")") : ("=" + lst); | ||
208 | try | ||
209 | { | ||
210 | ExecuteSql("DELETE FROM migrations where name " + sCond); | ||
211 | } | ||
212 | catch | ||
213 | { | ||
214 | } | ||
215 | } | ||
216 | |||
217 | /// <summary>Clear tables listed as parameters (without dropping them). | ||
218 | /// </summary> | ||
219 | /// <param name="tables"></param> | ||
220 | protected virtual void ClearTables(params string[] tables) | ||
221 | { | ||
222 | foreach (string tbl in tables) | ||
223 | { | ||
224 | try | ||
225 | { | ||
226 | ExecuteSql("DELETE FROM " + tbl + ";"); | ||
227 | } | ||
228 | catch | ||
229 | { | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
diff --git a/OpenSim/Data/Tests/DefaultTestConns.cs b/OpenSim/Data/Tests/DefaultTestConns.cs new file mode 100644 index 0000000..7b52af5 --- /dev/null +++ b/OpenSim/Data/Tests/DefaultTestConns.cs | |||
@@ -0,0 +1,63 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Linq; | ||
4 | using System.Text; | ||
5 | using System.Reflection; | ||
6 | using System.IO; | ||
7 | using Nini.Config; | ||
8 | |||
9 | namespace OpenSim.Data.Tests | ||
10 | { | ||
11 | /// <summary>This static class looks for TestDataConnections.ini file in the /bin directory to obtain | ||
12 | /// a connection string for testing one of the supported databases. | ||
13 | /// The connections must be in the section [TestConnections] with names matching the connection class | ||
14 | /// name for the specific database, e.g.: | ||
15 | /// | ||
16 | /// [TestConnections] | ||
17 | /// MySqlConnection="..." | ||
18 | /// SqlConnection="..." | ||
19 | /// SqliteConnection="..." | ||
20 | /// | ||
21 | /// Note that the conn string may also be set explicitly in the [TestCase()] attribute of test classes | ||
22 | /// based on BasicDataServiceTest.cs. | ||
23 | /// </summary> | ||
24 | |||
25 | static class DefaultTestConns | ||
26 | { | ||
27 | private static Dictionary<Type, string> conns = new Dictionary<Type, string>(); | ||
28 | |||
29 | public static string Get(Type connType) | ||
30 | { | ||
31 | string sConn; | ||
32 | |||
33 | if (conns.TryGetValue(connType, out sConn)) | ||
34 | return sConn; | ||
35 | |||
36 | Assembly asm = Assembly.GetExecutingAssembly(); | ||
37 | string sType = connType.Name; | ||
38 | |||
39 | // Note: when running from NUnit, the DLL is located in some temp dir, so how do we get | ||
40 | // to the INI file? Ok, so put it into the resources! | ||
41 | // string iniName = Path.Combine(Path.GetDirectoryName(asm.Location), "TestDataConnections.ini"); | ||
42 | |||
43 | string[] allres = asm.GetManifestResourceNames(); | ||
44 | string sResFile = Array.Find(allres, s => s.Contains("TestDataConnections.ini")); | ||
45 | |||
46 | if (String.IsNullOrEmpty(sResFile)) | ||
47 | throw new Exception(String.Format("Please add resource TestDataConnections.ini, with section [TestConnections] and settings like {0}=\"...\"", | ||
48 | sType)); | ||
49 | |||
50 | using (Stream resource = asm.GetManifestResourceStream(sResFile)) | ||
51 | { | ||
52 | IConfigSource source = new IniConfigSource(resource); | ||
53 | var cfg = source.Configs["TestConnections"]; | ||
54 | sConn = cfg.Get(sType, ""); | ||
55 | } | ||
56 | |||
57 | if (!String.IsNullOrEmpty(sConn)) | ||
58 | conns[connType] = sConn; | ||
59 | |||
60 | return sConn; | ||
61 | } | ||
62 | } | ||
63 | } | ||
diff --git a/OpenSim/Data/Tests/BasicEstateTest.cs b/OpenSim/Data/Tests/EstateTests.cs index d14d405..d6eed3d 100644 --- a/OpenSim/Data/Tests/BasicEstateTest.cs +++ b/OpenSim/Data/Tests/EstateTests.cs | |||
@@ -35,13 +35,57 @@ using OpenSim.Region.Framework.Interfaces; | |||
35 | using System.Text; | 35 | using System.Text; |
36 | using log4net; | 36 | using log4net; |
37 | using System.Reflection; | 37 | using System.Reflection; |
38 | using System.Data.Common; | ||
39 | |||
40 | #if !NUNIT25 | ||
41 | using NUnit.Framework.SyntaxHelpers; | ||
42 | #endif | ||
43 | |||
44 | |||
45 | // DBMS-specific: | ||
46 | using MySql.Data.MySqlClient; | ||
47 | using OpenSim.Data.MySQL; | ||
48 | |||
49 | using System.Data.SqlClient; | ||
50 | using OpenSim.Data.MSSQL; | ||
51 | |||
52 | using Mono.Data.Sqlite; | ||
53 | using OpenSim.Data.SQLite; | ||
54 | |||
38 | 55 | ||
39 | namespace OpenSim.Data.Tests | 56 | namespace OpenSim.Data.Tests |
40 | { | 57 | { |
41 | public class BasicEstateTest | 58 | |
59 | #if NUNIT25 | ||
60 | |||
61 | [TestFixture(typeof(MySqlConnection), typeof(MySQLEstateStore), Description = "Estate store tests (MySQL)")] | ||
62 | [TestFixture(typeof(SqlConnection), typeof(MSSQLEstateStore), Description = "Estate store tests (MS SQL Server)")] | ||
63 | [TestFixture(typeof(SqliteConnection), typeof(SQLiteEstateStore), Description = "Estate store tests (SQLite)")] | ||
64 | |||
65 | #else | ||
66 | |||
67 | [TestFixture(Description = "Estate store tests (SQLite)")] | ||
68 | public class SQLiteEstateTests : EstateTests<SqliteConnection, SQLiteEstateStore> | ||
69 | { | ||
70 | } | ||
71 | |||
72 | [TestFixture(Description = "Estate store tests (MySQL)")] | ||
73 | public class MySqlEstateTests : EstateTests<MySqlConnection, MySQLEstateStore> | ||
74 | { | ||
75 | } | ||
76 | |||
77 | [TestFixture(Description = "Estate store tests (MS SQL Server)")] | ||
78 | public class MSSQLEstateTests : EstateTests<SqlConnection, MSSQLEstateStore> | ||
79 | { | ||
80 | } | ||
81 | |||
82 | #endif | ||
83 | |||
84 | public class EstateTests<TConn, TEstateStore> : BasicDataServiceTest<TConn, TEstateStore> | ||
85 | where TConn : DbConnection, new() | ||
86 | where TEstateStore : class, IEstateDataStore, new() | ||
42 | { | 87 | { |
43 | public IEstateDataStore db; | 88 | public IEstateDataStore db; |
44 | public IRegionDataStore regionDb; | ||
45 | 89 | ||
46 | public static UUID REGION_ID = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed7"); | 90 | public static UUID REGION_ID = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed7"); |
47 | 91 | ||
@@ -54,9 +98,25 @@ namespace OpenSim.Data.Tests | |||
54 | public static UUID GROUP_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed5"); | 98 | public static UUID GROUP_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed5"); |
55 | public static UUID GROUP_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed6"); | 99 | public static UUID GROUP_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed6"); |
56 | 100 | ||
57 | public void SuperInit() | 101 | protected override void InitService(object service) |
102 | { | ||
103 | ClearDB(); | ||
104 | db = (IEstateDataStore)service; | ||
105 | db.Initialise(m_connStr); | ||
106 | } | ||
107 | |||
108 | private void ClearDB() | ||
58 | { | 109 | { |
59 | OpenSim.Tests.Common.TestLogging.LogToConsole(); | 110 | // if a new table is added, it has to be dropped here |
111 | DropTables( | ||
112 | "estate_managers", | ||
113 | "estate_groups", | ||
114 | "estate_users", | ||
115 | "estateban", | ||
116 | "estate_settings", | ||
117 | "estate_map" | ||
118 | ); | ||
119 | ResetMigrations("EstateStore"); | ||
60 | } | 120 | } |
61 | 121 | ||
62 | #region 0Tests | 122 | #region 0Tests |
@@ -292,8 +352,7 @@ namespace OpenSim.Data.Tests | |||
292 | // Letting estate store generate rows to database for us | 352 | // Letting estate store generate rows to database for us |
293 | EstateSettings originalSettings = db.LoadEstateSettings(regionId, true); | 353 | EstateSettings originalSettings = db.LoadEstateSettings(regionId, true); |
294 | 354 | ||
295 | SetEstateSettings( | 355 | SetEstateSettings(originalSettings, |
296 | originalSettings, | ||
297 | estateName, | 356 | estateName, |
298 | parentEstateID, | 357 | parentEstateID, |
299 | billableFactor, | 358 | billableFactor, |
@@ -319,30 +378,6 @@ namespace OpenSim.Data.Tests | |||
319 | estateOwner | 378 | estateOwner |
320 | ); | 379 | ); |
321 | 380 | ||
322 | originalSettings.EstateName = estateName; | ||
323 | originalSettings.ParentEstateID = parentEstateID; | ||
324 | originalSettings.BillableFactor = billableFactor; | ||
325 | originalSettings.PricePerMeter = pricePerMeter; | ||
326 | originalSettings.RedirectGridX = redirectGridX; | ||
327 | originalSettings.RedirectGridY = redirectGridY; | ||
328 | originalSettings.UseGlobalTime = useGlobalTime; | ||
329 | originalSettings.FixedSun = fixedSun; | ||
330 | originalSettings.SunPosition = sunPosition; | ||
331 | originalSettings.AllowVoice = allowVoice; | ||
332 | originalSettings.AllowDirectTeleport = allowDirectTeleport; | ||
333 | originalSettings.ResetHomeOnTeleport = resetHomeOnTeleport; | ||
334 | originalSettings.DenyAnonymous = denyAnonymous; | ||
335 | originalSettings.DenyIdentified = denyIdentified; | ||
336 | originalSettings.DenyTransacted = denyTransacted; | ||
337 | originalSettings.DenyMinors = denyMinors; | ||
338 | originalSettings.AbuseEmailToEstateOwner = abuseEmailToEstateOwner; | ||
339 | originalSettings.BlockDwell = blockDwell; | ||
340 | originalSettings.EstateSkipScripts = estateSkipScripts; | ||
341 | originalSettings.TaxFree = taxFree; | ||
342 | originalSettings.PublicAccess = publicAccess; | ||
343 | originalSettings.AbuseEmail = abuseEmail; | ||
344 | originalSettings.EstateOwner = estateOwner; | ||
345 | |||
346 | // Saving settings. | 381 | // Saving settings. |
347 | db.StoreEstateSettings(originalSettings); | 382 | db.StoreEstateSettings(originalSettings); |
348 | 383 | ||
@@ -350,8 +385,7 @@ namespace OpenSim.Data.Tests | |||
350 | EstateSettings loadedSettings = db.LoadEstateSettings(regionId, true); | 385 | EstateSettings loadedSettings = db.LoadEstateSettings(regionId, true); |
351 | 386 | ||
352 | // Checking that loaded values are correct. | 387 | // Checking that loaded values are correct. |
353 | ValidateEstateSettings( | 388 | ValidateEstateSettings(loadedSettings, |
354 | loadedSettings, | ||
355 | estateName, | 389 | estateName, |
356 | parentEstateID, | 390 | parentEstateID, |
357 | billableFactor, | 391 | billableFactor, |
diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/InventoryTests.cs index 900186b..c22e26c 100644 --- a/OpenSim/Data/Tests/BasicInventoryTest.cs +++ b/OpenSim/Data/Tests/InventoryTests.cs | |||
@@ -25,6 +25,8 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | // #define NUNIT25 | ||
29 | |||
28 | using System; | 30 | using System; |
29 | using log4net.Config; | 31 | using log4net.Config; |
30 | using NUnit.Framework; | 32 | using NUnit.Framework; |
@@ -33,62 +35,95 @@ using OpenMetaverse; | |||
33 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
34 | using log4net; | 36 | using log4net; |
35 | using System.Reflection; | 37 | using System.Reflection; |
38 | using System.Data.Common; | ||
39 | |||
40 | #if !NUNIT25 | ||
41 | using NUnit.Framework.SyntaxHelpers; | ||
42 | #endif | ||
43 | |||
44 | // DBMS-specific: | ||
45 | using MySql.Data.MySqlClient; | ||
46 | using OpenSim.Data.MySQL; | ||
47 | |||
48 | using System.Data.SqlClient; | ||
49 | using OpenSim.Data.MSSQL; | ||
50 | |||
51 | using Mono.Data.Sqlite; | ||
52 | using OpenSim.Data.SQLite; | ||
36 | 53 | ||
37 | namespace OpenSim.Data.Tests | 54 | namespace OpenSim.Data.Tests |
38 | { | 55 | { |
39 | public class BasicInventoryTest | 56 | #if NUNIT25 |
57 | |||
58 | [TestFixture(typeof(SqliteConnection), typeof(SQLiteInventoryStore), Description = "Inventory store tests (SQLite)")] | ||
59 | [TestFixture(typeof(MySqlConnection), typeof(MySQLInventoryData), Description = "Inventory store tests (MySQL)")] | ||
60 | [TestFixture(typeof(SqlConnection), typeof(MSSQLInventoryData), Description = "Inventory store tests (MS SQL Server)")] | ||
61 | |||
62 | #else | ||
63 | |||
64 | [TestFixture(Description = "Inventory store tests (SQLite)")] | ||
65 | public class SQLiteInventoryTests : InventoryTests<SqliteConnection, SQLiteInventoryStore> | ||
66 | { | ||
67 | } | ||
68 | |||
69 | [TestFixture(Description = "Inventory store tests (MySQL)")] | ||
70 | public class MySqlInventoryTests : InventoryTests<MySqlConnection, MySQLInventoryData> | ||
71 | { | ||
72 | } | ||
73 | |||
74 | [TestFixture(Description = "Inventory store tests (MS SQL Server)")] | ||
75 | public class MSSQLInventoryTests : InventoryTests<SqlConnection, MSSQLInventoryData> | ||
76 | { | ||
77 | } | ||
78 | #endif | ||
79 | |||
80 | public class InventoryTests<TConn, TInvStore> : BasicDataServiceTest<TConn, TInvStore> | ||
81 | where TConn : DbConnection, new() | ||
82 | where TInvStore : class, IInventoryDataPlugin, new() | ||
40 | { | 83 | { |
41 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | public IInventoryDataPlugin db; | 84 | public IInventoryDataPlugin db; |
85 | |||
43 | public UUID zero = UUID.Zero; | 86 | public UUID zero = UUID.Zero; |
44 | 87 | ||
45 | public UUID folder1; | 88 | public UUID folder1 = UUID.Random(); |
46 | public UUID folder2; | 89 | public UUID folder2 = UUID.Random(); |
47 | public UUID folder3; | 90 | public UUID folder3 = UUID.Random(); |
48 | public UUID owner1; | 91 | public UUID owner1 = UUID.Random(); |
49 | public UUID owner2; | 92 | public UUID owner2 = UUID.Random(); |
50 | public UUID owner3; | 93 | public UUID owner3 = UUID.Random(); |
51 | 94 | ||
52 | public UUID item1; | 95 | public UUID item1 = UUID.Random(); |
53 | public UUID item2; | 96 | public UUID item2 = UUID.Random(); |
54 | public UUID item3; | 97 | public UUID item3 = UUID.Random(); |
55 | public UUID asset1; | 98 | public UUID asset1 = UUID.Random(); |
56 | public UUID asset2; | 99 | public UUID asset2 = UUID.Random(); |
57 | public UUID asset3; | 100 | public UUID asset3 = UUID.Random(); |
58 | 101 | ||
59 | public string name1; | 102 | public string name1; |
60 | public string name2; | 103 | public string name2 = "First Level folder"; |
61 | public string name3; | 104 | public string name3 = "First Level folder 2"; |
62 | public string niname1; | 105 | public string niname1 = "My Shirt"; |
63 | public string iname1; | 106 | public string iname1 = "Shirt"; |
64 | public string iname2; | 107 | public string iname2 = "Text Board"; |
65 | public string iname3; | 108 | public string iname3 = "No Pants Barrel"; |
66 | 109 | ||
67 | public void SuperInit() | 110 | public InventoryTests(string conn) : base(conn) |
68 | { | 111 | { |
69 | OpenSim.Tests.Common.TestLogging.LogToConsole(); | ||
70 | |||
71 | folder1 = UUID.Random(); | ||
72 | folder2 = UUID.Random(); | ||
73 | folder3 = UUID.Random(); | ||
74 | owner1 = UUID.Random(); | ||
75 | owner2 = UUID.Random(); | ||
76 | owner3 = UUID.Random(); | ||
77 | item1 = UUID.Random(); | ||
78 | item2 = UUID.Random(); | ||
79 | item3 = UUID.Random(); | ||
80 | asset1 = UUID.Random(); | ||
81 | asset2 = UUID.Random(); | ||
82 | asset3 = UUID.Random(); | ||
83 | |||
84 | name1 = "Root Folder for " + owner1.ToString(); | 112 | name1 = "Root Folder for " + owner1.ToString(); |
85 | name2 = "First Level folder"; | 113 | } |
86 | name3 = "First Level folder 2"; | 114 | public InventoryTests() : this("") { } |
87 | niname1 = "My Shirt"; | ||
88 | iname1 = "Shirt"; | ||
89 | iname2 = "Text Board"; | ||
90 | iname3 = "No Pants Barrel"; | ||
91 | 115 | ||
116 | protected override void InitService(object service) | ||
117 | { | ||
118 | ClearDB(); | ||
119 | db = (IInventoryDataPlugin)service; | ||
120 | db.Initialise(m_connStr); | ||
121 | } | ||
122 | |||
123 | private void ClearDB() | ||
124 | { | ||
125 | DropTables("inventoryitems", "inventoryfolders"); | ||
126 | ResetMigrations("InventoryStore"); | ||
92 | } | 127 | } |
93 | 128 | ||
94 | [Test] | 129 | [Test] |
@@ -159,8 +194,10 @@ namespace OpenSim.Data.Tests | |||
159 | [Test] | 194 | [Test] |
160 | public void T013_FolderHierarchy() | 195 | public void T013_FolderHierarchy() |
161 | { | 196 | { |
162 | Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))"); | 197 | int n = db.getFolderHierarchy(zero).Count; // (for dbg - easier to see what's returned) |
163 | Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))"); | 198 | Assert.That(n, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))"); |
199 | n = db.getFolderHierarchy(folder1).Count; | ||
200 | Assert.That(n, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))"); | ||
164 | Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))"); | 201 | Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))"); |
165 | Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0))"); | 202 | Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0))"); |
166 | Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))"); | 203 | Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))"); |
diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/RegionTests.cs index dfbf522..1f654d3 100644 --- a/OpenSim/Data/Tests/BasicRegionTest.cs +++ b/OpenSim/Data/Tests/RegionTests.cs | |||
@@ -38,59 +38,112 @@ using OpenSim.Region.Framework.Interfaces; | |||
38 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | using log4net; | 39 | using log4net; |
40 | using System.Reflection; | 40 | using System.Reflection; |
41 | using System.Data.Common; | ||
42 | |||
43 | #if !NUNIT25 | ||
44 | using NUnit.Framework.SyntaxHelpers; | ||
45 | #endif | ||
46 | |||
47 | // DBMS-specific: | ||
48 | using MySql.Data.MySqlClient; | ||
49 | using OpenSim.Data.MySQL; | ||
50 | |||
51 | using System.Data.SqlClient; | ||
52 | using OpenSim.Data.MSSQL; | ||
53 | |||
54 | using Mono.Data.Sqlite; | ||
55 | using OpenSim.Data.SQLite; | ||
41 | 56 | ||
42 | namespace OpenSim.Data.Tests | 57 | namespace OpenSim.Data.Tests |
43 | { | 58 | { |
44 | public class BasicRegionTest | 59 | #if NUNIT25 |
60 | |||
61 | [TestFixture(typeof(SqliteConnection), typeof(SQLiteRegionData), Description = "Region store tests (SQLite)")] | ||
62 | [TestFixture(typeof(MySqlConnection), typeof(MySqlRegionData), Description = "Region store tests (MySQL)")] | ||
63 | [TestFixture(typeof(SqlConnection), typeof(MSSQLRegionData), Description = "Region store tests (MS SQL Server)")] | ||
64 | |||
65 | #else | ||
66 | |||
67 | [TestFixture(Description = "Region store tests (SQLite)")] | ||
68 | public class SQLiteRegionTests : RegionTests<SqliteConnection, SQLiteRegionData> | ||
69 | { | ||
70 | } | ||
71 | |||
72 | [TestFixture(Description = "Region store tests (MySQL)")] | ||
73 | public class MySqlRegionTests : RegionTests<MySqlConnection, MySQLDataStore> | ||
45 | { | 74 | { |
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 75 | } |
76 | |||
77 | [TestFixture(Description = "Region store tests (MS SQL Server)")] | ||
78 | public class MSSQLRegionTests : RegionTests<SqlConnection, MSSQLRegionDataStore> | ||
79 | { | ||
80 | } | ||
81 | |||
82 | #endif | ||
83 | |||
84 | public class RegionTests<TConn, TRegStore> : BasicDataServiceTest<TConn, TRegStore> | ||
85 | where TConn : DbConnection, new() | ||
86 | where TRegStore : class, IRegionDataStore, new() | ||
87 | { | ||
88 | bool m_rebuildDB; | ||
89 | |||
47 | public IRegionDataStore db; | 90 | public IRegionDataStore db; |
48 | public UUID zero = UUID.Zero; | 91 | public UUID zero = UUID.Zero; |
49 | public UUID region1; | 92 | public UUID region1 = UUID.Random(); |
50 | public UUID region2; | 93 | public UUID region2 = UUID.Random(); |
51 | public UUID region3; | 94 | public UUID region3 = UUID.Random(); |
52 | public UUID region4; | 95 | public UUID region4 = UUID.Random(); |
53 | public UUID prim1; | 96 | public UUID prim1 = UUID.Random(); |
54 | public UUID prim2; | 97 | public UUID prim2 = UUID.Random(); |
55 | public UUID prim3; | 98 | public UUID prim3 = UUID.Random(); |
56 | public UUID prim4; | 99 | public UUID prim4 = UUID.Random(); |
57 | public UUID prim5; | 100 | public UUID prim5 = UUID.Random(); |
58 | public UUID prim6; | 101 | public UUID prim6 = UUID.Random(); |
59 | public UUID item1; | 102 | public UUID item1 = UUID.Random(); |
60 | public UUID item2; | 103 | public UUID item2 = UUID.Random(); |
61 | public UUID item3; | 104 | public UUID item3 = UUID.Random(); |
62 | 105 | ||
63 | public static Random random; | 106 | public static Random random = new Random(); |
64 | 107 | ||
65 | public string itemname1 = "item1"; | 108 | public string itemname1 = "item1"; |
66 | 109 | ||
67 | public uint localID; | 110 | public uint localID = 1; |
68 | 111 | ||
69 | public double height1; | 112 | public double height1 = 20; |
70 | public double height2; | 113 | public double height2 = 100; |
71 | 114 | ||
72 | public void SuperInit() | 115 | public RegionTests(string conn, bool rebuild) |
116 | : base(conn) | ||
73 | { | 117 | { |
74 | OpenSim.Tests.Common.TestLogging.LogToConsole(); | 118 | m_rebuildDB = rebuild; |
75 | |||
76 | region1 = UUID.Random(); | ||
77 | region3 = UUID.Random(); | ||
78 | region4 = UUID.Random(); | ||
79 | prim1 = UUID.Random(); | ||
80 | prim2 = UUID.Random(); | ||
81 | prim3 = UUID.Random(); | ||
82 | prim4 = UUID.Random(); | ||
83 | prim5 = UUID.Random(); | ||
84 | prim6 = UUID.Random(); | ||
85 | item1 = UUID.Random(); | ||
86 | item2 = UUID.Random(); | ||
87 | item3 = UUID.Random(); | ||
88 | random = new Random(); | ||
89 | localID = 1; | ||
90 | height1 = 20; | ||
91 | height2 = 100; | ||
92 | } | 119 | } |
93 | 120 | ||
121 | public RegionTests() : this("", true) { } | ||
122 | public RegionTests(string conn) : this(conn, true) {} | ||
123 | public RegionTests(bool rebuild): this("", rebuild) {} | ||
124 | |||
125 | |||
126 | protected override void InitService(object service) | ||
127 | { | ||
128 | ClearDB(); | ||
129 | db = (IRegionDataStore)service; | ||
130 | db.Initialise(m_connStr); | ||
131 | } | ||
132 | |||
133 | private void ClearDB() | ||
134 | { | ||
135 | string[] reg_tables = new string[] { | ||
136 | "prims", "primshapes", "primitems", "terrain", "land", "landaccesslist", "regionban", "regionsettings" | ||
137 | }; | ||
138 | if (m_rebuildDB) | ||
139 | { | ||
140 | DropTables(reg_tables); | ||
141 | ResetMigrations("RegionStore"); | ||
142 | }else | ||
143 | ClearTables(reg_tables); | ||
144 | } | ||
145 | |||
146 | |||
94 | // Test Plan | 147 | // Test Plan |
95 | // Prims | 148 | // Prims |
96 | // - empty test - 001 | 149 | // - empty test - 001 |
@@ -580,68 +633,88 @@ namespace OpenSim.Data.Tests | |||
580 | .IgnoreProperty(x=>x.PassCollision) | 633 | .IgnoreProperty(x=>x.PassCollision) |
581 | .IgnoreProperty(x=>x.RootPart)); | 634 | .IgnoreProperty(x=>x.RootPart)); |
582 | } | 635 | } |
636 | |||
637 | |||
638 | private SceneObjectGroup GetMySOG(string name) | ||
639 | { | ||
640 | SceneObjectGroup sog = FindSOG(name, region1); | ||
641 | if (sog == null) | ||
642 | { | ||
643 | sog = NewSOG(name, prim1, region1); | ||
644 | db.StoreObject(sog, region1); | ||
645 | } | ||
646 | return sog; | ||
647 | } | ||
583 | 648 | ||
649 | |||
650 | // NOTE: it is a bad practice to rely on some of the previous tests having been run before. | ||
651 | // If the tests are run manually, one at a time, each starts with full class init (DB cleared). | ||
652 | // Even when all tests are run, NUnit 2.5+ no longer guarantee a specific test order. | ||
653 | // We shouldn't expect to find anything in the DB if we haven't put it there *in the same test*! | ||
654 | |||
584 | [Test] | 655 | [Test] |
585 | public void T020_PrimInventoryEmpty() | 656 | public void T020_PrimInventoryEmpty() |
586 | { | 657 | { |
587 | SceneObjectGroup sog = FindSOG("object1", region1); | 658 | SceneObjectGroup sog = GetMySOG("object1"); |
588 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | 659 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); |
589 | Assert.That(t, Is.Null); | 660 | Assert.That(t, Is.Null); |
590 | } | 661 | } |
591 | 662 | ||
592 | [Test] | 663 | // TODO: Is there any point to call StorePrimInventory on a list, rather than on the prim itself? |
593 | public void T021_PrimInventoryStore() | ||
594 | { | ||
595 | SceneObjectGroup sog = FindSOG("object1", region1); | ||
596 | InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero); | ||
597 | |||
598 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); | ||
599 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | ||
600 | Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
601 | |||
602 | // TODO: seriously??? this is the way we need to loop to get this? | ||
603 | 664 | ||
665 | private void StoreInventory(SceneObjectGroup sog) | ||
666 | { | ||
604 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); | 667 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); |
668 | // TODO: seriously??? this is the way we need to loop to get this? | ||
605 | foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList()) | 669 | foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList()) |
606 | { | 670 | { |
607 | list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid)); | 671 | list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid)); |
608 | } | 672 | } |
609 | 673 | ||
610 | db.StorePrimInventory(prim1, list); | 674 | db.StorePrimInventory(sog.RootPart.UUID, list); |
611 | } | 675 | } |
612 | 676 | ||
613 | [Test] | ||
614 | public void T022_PrimInventoryRetrieve() | ||
615 | { | ||
616 | SceneObjectGroup sog = FindSOG("object1", region1); | ||
617 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | ||
618 | 677 | ||
619 | Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
620 | } | ||
621 | |||
622 | [Test] | 678 | [Test] |
623 | public void T023_PrimInventoryUpdate() | 679 | public void T021_PrimInventoryBasic() |
624 | { | 680 | { |
625 | SceneObjectGroup sog = FindSOG("object1", region1); | 681 | SceneObjectGroup sog = GetMySOG("object1"); |
682 | InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero); | ||
683 | |||
684 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); | ||
626 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | 685 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); |
686 | Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
627 | 687 | ||
628 | t.Name = "My New Name"; | 688 | StoreInventory(sog); |
629 | sog.UpdateInventoryItem(t); | ||
630 | 689 | ||
631 | Assert.That(t.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))"); | 690 | SceneObjectGroup sog1 = FindSOG("object1", region1); |
691 | Assert.That(sog1, Is.Not.Null); | ||
632 | 692 | ||
633 | } | 693 | TaskInventoryItem t1 = sog1.GetInventoryItem(sog1.RootPart.LocalId, item1); |
694 | Assert.That(t1, Is.Not.Null); | ||
695 | Assert.That(t1.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
696 | |||
697 | // Updating inventory | ||
698 | t1.Name = "My New Name"; | ||
699 | sog1.UpdateInventoryItem(t1); | ||
700 | |||
701 | StoreInventory(sog1); | ||
702 | |||
703 | SceneObjectGroup sog2 = FindSOG("object1", region1); | ||
704 | TaskInventoryItem t2 = sog2.GetInventoryItem(sog2.RootPart.LocalId, item1); | ||
705 | Assert.That(t2.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))"); | ||
706 | |||
707 | // Removing inventory | ||
634 | 708 | ||
635 | [Test] | ||
636 | public void T024_PrimInventoryRemove() | ||
637 | { | ||
638 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); | 709 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); |
639 | db.StorePrimInventory(prim1, list); | 710 | db.StorePrimInventory(prim1, list); |
640 | 711 | ||
641 | SceneObjectGroup sog = FindSOG("object1", region1); | 712 | sog = FindSOG("object1", region1); |
642 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | 713 | t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); |
643 | Assert.That(t, Is.Null); | 714 | Assert.That(t, Is.Null); |
715 | |||
644 | } | 716 | } |
717 | |||
645 | 718 | ||
646 | [Test] | 719 | [Test] |
647 | public void T025_PrimInventoryPersistency() | 720 | public void T025_PrimInventoryPersistency() |
@@ -685,7 +758,7 @@ namespace OpenSim.Data.Tests | |||
685 | int creationd = random.Next(); | 758 | int creationd = random.Next(); |
686 | i.CreationDate = creationd; | 759 | i.CreationDate = creationd; |
687 | 760 | ||
688 | SceneObjectGroup sog = FindSOG("object1", region1); | 761 | SceneObjectGroup sog = GetMySOG("object1"); |
689 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); | 762 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); |
690 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id); | 763 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id); |
691 | 764 | ||
diff --git a/OpenSim/Data/Tests/Resources/TestDataConnections.ini b/OpenSim/Data/Tests/Resources/TestDataConnections.ini new file mode 100644 index 0000000..5e68ab0 --- /dev/null +++ b/OpenSim/Data/Tests/Resources/TestDataConnections.ini | |||
@@ -0,0 +1,24 @@ | |||
1 | ; The default connections to the test databases. Used by all data tests based on BasicDataServiceTest.cs. | ||
2 | ; This is read by code in DefaultTestConns.cs. | ||
3 | |||
4 | ; NOTE that this INI file is currently loaded as a embedded RESOURCE, which is weird and has a | ||
5 | ; disadvantage of having to rebuild the Tests whenever the conn strings are changed. | ||
6 | ; The only reason is that I couldn't figure out a reliable way to put this INI into the correct | ||
7 | ; dir at runtime. If somebody can do it, that would be cool. | ||
8 | |||
9 | ; I'm using a local MSDE server for testing. Obviously, you'll have to modify | ||
10 | ; the conn string to whatever MS SQL server is available to you. | ||
11 | |||
12 | ; If any of the conn strings is commented out, emty or not valid on your system, | ||
13 | ; the relevant tests will be ignored, rather than fail. | ||
14 | |||
15 | ; As to SQLite, if the conn string here is empty, it will work anyway using a temporary | ||
16 | ; file for the DB. If you want the resulting DB to persist (e.g. for performance testing, | ||
17 | ; when filling up the tables can take a long time), explicitly specify a conn string like this: | ||
18 | |||
19 | ; SqliteConnection="URI=file:<path_to_your_file>,version=3" | ||
20 | |||
21 | [TestConnections] | ||
22 | MySqlConnection="Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;" | ||
23 | SqlConnection="Server=.\SQL2008;Database=opensim-nunit;Trusted_Connection=True;" | ||
24 | SqliteConnection="" \ No newline at end of file | ||