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