[Usb][Non-ACR] Read bcdUSB directly from device descriptor 62/214062/2
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Tue, 17 Sep 2019 13:03:38 +0000 (15:03 +0200)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Tue, 17 Sep 2019 13:45:20 +0000 (15:45 +0200)
Although we fully control the virtual device we use for testing, the
bcdUSB (usb version) field can be overridden by system. Testing its
getter requires reading the actual value from the device descriptor.

Change-Id: I9e501c3cd550863f5ea20d438178eb8b3e6db388
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbDeviceInformation.cs

index a97cfe7..f2598ae 100755 (executable)
@@ -18,6 +18,7 @@ using NUnit.Framework;
 using NUnit.Framework.TUnit;
 using System;
 using System.Linq;
+using System.IO;
 
 namespace Tizen.System.Usb.Tests
 {
@@ -67,18 +68,17 @@ namespace Tizen.System.Usb.Tests
                 foreach (var testdata in Helper.GetDeviceTestData())
                 {
                     var deviceUnderTest = testdata.Key;
-                    var expectedTestData = testdata.Value;
 
                     // PRECONDITION
                     Assert.IsNotNull(deviceUnderTest, "Invalid USB Device for test");
-                    Assert.IsNotNull(expectedTestData, "Unable to fetch test data for USB device");
-
                     var testDeviceInfo = deviceUnderTest.DeviceInformation;
-                    var expectedDeviceInfo = expectedTestData.DeviceInformation;
+
+                    byte[] desc = File.ReadAllBytes($"/dev/bus/usb/{deviceUnderTest.BusId:D3}/{deviceUnderTest.Address:D3}");
+                    var expectedVersion = BitConverter.ToUInt16(desc, 2);
 
                     // TEST CODE
-                    Assert.IsTrue(expectedDeviceInfo.UsbVersion == testDeviceInfo.UsbVersion,
-                        $"Wrong UsbVersion, Expected: {expectedDeviceInfo.UsbVersion}, Actual: {testDeviceInfo.UsbVersion}");
+                    Assert.IsTrue(expectedVersion == testDeviceInfo.UsbVersion,
+                        $"Wrong UsbVersion, Expected: {expectedVersion}, Actual: {testDeviceInfo.UsbVersion}");
                 }
             }
             catch (NotSupportedException)