clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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.Diagnostics;
30 using System.IO;
31 using System.Text;
32 using NUnit.Framework;
33 using OpenMetaverse;
34  
35 namespace OpenSim.Tests.Common
36 {
37 public class TestHelpers
38 {
39 private static Stream EnableLoggingConfigStream
40 = new MemoryStream(
41 Encoding.UTF8.GetBytes(
42 @"<log4net>
43 <!-- A1 is set to be a ConsoleAppender -->
44 <appender name=""A1"" type=""log4net.Appender.ConsoleAppender"">
45  
46 <!-- A1 uses PatternLayout -->
47 <layout type=""log4net.Layout.PatternLayout"">
48 <!-- Print the date in ISO 8601 format -->
49 <!-- <conversionPattern value=""%date [%thread] %-5level %logger %ndc - %message%newline"" /> -->
50 <conversionPattern value=""%date %message%newline"" />
51 </layout>
52 </appender>
53  
54 <!-- Set root logger level to DEBUG and its only appender to A1 -->
55 <root>
56 <level value=""DEBUG"" />
57 <appender-ref ref=""A1"" />
58 </root>
59 </log4net>"));
60  
61 private static MemoryStream DisableLoggingConfigStream
62 = new MemoryStream(
63 Encoding.UTF8.GetBytes(
64 // "<?xml version=\"1.0\" encoding=\"utf-8\" ?><configuration><log4net><root><level value=\"OFF\"/><appender-ref ref=\"A1\"/></root></log4net></configuration>"));
65 //"<?xml version=\"1.0\" encoding=\"utf-8\" ?><configuration><log4net><root><level value=\"OFF\"/></root></log4net></configuration>")));
66 // "<configuration><log4net><root><level value=\"OFF\"/></root></log4net></configuration>"));
67 // "<configuration><log4net><root></root></log4net></configuration>")));
68 // "<configuration><log4net><root/></log4net></configuration>"));
69 "<log4net><root/></log4net>"));
70  
71 public static bool AssertThisDelegateCausesArgumentException(TestDelegate d)
72 {
73 try
74 {
75 d();
76 }
77 catch(ArgumentException)
78 {
79 return true;
80 }
81  
82 return false;
83 }
84  
85 /// <summary>
86 /// A debugging method that can be used to print out which test method you are in
87 /// </summary>
88 public static void InMethod()
89 {
90 StackTrace stackTrace = new StackTrace();
91 Console.WriteLine();
92 Console.WriteLine("===> In Test Method : {0} <===", stackTrace.GetFrame(1).GetMethod().Name);
93 }
94  
95 public static void EnableLogging()
96 {
97 log4net.Config.XmlConfigurator.Configure(EnableLoggingConfigStream);
98 EnableLoggingConfigStream.Position = 0;
99 }
100  
101 /// <summary>
102 /// Disable logging whilst running the tests.
103 /// </summary>
104 /// <remarks>
105 /// Remember, if a regression test throws an exception before completing this will not be invoked if it's at
106 /// the end of the test.
107 /// TODO: Always invoke this after every test - probably need to make all test cases inherit from a common
108 /// TestCase class where this can be done.
109 /// </remarks>
110 public static void DisableLogging()
111 {
112 log4net.Config.XmlConfigurator.Configure(DisableLoggingConfigStream);
113 DisableLoggingConfigStream.Position = 0;
114 }
115  
116 /// <summary>
117 /// Parse a UUID stem into a full UUID.
118 /// </summary>
119 /// <remarks>
120 /// The fragment will come at the start of the UUID. The rest will be 0s
121 /// </remarks>
122 /// <returns></returns>
123 /// <param name='frag'>
124 /// A UUID fragment that will be parsed into a full UUID. Therefore, it can only contain
125 /// cahracters which are valid in a UUID, except for "-" which is currently only allowed if a full UUID is
126 /// given as the 'fragment'.
127 /// </param>
128 public static UUID ParseStem(string stem)
129 {
130 string rawUuid = stem.PadRight(32, '0');
131  
132 return UUID.Parse(rawUuid);
133 }
134  
135 /// <summary>
136 /// Parse tail section into full UUID.
137 /// </summary>
138 /// <param name="tail"></param>
139 /// <returns></returns>
140 public static UUID ParseTail(int tail)
141 {
142 return new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", tail));
143 }
144  
145 /// <summary>
146 /// Parse a UUID tail section into a full UUID.
147 /// </summary>
148 /// <remarks>
149 /// The fragment will come at the end of the UUID. The rest will be 0s
150 /// </remarks>
151 /// <returns></returns>
152 /// <param name='frag'>
153 /// A UUID fragment that will be parsed into a full UUID. Therefore, it can only contain
154 /// cahracters which are valid in a UUID, except for "-" which is currently only allowed if a full UUID is
155 /// given as the 'fragment'.
156 /// </param>
157 public static UUID ParseTail(string stem)
158 {
159 string rawUuid = stem.PadLeft(32, '0');
160  
161 return UUID.Parse(rawUuid);
162 }
163 }
164 }