opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 OpenSim.Tests.Common; |
||
36 | using System.Data.Common; |
||
37 | using log4net; |
||
38 | |||
39 | // DBMS-specific: |
||
40 | using MySql.Data.MySqlClient; |
||
41 | using OpenSim.Data.MySQL; |
||
42 | |||
43 | using System.Data.SqlClient; |
||
44 | using OpenSim.Data.MSSQL; |
||
45 | |||
46 | using Mono.Data.Sqlite; |
||
47 | using OpenSim.Data.SQLite; |
||
48 | |||
49 | namespace OpenSim.Data.Tests |
||
50 | { |
||
51 | [TestFixture(Description = "Asset store tests (SQLite)")] |
||
52 | public class SQLiteAssetTests : AssetTests<SqliteConnection, SQLiteAssetData> |
||
53 | { |
||
54 | } |
||
55 | |||
56 | [TestFixture(Description = "Asset store tests (MySQL)")] |
||
57 | public class MySqlAssetTests : AssetTests<MySqlConnection, MySQLAssetData> |
||
58 | { |
||
59 | } |
||
60 | |||
61 | [TestFixture(Description = "Asset store tests (MS SQL Server)")] |
||
62 | public class MSSQLAssetTests : AssetTests<SqlConnection, MSSQLAssetData> |
||
63 | { |
||
64 | } |
||
65 | |||
66 | public class AssetTests<TConn, TAssetData> : BasicDataServiceTest<TConn, TAssetData> |
||
67 | where TConn : DbConnection, new() |
||
68 | where TAssetData : AssetDataBase, new() |
||
69 | { |
||
70 | TAssetData m_db; |
||
71 | |||
72 | public UUID uuid1 = UUID.Random(); |
||
73 | public UUID uuid2 = UUID.Random(); |
||
74 | public UUID uuid3 = UUID.Random(); |
||
75 | |||
76 | public string critter1 = UUID.Random().ToString(); |
||
77 | public string critter2 = UUID.Random().ToString(); |
||
78 | public string critter3 = UUID.Random().ToString(); |
||
79 | |||
80 | public byte[] data1 = new byte[100]; |
||
81 | |||
82 | PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>() |
||
83 | .DontScramble(x => x.ID) |
||
84 | .DontScramble(x => x.Type) |
||
85 | .DontScramble(x => x.FullID) |
||
86 | .DontScramble(x => x.Metadata.ID) |
||
87 | .DontScramble(x => x.Metadata.CreatorID) |
||
88 | .DontScramble(x => x.Metadata.ContentType) |
||
89 | .DontScramble(x => x.Metadata.FullID) |
||
90 | .DontScramble(x => x.Data); |
||
91 | |||
92 | protected override void InitService(object service) |
||
93 | { |
||
94 | ClearDB(); |
||
95 | m_db = (TAssetData)service; |
||
96 | m_db.Initialise(m_connStr); |
||
97 | } |
||
98 | |||
99 | private void ClearDB() |
||
100 | { |
||
101 | DropTables("assets"); |
||
102 | ResetMigrations("AssetStore"); |
||
103 | } |
||
104 | |||
105 | |||
106 | [Test] |
||
107 | public void T001_LoadEmpty() |
||
108 | { |
||
109 | TestHelpers.InMethod(); |
||
110 | |||
111 | Assert.That(m_db.ExistsAsset(uuid1), Is.False); |
||
112 | Assert.That(m_db.ExistsAsset(uuid2), Is.False); |
||
113 | Assert.That(m_db.ExistsAsset(uuid3), Is.False); |
||
114 | } |
||
115 | |||
116 | [Test] |
||
117 | public void T010_StoreReadVerifyAssets() |
||
118 | { |
||
119 | TestHelpers.InMethod(); |
||
120 | |||
121 | AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1.ToString()); |
||
122 | AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2.ToString()); |
||
123 | AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3.ToString()); |
||
124 | a1.Data = data1; |
||
125 | a2.Data = data1; |
||
126 | a3.Data = data1; |
||
127 | |||
128 | scrambler.Scramble(a1); |
||
129 | scrambler.Scramble(a2); |
||
130 | scrambler.Scramble(a3); |
||
131 | |||
132 | m_db.StoreAsset(a1); |
||
133 | m_db.StoreAsset(a2); |
||
134 | m_db.StoreAsset(a3); |
||
135 | |||
136 | AssetBase a1a = m_db.GetAsset(uuid1); |
||
137 | Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); |
||
138 | |||
139 | AssetBase a2a = m_db.GetAsset(uuid2); |
||
140 | Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); |
||
141 | |||
142 | AssetBase a3a = m_db.GetAsset(uuid3); |
||
143 | Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); |
||
144 | |||
145 | scrambler.Scramble(a1a); |
||
146 | scrambler.Scramble(a2a); |
||
147 | scrambler.Scramble(a3a); |
||
148 | |||
149 | m_db.StoreAsset(a1a); |
||
150 | m_db.StoreAsset(a2a); |
||
151 | m_db.StoreAsset(a3a); |
||
152 | |||
153 | AssetBase a1b = m_db.GetAsset(uuid1); |
||
154 | Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); |
||
155 | |||
156 | AssetBase a2b = m_db.GetAsset(uuid2); |
||
157 | Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); |
||
158 | |||
159 | AssetBase a3b = m_db.GetAsset(uuid3); |
||
160 | Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); |
||
161 | |||
162 | Assert.That(m_db.ExistsAsset(uuid1), Is.True); |
||
163 | Assert.That(m_db.ExistsAsset(uuid2), Is.True); |
||
164 | Assert.That(m_db.ExistsAsset(uuid3), Is.True); |
||
165 | |||
166 | List<AssetMetadata> metadatas = m_db.FetchAssetMetadataSet(0, 1000); |
||
167 | |||
168 | Assert.That(metadatas.Count >= 3, "FetchAssetMetadataSet() should have returned at least 3 assets!"); |
||
169 | |||
170 | // It is possible that the Asset table is filled with data, in which case we don't try to find "our" |
||
171 | // assets there: |
||
172 | if (metadatas.Count < 1000) |
||
173 | { |
||
174 | AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1); |
||
175 | Assert.That(metadata.Name, Is.EqualTo(a1b.Name)); |
||
176 | Assert.That(metadata.Description, Is.EqualTo(a1b.Description)); |
||
177 | Assert.That(metadata.Type, Is.EqualTo(a1b.Type)); |
||
178 | Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary)); |
||
179 | Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID)); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | [Test] |
||
184 | public void T020_CheckForWeirdCreatorID() |
||
185 | { |
||
186 | TestHelpers.InMethod(); |
||
187 | |||
188 | // It is expected that eventually the CreatorID might be an arbitrary string (an URI) |
||
189 | // rather than a valid UUID (?). This test is to make sure that the database layer does not |
||
190 | // attempt to convert CreatorID to GUID, but just passes it both ways as a string. |
||
191 | AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1); |
||
192 | AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, "This is not a GUID!"); |
||
193 | AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, ""); |
||
194 | a1.Data = data1; |
||
195 | a2.Data = data1; |
||
196 | a3.Data = data1; |
||
197 | |||
198 | m_db.StoreAsset(a1); |
||
199 | m_db.StoreAsset(a2); |
||
200 | m_db.StoreAsset(a3); |
||
201 | |||
202 | AssetBase a1a = m_db.GetAsset(uuid1); |
||
203 | Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); |
||
204 | |||
205 | AssetBase a2a = m_db.GetAsset(uuid2); |
||
206 | Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); |
||
207 | |||
208 | AssetBase a3a = m_db.GetAsset(uuid3); |
||
209 | Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); |
||
210 | } |
||
211 | } |
||
212 | } |