View Javadoc

1   package org.minetti.astrodevice.server.usb.jni;
2   
3   import static org.junit.Assert.*;
4   import org.junit.Test;
5   
6   /**
7    * @author jp
8    */
9   public final class UsbLibraryTest {
10  
11  	protected final class MockUsbDeviceTreeBuilder
12  			implements UsbDeviceTreeBuilder {
13  
14  		/**
15  		 * Current deep of USB device tree.
16  		 */
17  		private int level = 0;
18  
19  		/*
20  		 * (non-Javadoc)
21  		 * @see org.minetti.astrodevice.server.usb.jni.UsbDeviceTreeBuilder#down()
22  		 */
23  		public void down () {
24  			this.level++;
25  		}
26  
27  		/*
28  		 * (non-Javadoc)
29  		 * @see org.minetti.astrodevice.server.usb.jni.UsbDeviceTreeBuilder#up()
30  		 */
31  		public void up () {
32  			this.level--;
33  		}
34  
35  		/*
36  		 * (non-Javadoc)
37  		 * @see
38  		 * org.minetti.astrodevice.server.usb.jni.UsbDeviceTreeBuilder#addHostController(java.lang
39  		 * .String)
40  		 */
41  		public void addHostController (final String description) {
42  			for (int i = 0; i < this.level; i++) {
43  				System.out.print("  ");
44  			}
45  			System.out.println("=> " + description);
46  		}
47  
48  		/*
49  		 * (non-Javadoc)
50  		 * @see org.minetti.astrodevice.server.usb.jni.UsbDeviceTreeBuilder#addRootHub()
51  		 */
52  		public void addRootHub () {
53  			for (int i = 0; i < this.level; i++) {
54  				System.out.print("  ");
55  			}
56  			System.out.println("=> Root hub");
57  		}
58  
59  		/*
60  		 * (non-Javadoc)
61  		 * @see org.minetti.astrodevice.server.usb.jni.UsbDeviceTreeBuilder#addHub(int, int,
62  		 * java.lang.String, java.lang.String, int, java.lang.String, short, short, short)
63  		 */
64  		public void addHub (final int vendorId, final int productId, final String manufacturerName, final String productDescription, final int productVersion,
65  				final String serialNumber, final short deviceClass, final short deviceSubClass, final short deviceProtocol) {
66  			for (int i = 0; i < this.level; i++) {
67  				System.out.print("  ");
68  			}
69  			System.out.format("=> hub %04X:%04X %s - %s v%04X - S/N %s - class/protocol %02X/%02X/%02X\n", new Integer(vendorId), new Integer(productId),
70  					manufacturerName, productDescription, new Integer(productVersion), serialNumber, new Short(deviceClass), new Short(deviceSubClass), new Short(
71  							deviceProtocol));
72  		}
73  
74  		/*
75  		 * (non-Javadoc)
76  		 * @see org.minetti.astrodevice.server.usb.jni.UsbDeviceTreeBuilder#add(int, int,
77  		 * java.lang.String, java.lang.String, int, java.lang.String, short, short, short)
78  		 */
79  		public void add (final int vendorId, final int productId, final String manufacturerName, final String productDescription, final int productVersion,
80  				final String serialNumber, final short deviceClass, final short deviceSubClass, final short deviceProtocol) {
81  			for (int i = 0; i < this.level; i++) {
82  				System.out.print("  ");
83  			}
84  			System.out.format("=> %04X:%04X %s - %s v%04X - S/N %s - class/protocol %02X/%02X/%02X\n", new Integer(vendorId), new Integer(productId),
85  					manufacturerName, productDescription, new Integer(productVersion), serialNumber, new Short(deviceClass), new Short(deviceSubClass), new Short(
86  							deviceProtocol));
87  		}
88  		
89  	}
90  
91  	/**
92  	 * Test method for
93  	 * {@link org.minetti.astrodevice.server.usb.jni.UsbLibrary#startPlugMonitoring()}.
94  	 */
95  	@Test
96  	public void testStartPlugMonitoring () {
97  		fail("Not yet implemented");
98  	}
99  
100 	/**
101 	 * Test method for
102 	 * {@link org.minetti.astrodevice.server.usb.jni.UsbLibrary#stopPlugMonitoring()}.
103 	 */
104 	@Test
105 	public void testStopPlugMonitoring () {
106 		fail("Not yet implemented");
107 	}
108 
109 	/**
110 	 * Test method for
111 	 * {@link org.minetti.astrodevice.server.usb.jni.UsbLibrary#loadDeviceTree(org.minetti.astrodevice.server.usb.jni.UsbDeviceTreeBuilder)}
112 	 * .
113 	 */
114 	@Test
115 	public void testLoadDeviceTree () {
116 		final UsbLibrary usbLibrary = new UsbLibrary();
117 		UsbDeviceTreeBuilder builder = new MockUsbDeviceTreeBuilder();
118 		usbLibrary.loadDeviceTree(builder);
119 	}
120 
121 }