diff options
Diffstat (limited to 'OpenSim/Data/Tests/AssetTests.cs')
-rw-r--r-- | OpenSim/Data/Tests/AssetTests.cs | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/OpenSim/Data/Tests/AssetTests.cs b/OpenSim/Data/Tests/AssetTests.cs new file mode 100644 index 0000000..acd5449 --- /dev/null +++ b/OpenSim/Data/Tests/AssetTests.cs | |||
@@ -0,0 +1,161 @@ | |||
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 | // DBMS-specific: | ||
39 | using MySql.Data.MySqlClient; | ||
40 | using OpenSim.Data.MySQL; | ||
41 | |||
42 | using System.Data.SqlClient; | ||
43 | using OpenSim.Data.MSSQL; | ||
44 | |||
45 | using Mono.Data.Sqlite; | ||
46 | using OpenSim.Data.SQLite; | ||
47 | |||
48 | namespace OpenSim.Data.Tests | ||
49 | { | ||
50 | [TestFixture(typeof(MySqlConnection), typeof(MySQLAssetData), Description="Basic Asset store tests (MySQL)")] | ||
51 | [TestFixture(typeof(SqlConnection), typeof(MSSQLAssetData), Description = "Basic Asset store tests (MS SQL Server)")] | ||
52 | [TestFixture(typeof(SqliteConnection), typeof(SQLiteAssetData), Description = "Basic Asset store tests (SQLite)")] | ||
53 | |||
54 | public class AssetTests<TConn, TAssetData> : BasicDataServiceTest<TConn, TAssetData> | ||
55 | where TConn : DbConnection, new() | ||
56 | where TAssetData : AssetDataBase, new() | ||
57 | { | ||
58 | TAssetData m_db; | ||
59 | |||
60 | const bool COMPARE_CREATOR = false; | ||
61 | |||
62 | public UUID uuid1 = UUID.Random(); | ||
63 | public UUID uuid2 = UUID.Random(); | ||
64 | public UUID uuid3 = UUID.Random(); | ||
65 | |||
66 | public UUID critter1 = COMPARE_CREATOR ? UUID.Random() : UUID.Zero; | ||
67 | public UUID critter2 = COMPARE_CREATOR ? UUID.Random() : UUID.Zero; | ||
68 | public UUID critter3 = COMPARE_CREATOR ? UUID.Random() : UUID.Zero; | ||
69 | |||
70 | public byte[] data1 = new byte[100]; | ||
71 | |||
72 | PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>() | ||
73 | .DontScramble(x => x.ID) | ||
74 | .DontScramble(x => x.Type) | ||
75 | .DontScramble(x => x.FullID) | ||
76 | .DontScramble(x => x.Metadata.ID) | ||
77 | .DontScramble(x => x.Metadata.CreatorID) | ||
78 | .DontScramble(x => x.Metadata.ContentType) | ||
79 | .DontScramble(x => x.Metadata.FullID) | ||
80 | .DontScramble(x => x.Data); | ||
81 | |||
82 | protected override void InitService(object service) | ||
83 | { | ||
84 | m_db = (TAssetData)service; | ||
85 | m_db.Initialise(m_connStr); | ||
86 | } | ||
87 | |||
88 | [Test] | ||
89 | public void T001_LoadEmpty() | ||
90 | { | ||
91 | Assert.That(m_db.ExistsAsset(uuid1), Is.False); | ||
92 | Assert.That(m_db.ExistsAsset(uuid2), Is.False); | ||
93 | Assert.That(m_db.ExistsAsset(uuid3), Is.False); | ||
94 | } | ||
95 | |||
96 | [Test] | ||
97 | public void T010_StoreReadVerifyAssets() | ||
98 | { | ||
99 | AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1.ToString()); | ||
100 | AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2.ToString()); | ||
101 | AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3.ToString()); | ||
102 | a1.Data = data1; | ||
103 | a2.Data = data1; | ||
104 | a3.Data = data1; | ||
105 | |||
106 | scrambler.Scramble(a1); | ||
107 | scrambler.Scramble(a2); | ||
108 | scrambler.Scramble(a3); | ||
109 | |||
110 | m_db.StoreAsset(a1); | ||
111 | m_db.StoreAsset(a2); | ||
112 | m_db.StoreAsset(a3); | ||
113 | |||
114 | AssetBase a1a = m_db.GetAsset(uuid1); | ||
115 | Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); | ||
116 | |||
117 | AssetBase a2a = m_db.GetAsset(uuid2); | ||
118 | Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); | ||
119 | |||
120 | AssetBase a3a = m_db.GetAsset(uuid3); | ||
121 | Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); | ||
122 | |||
123 | scrambler.Scramble(a1a); | ||
124 | scrambler.Scramble(a2a); | ||
125 | scrambler.Scramble(a3a); | ||
126 | |||
127 | m_db.StoreAsset(a1a); | ||
128 | m_db.StoreAsset(a2a); | ||
129 | m_db.StoreAsset(a3a); | ||
130 | |||
131 | AssetBase a1b = m_db.GetAsset(uuid1); | ||
132 | Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); | ||
133 | |||
134 | AssetBase a2b = m_db.GetAsset(uuid2); | ||
135 | Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); | ||
136 | |||
137 | AssetBase a3b = m_db.GetAsset(uuid3); | ||
138 | Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); | ||
139 | |||
140 | Assert.That(m_db.ExistsAsset(uuid1), Is.True); | ||
141 | Assert.That(m_db.ExistsAsset(uuid2), Is.True); | ||
142 | Assert.That(m_db.ExistsAsset(uuid3), Is.True); | ||
143 | |||
144 | List<AssetMetadata> metadatas = m_db.FetchAssetMetadataSet(0, 1000); | ||
145 | |||
146 | Assert.That(metadatas.Count >= 3, "FetchAssetMetadataSet() should have returned at least 3 assets!"); | ||
147 | |||
148 | // It is possible that the Asset table is filled with data, in which case we don't try to find "our" | ||
149 | // assets there: | ||
150 | if (metadatas.Count < 1000) | ||
151 | { | ||
152 | AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1); | ||
153 | Assert.That(metadata.Name, Is.EqualTo(a1b.Name)); | ||
154 | Assert.That(metadata.Description, Is.EqualTo(a1b.Description)); | ||
155 | Assert.That(metadata.Type, Is.EqualTo(a1b.Type)); | ||
156 | Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary)); | ||
157 | Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID)); | ||
158 | } | ||
159 | } | ||
160 | } | ||
161 | } | ||