aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Tests/ScrambleForTesting.cs
diff options
context:
space:
mode:
authorKunnis2009-08-16 03:35:31 -0500
committerTeravus Ovares (Dan Olivares)2009-08-16 14:34:16 -0400
commitdd78c250aed0924d06e28a826c2ad565ca232045 (patch)
tree331487699d7d2fba8d00cd2a8e57b85e8f77e794 /OpenSim/Data/Tests/ScrambleForTesting.cs
parent* More improvements to BasicAssetTest.cs (diff)
downloadopensim-SC_OLD-dd78c250aed0924d06e28a826c2ad565ca232045.zip
opensim-SC_OLD-dd78c250aed0924d06e28a826c2ad565ca232045.tar.gz
opensim-SC_OLD-dd78c250aed0924d06e28a826c2ad565ca232045.tar.bz2
opensim-SC_OLD-dd78c250aed0924d06e28a826c2ad565ca232045.tar.xz
* Added Expression based ignores to the PropertyScrambler, which makes a lot of the tests clearer because I'm not constantly resetting properties.
Diffstat (limited to 'OpenSim/Data/Tests/ScrambleForTesting.cs')
-rw-r--r--OpenSim/Data/Tests/ScrambleForTesting.cs129
1 files changed, 0 insertions, 129 deletions
diff --git a/OpenSim/Data/Tests/ScrambleForTesting.cs b/OpenSim/Data/Tests/ScrambleForTesting.cs
deleted file mode 100644
index 3a22347..0000000
--- a/OpenSim/Data/Tests/ScrambleForTesting.cs
+++ /dev/null
@@ -1,129 +0,0 @@
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;
30using System.Reflection;
31using System.Text;
32using NUnit.Framework;
33using OpenMetaverse;
34using OpenSim.Framework;
35
36namespace OpenSim.Data.Tests
37{
38 public static class ScrambleForTesting
39 {
40 private static readonly Random random = new Random();
41 public static void Scramble(object obj)
42 {
43 PropertyInfo[] properties = obj.GetType().GetProperties();
44 foreach (var property in properties)
45 {
46 //Skip indexers of classes. We will assume that everything that has an indexer
47 // is also IEnumberable. May not always be true, but should be true normally.
48 if (property.GetIndexParameters().Length > 0)
49 continue;
50
51 RandomizeProperty(obj, property, null);
52 }
53 //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize
54 // everything inside of it.
55 IEnumerable enumerable = obj as IEnumerable;
56 if (enumerable != null)
57 {
58 foreach (object value in enumerable)
59 {
60 Scramble(value);
61 }
62 }
63 }
64
65 private static void RandomizeProperty(object obj, PropertyInfo property, object[] index)
66 {
67 Type t = property.PropertyType;
68 if (!property.CanWrite)
69 return;
70 object value = property.GetValue(obj, index);
71 if (value == null)
72 return;
73
74 if (t == typeof (string))
75 property.SetValue(obj, RandomName(), index);
76 else if (t == typeof (UUID))
77 property.SetValue(obj, UUID.Random(), index);
78 else if (t == typeof (sbyte))
79 property.SetValue(obj, (sbyte)random.Next(sbyte.MinValue, sbyte.MaxValue), index);
80 else if (t == typeof (short))
81 property.SetValue(obj, (short)random.Next(short.MinValue, short.MaxValue), index);
82 else if (t == typeof (int))
83 property.SetValue(obj, random.Next(), index);
84 else if (t == typeof (long))
85 property.SetValue(obj, random.Next() * int.MaxValue, index);
86 else if (t == typeof (byte))
87 property.SetValue(obj, (byte)random.Next(byte.MinValue, byte.MaxValue), index);
88 else if (t == typeof (ushort))
89 property.SetValue(obj, (ushort)random.Next(ushort.MinValue, ushort.MaxValue), index);
90 else if (t == typeof (uint))
91 property.SetValue(obj, Convert.ToUInt32(random.Next()), index);
92 else if (t == typeof (ulong))
93 property.SetValue(obj, Convert.ToUInt64(random.Next()) * Convert.ToUInt64(UInt32.MaxValue), index);
94 else if (t == typeof (bool))
95 property.SetValue(obj, true, index);
96 else if (t == typeof (byte[]))
97 {
98 byte[] bytes = new byte[30];
99 random.NextBytes(bytes);
100 property.SetValue(obj, bytes, index);
101 }
102 else
103 Scramble(value);
104 }
105
106 private static string RandomName()
107 {
108 StringBuilder name = new StringBuilder();
109 int size = random.Next(5, 12);
110 for (int i = 0; i < size; i++)
111 {
112 char ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
113 name.Append(ch);
114 }
115 return name.ToString();
116 }
117 }
118
119 [TestFixture]
120 public class ScrableForTestingTest
121 {
122 [Test]
123 public void TestScramble()
124 {
125 AssetBase actual = new AssetBase(UUID.Random(), "asset one");
126 ScrambleForTesting.Scramble(actual);
127 }
128 }
129} \ No newline at end of file