diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test/inventory.cpp | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/linden/indra/test/inventory.cpp b/linden/indra/test/inventory.cpp new file mode 100644 index 0000000..2099da3 --- /dev/null +++ b/linden/indra/test/inventory.cpp | |||
@@ -0,0 +1,167 @@ | |||
1 | /** | ||
2 | * @file inventory.cpp | ||
3 | * @author Phoenix | ||
4 | * @date 2005-11-15 | ||
5 | * @brief Functions for inventory test framework | ||
6 | * | ||
7 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | /** | ||
31 | * | ||
32 | * THOROUGH_DESCRIPTION of inventory.cpp | ||
33 | * | ||
34 | */ | ||
35 | |||
36 | #include "linden_common.h" | ||
37 | #include "lltut.h" | ||
38 | #include "llinventory.h" | ||
39 | #include "llsd.h" | ||
40 | |||
41 | LLPointer<LLInventoryItem> create_random_inventory_item() | ||
42 | { | ||
43 | LLUUID item_id; | ||
44 | item_id.generate(); | ||
45 | LLUUID parent_id; | ||
46 | parent_id.generate(); | ||
47 | LLPermissions perm; | ||
48 | LLUUID creator_id; | ||
49 | creator_id.generate(); | ||
50 | LLUUID owner_id; | ||
51 | owner_id.generate(); | ||
52 | LLUUID last_owner_id; | ||
53 | last_owner_id.generate(); | ||
54 | LLUUID group_id; | ||
55 | group_id.generate(); | ||
56 | perm.init(creator_id, owner_id, last_owner_id, group_id); | ||
57 | perm.initMasks(PERM_ALL, PERM_ALL, PERM_COPY, PERM_COPY, PERM_MODIFY | PERM_COPY); | ||
58 | LLUUID asset_id; | ||
59 | asset_id.generate(); | ||
60 | S32 price = rand(); | ||
61 | LLSaleInfo sale_info(LLSaleInfo::FS_COPY, price); | ||
62 | U32 flags = rand(); | ||
63 | S32 creation = time(NULL); | ||
64 | |||
65 | LLPointer<LLInventoryItem> item = new LLInventoryItem( | ||
66 | item_id, | ||
67 | parent_id, | ||
68 | perm, | ||
69 | asset_id, | ||
70 | LLAssetType::AT_OBJECT, | ||
71 | LLInventoryType::IT_ATTACHMENT, | ||
72 | "Sample Object", | ||
73 | "Used for Testing", | ||
74 | sale_info, | ||
75 | flags, | ||
76 | creation); | ||
77 | return item; | ||
78 | } | ||
79 | |||
80 | LLPointer<LLInventoryCategory> create_random_inventory_cat() | ||
81 | { | ||
82 | LLUUID item_id; | ||
83 | item_id.generate(); | ||
84 | LLUUID parent_id; | ||
85 | parent_id.generate(); | ||
86 | |||
87 | LLPointer<LLInventoryCategory> cat = new LLInventoryCategory( | ||
88 | item_id, | ||
89 | parent_id, | ||
90 | LLAssetType::AT_NONE, | ||
91 | "Sample category"); | ||
92 | return cat; | ||
93 | } | ||
94 | |||
95 | namespace tut | ||
96 | { | ||
97 | struct inventory_data | ||
98 | { | ||
99 | }; | ||
100 | typedef test_group<inventory_data> inventory_test; | ||
101 | typedef inventory_test::object inventory_object; | ||
102 | tut::inventory_test inv("llinventory"); | ||
103 | |||
104 | template<> template<> | ||
105 | void inventory_object::test<1>() | ||
106 | { | ||
107 | LLPointer<LLInventoryItem> src = create_random_inventory_item(); | ||
108 | LLSD sd = ll_create_sd_from_inventory_item(src); | ||
109 | //llinfos << "sd: " << *sd << llendl; | ||
110 | LLPointer<LLInventoryItem> dst; | ||
111 | dst = ll_create_item_from_sd(sd); | ||
112 | ensure_equals("item id", dst->getUUID(), src->getUUID()); | ||
113 | ensure_equals("parent", dst->getParentUUID(), src->getParentUUID()); | ||
114 | ensure_equals("name", dst->getName(), src->getName()); | ||
115 | ensure_equals("type", dst->getType(), src->getType()); | ||
116 | ensure_equals( | ||
117 | "permissions", | ||
118 | dst->getPermissions(), | ||
119 | src->getPermissions()); | ||
120 | ensure_equals( | ||
121 | "description", | ||
122 | dst->getDescription(), | ||
123 | src->getDescription()); | ||
124 | ensure_equals( | ||
125 | "sale type", | ||
126 | dst->getSaleInfo().getSaleType(), | ||
127 | src->getSaleInfo().getSaleType()); | ||
128 | ensure_equals( | ||
129 | "sale price", | ||
130 | dst->getSaleInfo().getSalePrice(), | ||
131 | src->getSaleInfo().getSalePrice()); | ||
132 | ensure_equals("asset id", dst->getAssetUUID(), src->getAssetUUID()); | ||
133 | ensure_equals( | ||
134 | "inventory type", | ||
135 | dst->getInventoryType(), | ||
136 | src->getInventoryType()); | ||
137 | ensure_equals("flags", dst->getFlags(), src->getFlags()); | ||
138 | ensure_equals( | ||
139 | "creation", | ||
140 | dst->getCreationDate(), | ||
141 | src->getCreationDate()); | ||
142 | } | ||
143 | |||
144 | template<> template<> | ||
145 | void inventory_object::test<2>() | ||
146 | { | ||
147 | LLPointer<LLInventoryCategory> src = create_random_inventory_cat(); | ||
148 | LLSD sd = ll_create_sd_from_inventory_category(src); | ||
149 | LLPointer<LLInventoryCategory> dst = ll_create_category_from_sd(sd); | ||
150 | ensure_equals("item id", dst->getUUID(), src->getUUID()); | ||
151 | ensure_equals("parent", dst->getParentUUID(), src->getParentUUID()); | ||
152 | ensure_equals("name", dst->getName(), src->getName()); | ||
153 | ensure_equals("type", dst->getType(), src->getType()); | ||
154 | ensure_equals( | ||
155 | "preferred type", | ||
156 | dst->getPreferredType(), | ||
157 | src->getPreferredType()); | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | template<> template<> | ||
162 | void inventory_object::test<3>() | ||
163 | { | ||
164 | |||
165 | } | ||
166 | */ | ||
167 | } | ||