OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
TestHelpers.cs
Go to the documentation of this file.
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 
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 
110  public static void DisableLogging()
111  {
112  log4net.Config.XmlConfigurator.Configure(DisableLoggingConfigStream);
113  DisableLoggingConfigStream.Position = 0;
114  }
115 
128  public static UUID ParseStem(string stem)
129  {
130  string rawUuid = stem.PadRight(32, '0');
131 
132  return UUID.Parse(rawUuid);
133  }
134 
140  public static UUID ParseTail(int tail)
141  {
142  return new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", tail));
143  }
144 
157  public static UUID ParseTail(string stem)
158  {
159  string rawUuid = stem.PadLeft(32, '0');
160 
161  return UUID.Parse(rawUuid);
162  }
163  }
164 }
static UUID ParseTail(string stem)
Parse a UUID tail section into a full UUID.
Definition: TestHelpers.cs:157
static void InMethod()
A debugging method that can be used to print out which test method you are in
Definition: TestHelpers.cs:88
static UUID ParseStem(string stem)
Parse a UUID stem into a full UUID.
Definition: TestHelpers.cs:128
static UUID ParseTail(int tail)
Parse tail section into full UUID.
Definition: TestHelpers.cs:140
static bool AssertThisDelegateCausesArgumentException(TestDelegate d)
Definition: TestHelpers.cs:71
static void DisableLogging()
Disable logging whilst running the tests.
Definition: TestHelpers.cs:110