From 75fe5305f5fd10aa55e8a930709207ca8121fc63 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 2 Nov 2018 15:59:04 -0700 Subject: [PATCH] Validate that at least one argument is provided for Cursor --- .../com/google/cloud/firestore/Query.java | 3 +++ .../cloud/firestore/ConformanceTest.java | 24 +++++++++++++----- .../src/test/resources/test-suite.binproto | Bin 37901 -> 55916 bytes 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java index aaa67f730cc7..1f72da177ce4 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java @@ -336,6 +336,9 @@ private Cursor createCursor( private Cursor createCursor(List order, Object[] fieldValues, boolean before) { Cursor.Builder result = Cursor.newBuilder(); + Preconditions.checkState( + fieldValues.length != 0, "At least one cursor value must be specified."); + Preconditions.checkState( fieldValues.length <= order.size(), "Too many cursor values specified. The specified values must match the " diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java index 2d3b118a5bdb..8342b4b611f0 100644 --- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java +++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java @@ -106,6 +106,9 @@ private interface ConformanceTestCase extends Test, Describable {} /** If non-empty, only runs tests included in this set. */ private final Set includedTests = Collections.emptySet(); + /** If true, prints debug information to System.out. */ + private final boolean DEBUG_MODE = !includedTests.isEmpty(); + @Captor private ArgumentCaptor commitCapture; @Captor private ArgumentCaptor getAllCapture; @@ -331,11 +334,19 @@ public int compare(QueryDocumentSnapshot o1, QueryDocumentSnapshot o2) { } /** Helper function to convert test values in a list to Firestore API types. */ - private List convertArray(List list) { - for (int i = 0; i < list.size(); ++i) { - list.set(i, convertValue(list.get(i))); + private Object convertArray(List list) { + if (!list.isEmpty() && list.get(0).equals("ArrayUnion")) { + return FieldValue.arrayUnion( + ((List) convertArray(list.subList(1, list.size()))).toArray()); + } else if (!list.isEmpty() && list.get(0).equals("ArrayRemove")) { + return FieldValue.arrayRemove( + ((List) convertArray(list.subList(1, list.size()))).toArray()); + } else { + for (int i = 0; i < list.size(); ++i) { + list.set(i, convertValue(list.get(i))); + } + return list; } - return list; } /** Reads the test definition from the Proto file. */ @@ -378,8 +389,9 @@ public void run(TestResult testResult) { new Protectable() { @Override public void protect() throws Throwable { - // Uncomment to print the test protobuf: - // System.out.println(testDefinition); + if (DEBUG_MODE) { + System.out.println(testDefinition); + } switch (testDefinition.getTestCase()) { case GET: diff --git a/google-cloud-clients/google-cloud-firestore/src/test/resources/test-suite.binproto b/google-cloud-clients/google-cloud-firestore/src/test/resources/test-suite.binproto index c3a4962d0cf41125163a5b1ebd0ae28198d7b229..6e3ce397375224cab4ee93e9ae05495a182bc983 100644 GIT binary patch delta 8222 zcmb`MYj7LY700=|e%>UmEjzZeeyumQBX9gb>%?~CJZfi596PpSLi(8Cwrgn3ntMup`pKx7kq-3KO*!;qw?J0P#_!< z+IUYJFSYSqllZFNxO%fP6F#os%iG%c?QMMbWP*DGphizCy1QT>t4KcN8QU$ELEw|t zL#7nq7lU7{3xDMIl8^H6D<8iK;Ij;DME$Tj`F4Ia5ME?pt*+h>!ru{yPxF2`E_06( z$zsdAAY(aLoiJs{S}r=lyA?kuFl;)`^q6Z)v;_1;BOen+X>KuRu!Bj3Z#w<3anYMlTe{bSeA&JihRKRAp-?n$INUn z9*E$wT%L*;cZnz&A2BO&u2NFN^Xav!7e%U66WmfNQ_SZi^k8Mr&2+WQRpG+QeI0)K zp;4{(uyC`z==Ai(xHpOFiBVhCmdt5e&m=qbrA)fpZK_Pu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