summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/openslx/libvirt/domain/device/HostdevPciDeviceDescriptionTest.java
blob: 7a740ac578790a64b567eb5e054da4fe1cf8b99d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.openslx.libvirt.domain.device;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class HostdevPciDeviceDescriptionTest
{
	@Test
	@DisplayName( "Test that a PCI device description instance is not created if invalid values are specified" )
	public void testHostdevPciDeviceDescriptionInstanceInvalid()
	{
		assertThrows( IllegalArgumentException.class,
				() -> new HostdevPciDeviceDescription( Integer.MIN_VALUE, 0x293a ) );
		assertThrows( IllegalArgumentException.class,
				() -> new HostdevPciDeviceDescription( 0x8086, Integer.MAX_VALUE ) );
	}

	@Test
	@DisplayName( "Test that a PCI device description instance is parsed from a valid String" )
	public void testHostdevPciDeviceDescriptionValueOfValid()
	{
		final HostdevPciDeviceDescription pciDeviceDesc = HostdevPciDeviceDescription.valueOf( "8086:293a" );

		assertNotNull( pciDeviceDesc );
		assertEquals( 0x8086, pciDeviceDesc.getVendorId() );
		assertEquals( "8086", pciDeviceDesc.getVendorIdAsString() );
		assertEquals( 0x293a, pciDeviceDesc.getDeviceId() );
		assertEquals( "293a", pciDeviceDesc.getDeviceIdAsString() );
	}

	@Test
	@DisplayName( "Test that no PCI device description instance is parsed from an invalid String" )
	public void testHostdevPciDeviceDescriptionValueOfInvalid()
	{
		final HostdevPciDeviceDescription pciDeviceDesc = HostdevPciDeviceDescription.valueOf( "bba93e215" );

		assertNull( pciDeviceDesc );
	}

	@Test
	@DisplayName( "Test that two PCI device description instances are equal" )
	public void testHostdevPciDeviceDescriptionEquals()
	{
		final HostdevPciDeviceDescription pciDeviceDesc1 = new HostdevPciDeviceDescription( 0x8086, 0x293a );
		final HostdevPciDeviceDescription pciDeviceDesc2 = new HostdevPciDeviceDescription( 0x8086, 0x293a );

		assertTrue( pciDeviceDesc1.equals( pciDeviceDesc2 ) );
	}

	@Test
	@DisplayName( "Test that two PCI device description instances are not equal" )
	public void testHostdevPciDeviceDescriptionNotEquals()
	{
		final HostdevPciDeviceDescription pciDeviceDesc1 = new HostdevPciDeviceDescription( 0x8086, 0x293a );
		final HostdevPciDeviceDescription pciDeviceDesc2 = new HostdevPciDeviceDescription( 0x293a, 0x8086 );

		assertFalse( pciDeviceDesc1.equals( pciDeviceDesc2 ) );
	}

	@Test
	@DisplayName( "Test that a PCI device description can be dumped to a String" )
	public void testHostdevPciDeviceDescriptionToString()
	{
		final HostdevPciDeviceDescription pciDeviceDesc = new HostdevPciDeviceDescription( 0x00b1, 0x293a );

		assertEquals( "00b1:293a", pciDeviceDesc.toString() );
	}
}