Skip to content

Commit

Permalink
Stub in test (presently fails)
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Aug 24, 2023
1 parent 7e32721 commit 9add55b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 4 deletions.
4 changes: 0 additions & 4 deletions user/super/com/google/gwt/emul/java/util/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,6 @@ public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s) {
return s;
}

/*
* TODO: make the unmodifiable collections serializable.
*/

static class UnmodifiableCollection<T> implements Collection<T>, Serializable {
protected final Collection<? extends T> coll;

Expand Down
20 changes: 20 additions & 0 deletions user/test/com/google/gwt/user/client/rpc/CollectionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeSingleton;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeMap;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeSet;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeUnmodifiable;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeVector;
import com.google.gwt.user.client.rpc.core.java.util.LinkedHashMap_CustomFieldSerializer;

Expand Down Expand Up @@ -854,6 +855,25 @@ public void onSuccess(List<MarkerTypeSingleton> result) {
});
}

public void testUnmodifiableList() {
CollectionsTestServiceAsync service = getServiceAsync();
delayTestFinishForRpc();
service.echoUnmodifiableList(TestSetFactory.createUnmodifiableList(),
new AsyncCallback<List<MarkerTypeUnmodifiable>>() {
@Override
public void onFailure(Throwable caught) {
TestSetValidator.rethrowException(caught);
}

@Override
public void onSuccess(List<MarkerTypeUnmodifiable> result) {
assertNotNull(result);
assertTrue(TestSetValidator.isValidUnmodifiableList(result));
finishTest();
}
});
}

public void testSqlDateArray() {
CollectionsTestServiceAsync service = getServiceAsync();
final java.sql.Date[] expected = TestSetFactory.createSqlDateArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeSingleton;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeMap;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeSet;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeUnmodifiable;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeVector;

import java.sql.Time;
Expand Down Expand Up @@ -193,4 +194,8 @@ IdentityHashMap<MarkerTypeEnum, MarkerTypeIdentityHashMapValue> echoEnumKey(
// For Collections.singletonList()
List<MarkerTypeSingleton> echoSingletonList(List<MarkerTypeSingleton> value)
throws CollectionsTestServiceException;

// For Collections.unmodifiableList()
List<MarkerTypeUnmodifiable> echoUnmodifiableList(List<MarkerTypeUnmodifiable> value)
throws CollectionsTestServiceException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeSingleton;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeMap;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeSet;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeUnmodifiable;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeVector;

import java.sql.Time;
Expand Down Expand Up @@ -168,4 +169,8 @@ void echoEnumKey(IdentityHashMap<MarkerTypeEnum, MarkerTypeIdentityHashMapValue>
// For Collections.singletonList()
void echoSingletonList(List<MarkerTypeSingleton> value,
AsyncCallback<List<MarkerTypeSingleton>> callback);

// For Collections.unmodifiableList()
void echoUnmodifiableList(List<MarkerTypeUnmodifiable> value,
AsyncCallback<List<MarkerTypeUnmodifiable>> callback);
}
14 changes: 14 additions & 0 deletions user/test/com/google/gwt/user/client/rpc/TestSetFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.EnumMap;
Expand Down Expand Up @@ -313,6 +314,15 @@ public static final class MarkerTypeSingleton extends MarkerBase {
super("singleton");
}
}
/**
* A single-use marker type to independently check type parameter exposure in
* unmodifiable collections.
*/
public static final class MarkerTypeUnmodifiable extends MarkerBase {
MarkerTypeUnmodifiable() {
super("unmodifiable");
}
}

/**
* A single-use marker type to independently check type parameter exposure in
Expand Down Expand Up @@ -783,6 +793,10 @@ public static List<MarkerTypeSingleton> createSingletonList() {
return java.util.Collections.singletonList(new MarkerTypeSingleton());
}

public static List<MarkerTypeUnmodifiable> createUnmodifiableList() {
return java.util.Collections.unmodifiableList(Collections.singletonList(new MarkerTypeUnmodifiable()));
}

public static java.sql.Date[] createSqlDateArray() {
return new java.sql.Date[]{new java.sql.Date(500L), new java.sql.Date(500000000L)};
}
Expand Down
23 changes: 23 additions & 0 deletions user/test/com/google/gwt/user/client/rpc/TestSetValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeSingleton;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeMap;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeSet;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeUnmodifiable;
import com.google.gwt.user.client.rpc.TestSetFactory.SerializableDoublyLinkedNode;
import com.google.gwt.user.client.rpc.TestSetFactory.SerializableGraphWithCFS;
import com.google.gwt.user.client.rpc.TestSetFactory.SerializablePrivateNoArg;
Expand Down Expand Up @@ -822,6 +823,28 @@ public static boolean isValidSingletonList(List<MarkerTypeSingleton> list) {
return true;
}

public static boolean isValidUnmodifiableList(List<MarkerTypeUnmodifiable> list) {
if (list == null) {
return false;
}
try {
list.add(new MarkerTypeUnmodifiable());
return false;
} catch (UnsupportedOperationException ignored) {
// expected
}
Object value = list.get(0);
// Perform instanceof check in case RPC did the wrong thing
if (!(value instanceof MarkerTypeUnmodifiable)) {
return false;
}
MarkerTypeSingleton singleton = (MarkerTypeSingleton) value;
if (!"unmodifiable".equals(singleton.getValue())) {
return false;
}
return true;
}

public static boolean isValidTrivialCyclicGraph(
SerializableDoublyLinkedNode actual) {
if (actual == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeSingleton;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeMap;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeTreeSet;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeUnmodifiable;
import com.google.gwt.user.client.rpc.TestSetFactory.MarkerTypeVector;
import com.google.gwt.user.client.rpc.TestSetValidator;

Expand Down Expand Up @@ -564,6 +565,15 @@ public List<MarkerTypeSingleton> echoSingletonList(
throw new CollectionsTestServiceException();
}

return value;
}
@Override
public List<MarkerTypeUnmodifiable> echoUnmodifiableList(
List<MarkerTypeUnmodifiable> value) throws CollectionsTestServiceException {
if (!TestSetValidator.isValidUnmodifiableList(value)) {
throw new CollectionsTestServiceException();
}

return value;
}
}

0 comments on commit 9add55b

Please sign in to comment.