Fix true update queries for blobs.

This commit is contained in:
Greyson Parrelli
2022-03-16 17:33:47 -04:00
committed by Cody Henthorne
parent 0ca438ed25
commit 0359f27cd9
2 changed files with 34 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.thoughtcrime.securesms.recipients.RecipientId;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -97,6 +98,22 @@ public final class SqlUtilTest {
assertArrayEquals(new String[] { "1", "2", "3" }, updateQuery.getWhereArgs());
}
@Test
public void buildTrueUpdateQuery_blobComplex() {
String selection = "_id = ?";
String[] args = new String[]{"1"};
ContentValues values = new ContentValues();
values.put("a", hexToBytes("FF"));
values.put("b", 2);
values.putNull("c");
SqlUtil.Query updateQuery = SqlUtil.buildTrueUpdateQuery(selection, args, values);
assertEquals("(_id = ?) AND (hex(a) != ? OR a IS NULL OR b != ? OR b IS NULL OR c NOT NULL)", updateQuery.getWhere());
assertArrayEquals(new String[] { "1", "FF", "2" }, updateQuery.getWhereArgs());
}
@Test
public void buildCollectionQuery_single() {
SqlUtil.Query updateQuery = SqlUtil.buildCollectionQuery("a", Arrays.asList(1));
@@ -255,4 +272,12 @@ public final class SqlUtilTest {
assertEquals("INSERT INTO mytable (a, b) VALUES (?, ?)", output.get(1).getWhere());
assertArrayEquals(new String[] { "5", "6" }, output.get(1).getWhereArgs());
}
private static byte[] hexToBytes(String hex) {
try {
return Hex.fromStringCondensed(hex);
} catch (IOException e) {
throw new AssertionError(e);
}
}
}