| 1 | # |
| 2 | # Copyright (C) 2019 EfficiOS Inc. |
| 3 | # |
| 4 | # This program is free software; you can redistribute it and/or |
| 5 | # modify it under the terms of the GNU General Public License |
| 6 | # as published by the Free Software Foundation; only version 2 |
| 7 | # of the License. |
| 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, write to the Free Software |
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | # |
| 18 | |
| 19 | import unittest |
| 20 | import uuid |
| 21 | import copy |
| 22 | import bt2 |
| 23 | |
| 24 | |
| 25 | @unittest.skip("this is broken") |
| 26 | class CtfWriterClockTestCase(unittest.TestCase): |
| 27 | def setUp(self): |
| 28 | self._clock = bt2.CtfWriterClock('salut') |
| 29 | |
| 30 | def tearDown(self): |
| 31 | del self._clock |
| 32 | |
| 33 | def test_create_default(self): |
| 34 | self.assertEqual(self._clock.name, 'salut') |
| 35 | |
| 36 | def test_create_invalid_no_name(self): |
| 37 | with self.assertRaises(TypeError): |
| 38 | bt2.CtfWriterClock() |
| 39 | |
| 40 | def test_create_full(self): |
| 41 | my_uuid = uuid.uuid1() |
| 42 | cc = bt2.CtfWriterClock(name='name', description='some description', |
| 43 | frequency=1001, precision=176, |
| 44 | offset=bt2.ClockClassOffset(45, 3003), |
| 45 | is_absolute=True, uuid=my_uuid) |
| 46 | self.assertEqual(cc.name, 'name') |
| 47 | self.assertEqual(cc.description, 'some description') |
| 48 | self.assertEqual(cc.frequency, 1001) |
| 49 | self.assertEqual(cc.precision, 176) |
| 50 | self.assertEqual(cc.offset, bt2.ClockClassOffset(45, 3003)) |
| 51 | self.assertEqual(cc.is_absolute, True) |
| 52 | self.assertEqual(cc.uuid, copy.deepcopy(my_uuid)) |
| 53 | |
| 54 | def test_assign_description(self): |
| 55 | self._clock.description = 'hi people' |
| 56 | self.assertEqual(self._clock.description, 'hi people') |
| 57 | |
| 58 | def test_assign_invalid_description(self): |
| 59 | with self.assertRaises(TypeError): |
| 60 | self._clock.description = 23 |
| 61 | |
| 62 | def test_assign_frequency(self): |
| 63 | self._clock.frequency = 987654321 |
| 64 | self.assertEqual(self._clock.frequency, 987654321) |
| 65 | |
| 66 | def test_assign_invalid_frequency(self): |
| 67 | with self.assertRaises(TypeError): |
| 68 | self._clock.frequency = 'lel' |
| 69 | |
| 70 | def test_assign_precision(self): |
| 71 | self._clock.precision = 12 |
| 72 | self.assertEqual(self._clock.precision, 12) |
| 73 | |
| 74 | def test_assign_invalid_precision(self): |
| 75 | with self.assertRaises(TypeError): |
| 76 | self._clock.precision = 'lel' |
| 77 | |
| 78 | def test_assign_offset(self): |
| 79 | self._clock.offset = bt2.ClockClassOffset(12, 56) |
| 80 | self.assertEqual(self._clock.offset, bt2.ClockClassOffset(12, 56)) |
| 81 | |
| 82 | def test_assign_invalid_offset(self): |
| 83 | with self.assertRaises(TypeError): |
| 84 | self._clock.offset = object() |
| 85 | |
| 86 | def test_assign_absolute(self): |
| 87 | self._clock.is_absolute = True |
| 88 | self.assertTrue(self._clock.is_absolute) |
| 89 | |
| 90 | def test_assign_invalid_absolute(self): |
| 91 | with self.assertRaises(TypeError): |
| 92 | self._clock.is_absolute = 23 |
| 93 | |
| 94 | def test_assign_uuid(self): |
| 95 | the_uuid = uuid.uuid1() |
| 96 | self._clock.uuid = the_uuid |
| 97 | self.assertEqual(self._clock.uuid, the_uuid) |
| 98 | |
| 99 | def test_assign_invalid_uuid(self): |
| 100 | with self.assertRaises(TypeError): |
| 101 | self._clock.uuid = object() |
| 102 | |
| 103 | def test_assign_time(self): |
| 104 | self._clock.time = 41232 |
| 105 | |
| 106 | def test_assign_invalid_time(self): |
| 107 | with self.assertRaises(TypeError): |
| 108 | self._clock.time = object() |
| 109 | |
| 110 | def _test_copy(self, cpy): |
| 111 | self.assertIsNot(cpy, self._clock) |
| 112 | self.assertNotEqual(cpy.addr, self._clock.addr) |
| 113 | self.assertEqual(cpy, self._clock) |
| 114 | |
| 115 | def test_copy(self): |
| 116 | cpy = copy.copy(self._clock) |
| 117 | self._test_copy(cpy) |
| 118 | |
| 119 | def test_deepcopy(self): |
| 120 | cpy = copy.deepcopy(self._clock) |
| 121 | self._test_copy(cpy) |
| 122 | |
| 123 | def test_eq(self): |
| 124 | my_uuid = uuid.uuid1() |
| 125 | cc1 = bt2.CtfWriterClock(name='name', description='some description', |
| 126 | frequency=1001, precision=176, |
| 127 | offset=bt2.ClockClassOffset(45, 3003), |
| 128 | is_absolute=True, uuid=my_uuid) |
| 129 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 130 | frequency=1001, precision=176, |
| 131 | offset=bt2.ClockClassOffset(45, 3003), |
| 132 | is_absolute=True, uuid=my_uuid) |
| 133 | self.assertEqual(cc1, cc2) |
| 134 | |
| 135 | def test_ne_name(self): |
| 136 | my_uuid = uuid.uuid1() |
| 137 | cc1 = bt2.CtfWriterClock(name='mane', description='some description', |
| 138 | frequency=1001, precision=176, |
| 139 | offset=bt2.ClockClassOffset(45, 3003), |
| 140 | is_absolute=True, uuid=my_uuid) |
| 141 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 142 | frequency=1001, precision=176, |
| 143 | offset=bt2.ClockClassOffset(45, 3003), |
| 144 | is_absolute=True, uuid=my_uuid) |
| 145 | self.assertNotEqual(cc1, cc2) |
| 146 | |
| 147 | def test_ne_description(self): |
| 148 | my_uuid = uuid.uuid1() |
| 149 | cc1 = bt2.CtfWriterClock(name='name', description='some descripti2', |
| 150 | frequency=1001, precision=176, |
| 151 | offset=bt2.ClockClassOffset(45, 3003), |
| 152 | is_absolute=True, uuid=my_uuid) |
| 153 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 154 | frequency=1001, precision=176, |
| 155 | offset=bt2.ClockClassOffset(45, 3003), |
| 156 | is_absolute=True, uuid=my_uuid) |
| 157 | self.assertNotEqual(cc1, cc2) |
| 158 | |
| 159 | def test_ne_frequency(self): |
| 160 | my_uuid = uuid.uuid1() |
| 161 | cc1 = bt2.CtfWriterClock(name='name', description='some description', |
| 162 | frequency=1003, precision=176, |
| 163 | offset=bt2.ClockClassOffset(45, 3003), |
| 164 | is_absolute=True, uuid=my_uuid) |
| 165 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 166 | frequency=1001, precision=176, |
| 167 | offset=bt2.ClockClassOffset(45, 3003), |
| 168 | is_absolute=True, uuid=my_uuid) |
| 169 | self.assertNotEqual(cc1, cc2) |
| 170 | |
| 171 | def test_ne_precision(self): |
| 172 | my_uuid = uuid.uuid1() |
| 173 | cc1 = bt2.CtfWriterClock(name='name', description='some description', |
| 174 | frequency=1001, precision=171, |
| 175 | offset=bt2.ClockClassOffset(45, 3003), |
| 176 | is_absolute=True, uuid=my_uuid) |
| 177 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 178 | frequency=1001, precision=176, |
| 179 | offset=bt2.ClockClassOffset(45, 3003), |
| 180 | is_absolute=True, uuid=my_uuid) |
| 181 | self.assertNotEqual(cc1, cc2) |
| 182 | |
| 183 | def test_ne_offset(self): |
| 184 | my_uuid = uuid.uuid1() |
| 185 | cc1 = bt2.CtfWriterClock(name='name', description='some description', |
| 186 | frequency=1001, precision=176, |
| 187 | offset=bt2.ClockClassOffset(45, 3001), |
| 188 | is_absolute=True, uuid=my_uuid) |
| 189 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 190 | frequency=1001, precision=176, |
| 191 | offset=bt2.ClockClassOffset(45, 3003), |
| 192 | is_absolute=True, uuid=my_uuid) |
| 193 | self.assertNotEqual(cc1, cc2) |
| 194 | |
| 195 | def test_ne_absolute(self): |
| 196 | my_uuid = uuid.uuid1() |
| 197 | cc1 = bt2.CtfWriterClock(name='name', description='some description', |
| 198 | frequency=1001, precision=176, |
| 199 | offset=bt2.ClockClassOffset(45, 3003), |
| 200 | is_absolute=True, uuid=my_uuid) |
| 201 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 202 | frequency=1001, precision=176, |
| 203 | offset=bt2.ClockClassOffset(45, 3003), |
| 204 | is_absolute=False, uuid=my_uuid) |
| 205 | self.assertNotEqual(cc1, cc2) |
| 206 | |
| 207 | def test_ne_uuid(self): |
| 208 | cc1 = bt2.CtfWriterClock(name='name', description='some description', |
| 209 | frequency=1001, precision=176, |
| 210 | offset=bt2.ClockClassOffset(45, 3003), |
| 211 | is_absolute=True, uuid=uuid.uuid1()) |
| 212 | cc2 = bt2.CtfWriterClock(name='name', description='some description', |
| 213 | frequency=1001, precision=176, |
| 214 | offset=bt2.ClockClassOffset(45, 3003), |
| 215 | is_absolute=True, uuid=uuid.uuid1()) |
| 216 | self.assertNotEqual(cc1, cc2) |
| 217 | |
| 218 | def test_eq_invalid(self): |
| 219 | self.assertFalse(self._clock == 23) |