3 # Test for smbcontrol command line argument handling.
8 class NoArgs(comfychair
.TestCase
):
9 """Test no arguments produces usage message."""
11 out
= self
.runcmd("smbcontrol", expectedResult
= 1)
12 self
.assert_re_match("Usage: smbcontrol", out
[1])
14 class OneArg(comfychair
.TestCase
):
15 """Test single argument produces usage message."""
17 out
= self
.runcmd("smbcontrol foo", expectedResult
= 1)
18 self
.assert_re_match("Usage: smbcontrol", out
[1])
20 class SmbdDest(comfychair
.TestCase
):
21 """Test the broadcast destination 'smbd'."""
23 out
= self
.runcmd("smbcontrol smbd noop")
25 class NmbdDest(comfychair
.TestCase
):
26 """Test the destination 'nmbd'."""
28 # We need a way to start/stop/whatever nmbd
29 raise comfychair
.NotRunError
, "not implemented"
31 class PidDest(comfychair
.TestCase
):
32 """Test a pid number destination'."""
34 out
= self
.runcmd("smbcontrol 1234 noop")
36 class SelfDest(comfychair
.TestCase
):
37 """Test the destination 'self'."""
39 out
= self
.runcmd("smbcontrol self noop")
41 class WinbinddDest(comfychair
.TestCase
):
42 """Test the destination 'winbindd'."""
44 # We need a way to start/stop/whatever winbindd
45 raise comfychair
.NotRunError
, "not implemented"
47 class BadDest(comfychair
.TestCase
):
48 """Test a bad destination."""
50 out
= self
.runcmd("smbcontrol foo noop", expectedResult
= 1)
52 class BadCmd(comfychair
.TestCase
):
53 """Test a bad command."""
55 out
= self
.runcmd("smbcontrol self spottyfoot", expectedResult
= 1)
56 self
.assert_re_match("smbcontrol: unknown command", out
[1]);
58 class NoArgCmdTest(comfychair
.TestCase
):
59 """A test class that tests a command with no argument."""
62 out
= self
.runcmd("smbcontrol self %s" % self
.cmd
)
63 out
= self
.runcmd("smbcontrol self %s spottyfoot" % self
.cmd
,
66 class ForceElection(NoArgCmdTest
):
67 """Test a force-election message."""
69 self
.cmd
= "force-election"
71 class SamSync(NoArgCmdTest
):
72 """Test a samsync message."""
76 class SamRepl(NoArgCmdTest
):
77 """Test a samrepl message."""
81 class DmallocChanged(NoArgCmdTest
):
82 """Test a dmalloc-changed message."""
84 self
.cmd
= "dmalloc-log-changed"
86 class DmallocMark(NoArgCmdTest
):
87 """Test a dmalloc-mark message."""
89 self
.cmd
= "dmalloc-mark"
91 class Shutdown(NoArgCmdTest
):
92 """Test a shutdown message."""
96 class Ping(NoArgCmdTest
):
97 """Test a ping message."""
101 class Debuglevel(NoArgCmdTest
):
102 """Test a debuglevel message."""
104 self
.cmd
= "debuglevel"
106 class OneArgCmdTest(comfychair
.TestCase
):
107 """A test class that tests a command with one argument."""
110 out
= self
.runcmd("smbcontrol self %s spottyfoot" % self
.cmd
)
111 out
= self
.runcmd("smbcontrol self %s" % self
.cmd
, expectedResult
= 1)
113 class DrvUpgrade(OneArgCmdTest
):
114 """Test driver upgrade message."""
116 self
.cmd
= "drvupgrade"
118 class CloseShare(OneArgCmdTest
):
119 """Test close share message."""
121 self
.cmd
= "close-share"
123 class Debug(OneArgCmdTest
):
124 """Test a debug message."""
128 class PrintNotify(comfychair
.TestCase
):
129 """Test print notification commands."""
134 out
= self
.runcmd("smbcontrol self printnotify", expectedResult
= 1)
135 self
.assert_re_match("Must specify subcommand", out
[1]);
137 # Invalid subcommand name
139 out
= self
.runcmd("smbcontrol self printnotify spottyfoot",
141 self
.assert_re_match("Invalid subcommand", out
[1]);
145 for cmd
in ["queuepause", "queueresume"]:
147 out
= self
.runcmd("smbcontrol self printnotify %s" % cmd
,
149 self
.assert_re_match("Usage:", out
[1])
151 out
= self
.runcmd("smbcontrol self printnotify %s spottyfoot"
156 for cmd
in ["jobpause", "jobresume", "jobdelete"]:
158 out
= self
.runcmd("smbcontrol self printnotify %s" % cmd
,
160 self
.assert_re_match("Usage:", out
[1])
162 out
= self
.runcmd("smbcontrol self printnotify %s spottyfoot"
163 % cmd
, expectedResult
= 1)
164 self
.assert_re_match("Usage:", out
[1])
166 out
= self
.runcmd("smbcontrol self printnotify %s spottyfoot 123"
171 out
= self
.runcmd("smbcontrol self printnotify printer",
173 self
.assert_re_match("Usage", out
[1])
175 out
= self
.runcmd("smbcontrol self printnotify printer spottyfoot",
177 self
.assert_re_match("Usage", out
[1])
179 for cmd
in ["comment", "port", "driver"]:
181 out
= self
.runcmd("smbcontrol self printnotify printer spottyfoot "
182 "%s" % cmd
, expectedResult
= 1)
183 self
.assert_re_match("Usage", out
[1])
185 out
= self
.runcmd("smbcontrol self printnotify printer spottyfoot "
188 class Profile(comfychair
.TestCase
):
189 """Test setting the profiling level."""
192 out
= self
.runcmd("smbcontrol self profile", expectedResult
= 1)
193 self
.assert_re_match("Usage", out
[1])
195 out
= self
.runcmd("smbcontrol self profile spottyfoot",
197 self
.assert_re_match("Unknown", out
[1])
199 for cmd
in ["off", "count", "on", "flush"]:
200 out
= self
.runcmd("smbcontrol self profile %s" % cmd
)
202 class ProfileLevel(comfychair
.TestCase
):
203 """Test requesting the current profiling level."""
206 out
= self
.runcmd("smbcontrol self profilelevel spottyfoot",
208 self
.assert_re_match("Usage", out
[1])
210 out
= self
.runcmd("smbcontrol self profilelevel")
212 class TimeoutArg(comfychair
.TestCase
):
213 """Test the --timeout argument."""
215 out
= self
.runcmd("smbcontrol --timeout 5 self noop")
216 out
= self
.runcmd("smbcontrol --timeout spottyfoot self noop",
219 class ConfigFileArg(comfychair
.TestCase
):
220 """Test the --configfile argument."""
222 out
= self
.runcmd("smbcontrol --configfile /dev/null self noop")
224 class BogusArg(comfychair
.TestCase
):
225 """Test a bogus command line argument."""
227 out
= self
.runcmd("smbcontrol --bogus self noop", expectedResult
= 1)
229 tests
= [NoArgs
, OneArg
, SmbdDest
, NmbdDest
, WinbinddDest
, PidDest
,
230 SelfDest
, BadDest
, BadCmd
, Debug
, ForceElection
, SamSync
,
231 SamRepl
, DmallocMark
, DmallocChanged
, Shutdown
, DrvUpgrade
,
232 CloseShare
, Ping
, Debuglevel
, PrintNotify
, Profile
, ProfileLevel
,
233 TimeoutArg
, ConfigFileArg
, BogusArg
]
235 # Handle execution of this file as a main program
237 if __name__
== '__main__':
238 comfychair
.main(tests
)