/******************************************************************************* * 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