Skip to content

Commit f9789c9

Browse files
committed
Test NetworkManagerDevice.deviceType
1 parent 820c8d0 commit f9789c9

File tree

1 file changed

+101
-7
lines changed

1 file changed

+101
-7
lines changed

test/nm_test.dart

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,14 +2276,16 @@ void main() {
22762276
var nm = MockNetworkManagerServer(clientAddress);
22772277
addTearDown(() async => await nm.close());
22782278
await nm.start();
2279-
await nm.addDevice(hasBluetooth: true, btCapabilities: 0x3, name: 'NAME');
2279+
await nm.addDevice(
2280+
deviceType: 5, hasBluetooth: true, btCapabilities: 0x3, name: 'NAME');
22802281

22812282
var client = NetworkManagerClient(bus: DBusClient(clientAddress));
22822283
addTearDown(() async => await client.close());
22832284
await client.connect();
22842285

22852286
expect(client.devices, hasLength(1));
22862287
var device = client.devices[0];
2288+
expect(device.deviceType, equals(NetworkManagerDeviceType.bluetooth));
22872289
expect(device.bluetooth, isNotNull);
22882290
expect(
22892291
device.bluetooth?.btCapabilities,
@@ -2305,14 +2307,15 @@ void main() {
23052307
await nm.start();
23062308
var d1 = await nm.addDevice(hwAddress: 'DE:71:CE:00:00:01');
23072309
var d2 = await nm.addDevice(hwAddress: 'DE:71:CE:00:00:02');
2308-
await nm.addDevice(hasBridge: true, slaves: [d1, d2]);
2310+
await nm.addDevice(deviceType: 13, hasBridge: true, slaves: [d1, d2]);
23092311

23102312
var client = NetworkManagerClient(bus: DBusClient(clientAddress));
23112313
addTearDown(() async => await client.close());
23122314
await client.connect();
23132315

23142316
expect(client.devices, hasLength(3));
23152317
var device = client.devices[2];
2318+
expect(device.deviceType, equals(NetworkManagerDeviceType.bridge));
23162319
expect(device.bridge, isNotNull);
23172320
expect(device.bridge!.slaves, hasLength(2));
23182321
expect(device.bridge!.slaves[0].hwAddress, equals('DE:71:CE:00:00:01'));
@@ -2328,14 +2331,16 @@ void main() {
23282331
var nm = MockNetworkManagerServer(clientAddress);
23292332
addTearDown(() async => await nm.close());
23302333
await nm.start();
2331-
await nm.addDevice(hasGeneric: true, typeDescription: 'TYPE-DESCRIPTION');
2334+
await nm.addDevice(
2335+
deviceType: 14, hasGeneric: true, typeDescription: 'TYPE-DESCRIPTION');
23322336

23332337
var client = NetworkManagerClient(bus: DBusClient(clientAddress));
23342338
addTearDown(() async => await client.close());
23352339
await client.connect();
23362340

23372341
expect(client.devices, hasLength(1));
23382342
var device = client.devices[0];
2343+
expect(device.deviceType, equals(NetworkManagerDeviceType.generic));
23392344
expect(device.generic, isNotNull);
23402345
expect(device.generic!.typeDescription, equals('TYPE-DESCRIPTION'));
23412346
});
@@ -2350,6 +2355,7 @@ void main() {
23502355
addTearDown(() async => await nm.close());
23512356
await nm.start();
23522357
await nm.addDevice(
2358+
deviceType: 16,
23532359
hasTun: true,
23542360
owner: 1000,
23552361
group: 1001,
@@ -2364,6 +2370,7 @@ void main() {
23642370

23652371
expect(client.devices, hasLength(1));
23662372
var device = client.devices[0];
2373+
expect(device.deviceType, equals(NetworkManagerDeviceType.tun));
23672374
expect(device.tun, isNotNull);
23682375
expect(device.tun!.owner, equals(1000));
23692376
expect(device.tun!.group, equals(1001));
@@ -2383,20 +2390,21 @@ void main() {
23832390
addTearDown(() async => await nm.close());
23842391
await nm.start();
23852392
var d = await nm.addDevice(hwAddress: 'DE:71:CE:00:00:01');
2386-
await nm.addDevice(hasVlan: true, parent: d, vlanId: 42);
2393+
await nm.addDevice(deviceType: 11, hasVlan: true, parent: d, vlanId: 42);
23872394

23882395
var client = NetworkManagerClient(bus: DBusClient(clientAddress));
23892396
addTearDown(() async => await client.close());
23902397
await client.connect();
23912398

23922399
expect(client.devices, hasLength(2));
23932400
var device = client.devices[1];
2401+
expect(device.deviceType, equals(NetworkManagerDeviceType.vlan));
23942402
expect(device.vlan, isNotNull);
23952403
expect(device.vlan!.vlanId, equals(42));
23962404
expect(device.vlan!.parent.hwAddress, equals('DE:71:CE:00:00:01'));
23972405
});
23982406

2399-
test('wired device', () async {
2407+
test('ethernet device', () async {
24002408
var server = DBusServer();
24012409
addTearDown(() async => await server.close());
24022410
var clientAddress =
@@ -2406,20 +2414,24 @@ void main() {
24062414
addTearDown(() async => await nm.close());
24072415
await nm.start();
24082416
await nm.addDevice(
2409-
hasWired: true, permHwAddress: 'DE:71:CE:00:00:01', speed: 100);
2417+
deviceType: 1,
2418+
hasWired: true,
2419+
permHwAddress: 'DE:71:CE:00:00:01',
2420+
speed: 100);
24102421

24112422
var client = NetworkManagerClient(bus: DBusClient(clientAddress));
24122423
addTearDown(() async => await client.close());
24132424
await client.connect();
24142425

24152426
expect(client.devices, hasLength(1));
24162427
var device = client.devices[0];
2428+
expect(device.deviceType, equals(NetworkManagerDeviceType.ethernet));
24172429
expect(device.wired, isNotNull);
24182430
expect(device.wired!.permHwAddress, equals('DE:71:CE:00:00:01'));
24192431
expect(device.wired!.speed, equals(100));
24202432
});
24212433

2422-
test('wireless device', () async {
2434+
test('wifi device', () async {
24232435
var server = DBusServer();
24242436
addTearDown(() async => await server.close());
24252437
var clientAddress =
@@ -2442,6 +2454,7 @@ void main() {
24422454
var ap2 = await nm.addAccessPoint(hwAddress: 'AC:CE:55:00:00:02');
24432455
var ap3 = await nm.addAccessPoint(hwAddress: 'AC:CE:55:00:00:03');
24442456
await nm.addDevice(
2457+
deviceType: 2,
24452458
hasWireless: true,
24462459
accessPoints: [ap1, ap2, ap3],
24472460
activeAccessPoint: ap1,
@@ -2457,6 +2470,7 @@ void main() {
24572470

24582471
expect(client.devices, hasLength(1));
24592472
var device = client.devices[0];
2473+
expect(device.deviceType, equals(NetworkManagerDeviceType.wifi));
24602474
expect(device.wireless, isNotNull);
24612475
expect(device.wireless!.accessPoints, hasLength(3));
24622476
expect(device.wireless!.accessPoints[0].hwAddress,
@@ -2546,6 +2560,86 @@ void main() {
25462560
}));
25472561
});
25482562

2563+
test('other device types', () async {
2564+
var server = DBusServer();
2565+
addTearDown(() async => await server.close());
2566+
var clientAddress =
2567+
await server.listenAddress(DBusAddress.unix(dir: Directory.systemTemp));
2568+
2569+
var nm = MockNetworkManagerServer(clientAddress);
2570+
addTearDown(() async => await nm.close());
2571+
await nm.start();
2572+
await nm.addDevice(deviceType: 6, permHwAddress: 'DE:71:CE:00:00:01');
2573+
await nm.addDevice(deviceType: 7, permHwAddress: 'DE:71:CE:00:00:02');
2574+
await nm.addDevice(deviceType: 8, permHwAddress: 'DE:71:CE:00:00:03');
2575+
await nm.addDevice(deviceType: 9, permHwAddress: 'DE:71:CE:00:00:04');
2576+
await nm.addDevice(deviceType: 10, permHwAddress: 'DE:71:CE:00:00:05');
2577+
await nm.addDevice(deviceType: 11, permHwAddress: 'DE:71:CE:00:00:06');
2578+
await nm.addDevice(deviceType: 12, permHwAddress: 'DE:71:CE:00:00:07');
2579+
await nm.addDevice(deviceType: 15, permHwAddress: 'DE:71:CE:00:00:08');
2580+
await nm.addDevice(deviceType: 17, permHwAddress: 'DE:71:CE:00:00:09');
2581+
await nm.addDevice(deviceType: 18, permHwAddress: 'DE:71:CE:00:00:10');
2582+
await nm.addDevice(deviceType: 19, permHwAddress: 'DE:71:CE:00:00:11');
2583+
await nm.addDevice(deviceType: 20, permHwAddress: 'DE:71:CE:00:00:12');
2584+
await nm.addDevice(deviceType: 21, permHwAddress: 'DE:71:CE:00:00:13');
2585+
await nm.addDevice(deviceType: 22, permHwAddress: 'DE:71:CE:00:00:14');
2586+
await nm.addDevice(deviceType: 23, permHwAddress: 'DE:71:CE:00:00:15');
2587+
await nm.addDevice(deviceType: 24, permHwAddress: 'DE:71:CE:00:00:16');
2588+
await nm.addDevice(deviceType: 25, permHwAddress: 'DE:71:CE:00:00:17');
2589+
await nm.addDevice(deviceType: 26, permHwAddress: 'DE:71:CE:00:00:18');
2590+
await nm.addDevice(deviceType: 27, permHwAddress: 'DE:71:CE:00:00:19');
2591+
await nm.addDevice(deviceType: 28, permHwAddress: 'DE:71:CE:00:00:20');
2592+
await nm.addDevice(deviceType: 29, permHwAddress: 'DE:71:CE:00:00:21');
2593+
await nm.addDevice(deviceType: 30, permHwAddress: 'DE:71:CE:00:00:22');
2594+
await nm.addDevice(deviceType: 31, permHwAddress: 'DE:71:CE:00:00:23');
2595+
2596+
var client = NetworkManagerClient(bus: DBusClient(clientAddress));
2597+
addTearDown(() async => await client.close());
2598+
await client.connect();
2599+
2600+
expect(client.devices, hasLength(23));
2601+
expect(client.devices[0].deviceType,
2602+
equals(NetworkManagerDeviceType.olpcMesh));
2603+
expect(
2604+
client.devices[1].deviceType, equals(NetworkManagerDeviceType.wimax));
2605+
expect(
2606+
client.devices[2].deviceType, equals(NetworkManagerDeviceType.modem));
2607+
expect(client.devices[3].deviceType,
2608+
equals(NetworkManagerDeviceType.infiniband));
2609+
expect(client.devices[4].deviceType, equals(NetworkManagerDeviceType.bond));
2610+
expect(client.devices[5].deviceType, equals(NetworkManagerDeviceType.vlan));
2611+
expect(client.devices[6].deviceType, equals(NetworkManagerDeviceType.adsl));
2612+
expect(client.devices[7].deviceType, equals(NetworkManagerDeviceType.team));
2613+
expect(client.devices[8].deviceType,
2614+
equals(NetworkManagerDeviceType.ipTunnel));
2615+
expect(
2616+
client.devices[9].deviceType, equals(NetworkManagerDeviceType.macVlan));
2617+
expect(
2618+
client.devices[10].deviceType, equals(NetworkManagerDeviceType.vxlan));
2619+
expect(
2620+
client.devices[11].deviceType, equals(NetworkManagerDeviceType.veth));
2621+
expect(
2622+
client.devices[12].deviceType, equals(NetworkManagerDeviceType.macsec));
2623+
expect(
2624+
client.devices[13].deviceType, equals(NetworkManagerDeviceType.dummy));
2625+
expect(client.devices[14].deviceType, equals(NetworkManagerDeviceType.ppp));
2626+
expect(client.devices[15].deviceType,
2627+
equals(NetworkManagerDeviceType.ovsInterface));
2628+
expect(client.devices[16].deviceType,
2629+
equals(NetworkManagerDeviceType.ovsPort));
2630+
expect(client.devices[17].deviceType,
2631+
equals(NetworkManagerDeviceType.ovsBridge));
2632+
expect(
2633+
client.devices[18].deviceType, equals(NetworkManagerDeviceType.wpan));
2634+
expect(client.devices[19].deviceType,
2635+
equals(NetworkManagerDeviceType.sixLoWpan));
2636+
expect(client.devices[20].deviceType,
2637+
equals(NetworkManagerDeviceType.wireguard));
2638+
expect(client.devices[21].deviceType,
2639+
equals(NetworkManagerDeviceType.wifiP2p));
2640+
expect(client.devices[22].deviceType, equals(NetworkManagerDeviceType.vrf));
2641+
});
2642+
25492643
test('device statistics', () async {
25502644
var server = DBusServer();
25512645
addTearDown(() async => await server.close());

0 commit comments

Comments
 (0)