cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [3/4] git commit: updated refs/heads/master to d091b91
Date Mon, 14 Sep 2015 10:03:31 GMT
Added Unit Tests for QCOW2Utils.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/aa19a6a0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/aa19a6a0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/aa19a6a0

Branch: refs/heads/master
Commit: aa19a6a05ab2ae17266201fd44b7c3c7f044e7bf
Parents: 4a770fc
Author: Boris Schrijver <boris@pcextreme.nl>
Authored: Mon Sep 14 10:56:21 2015 +0200
Committer: Boris Schrijver <boris@pcextreme.nl>
Committed: Mon Sep 14 10:56:21 2015 +0200

----------------------------------------------------------------------
 .../com/cloud/utils/storage/QCOW2UtilsTest.java | 121 +++++++++++++++++++
 1 file changed, 121 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa19a6a0/utils/src/test/java/com/cloud/utils/storage/QCOW2UtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/src/test/java/com/cloud/utils/storage/QCOW2UtilsTest.java b/utils/src/test/java/com/cloud/utils/storage/QCOW2UtilsTest.java
new file mode 100644
index 0000000..92881a6
--- /dev/null
+++ b/utils/src/test/java/com/cloud/utils/storage/QCOW2UtilsTest.java
@@ -0,0 +1,121 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+package com.cloud.utils.storage;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class QCOW2UtilsTest {
+
+    InputStream inputStream;
+
+    final Long virtualSize = 21474836480L;
+
+    /**
+     * The QCOW2 Header
+     *
+     * uint32_t magic;
+     * uint32_t version;
+     *
+     * uint64_t backing_file_offset;
+     * uint32_t backing_file_size;
+     *
+     * uint32_t cluster_bits;
+     * uint64_t size;
+     *
+     * uint32_t crypt_method;
+     *
+     * uint32_t l1_size;
+     * int64_t l1_table_offset;
+     *
+     * uint64_t refcount_table_offset;
+     * uint32_t refcount_table_clusters;
+     *
+     * uint32_t nb_snapshots;
+     * uint64_t snapshots_offset;
+     *
+     * @see https://people.gnome.org/~markmc/qcow-image-format.html
+     */
+
+    @Before
+    public void setup() {
+
+        ByteBuffer byteBuffer = ByteBuffer.allocate(72);
+
+        // Magic
+        byteBuffer.put("QFI".getBytes(Charset.forName("UTF-8")));
+        byteBuffer.put((byte)0xfb);
+
+        // Version
+        byteBuffer.putInt(2);
+
+        // Backing file offset
+        byteBuffer.putLong(0L);
+
+        // Backing file size
+        byteBuffer.putInt(0);
+
+        // Cluster bits
+        byteBuffer.putInt(0);
+
+        // Size
+        byteBuffer.putLong(virtualSize);
+
+        // Crypt method
+        byteBuffer.putInt(0);
+
+        // L1 Size
+        byteBuffer.putInt(0);
+
+        // L1 Table offset
+        byteBuffer.putLong(0L);
+
+        // Refcount table offset
+        byteBuffer.putLong(0L);
+
+        // Refcount table cluster
+        byteBuffer.putInt(0);
+
+        // NB Snapshots
+        byteBuffer.putInt(0);
+
+        // Snapshots offset
+        byteBuffer.putLong(0L);
+
+        inputStream = new ByteArrayInputStream(byteBuffer.array());
+    }
+
+    @Test
+    public void getVirtualSizeHeaderLocation() {
+        assertEquals(24, QCOW2Utils.getVirtualSizeHeaderLocation());
+    }
+
+    @Test
+    public void getVirtualSizeTest() throws IOException {
+        assertEquals(virtualSize.longValue(), QCOW2Utils.getVirtualSize(inputStream));
+    }
+}


Mime
View raw message