< prev index next >

test/jdk/java/foreign/TestStringEncoding.java

Print this page
*** 20,14 ***
   *  or visit www.oracle.com if you need additional information or have any
   *  questions.
   *
   */
  
- import jdk.incubator.foreign.CLinker;
  import jdk.incubator.foreign.MemorySegment;
  
  import jdk.incubator.foreign.ResourceScope;
  import org.testng.annotations.*;
  import static org.testng.Assert.*;
  
  /*
   * @test
--- 20,14 ---
   *  or visit www.oracle.com if you need additional information or have any
   *  questions.
   *
   */
  
  import jdk.incubator.foreign.MemorySegment;
  
  import jdk.incubator.foreign.ResourceScope;
+ import jdk.incubator.foreign.SegmentAllocator;
  import org.testng.annotations.*;
  import static org.testng.Assert.*;
  
  /*
   * @test

*** 38,15 ***
  public class TestStringEncoding {
  
      @Test(dataProvider = "strings")
      public void testStrings(String testString, int expectedByteLength) {
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
!             MemorySegment text = CLinker.toCString(testString, scope);
  
              assertEquals(text.byteSize(), expectedByteLength);
  
!             String roundTrip = CLinker.toJavaString(text);
              assertEquals(roundTrip, testString);
          }
      }
  
      @DataProvider
--- 38,16 ---
  public class TestStringEncoding {
  
      @Test(dataProvider = "strings")
      public void testStrings(String testString, int expectedByteLength) {
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
!             SegmentAllocator allocator = SegmentAllocator.newNativeArena(expectedByteLength, scope);
+             MemorySegment text = allocator.allocateUtf8String(testString);
  
              assertEquals(text.byteSize(), expectedByteLength);
  
!             String roundTrip = text.getUtf8String(0);
              assertEquals(roundTrip, testString);
          }
      }
  
      @DataProvider
< prev index next >