[libvirt-java] [PATCH 3/3] test: add testDomainScreenshot JUnit test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/test/java/org/libvirt/TestJavaBindings.java | 38 +++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java
index bba4cdb..2d4ad9d 100644
--- a/src/test/java/org/libvirt/TestJavaBindings.java
+++ b/src/test/java/org/libvirt/TestJavaBindings.java
@@ -1,5 +1,8 @@
 package org.libvirt;
 
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
 import java.util.UUID;
 
 import junit.framework.TestCase;
@@ -216,4 +219,39 @@ public final class TestJavaBindings extends TestCase {
         assertTrue("pool1 should not be active", pool1.isActive() == 0);        
         assertTrue("Domain2 should be active", defaultPool.isActive() == 1);         
     }
+
+    public void testDomainScreenshot() throws Exception {
+        Stream str = this.conn.streamNew(0);
+        Domain dom = this.conn.domainLookupByName("test");
+
+        assertFalse("Domain \"test\" not found", dom == null);
+
+        String mimetype = dom.screenshot(str, 0);
+
+        ByteBuffer bb = ByteBuffer.allocateDirect(8192);
+
+        while (str.read(bb) != -1) // consume data
+            bb.clear();
+
+        // ensure that read() repeatedly returns -1 after EOF
+
+        assertEquals("Stream is at EOF (1)", -1, str.read(bb));
+        assertEquals("Stream is at EOF (2)", -1, str.read(bb));
+        assertEquals("Stream is at EOF (3)", -1, str.read(bb));
+
+        // ensure that an ClosedChannelException gets thrown when
+        // trying to read() after closing the stream
+
+        boolean exceptionThrown = false;
+
+        str.close();
+
+        try {
+            str.read(bb);
+        } catch (ClosedChannelException e) {
+            exceptionThrown = true;
+        }
+        assertTrue("ClosedChannelException is thrown calling read() on a closed stream",
+                   exceptionThrown);
+    }
 }
-- 
1.8.5.2.msysgit.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]