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 *
29 def ntdsconn_schedule(times):
32 from samba.dcerpc import drsblobs
33 schedule = drsblobs.schedule()
35 schedule.bandwidth = 0
36 schedule.numberOfSchedules = 1
37 header = drsblobs.scheduleHeader()
40 schedule.headerArray = [header]
41 data = drsblobs.scheduleSlots()
43 schedule.dataArray = [data]
47 class GraphFunctionTests(samba.tests.TestCase):
49 def test_total_schedule(self):
50 schedule = [0x81] * 84
51 for schedule, total in (
53 ([0xff] * 84, 84 * 8),
54 ([0xaa] * 84, 84 * 4),
55 ([0x03, 0x33] * 42, 42 * 6),
56 (list(range(7)) * 12, 12 * 9),
57 (list(range(4)) * 21, 21 * 4)):
58 self.assertEquals(total_schedule(schedule), total)
60 def test_convert_schedule_to_repltimes(self):
61 for ntdsconn_times, repltimes in (
62 ([0x01] * 168, [0x11] * 84),
64 ([0x06] * 168, [0x66] * 84),
65 ([0x03, 0xa] * 84, [0x3a] * 84),
67 [0x01, 0x23, 0x45, 0x60, 0x12, 0x34, 0x56] * 12)):
68 schedule = ntdsconn_schedule(ntdsconn_times)
69 self.assertEquals(convert_schedule_to_repltimes(schedule),