| 1 |
// Licensed to the .NET Foundation under one or more agreements. |
| 2 |
// The .NET Foundation licenses this file to you under the MIT license. |
| 3 |
// See the LICENSE file in the project root for more information. |
| 4 |
using System; |
| 5 |
using System.Collections; |
| 6 |
using System.Collections.Generic; |
| 7 |
|
| 8 |
namespace Microsoft.Win32.RegistryTests |
| 9 |
{ |
| 10 |
internal static class TestData |
| 11 |
{ |
| 12 |
private static readonly object[][] s_testValueTypes; |
| 13 |
|
| 14 |
private static readonly object[][] s_testObjects; |
| 15 |
|
| 16 |
private static readonly object[][] s_testEnvironment; |
| 17 |
|
| 18 |
private static readonly object[][] s_testExpandableStrings; |
| 19 |
|
| 20 |
private static readonly object[][] s_testValueNames; |
| 21 |
|
| 22 |
internal const string DefaultValue = "default"; |
| 23 |
|
| 24 |
static TestData() |
| 25 |
{ |
| 26 |
var rand = new Random(-55); |
| 27 |
|
| 28 |
s_testValueTypes = new[] |
| 29 |
{ |
| 30 |
new object[] { "Test_01", (byte)rand.Next(byte.MinValue, sbyte.MaxValue) }, |
| 31 |
new object[] { "Test_02", (sbyte)rand.Next(sbyte.MinValue, sbyte.MaxValue) }, |
| 32 |
new object[] { "Test_03", (short)rand.Next(short.MinValue, short.MaxValue) }, |
| 33 |
new object[] { "Test_04", (ushort)rand.Next(ushort.MinValue, ushort.MaxValue) }, |
| 34 |
new object[] { "Test_05", (int)rand.Next(int.MinValue, int.MaxValue) }, |
| 35 |
new object[] { "Test_06", (uint)rand.Next(0, int.MaxValue) }, |
| 36 |
new object[] { "Test_07", (long)rand.Next(int.MinValue, int.MaxValue) }, |
| 37 |
new object[] { "Test_08", (ulong)rand.Next(0, int.MaxValue) }, |
| 38 |
new object[] { "Test_09", new decimal(((double)decimal.MaxValue) * rand.NextDouble()) }, |
| 39 |
new object[] { "Test_10", new decimal(((double)decimal.MinValue) * rand.NextDouble()) }, |
| 40 |
new object[] { "Test_11", new decimal(((double)decimal.MinValue) * rand.NextDouble()) }, |
| 41 |
new object[] { "Test_12", new decimal(((double)decimal.MaxValue) * rand.NextDouble()) }, |
| 42 |
new object[] { "Test_13", int.MaxValue *rand.NextDouble() }, |
| 43 |
new object[] { "Test_14", int.MinValue * rand.NextDouble() }, |
| 44 |
new object[] { "Test_15", int.MaxValue * (float)rand.NextDouble() }, |
| 45 |
new object[] { "Test_16", int.MinValue * (float)rand.NextDouble() } |
| 46 |
}; |
| 47 |
|
| 48 |
var bytes = new byte[rand.Next(0, 100)]; |
| 49 |
rand.NextBytes(bytes); |
| 50 |
var obj = new object(); |
| 51 |
s_testObjects = new[] |
| 52 |
{ |
| 53 |
// Standard Random Numbers |
| 54 |
new object[] { 0, (byte)rand.Next(byte.MinValue, byte.MaxValue), RegistryValueKind.String }, |
| 55 |
new object[] { 1, (sbyte)rand.Next(sbyte.MinValue, sbyte.MaxValue), RegistryValueKind.String }, |
| 56 |
new object[] { 2, (short)rand.Next(short.MinValue, short.MaxValue), RegistryValueKind.String }, |
| 57 |
new object[] { 3, (ushort)rand.Next(ushort.MinValue, UInt16.MaxValue), RegistryValueKind.String }, |
| 58 |
new object[] { 4, (char)rand.Next(char.MinValue, char.MaxValue), RegistryValueKind.String }, |
| 59 |
new object[] { 5, (int)rand.Next(int.MinValue, int.MaxValue), RegistryValueKind.DWord }, |
| 60 |
// Random Numbers that can fit into Int32 |
| 61 |
new object[] { 6, (uint)(rand.NextDouble() * int.MaxValue), RegistryValueKind.String }, |
| 62 |
new object[] { 7, (long)(rand.NextDouble() * int.MaxValue), RegistryValueKind.String }, |
| 63 |
new object[] { 8, (long)(rand.NextDouble() * int.MinValue), RegistryValueKind.String }, |
| 64 |
new object[] { 9, (ulong)(rand.NextDouble() * int.MaxValue), RegistryValueKind.String }, |
| 65 |
new object[] { 10, (decimal)(rand.NextDouble() * int.MaxValue), RegistryValueKind.String }, |
| 66 |
new object[] { 11, (decimal)(rand.NextDouble() * int.MinValue), RegistryValueKind.String }, |
| 67 |
new object[] { 12, (float)(rand.NextDouble() * int.MaxValue), RegistryValueKind.String }, |
| 68 |
new object[] { 13, (float)(rand.NextDouble() * int.MinValue), RegistryValueKind.String }, |
| 69 |
new object[] { 14, (double)(rand.NextDouble() * int.MaxValue), RegistryValueKind.String }, |
| 70 |
new object[] { 15, (double)(rand.NextDouble() * int.MinValue), RegistryValueKind.String }, |
| 71 |
// Random Numbers that can't fit into Int32 but can fit into Int64 |
| 72 |
new object[] { 16, (uint)(rand.NextDouble() * (uint.MaxValue - int.MaxValue) + int.MaxValue), RegistryValueKind.String }, |
| 73 |
new object[] { 17, (long)(rand.NextDouble() * (long.MaxValue - int.MaxValue) + int.MaxValue), RegistryValueKind.String }, |
| 74 |
new object[] { 18, (long)(rand.NextDouble() * (long.MinValue - int.MinValue) + int.MinValue), RegistryValueKind.String }, |
| 75 |
new object[] { 19, (ulong)(rand.NextDouble() * (long.MaxValue - (ulong)int.MaxValue) + int.MaxValue), RegistryValueKind.String }, |
| 76 |
new object[] { 20, (decimal)(rand.NextDouble() * (long.MaxValue - int.MaxValue) + int.MaxValue), RegistryValueKind.String }, |
| 77 |
new object[] { 21, (decimal)(rand.NextDouble() * (long.MinValue - int.MinValue) + int.MinValue), RegistryValueKind.String }, |
| 78 |
new object[] { 22, (float)(rand.NextDouble() * (long.MaxValue - int.MaxValue) + int.MaxValue), RegistryValueKind.String }, |
| 79 |
new object[] { 23, (float)(rand.NextDouble() * (long.MinValue - int.MinValue) + int.MinValue), RegistryValueKind.String }, |
| 80 |
new object[] { 24, (double)(rand.NextDouble() * (long.MaxValue - int.MaxValue) + int.MaxValue), RegistryValueKind.String }, |
| 81 |
new object[] { 25, (double)(rand.NextDouble() * (long.MinValue - int.MinValue) + int.MinValue), RegistryValueKind.String }, |
| 82 |
// Random Numbers that can't fit into Int32 or Int64 |
| 83 |
new object[] { 26, (ulong)(rand.NextDouble() * (ulong.MaxValue - long.MaxValue) + long.MaxValue), RegistryValueKind.String }, |
| 84 |
new object[] { 27, decimal.MaxValue, RegistryValueKind.String }, |
| 85 |
new object[] { 28, decimal.MinValue, RegistryValueKind.String }, |
| 86 |
new object[] { 29, float.MaxValue, RegistryValueKind.String }, |
| 87 |
new object[] { 30, float.MinValue, RegistryValueKind.String }, |
| 88 |
new object[] { 31, double.MaxValue, RegistryValueKind.String }, |
| 89 |
new object[] { 32, double.MinValue, RegistryValueKind.String }, |
| 90 |
// Various other types |
| 91 |
new object[] { 33, "Hello World", RegistryValueKind.String }, |
| 92 |
new object[] { 34, "Hello %path5% World", RegistryValueKind.String }, |
| 93 |
new object[] { 35, new[] { "Hello World", "Hello %path% World" }, RegistryValueKind.MultiString }, |
| 94 |
new object[] { 36, obj, RegistryValueKind.String }, |
| 95 |
new object[] { 37, bytes, RegistryValueKind.Binary } |
| 96 |
}; |
| 97 |
|
| 98 |
var envs = new List<object[]>(); |
| 99 |
int counter = 0; |
| 100 |
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables()) |
| 101 |
{ |
| 102 |
envs.Add(new[] { "ExpandedTest_" + counter.ToString(), entry.Key, entry.Value }); |
| 103 |
++counter; |
| 104 |
} |
| 105 |
s_testEnvironment = envs.ToArray(); |
| 106 |
|
| 107 |
const string sysRootVar = "%Systemroot%"; |
| 108 |
const string pathVar = "%path%"; |
| 109 |
const string tmpVar = "%tmp%"; |
| 110 |
s_testExpandableStrings = new[] |
| 111 |
{ |
| 112 |
new object[] |
| 113 |
{ |
| 114 |
sysRootVar + @"\mydrive\mydirectory\myfile.xxx", |
| 115 |
Environment.ExpandEnvironmentVariables(sysRootVar) + @"\mydrive\mydirectory\myfile.xxx" |
| 116 |
}, |
| 117 |
new object[] |
| 118 |
{ |
| 119 |
tmpVar + @"\gfdhghdfgk\fsdfds\dsd.yyy", |
| 120 |
Environment.ExpandEnvironmentVariables(tmpVar) + @"\gfdhghdfgk\fsdfds\dsd.yyy" |
| 121 |
}, |
| 122 |
new object[] |
| 123 |
{ |
| 124 |
pathVar + @"\rwerew.zzz", |
| 125 |
Environment.ExpandEnvironmentVariables(pathVar) + @"\rwerew.zzz" |
| 126 |
}, |
| 127 |
new object[] |
| 128 |
{ |
| 129 |
sysRootVar + @"\mydrive\" + pathVar + @"\myfile.xxx", |
| 130 |
Environment.ExpandEnvironmentVariables(sysRootVar) + @"\mydrive\" + |
| 131 |
Environment.ExpandEnvironmentVariables(pathVar) + @"\myfile.xxx" |
| 132 |
} |
| 133 |
}; |
| 134 |
|
| 135 |
s_testValueNames = new[] |
| 136 |
{ |
| 137 |
new object[] { string.Empty }, |
| 138 |
new object[] { null }, |
| 139 |
new object[] { new string('a', 256) } // the name length limit is 255 but prior to V4 the limit is 16383 |
| 140 |
}; |
| 141 |
} |
| 142 |
|
| 143 |
public static IEnumerable<object[]> TestValueTypes { get { return s_testValueTypes; } } |
| 144 |
|
| 145 |
public static IEnumerable<object[]> TestObjects { get { return s_testObjects; } } |
| 146 |
|
| 147 |
public static IEnumerable<object[]> TestEnvironment { get { return s_testEnvironment; } } |
| 148 |
|
| 149 |
public static IEnumerable<object[]> TestExpandableStrings { get { return s_testExpandableStrings; } } |
| 150 |
|
| 151 |
public static IEnumerable<object[]> TestValueNames { get { return s_testValueNames; } } |
| 152 |
} |
| 153 |
} |