traffic: new version of model with packet_rate, version number
[samba.git] / python / samba / tests / registry.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 """Tests for samba.registry."""
19
20 import os
21 from samba import registry
22 import samba.tests
23 from samba import WERRORError
24 from subprocess import Popen, PIPE
25
26
27 class HelperTests(samba.tests.TestCase):
28
29     def test_predef_to_name(self):
30         self.assertEquals("HKEY_LOCAL_MACHINE",
31                           registry.get_predef_name(0x80000002))
32
33     def test_str_regtype(self):
34         self.assertEquals("REG_DWORD", registry.str_regtype(4))
35
36
37 class HiveTests(samba.tests.TestCaseInTempDir):
38
39     def setUp(self):
40         super(HiveTests, self).setUp()
41         self.hive_path = os.path.join(self.tempdir, "ldb_new.ldb")
42         self.hive = registry.open_ldb(self.hive_path)
43
44     def tearDown(self):
45         del self.hive
46         os.unlink(self.hive_path)
47         super(HiveTests, self).tearDown()
48
49     def test_ldb_new(self):
50         self.assertTrue(self.hive is not None)
51
52     def test_set_value(self):
53         self.assertIsNone(self.hive.set_value('foo1', 1, 'bar1'))
54
55     def test_flush(self):
56         self.assertIsNone(self.hive.set_value('foo2', 1, 'bar2'))
57         self.assertIsNone(self.hive.flush())
58
59         tdbdump_tool = 'tdbdump'
60         if os.path.isfile('bin/tdbdump'):
61             tdbdump_tool = 'bin/tdbdump'
62
63         proc = Popen([tdbdump_tool, self.hive_path], stdout=PIPE, stderr=PIPE)
64         tdb_dump, err = proc.communicate()
65         self.assertTrue(b'DN=VALUE=FOO2,HIVE=NONE' in tdb_dump)
66
67     def test_del_value(self):
68         self.assertIsNone(self.hive.set_value('foo3', 1, 'bar3'))
69         self.assertIsNone(self.hive.del_value('foo3'))
70
71     def test_del_nonexisting_value(self):
72         self.assertRaises(WERRORError, self.hive.del_value, 'foo4')
73
74
75 class RegistryTests(samba.tests.TestCase):
76
77     def test_new(self):
78         self.registry = registry.Registry()
79         self.assertIsNotNone(self.registry)