[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Internal / TestParameters.cs
1 // ***********************************************************************
2 // Copyright (c) 2015 Charlie Poole
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using NUnit.Framework.Interfaces;
31
32 namespace NUnit.Framework.Internal
33 {
34     /// <summary>
35     /// TestParameters is the abstract base class for all classes
36     /// that know how to provide data for constructing a test.
37     /// </summary>
38     public abstract class TestParameters : ITestData, IApplyToTest
39     {
40         #region Constructors
41
42         /// <summary>
43         /// Default Constructor creates an empty parameter set
44         /// </summary>
45         public TestParameters()
46         {
47             RunState = RunState.Runnable;
48             Properties = new PropertyBag();
49         }
50
51         /// <summary>
52         /// Construct a parameter set with a list of arguments
53         /// </summary>
54         /// <param name="args"></param>
55         public TestParameters(object[] args)
56         {
57             RunState = RunState.Runnable;
58             InitializeAguments(args);
59             Properties = new PropertyBag();
60         }
61
62         /// <summary>
63         /// Construct a non-runnable ParameterSet, specifying
64         /// the provider exception that made it invalid.
65         /// </summary>
66         public TestParameters(Exception exception)
67         {
68             RunState = RunState.NotRunnable;
69             Properties = new PropertyBag();
70
71             Properties.Set(PropertyNames.SkipReason, ExceptionHelper.BuildMessage(exception));
72             Properties.Set(PropertyNames.ProviderStackTrace, ExceptionHelper.BuildStackTrace(exception));
73         }
74
75         /// <summary>
76         /// Construct a ParameterSet from an object implementing ITestData
77         /// </summary>
78         /// <param name="data"></param>
79         public TestParameters(ITestData data)
80         {
81             RunState = data.RunState;
82             Properties = new PropertyBag();
83
84             TestName = data.TestName;
85
86             InitializeAguments(data.Arguments);
87
88             foreach (string key in data.Properties.Keys)
89                 this.Properties[key] = data.Properties[key];
90         }
91
92         private void InitializeAguments(object[] args)
93         {
94             OriginalArguments = args;
95
96             // We need to copy args, since we may change them
97             var numArgs = args.Length;
98             Arguments = new object[numArgs];
99             Array.Copy(args, Arguments, numArgs);
100         }
101
102         #endregion
103
104         #region ITestData Members
105
106         /// <summary>
107         /// The RunState for this set of parameters.
108         /// </summary>
109         public RunState RunState { get; set; }
110
111         /// <summary>
112         /// The arguments to be used in running the test,
113         /// which must match the method signature.
114         /// </summary>
115         public object[] Arguments { get; internal set; }
116
117         /// <summary>
118         /// A name to be used for this test case in lieu
119         /// of the standard generated name containing
120         /// the argument list.
121         /// </summary>
122         public string TestName { get; set; }
123
124         /// <summary>
125         /// Gets the property dictionary for this test
126         /// </summary>
127         public IPropertyBag Properties { get; private set; }
128
129         #endregion
130
131         #region IApplyToTest Members
132
133         /// <summary>
134         /// Applies ParameterSet _values to the test itself.
135         /// </summary>
136         /// <param name="test">A test.</param>
137         public void ApplyToTest(Test test)
138         {
139             if (this.RunState != RunState.Runnable)
140                 test.RunState = this.RunState;
141
142             foreach (string key in Properties.Keys)
143                 foreach (object value in Properties[key])
144                     test.Properties.Add(key, value);
145         }
146
147         #endregion
148
149         #region Other Public Properties
150
151         /// <summary>
152         /// The original arguments provided by the user,
153         /// used for display purposes.
154         /// </summary>
155         public object[] OriginalArguments { get; private set; }
156
157         #endregion
158     }
159 }