Skip to content

Commit

Permalink
WIP: Test Unsafe classes
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Aug 3, 2022
1 parent ed314be commit 96f792b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,13 @@
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.imglib2.img.basictypeaccess.unsafe;

import net.imglib2.img.basictypelongaccess.unsafe.ByteUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.UnsafeUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ByteUnsafeTest
{

private ByteUnsafe b;

private final Byte startingValue = 5;

@Before
public void setup()
{
int numBytes = 8;
// Allocate heap memory for testing
long address = UnsafeUtil.UNSAFE.allocateMemory( 8 );

b = new ByteUnsafe( address );
b.setValue( 0, startingValue );
for ( int i = 1; i < numBytes; i++ )
{
b.setValue( i, ( byte ) 0 );
}
}

@After
public void tearDown()
{
// Free heap memory
UnsafeUtil.UNSAFE.freeMemory( b.getAddres() );
}

@Test
public void testByteUnsafeGetValue()
{
assertEquals( ( long ) startingValue, b.getValue( 0 ) );
}

}

0 comments on commit 96f792b

Please sign in to comment.