1 # Unix SMB/CIFS implementation. Tests for kcc.graph routines
2 # Copyright (C) Andrew Bartlett 2015
4 # Written by Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Tests for samba.kcc.graph"""
24 from samba.kcc.graph import total_schedule, convert_schedule_to_repltimes
26 def ntdsconn_schedule(times):
29 from samba.dcerpc import drsblobs
30 schedule = drsblobs.schedule()
32 schedule.bandwidth = 0
33 schedule.numberOfSchedules = 1
34 header = drsblobs.scheduleHeader()
37 schedule.headerArray = [header]
38 data = drsblobs.scheduleSlots()
40 schedule.dataArray = [data]
44 class GraphFunctionTests(samba.tests.TestCase):
46 def test_total_schedule(self):
47 schedule = [0x81] * 84
48 for schedule, total in (
50 ([0xff] * 84, 84 * 8),
51 ([0xaa] * 84, 84 * 4),
52 ([0x03, 0x33] * 42, 42 * 6),
53 (list(range(7)) * 12, 12 * 9),
54 (list(range(4)) * 21, 21 * 4)):
55 self.assertEqual(total_schedule(schedule), total)
57 def test_convert_schedule_to_repltimes(self):
58 for ntdsconn_times, repltimes in (
59 ([0x01] * 168, [0x11] * 84),
61 ([0x06] * 168, [0x66] * 84),
62 ([0x03, 0xa] * 84, [0x3a] * 84),
64 [0x01, 0x23, 0x45, 0x60, 0x12, 0x34, 0x56] * 12)):
65 schedule = ntdsconn_schedule(ntdsconn_times)
66 self.assertEqual(convert_schedule_to_repltimes(schedule),