diff options
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs')
-rw-r--r-- | OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs b/OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs new file mode 100644 index 0000000..9e3fa69 --- /dev/null +++ b/OpenSim/Services/InventoryService/Tests/XInventoryServiceTests.cs | |||
@@ -0,0 +1,177 @@ | |||
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 Nini.Config; | ||
30 | using NUnit.Framework; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Tests.Common; | ||
36 | |||
37 | namespace OpenSim.Services.InventoryService.Tests | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// Tests for the XInventoryService | ||
41 | /// </summary> | ||
42 | /// <remarks> | ||
43 | /// TODO: Fill out more tests. | ||
44 | /// </remarks> | ||
45 | [TestFixture] | ||
46 | public class XInventoryServiceTests : OpenSimTestCase | ||
47 | { | ||
48 | private IInventoryService CreateXInventoryService() | ||
49 | { | ||
50 | IConfigSource config = new IniConfigSource(); | ||
51 | config.AddConfig("InventoryService"); | ||
52 | config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
53 | |||
54 | return ServerUtils.LoadPlugin<IInventoryService>( | ||
55 | "OpenSim.Services.InventoryService.dll:XInventoryService", new Object[] { config }); | ||
56 | } | ||
57 | |||
58 | /// <summary> | ||
59 | /// Tests add item operation. | ||
60 | /// </summary> | ||
61 | /// <remarks> | ||
62 | /// TODO: Test all operations. | ||
63 | /// </remarks> | ||
64 | [Test] | ||
65 | public void TestAddItem() | ||
66 | { | ||
67 | TestHelpers.InMethod(); | ||
68 | |||
69 | string creatorId = TestHelpers.ParseTail(0x1).ToString(); | ||
70 | UUID ownerId = TestHelpers.ParseTail(0x2); | ||
71 | UUID itemId = TestHelpers.ParseTail(0x10); | ||
72 | UUID assetId = TestHelpers.ParseTail(0x20); | ||
73 | UUID folderId = TestHelpers.ParseTail(0x30); | ||
74 | int invType = (int)InventoryType.Animation; | ||
75 | int assetType = (int)AssetType.Animation; | ||
76 | string itemName = "item1"; | ||
77 | |||
78 | IInventoryService xis = CreateXInventoryService(); | ||
79 | |||
80 | InventoryItemBase itemToStore | ||
81 | = new InventoryItemBase(itemId, ownerId) | ||
82 | { | ||
83 | CreatorIdentification = creatorId.ToString(), | ||
84 | AssetID = assetId, | ||
85 | Name = itemName, | ||
86 | Folder = folderId, | ||
87 | InvType = invType, | ||
88 | AssetType = assetType | ||
89 | }; | ||
90 | |||
91 | Assert.That(xis.AddItem(itemToStore), Is.True); | ||
92 | |||
93 | InventoryItemBase itemRetrieved = new InventoryItemBase(itemId); | ||
94 | itemRetrieved = xis.GetItem(itemRetrieved); | ||
95 | |||
96 | Assert.That(itemRetrieved, Is.Not.Null); | ||
97 | Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId)); | ||
98 | Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId)); | ||
99 | Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId)); | ||
100 | Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId)); | ||
101 | Assert.That(itemRetrieved.InvType, Is.EqualTo(invType)); | ||
102 | Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType)); | ||
103 | Assert.That(itemRetrieved.Name, Is.EqualTo(itemName)); | ||
104 | } | ||
105 | |||
106 | [Test] | ||
107 | public void TestUpdateItem() | ||
108 | { | ||
109 | TestHelpers.InMethod(); | ||
110 | // TestHelpers.EnableLogging(); | ||
111 | |||
112 | string creatorId = TestHelpers.ParseTail(0x1).ToString(); | ||
113 | UUID ownerId = TestHelpers.ParseTail(0x2); | ||
114 | UUID itemId = TestHelpers.ParseTail(0x10); | ||
115 | UUID assetId = TestHelpers.ParseTail(0x20); | ||
116 | UUID folderId = TestHelpers.ParseTail(0x30); | ||
117 | int invType = (int)InventoryType.Animation; | ||
118 | int assetType = (int)AssetType.Animation; | ||
119 | string itemName = "item1"; | ||
120 | string itemName2 = "item2"; | ||
121 | |||
122 | IInventoryService xis = CreateXInventoryService(); | ||
123 | |||
124 | InventoryItemBase itemToStore | ||
125 | = new InventoryItemBase(itemId, ownerId) | ||
126 | { | ||
127 | CreatorIdentification = creatorId.ToString(), | ||
128 | AssetID = assetId, | ||
129 | Name = itemName, | ||
130 | Folder = folderId, | ||
131 | InvType = invType, | ||
132 | AssetType = assetType | ||
133 | }; | ||
134 | |||
135 | Assert.That(xis.AddItem(itemToStore), Is.True); | ||
136 | |||
137 | // Normal update | ||
138 | itemToStore.Name = itemName2; | ||
139 | |||
140 | Assert.That(xis.UpdateItem(itemToStore), Is.True); | ||
141 | |||
142 | InventoryItemBase itemRetrieved = new InventoryItemBase(itemId); | ||
143 | itemRetrieved = xis.GetItem(itemRetrieved); | ||
144 | |||
145 | Assert.That(itemRetrieved, Is.Not.Null); | ||
146 | Assert.That(itemRetrieved.Name, Is.EqualTo(itemName2)); | ||
147 | |||
148 | // Attempt to update properties that should never change | ||
149 | string creatorId2 = TestHelpers.ParseTail(0x7).ToString(); | ||
150 | UUID ownerId2 = TestHelpers.ParseTail(0x8); | ||
151 | UUID folderId2 = TestHelpers.ParseTail(0x70); | ||
152 | int invType2 = (int)InventoryType.CallingCard; | ||
153 | int assetType2 = (int)AssetType.CallingCard; | ||
154 | string itemName3 = "item3"; | ||
155 | |||
156 | itemToStore.CreatorIdentification = creatorId2.ToString(); | ||
157 | itemToStore.Owner = ownerId2; | ||
158 | itemToStore.Folder = folderId2; | ||
159 | itemToStore.InvType = invType2; | ||
160 | itemToStore.AssetType = assetType2; | ||
161 | itemToStore.Name = itemName3; | ||
162 | |||
163 | Assert.That(xis.UpdateItem(itemToStore), Is.True); | ||
164 | |||
165 | itemRetrieved = xis.GetItem(itemRetrieved); | ||
166 | |||
167 | Assert.That(itemRetrieved, Is.Not.Null); | ||
168 | Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId)); | ||
169 | Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId)); | ||
170 | Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId)); | ||
171 | Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId)); | ||
172 | Assert.That(itemRetrieved.InvType, Is.EqualTo(invType)); | ||
173 | Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType)); | ||
174 | Assert.That(itemRetrieved.Name, Is.EqualTo(itemName3)); | ||
175 | } | ||
176 | } | ||
177 | } \ No newline at end of file | ||