X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Ftestcases%2Forg%2Fsimantics%2Fdataboard%2Ftests%2FTestBlob.java;fp=bundles%2Forg.simantics.databoard%2Ftestcases%2Forg%2Fsimantics%2Fdataboard%2Ftests%2FTestBlob.java;h=4abd50f227c62fa77a2bbf3aa25524443956f840;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/testcases/org/simantics/databoard/tests/TestBlob.java b/bundles/org.simantics.databoard/testcases/org/simantics/databoard/tests/TestBlob.java new file mode 100644 index 000000000..4abd50f22 --- /dev/null +++ b/bundles/org.simantics.databoard/testcases/org/simantics/databoard/tests/TestBlob.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.databoard.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Test; +import org.simantics.databoard.util.binary.BinaryMemory; +import org.simantics.databoard.util.binary.Blob; +import org.simantics.databoard.util.binary.RandomAccessBinary; +import org.simantics.databoard.util.binary.RandomAccessBinary.ByteSide; + +public class TestBlob { + + // Blob with 0..1600 bytes + Blob blob; + // 10 sub blobs of 160 bytes + Blob[] level1; + // 10*10 sub-blobs of 16 bytes + Blob[][] level2; + + public @Before void initData() throws Exception { + RandomAccessBinary mem; + mem = new BinaryMemory(1600); +// mem = BinaryFile.tempFile(1600); + blob = new Blob(mem); + level1 = new Blob[10]; + level2 = new Blob[10][]; + for (int i=0; i<10; i++) { + level1[i] = blob.createSubBlob(i*100, 160); + level2[i] = new Blob[10]; + for (int j=0; j<10; j++) { + level2[i][j] = level1[i].createSubBlob(i*10, 16); + } + } + } + + public @Test void testSize() throws Exception { + Blob b = blob; + assertEquals(b.length(), 1600); + + for (int l=0; l<10; l++) { + b = level1[l]; + assertEquals(b.length(), 160); + + for (int l2=0; l2<10; l2++) { + b = level2[l][l2]; + assertEquals(b.length(), 16); + } + } + } + + public @Test void testIsolation() throws Exception { + + Blob b = blob; + testIsolation(b); + testInsertRemove(b); + + for (int i=0; i<10; i++) { + b = level1[i]; + testIsolation(b); + testInsertRemove(b); + + for (int j=0; j<10; j++) { + b = level2[i][j]; + testIsolation(b); + testInsertRemove(b); + } + } + + } + + void testIsolation(Blob b) throws Exception { + int parentCount = (int) b.getSource().length()/4; + int c = (int) b.length()/4; + + // Write test + b.position(0); + for (int i=0; i