Skip to content

Commit

Permalink
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 f52dcdf
Show file tree
Hide file tree
Showing 10 changed files with 574 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,63 @@
package net.imglib2.img.basictypeaccess.unsafe;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import net.imglib2.img.basictypelongaccess.unsafe.BooleanUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.UnsafeUtil;

/**
* Tests basic {@link BooleanUnsafe} functionality
*
* @author Gabriel Selzer
*/
public class BooleanUnsafeTest
{

private BooleanUnsafe b;

private long address;

private final Boolean startingValue = false;

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

b = new BooleanUnsafe( address );
b.setValue( 0, startingValue );
}

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

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

@Test
public void testBooleanUnsafeSetValue()
{
boolean newValue = true;
b.setValue( 0, newValue );
assertEquals( newValue, b.getValue( 0 ) );
}

@Test
public void testBooleanUnsafeGetAddress()
{
assertEquals( address, b.getAddres() );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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;

/**
* Tests basic {@link ByteUnsafe} functionality
*
* @author Gabriel Selzer
*/
public class ByteUnsafeTest
{

private ByteUnsafe b;

private long address;

private final Byte startingValue = 5;

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

b = new ByteUnsafe( address );
b.setValue( 0, startingValue );
}

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

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

@Test
public void testByteUnsafeSetValue()
{
byte newValue = 6;
b.setValue( 0, newValue );
assertEquals( newValue, b.getValue( 0 ) );
}

@Test
public void testByteUnsafeGetAddress()
{
assertEquals( address, b.getAddres() );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.imglib2.img.basictypeaccess.unsafe;

import static org.junit.Assert.assertEquals;

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

import net.imglib2.img.basictypelongaccess.unsafe.UnsafeUtil;

/**
* Tests basic {@link CharUnsafe} functionality
*
* @author Gabriel Selzer
*/
public class CharUnsafeTest
{

private CharUnsafe c;

private long address;

private final Character startingValue = 'a';

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

c = new CharUnsafe( address );
c.setValue( 0, startingValue );
}

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

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

@Test
public void testCharUnsafeSetValue()
{
char newValue = 'b';
c.setValue( 0, newValue );
assertEquals( newValue, c.getValue( 0 ) );
}

@Test
public void testCharUnsafeGetAddress()
{
assertEquals( address, c.getAddres() );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.imglib2.img.basictypeaccess.unsafe;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import net.imglib2.img.basictypelongaccess.unsafe.DoubleUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.UnsafeUtil;

/**
* Tests basic {@link DoubleUnsafe} functionality
*
* @author Gabriel Selzer
*/
public class DoubleUnsafeTest
{

private DoubleUnsafe d;

private long address;

private final Double startingValue = 5d;

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

d = new DoubleUnsafe( address );
d.setValue( 0, startingValue );
}

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

@Test
public void testDoubleUnsafeGetValue()
{
assertEquals( startingValue, d.getValue( 0 ), 1e-6 );
}

@Test
public void testDoubleUnsafeSetValue()
{
double newValue = 6d;
d.setValue( 0, newValue );
assertEquals( newValue, d.getValue( 0 ), 1e-6 );
}

@Test
public void testDoubleUnsafeGetAddress()
{
assertEquals( address, d.getAddres() );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.imglib2.img.basictypeaccess.unsafe;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import net.imglib2.img.basictypelongaccess.unsafe.FloatUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.UnsafeUtil;

/**
* Tests basic {@link FloatUnsafe} functionality
*
* @author Gabriel Selzer
*/
public class FloatUnsafeTest
{

private FloatUnsafe f;

private long address;

private final Float startingValue = 5f;

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

f = new FloatUnsafe( address );
f.setValue( 0, startingValue );
}

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

@Test
public void testFloatUnsafeGetValue()
{
assertEquals( startingValue, f.getValue( 0 ), 1e-6 );
}

@Test
public void testFloatUnsafeSetValue()
{
float newValue = 6f;
f.setValue( 0, newValue );
assertEquals( newValue, f.getValue( 0 ), 1e-6 );
}

@Test
public void testFloatUnsafeGetAddress()
{
assertEquals( address, f.getAddres() );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.imglib2.img.basictypeaccess.unsafe;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import net.imglib2.img.basictypelongaccess.unsafe.IntUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.UnsafeUtil;

/**
* Tests basic {@link IntUnsafe} functionality
*
* @author Gabriel Selzer
*/
public class IntUnsafeTest
{

private IntUnsafe i;

private long address;

private final Integer startingValue = 5;

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

i = new IntUnsafe( address );
i.setValue( 0, startingValue );
}

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

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

@Test
public void testIntUnsafeSetValue()
{
int newValue = 6;
i.setValue( 0, newValue );
assertEquals( newValue, i.getValue( 0 ) );
}

@Test
public void testIntUnsafeGetAddress()
{
assertEquals( address, i.getAddres() );
}

}
Loading

0 comments on commit f52dcdf

Please sign in to comment.