package nxm.sys.test.junit.lib;

import nxm.sys.lib.*;
import nxm.sys.test.junit.NMTestCase;

/** This will test the Native class.
    @author Neon Ngo
    @since NeXtMidas 3.5.1
 */
public final class NativeTest extends NMTestCase {

  /** constructor required by NeXtMidas Unit Testing framework (i.e. UNITTEST command).
      @param methodName The name of the method being called.
   */
  public NativeTest(String methodName) {
    super(methodName, null);
  }

  /** constructor required by NeXtMidas Unit Testing framework (i.e. UNITTEST command).
      @param methodName The name of the method being called.
      @param midas      The midas context testTo use when running the tests.
   */
  public NativeTest(String methodName, Midas midas) {
    super(methodName, midas);
  }

  public void testAlloc() { // test for BUG 2848
    if (Native.canUse) {
      final int allocBytes = 8;
      long nativePtrAddress = Native.alloc(allocBytes);
      assertTrue("Native.alloc() -> " + nativePtrAddress, nativePtrAddress != 0);
      int freeResult = Native.free(nativePtrAddress);
      assertEquals("Native.free() -> " + freeResult, 0, freeResult);
    }
    else {
      info("Native code not available for use. Skipping test");
    }
  }

  /** tested in {@link #testAlloc()} */
  public void testFree() {}
}
