diff options
author | Mike Rieker | 2010-05-27 21:31:10 -0400 |
---|---|---|
committer | Mike Rieker | 2010-05-27 21:31:10 -0400 |
commit | 9ea42fdfab2ac99e24b386d67a08cf0024230f54 (patch) | |
tree | fdefa445346d03ad2d73b62687ffae4e3b635ba9 /OpenSim/Data/Tests/AssetTests.cs | |
parent | fix hanging output throttle arithmetic (diff) | |
parent | Prevent a null ref (diff) | |
download | opensim-SC-9ea42fdfab2ac99e24b386d67a08cf0024230f54.zip opensim-SC-9ea42fdfab2ac99e24b386d67a08cf0024230f54.tar.gz opensim-SC-9ea42fdfab2ac99e24b386d67a08cf0024230f54.tar.bz2 opensim-SC-9ea42fdfab2ac99e24b386d67a08cf0024230f54.tar.xz |
Merge branch 'careminster-presence-refactor' of www.3dhosting.de:/var/git/careminster into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Data/Tests/AssetTests.cs')
-rw-r--r-- | OpenSim/Data/Tests/AssetTests.cs | 221 |
1 files changed, 221 insertions, 0 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 | } | ||