package com.oracle;

import org.junit.jupiter.api.Test;
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
import java.lang.foreign.ValueLayout;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Main {
    @Test
    public void testGetAtIndex_32BitAddress() {
        try (MemorySession ms = MemorySession.openConfined()) {

            MemorySegment pointerArray = MemorySegment.allocateNative(128, ms);
            MemoryAddress expected = MemoryAddress.ofLong(0x0000000080000000L);

            pointerArray.setAtIndex(ValueLayout.ADDRESS, 0, expected);

            MemoryAddress actual = pointerArray.getAtIndex(ValueLayout.ADDRESS, 0);

            assertEquals(expected, actual);
        }
    }

    @Test
    public void testGet_32BitAddress() {
        try (MemorySession ms = MemorySession.openConfined()) {

            MemorySegment pointerArray = MemorySegment.allocateNative(128, ms);
            MemoryAddress expected = MemoryAddress.ofLong(0x0000000080000000L);

            pointerArray.set(ValueLayout.ADDRESS, 0, expected);

            MemoryAddress actual = pointerArray.get(ValueLayout.ADDRESS, 0);

            assertEquals(expected, actual);
        }
    }

}
