@@ -8,6 +8,31 @@ import { UDID, fixtures, getServerWithFixtures } from '../fixtures/index.js';
88
99use ( chaiAsPromised ) ;
1010
11+ const DUP_UDID = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ;
12+
13+ function mockUsbmuxDevice (
14+ deviceId : number ,
15+ serialNumber : string ,
16+ connectionType : 'USB' | 'Network' ,
17+ opts ?: { connectionSpeed ?: number ; productId ?: number } ,
18+ ) : Device {
19+ const connectionSpeed = opts ?. connectionSpeed ?? 480000000 ;
20+ const productId = opts ?. productId ?? 4776 ;
21+ return {
22+ DeviceID : deviceId ,
23+ MessageType : 'Attached' ,
24+ Properties : {
25+ ConnectionSpeed : connectionSpeed ,
26+ ConnectionType : connectionType ,
27+ DeviceID : deviceId ,
28+ LocationID : 0 ,
29+ ProductID : productId ,
30+ SerialNumber : serialNumber ,
31+ USBSerialNumber : serialNumber ,
32+ } ,
33+ } ;
34+ }
35+
1136describe ( 'usbmux' , function ( ) {
1237 let usbmux : Usbmux | null ;
1338 let server : Server | null ;
@@ -62,113 +87,46 @@ describe('usbmux', function () {
6287 } ) ;
6388
6489 it ( 'should order duplicate UDIDs with USB before Network' , function ( ) {
65- const udid = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ;
66- const net : Device = {
67- DeviceID : 2 ,
68- MessageType : 'Attached' ,
69- Properties : {
70- ConnectionSpeed : 480000000 ,
71- ConnectionType : 'Network' ,
72- DeviceID : 2 ,
73- LocationID : 0 ,
74- ProductID : 4776 ,
75- SerialNumber : udid ,
76- USBSerialNumber : udid ,
77- } ,
78- } ;
79- const usb : Device = {
80- DeviceID : 1 ,
81- MessageType : 'Attached' ,
82- Properties : {
83- ConnectionSpeed : 480000000 ,
84- ConnectionType : 'USB' ,
85- DeviceID : 1 ,
86- LocationID : 0 ,
87- ProductID : 4776 ,
88- SerialNumber : udid ,
89- USBSerialNumber : udid ,
90- } ,
91- } ;
90+ const net = mockUsbmuxDevice ( 2 , DUP_UDID , 'Network' ) ;
91+ const usb = mockUsbmuxDevice ( 1 , DUP_UDID , 'USB' ) ;
9292 const sorted = prioritizeUsbOverNetworkForDuplicateUdids ( [ net , usb ] ) ;
9393 expect ( sorted . map ( ( d ) => d . DeviceID ) ) . to . deep . equal ( [ 1 , 2 ] ) ;
9494 } ) ;
9595
9696 it ( 'should not pull duplicate UDIDs into a block when another device is between' , function ( ) {
97- const udid = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ;
98- const net : Device = {
99- DeviceID : 2 ,
100- MessageType : 'Attached' ,
101- Properties : {
102- ConnectionSpeed : 480000000 ,
103- ConnectionType : 'Network' ,
104- DeviceID : 2 ,
105- LocationID : 0 ,
106- ProductID : 4776 ,
107- SerialNumber : udid ,
108- USBSerialNumber : udid ,
109- } ,
110- } ;
111- const usb : Device = {
112- DeviceID : 1 ,
113- MessageType : 'Attached' ,
114- Properties : {
115- ConnectionSpeed : 480000000 ,
116- ConnectionType : 'USB' ,
117- DeviceID : 1 ,
118- LocationID : 0 ,
119- ProductID : 4776 ,
120- SerialNumber : udid ,
121- USBSerialNumber : udid ,
122- } ,
123- } ;
124- const other : Device = {
125- DeviceID : 99 ,
126- MessageType : 'Attached' ,
127- Properties : {
128- ConnectionSpeed : 0 ,
129- ConnectionType : 'USB' ,
130- DeviceID : 99 ,
131- LocationID : 0 ,
132- ProductID : 0 ,
133- SerialNumber : 'other-udid' ,
134- USBSerialNumber : 'other-udid' ,
135- } ,
136- } ;
97+ const net = mockUsbmuxDevice ( 2 , DUP_UDID , 'Network' ) ;
98+ const usb = mockUsbmuxDevice ( 1 , DUP_UDID , 'USB' ) ;
99+ const other = mockUsbmuxDevice ( 99 , 'other-udid' , 'USB' , {
100+ connectionSpeed : 0 ,
101+ productId : 0 ,
102+ } ) ;
137103 const sorted = prioritizeUsbOverNetworkForDuplicateUdids ( [ net , other , usb ] ) ;
138104 expect ( sorted . map ( ( d ) => d . DeviceID ) ) . to . deep . equal ( [ 1 , 99 , 2 ] ) ;
139105 } ) ;
140106
141- it ( 'should preserve order for unique UDIDs' , function ( ) {
142- const a : Device = {
143- DeviceID : 1 ,
144- MessageType : 'Attached' ,
145- Properties : {
146- ConnectionSpeed : 0 ,
147- ConnectionType : 'USB' ,
148- DeviceID : 1 ,
149- LocationID : 0 ,
150- ProductID : 0 ,
151- SerialNumber : 'udid-a' ,
152- USBSerialNumber : 'udid-a' ,
153- } ,
154- } ;
155- const b : Device = {
156- DeviceID : 2 ,
157- MessageType : 'Attached' ,
158- Properties : {
159- ConnectionSpeed : 0 ,
160- ConnectionType : 'Network' ,
161- DeviceID : 2 ,
162- LocationID : 0 ,
163- ProductID : 0 ,
164- SerialNumber : 'udid-b' ,
165- USBSerialNumber : 'udid-b' ,
166- } ,
167- } ;
168- const sorted = prioritizeUsbOverNetworkForDuplicateUdids ( [ a , b ] ) ;
107+ it ( 'should reorder mixed duplicate and unique UDIDs without breaking interleaving' , function ( ) {
108+ const aNet = mockUsbmuxDevice ( 2 , 'dup-a' , 'Network' ) ;
109+ const bUsb = mockUsbmuxDevice ( 10 , 'only-b' , 'USB' , {
110+ connectionSpeed : 0 ,
111+ productId : 0 ,
112+ } ) ;
113+ const aUsb = mockUsbmuxDevice ( 1 , 'dup-a' , 'USB' ) ;
114+ const cNet = mockUsbmuxDevice ( 20 , 'only-c' , 'Network' , {
115+ connectionSpeed : 0 ,
116+ productId : 0 ,
117+ } ) ;
118+ const sorted = prioritizeUsbOverNetworkForDuplicateUdids ( [
119+ aNet ,
120+ bUsb ,
121+ aUsb ,
122+ cNet ,
123+ ] ) ;
124+ expect ( sorted . map ( ( d ) => d . DeviceID ) ) . to . deep . equal ( [ 1 , 10 , 2 , 20 ] ) ;
169125 expect ( sorted . map ( ( d ) => d . Properties . SerialNumber ) ) . to . deep . equal ( [
170- 'udid-a' ,
171- 'udid-b' ,
126+ 'dup-a' ,
127+ 'only-b' ,
128+ 'dup-a' ,
129+ 'only-c' ,
172130 ] ) ;
173131 } ) ;
174132} ) ;
0 commit comments