Skip to content

Commit

Permalink
Define unit tests involving arrays of empty value types
Browse files Browse the repository at this point in the history
This change defines some simple unit tests that create arrays of value
classes and null restricted value classes, where the classes have no
fields.  The objective is to ensure that allocation, assignment and
comparison of flattened arrays whose elements are of length zero does
not result in unexpected failures.
  • Loading branch information
hzongaro committed Sep 5, 2023
1 parent ac49658 commit 6fb2ec1
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,4 +668,49 @@ static public void testValueTypeAastore() throws Throwable {
writeArrayElementWithSomeVTClassImplIf(holder);
writeArrayElementWithSomeIdentityClassImplIf(holder);
}

public static primitive class EmptyPrim {
}

public static value class EmptyVal {
}

static void copyBetweenEmptyPrimArrays(EmptyPrim[] arr1, EmptyPrim[] arr2) {
for (int i = 0; i < arr1.length; i++) {
arr1[i] = arr2[i];
}
}

static void compareEmptyPrimArrays(EmptyPrim[] arr1, EmptyPrim[] arr2) {
for (int i = 0; i < arr1.length; i++) {
assertEquals(arr1[i], arr2[i]);
}
}

static void copyBetweenEmptyValArrays(EmptyVal[] arr1, EmptyVal[] arr2) {
for (int i = 0; i < arr1.length; i++) {
arr1[i] = arr2[i];
}
}

static void compareEmptyValArrays(EmptyVal[] arr1, EmptyVal[] arr2) {
for (int i = 0; i < arr1.length; i++) {
assertEquals(arr1[i], arr2[i]);
}
}

@Test(priority=1,invocationCount=2)
static public void testEmptyValueArrayElement() {
EmptyPrim[] primArr1 = new EmptyPrim[4];
EmptyPrim[] primArr2 = new EmptyPrim[4];

copyBetweenEmptyPrimArrays(primArr1, primArr2);
compareEmptyPrimArrays(primArr1, primArr2);

EmptyVal[] valArr1 = new EmptyVal[4];
EmptyVal[] valArr2 = new EmptyVal[4];

copyBetweenEmptyValArrays(valArr1, valArr2);
compareEmptyValArrays(valArr1, valArr2);
}
}

0 comments on commit 6fb2ec1

Please sign in to comment.