|
@@ -240,3 +240,113 @@ class SinkConfigTestCase(unittest.TestCase):
|
240
|
240
|
b"v: 15.00 V",
|
241
|
241
|
b"i: 3.00 A"])
|
242
|
242
|
self.assertEqual(ft_valid, self.obj_valid)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+class UnknownPDOTestCase(unittest.TestCase):
|
|
246
|
+
|
|
247
|
+ def setUp(self):
|
|
248
|
+ self.obj_zero = pdbuddy.UnknownPDO(value=0x00000000)
|
|
249
|
+ self.obj_notzero = pdbuddy.UnknownPDO(value=0xFFFFFFFF)
|
|
250
|
+
|
|
251
|
+ def test_str_zero(self):
|
|
252
|
+ self.assertEqual(str(self.obj_zero), "00000000")
|
|
253
|
+
|
|
254
|
+ def test_str_notzero(self):
|
|
255
|
+ self.assertEqual(str(self.obj_notzero), "FFFFFFFF")
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+class SrcFixedPDOTestCase(unittest.TestCase):
|
|
259
|
+
|
|
260
|
+ def setUp(self):
|
|
261
|
+ self.obj_everything = pdbuddy.SrcFixedPDO(True, True, True, True, True,
|
|
262
|
+ 3, 20000, 5000)
|
|
263
|
+ self.obj_minimal = pdbuddy.SrcFixedPDO(False, False, False, False,
|
|
264
|
+ False, 0, 5000, 1500)
|
|
265
|
+
|
|
266
|
+ def test_str_everything(self):
|
|
267
|
+ self.assertEqual(str(self.obj_everything),
|
|
268
|
+ "fixed\n\tdual_role_pwr: 1\n\tusb_suspend: 1\n"
|
|
269
|
+ "\tunconstrained_pwr: 1\n\tusb_comms: 1\n\tdual_role_data: 1\n"
|
|
270
|
+ "\tpeak_i: 3\n\tv: 20.00 V\n\ti: 5.00 A")
|
|
271
|
+
|
|
272
|
+ def test_str_minimal(self):
|
|
273
|
+ self.assertEqual(str(self.obj_minimal),
|
|
274
|
+ "fixed\n\tv: 5.00 V\n\ti: 1.50 A")
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+class ReadPDOTestCase(unittest.TestCase):
|
|
278
|
+
|
|
279
|
+ def setUp(self):
|
|
280
|
+ self.src_fixed_everything = pdbuddy.SrcFixedPDO(True, True, True, True,
|
|
281
|
+ True, 3, 20000, 5000)
|
|
282
|
+ self.src_fixed_minimal = pdbuddy.SrcFixedPDO(False, False, False,
|
|
283
|
+ False, False, 0, 5000, 1500)
|
|
284
|
+ self.unknown_zero = pdbuddy.UnknownPDO(value=0x00000000)
|
|
285
|
+ self.unknown_notzero = pdbuddy.UnknownPDO(value=0xFFFFFFFF)
|
|
286
|
+
|
|
287
|
+ def test_read_src_fixed_everything(self):
|
|
288
|
+ rp_src_fixed_everything = pdbuddy.read_pdo([b"PDO 1: fixed",
|
|
289
|
+ b"\tdual_role_pwr: 1",
|
|
290
|
+ b"\tusb_suspend: 1",
|
|
291
|
+ b"\tunconstrained_pwr: 1",
|
|
292
|
+ b"\tusb_comms: 1",
|
|
293
|
+ b"\tdual_role_data: 1",
|
|
294
|
+ b"\tpeak_i: 3",
|
|
295
|
+ b"\tv: 20.00 V",
|
|
296
|
+ b"\ti: 5.00 A"])
|
|
297
|
+ self.assertEqual(self.src_fixed_everything, rp_src_fixed_everything)
|
|
298
|
+
|
|
299
|
+ def test_read_src_fixed_minimal(self):
|
|
300
|
+ rp_src_fixed_minimal = pdbuddy.read_pdo([b"PDO 1: fixed",
|
|
301
|
+ b"\tv: 5.00 V",
|
|
302
|
+ b"\ti: 1.50 A"])
|
|
303
|
+ self.assertEqual(self.src_fixed_minimal, rp_src_fixed_minimal)
|
|
304
|
+
|
|
305
|
+ def test_read_src_fixed_minimal_no_index(self):
|
|
306
|
+ rp_src_fixed_minimal = pdbuddy.read_pdo([b"fixed",
|
|
307
|
+ b"\tv: 5.00 V",
|
|
308
|
+ b"\ti: 1.50 A"])
|
|
309
|
+ self.assertEqual(self.src_fixed_minimal, rp_src_fixed_minimal)
|
|
310
|
+
|
|
311
|
+ def test_read_unknown_zero(self):
|
|
312
|
+ rp_unknown_zero = pdbuddy.read_pdo([b"PDO 1: 00000000"])
|
|
313
|
+ self.assertEqual(self.unknown_zero, rp_unknown_zero)
|
|
314
|
+
|
|
315
|
+ def test_read_unknown_notzero(self):
|
|
316
|
+ rp_unknown_notzero = pdbuddy.read_pdo([b"PDO 1: FFFFFFFF"])
|
|
317
|
+ self.assertEqual(self.unknown_notzero, rp_unknown_notzero)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+class ReadPDOListTestCase(unittest.TestCase):
|
|
321
|
+
|
|
322
|
+ def setUp(self):
|
|
323
|
+ self.src_fixed_everything = pdbuddy.SrcFixedPDO(True, True, True, True,
|
|
324
|
+ True, 3, 20000, 5000)
|
|
325
|
+ self.src_fixed_minimal = pdbuddy.SrcFixedPDO(False, False, False,
|
|
326
|
+ False, False, 0, 5000, 1500)
|
|
327
|
+ self.unknown_zero = pdbuddy.UnknownPDO(value=0x00000000)
|
|
328
|
+ self.unknown_notzero = pdbuddy.UnknownPDO(value=0xFFFFFFFF)
|
|
329
|
+
|
|
330
|
+ def test_read_pdo_list(self):
|
|
331
|
+ # It's not a legal list for USB Power Delivery, but it works fine for
|
|
332
|
+ # testing this code
|
|
333
|
+ text = [b"PDO 1: fixed",
|
|
334
|
+ b"\tdual_role_pwr: 1",
|
|
335
|
+ b"\tusb_suspend: 1",
|
|
336
|
+ b"\tunconstrained_pwr: 1",
|
|
337
|
+ b"\tusb_comms: 1",
|
|
338
|
+ b"\tdual_role_data: 1",
|
|
339
|
+ b"\tpeak_i: 3",
|
|
340
|
+ b"\tv: 20.00 V",
|
|
341
|
+ b"\ti: 5.00 A",
|
|
342
|
+ b"PDO 2: fixed",
|
|
343
|
+ b"\tv: 5.00 V",
|
|
344
|
+ b"\ti: 1.50 A",
|
|
345
|
+ b"PDO 3: 00000000",
|
|
346
|
+ b"PDO 4: FFFFFFFF"]
|
|
347
|
+ pdo_list = pdbuddy.read_pdo_list(text)
|
|
348
|
+
|
|
349
|
+ self.assertEqual(pdo_list[0], self.src_fixed_everything)
|
|
350
|
+ self.assertEqual(pdo_list[1], self.src_fixed_minimal)
|
|
351
|
+ self.assertEqual(pdo_list[2], self.unknown_zero)
|
|
352
|
+ self.assertEqual(pdo_list[3], self.unknown_notzero)
|