diff options
author | Sean Dague | 2008-09-12 16:05:06 +0000 |
---|---|---|
committer | Sean Dague | 2008-09-12 16:05:06 +0000 |
commit | 96c720b04a7e96b4ebcada71484d183f503a785e (patch) | |
tree | 775940e0797201e18f4ef179e8b8fb20ca3aa102 /OpenSim | |
parent | add the m_host.AddScriptLPS(1); line. I'm not actually sure what it (diff) | |
download | opensim-SC-96c720b04a7e96b4ebcada71484d183f503a785e.zip opensim-SC-96c720b04a7e96b4ebcada71484d183f503a785e.tar.gz opensim-SC-96c720b04a7e96b4ebcada71484d183f503a785e.tar.bz2 opensim-SC-96c720b04a7e96b4ebcada71484d183f503a785e.tar.xz |
be more clever and move the bulk of the db tests for inventory into
OpenSim.Data.Tests, then subclass with custom init bits for sqlite.
As I've only been testing the plugin interfaces anyway, this should
make it very easy to write only a little bit of code to use these
tests for other databases. It will also give us the framework for
definining the datastore behavior and making sure that all the databases
do the same thing.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs | 143 | ||||
-rw-r--r-- | OpenSim/Data/Tests/BasicInventoryTests.cs | 184 |
2 files changed, 187 insertions, 140 deletions
diff --git a/OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs b/OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs index 4bc1b9a..ee6732b 100644 --- a/OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs +++ b/OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs | |||
@@ -30,6 +30,7 @@ using System.Collections.Generic; | |||
30 | using NUnit.Framework; | 30 | using NUnit.Framework; |
31 | using NUnit.Framework.SyntaxHelpers; | 31 | using NUnit.Framework.SyntaxHelpers; |
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Data.Tests; | ||
33 | using OpenSim.Data.SQLite; | 34 | using OpenSim.Data.SQLite; |
34 | using OpenSim.Region.Environment.Scenes; | 35 | using OpenSim.Region.Environment.Scenes; |
35 | using OpenMetaverse; | 36 | using OpenMetaverse; |
@@ -37,38 +38,18 @@ using OpenMetaverse; | |||
37 | namespace OpenSim.Data.SQLite.Tests | 38 | namespace OpenSim.Data.SQLite.Tests |
38 | { | 39 | { |
39 | [TestFixture] | 40 | [TestFixture] |
40 | public class SQLiteInventoryTest | 41 | public class SQLiteInventoryTest : BasicInventoryTest |
41 | { | 42 | { |
42 | public string file = "inventorytest.db"; | 43 | public string file = "inventorytest.db"; |
43 | public string connect; | 44 | public string connect; |
44 | public SQLiteInventoryStore db; | ||
45 | public UUID zero = UUID.Zero; | ||
46 | public UUID uuid1; | ||
47 | public UUID uuid2; | ||
48 | public UUID uuid3; | ||
49 | public UUID owner1; | ||
50 | public UUID owner2; | ||
51 | public UUID owner3; | ||
52 | public string name1; | ||
53 | public string name2; | ||
54 | public string name3; | ||
55 | |||
56 | 45 | ||
57 | [TestFixtureSetUp] | 46 | [TestFixtureSetUp] |
58 | public void Init() | 47 | public void Init() |
59 | { | 48 | { |
49 | SuperInit(); | ||
60 | connect = "URI=file:" + file + ",version=3"; | 50 | connect = "URI=file:" + file + ",version=3"; |
61 | db = new SQLiteInventoryStore(); | 51 | db = new SQLiteInventoryStore(); |
62 | db.Initialise(connect); | 52 | db.Initialise(connect); |
63 | uuid1 = UUID.Random(); | ||
64 | uuid2 = UUID.Random(); | ||
65 | uuid3 = UUID.Random(); | ||
66 | owner1 = UUID.Random(); | ||
67 | owner2 = UUID.Random(); | ||
68 | owner3 = UUID.Random(); | ||
69 | name1 = "Root Folder for " + owner1.ToString(); | ||
70 | name2 = "First Level folder"; | ||
71 | name3 = "First Level folder 2"; | ||
72 | } | 53 | } |
73 | 54 | ||
74 | [TestFixtureTearDown] | 55 | [TestFixtureTearDown] |
@@ -76,123 +57,5 @@ namespace OpenSim.Data.SQLite.Tests | |||
76 | { | 57 | { |
77 | System.IO.File.Delete(file); | 58 | System.IO.File.Delete(file); |
78 | } | 59 | } |
79 | |||
80 | [Test] | ||
81 | public void T001_LoadEmpty() | ||
82 | { | ||
83 | Assert.That(db.getInventoryItem(uuid1), Is.Null); | ||
84 | Assert.That(db.getUserRootFolder(owner1), Is.Null); | ||
85 | } | ||
86 | |||
87 | // 01x - folder tests | ||
88 | [Test] | ||
89 | public void T010_FolderNonParent() | ||
90 | { | ||
91 | InventoryFolderBase f1 = NewFolder(uuid2, uuid1, owner1, name2); | ||
92 | // the folder will go in | ||
93 | db.addInventoryFolder(f1); | ||
94 | InventoryFolderBase f1a = db.getUserRootFolder(owner1); | ||
95 | Assert.That(f1a, Is.Null); | ||
96 | } | ||
97 | |||
98 | [Test] | ||
99 | public void T011_FolderCreate() | ||
100 | { | ||
101 | InventoryFolderBase f1 = NewFolder(uuid1, zero, owner1, name1); | ||
102 | // TODO: this is probably wrong behavior, but is what we have | ||
103 | // db.updateInventoryFolder(f1); | ||
104 | // InventoryFolderBase f1a = db.getUserRootFolder(owner1); | ||
105 | // Assert.That(uuid1, Is.EqualTo(f1a.ID)) | ||
106 | // Assert.That(name1, Text.Matches(f1a.Name)); | ||
107 | // Assert.That(db.getUserRootFolder(owner1), Is.Null); | ||
108 | |||
109 | // succeed with true | ||
110 | db.addInventoryFolder(f1); | ||
111 | InventoryFolderBase f1a = db.getUserRootFolder(owner1); | ||
112 | Assert.That(uuid1, Is.EqualTo(f1a.ID)); | ||
113 | Assert.That(name1, Text.Matches(f1a.Name)); | ||
114 | } | ||
115 | |||
116 | // we now have the following tree | ||
117 | // uuid1 | ||
118 | // +--- uuid2 | ||
119 | // +--- uuid3 | ||
120 | |||
121 | [Test] | ||
122 | public void T012_FolderList() | ||
123 | { | ||
124 | InventoryFolderBase f2 = NewFolder(uuid3, uuid1, owner1, name3); | ||
125 | db.addInventoryFolder(f2); | ||
126 | |||
127 | Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1)); | ||
128 | |||
129 | Assert.That(db.getInventoryFolders(uuid1).Count, Is.EqualTo(2)); | ||
130 | |||
131 | Assert.That(db.getInventoryFolders(uuid2).Count, Is.EqualTo(0)); | ||
132 | |||
133 | Assert.That(db.getInventoryFolders(uuid3).Count, Is.EqualTo(0)); | ||
134 | |||
135 | Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0)); | ||
136 | |||
137 | } | ||
138 | |||
139 | [Test] | ||
140 | public void T013_FolderHierarchy() | ||
141 | { | ||
142 | Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0)); | ||
143 | |||
144 | Assert.That(db.getFolderHierarchy(uuid1).Count, Is.EqualTo(2)); | ||
145 | |||
146 | Assert.That(db.getFolderHierarchy(uuid2).Count, Is.EqualTo(0)); | ||
147 | |||
148 | Assert.That(db.getFolderHierarchy(uuid3).Count, Is.EqualTo(0)); | ||
149 | |||
150 | Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0)); | ||
151 | } | ||
152 | |||
153 | |||
154 | [Test] | ||
155 | public void T014_MoveFolder() | ||
156 | { | ||
157 | InventoryFolderBase f2 = db.getInventoryFolder(uuid2); | ||
158 | f2.ParentID = uuid3; | ||
159 | db.moveInventoryFolder(f2); | ||
160 | |||
161 | Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1)); | ||
162 | |||
163 | Assert.That(db.getInventoryFolders(uuid1).Count, Is.EqualTo(1)); | ||
164 | |||
165 | Assert.That(db.getInventoryFolders(uuid2).Count, Is.EqualTo(0)); | ||
166 | |||
167 | Assert.That(db.getInventoryFolders(uuid3).Count, Is.EqualTo(1)); | ||
168 | |||
169 | Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0)); | ||
170 | } | ||
171 | |||
172 | [Test] | ||
173 | public void T015_FolderHierarchy() | ||
174 | { | ||
175 | Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0)); | ||
176 | |||
177 | Assert.That(db.getFolderHierarchy(uuid1).Count, Is.EqualTo(2)); | ||
178 | |||
179 | Assert.That(db.getFolderHierarchy(uuid2).Count, Is.EqualTo(0)); | ||
180 | |||
181 | Assert.That(db.getFolderHierarchy(uuid3).Count, Is.EqualTo(1)); | ||
182 | |||
183 | Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0)); | ||
184 | } | ||
185 | |||
186 | |||
187 | |||
188 | private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name) | ||
189 | { | ||
190 | InventoryFolderBase f = new InventoryFolderBase(); | ||
191 | f.ID = id; | ||
192 | f.ParentID = parent; | ||
193 | f.Owner = owner; | ||
194 | f.Name = name; | ||
195 | return f; | ||
196 | } | ||
197 | } | 60 | } |
198 | } \ No newline at end of file | 61 | } \ No newline at end of file |
diff --git a/OpenSim/Data/Tests/BasicInventoryTests.cs b/OpenSim/Data/Tests/BasicInventoryTests.cs new file mode 100644 index 0000000..47a3393 --- /dev/null +++ b/OpenSim/Data/Tests/BasicInventoryTests.cs | |||
@@ -0,0 +1,184 @@ | |||
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 OpenSim 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 NUnit.Framework; | ||
31 | using NUnit.Framework.SyntaxHelpers; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Data.Tests; | ||
34 | using OpenSim.Region.Environment.Scenes; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Data.Tests | ||
38 | { | ||
39 | public class BasicInventoryTest | ||
40 | { | ||
41 | public IInventoryDataPlugin db; | ||
42 | public UUID zero = UUID.Zero; | ||
43 | public UUID uuid1; | ||
44 | public UUID uuid2; | ||
45 | public UUID uuid3; | ||
46 | public UUID owner1; | ||
47 | public UUID owner2; | ||
48 | public UUID owner3; | ||
49 | public string name1; | ||
50 | public string name2; | ||
51 | public string name3; | ||
52 | |||
53 | public void SuperInit() | ||
54 | { | ||
55 | uuid1 = UUID.Random(); | ||
56 | uuid2 = UUID.Random(); | ||
57 | uuid3 = UUID.Random(); | ||
58 | owner1 = UUID.Random(); | ||
59 | owner2 = UUID.Random(); | ||
60 | owner3 = UUID.Random(); | ||
61 | name1 = "Root Folder for " + owner1.ToString(); | ||
62 | name2 = "First Level folder"; | ||
63 | name3 = "First Level folder 2"; | ||
64 | } | ||
65 | |||
66 | [Test] | ||
67 | public void T001_LoadEmpty() | ||
68 | { | ||
69 | Assert.That(db.getInventoryItem(uuid1), Is.Null); | ||
70 | Assert.That(db.getUserRootFolder(owner1), Is.Null); | ||
71 | } | ||
72 | |||
73 | // 01x - folder tests | ||
74 | [Test] | ||
75 | public void T010_FolderNonParent() | ||
76 | { | ||
77 | InventoryFolderBase f1 = NewFolder(uuid2, uuid1, owner1, name2); | ||
78 | // the folder will go in | ||
79 | db.addInventoryFolder(f1); | ||
80 | InventoryFolderBase f1a = db.getUserRootFolder(owner1); | ||
81 | Assert.That(f1a, Is.Null); | ||
82 | } | ||
83 | |||
84 | [Test] | ||
85 | public void T011_FolderCreate() | ||
86 | { | ||
87 | InventoryFolderBase f1 = NewFolder(uuid1, zero, owner1, name1); | ||
88 | // TODO: this is probably wrong behavior, but is what we have | ||
89 | // db.updateInventoryFolder(f1); | ||
90 | // InventoryFolderBase f1a = db.getUserRootFolder(owner1); | ||
91 | // Assert.That(uuid1, Is.EqualTo(f1a.ID)) | ||
92 | // Assert.That(name1, Text.Matches(f1a.Name)); | ||
93 | // Assert.That(db.getUserRootFolder(owner1), Is.Null); | ||
94 | |||
95 | // succeed with true | ||
96 | db.addInventoryFolder(f1); | ||
97 | InventoryFolderBase f1a = db.getUserRootFolder(owner1); | ||
98 | Assert.That(uuid1, Is.EqualTo(f1a.ID)); | ||
99 | Assert.That(name1, Text.Matches(f1a.Name)); | ||
100 | } | ||
101 | |||
102 | // we now have the following tree | ||
103 | // uuid1 | ||
104 | // +--- uuid2 | ||
105 | // +--- uuid3 | ||
106 | |||
107 | [Test] | ||
108 | public void T012_FolderList() | ||
109 | { | ||
110 | InventoryFolderBase f2 = NewFolder(uuid3, uuid1, owner1, name3); | ||
111 | db.addInventoryFolder(f2); | ||
112 | |||
113 | Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1)); | ||
114 | |||
115 | Assert.That(db.getInventoryFolders(uuid1).Count, Is.EqualTo(2)); | ||
116 | |||
117 | Assert.That(db.getInventoryFolders(uuid2).Count, Is.EqualTo(0)); | ||
118 | |||
119 | Assert.That(db.getInventoryFolders(uuid3).Count, Is.EqualTo(0)); | ||
120 | |||
121 | Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0)); | ||
122 | |||
123 | } | ||
124 | |||
125 | [Test] | ||
126 | public void T013_FolderHierarchy() | ||
127 | { | ||
128 | Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0)); | ||
129 | |||
130 | Assert.That(db.getFolderHierarchy(uuid1).Count, Is.EqualTo(2)); | ||
131 | |||
132 | Assert.That(db.getFolderHierarchy(uuid2).Count, Is.EqualTo(0)); | ||
133 | |||
134 | Assert.That(db.getFolderHierarchy(uuid3).Count, Is.EqualTo(0)); | ||
135 | |||
136 | Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0)); | ||
137 | } | ||
138 | |||
139 | |||
140 | [Test] | ||
141 | public void T014_MoveFolder() | ||
142 | { | ||
143 | InventoryFolderBase f2 = db.getInventoryFolder(uuid2); | ||
144 | f2.ParentID = uuid3; | ||
145 | db.moveInventoryFolder(f2); | ||
146 | |||
147 | Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1)); | ||
148 | |||
149 | Assert.That(db.getInventoryFolders(uuid1).Count, Is.EqualTo(1)); | ||
150 | |||
151 | Assert.That(db.getInventoryFolders(uuid2).Count, Is.EqualTo(0)); | ||
152 | |||
153 | Assert.That(db.getInventoryFolders(uuid3).Count, Is.EqualTo(1)); | ||
154 | |||
155 | Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0)); | ||
156 | } | ||
157 | |||
158 | [Test] | ||
159 | public void T015_FolderHierarchy() | ||
160 | { | ||
161 | Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0)); | ||
162 | |||
163 | Assert.That(db.getFolderHierarchy(uuid1).Count, Is.EqualTo(2)); | ||
164 | |||
165 | Assert.That(db.getFolderHierarchy(uuid2).Count, Is.EqualTo(0)); | ||
166 | |||
167 | Assert.That(db.getFolderHierarchy(uuid3).Count, Is.EqualTo(1)); | ||
168 | |||
169 | Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0)); | ||
170 | } | ||
171 | |||
172 | |||
173 | |||
174 | private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name) | ||
175 | { | ||
176 | InventoryFolderBase f = new InventoryFolderBase(); | ||
177 | f.ID = id; | ||
178 | f.ParentID = parent; | ||
179 | f.Owner = owner; | ||
180 | f.Name = name; | ||
181 | return f; | ||
182 | } | ||
183 | } | ||
184 | } \ No newline at end of file | ||