-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionsTest.cs
214 lines (194 loc) · 8.24 KB
/
OptionsTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// This file is part of bugreport.
// Copyright (c) 2006-2009 The bugreport Developers.
// See AUTHORS.txt for details.
// Licensed under the GNU General Public License, Version 3 (GPLv3).
// See LICENSE.txt for details.
using System;
using System.Collections.ObjectModel;
using System.IO;
using NUnit.Framework;
namespace bugreport
{
[TestFixture]
public class OptionsTest
{
private FakeFileResolver fileResolver;
private String[] commandLine;
private sealed class FakeFileResolver : FileResolver
{
private readonly String expectedFileName;
private readonly String expectedPath;
private readonly Int32 numberOfFilesFound;
public FakeFileResolver(String expectedPath, String expectedFileName, Int32 numberOfFilesFound)
{
this.expectedPath = expectedPath;
this.expectedFileName = expectedFileName;
this.numberOfFilesFound = numberOfFilesFound;
}
[CoverageExclude]
public override ReadOnlyCollection<String> GetFilesFromDirectory(String path, String fileName)
{
if (path == expectedPath &&
fileName == expectedFileName)
{
return new ReadOnlyCollection<String>(new String[numberOfFilesFound]);
}
throw new ArgumentException(
String.Format(
"expectations not met: path = {0} , expected = {1} ; fileName = {2} , expected = {3}",
path,
expectedPath,
fileName,
expectedFileName
)
);
}
}
[Test]
public void DebugOption()
{
fileResolver = new FakeFileResolver(
@"/cygwin/home/steve/bugreport/tests/simple/heap",
@"simple-malloc-via-immediate*.dump",
12
);
Options.FileResolver = fileResolver;
commandLine = new[]
{
"--debug",
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate*.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.IsTrue(Options.IsDebugging);
commandLine = new[]
{
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate*.dump",
"--debug"
};
Options.ParseArgumentsFrom(commandLine);
Assert.IsTrue(Options.IsDebugging);
commandLine = new[]
{
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate*.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.IsFalse(Options.IsDebugging);
}
[Test]
public void FileResolver()
{
var realFileResolver = new FileResolver();
var files = realFileResolver.GetFilesFromDirectory(Environment.CurrentDirectory, "*");
Assert.IsNotNull(files);
}
[Test]
public void FunctionName()
{
commandLine = new[]
{
"--function=nomain",
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate_gcc403-02-g.dump"
,
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate2_gcc403-02-g.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.AreEqual("nomain", Options.FunctionToAnalyze);
Assert.AreEqual(2, Options.Filenames.Count);
commandLine = new[]
{
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate_gcc403-02-g.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.AreEqual("_start", Options.FunctionToAnalyze);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void FunctionNameWithoutEquals()
{
commandLine = new[]
{
"--function",
"alternatefuntionname",
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate2_gcc403-02-g.dump"
};
Options.ParseArgumentsFrom(commandLine);
}
[Test]
public void MultipleFilenames()
{
commandLine = new[]
{
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate_gcc403-02-g.dump"
,
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate2_gcc403-02-g.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.AreEqual(2, Options.Filenames.Count);
}
[Test]
public void TraceOption()
{
fileResolver = new FakeFileResolver(
@"/cygwin/home/steve/bugreport/tests/simple/heap",
@"simple-malloc-via-immediate*.dump",
12
);
Options.FileResolver = fileResolver;
commandLine = new[]
{
"--trace",
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate*.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.IsTrue(Options.IsTracing);
commandLine = new[]
{
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate*.dump",
"--trace"
};
Options.ParseArgumentsFrom(commandLine);
Assert.IsTrue(Options.IsTracing);
commandLine = new[]
{
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate*.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.IsFalse(Options.IsTracing);
}
[Test]
public void WildcardInFileName()
{
fileResolver = new FakeFileResolver(
@"/cygwin/home/steve/bugreport/tests/simple/heap",
@"simple-malloc-via-immediate*.dump",
12
);
Options.FileResolver = fileResolver;
commandLine = new[]
{
@"/cygwin/home/steve/bugreport/tests/simple/heap/simple-malloc-via-immediate*.dump"
};
Options.ParseArgumentsFrom(commandLine);
Assert.AreEqual(12, Options.Filenames.Count);
commandLine = new[] {"simple-malloc-via-immediate*.dump"};
var oldDirectory = Directory.GetCurrentDirectory();
try
{
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Directory.SetCurrentDirectory(desktopPath);
fileResolver = new FakeFileResolver(
desktopPath,
@"simple-malloc-via-immediate*.dump",
12
);
Options.FileResolver = fileResolver;
Options.ParseArgumentsFrom(commandLine);
Assert.AreEqual(12, Options.Filenames.Count);
}
finally
{
Directory.SetCurrentDirectory(oldDirectory);
}
}
}
}