-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathFixedCursorWindowAllocationTest.java
51 lines (46 loc) · 1.51 KB
/
FixedCursorWindowAllocationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package net.zetetic.tests;
import net.sqlcipher.Cursor;
import net.sqlcipher.CursorWindow;
import net.sqlcipher.CursorWindowAllocation;
import net.sqlcipher.CustomCursorWindowAllocation;
import net.sqlcipher.database.SQLiteDatabase;
public class FixedCursorWindowAllocationTest extends SQLCipherTest {
@Override
public boolean execute(SQLiteDatabase database) {
try {
int rowCount = 0;
int rows = 100;
long allocationSize = 1024;
final int dataSize = 491;
CursorWindowAllocation fixedAllocation = new CustomCursorWindowAllocation(allocationSize, 0, allocationSize);
CursorWindow.setCursorWindowAllocation(fixedAllocation);
buildDatabase(database, rows, 1, new RowColumnValueBuilder() {
@Override
public Object buildRowColumnValue(String[] columns, int row, int column) {
return generateRandomByteArray(dataSize);
}
});
Cursor cursor = database.rawQuery("SELECT * FROM t1;", new Object[]{});
if(cursor == null) return false;
while(cursor.moveToNext()){
byte[] data = cursor.getBlob(0);
if(data.length != dataSize) {
cursor.close();
return false;
}
rowCount++;
}
cursor.close();
return rowCount == rows;
} catch (Exception e){
String message = String.format("Error:%s", e.getMessage());
log(message);
setMessage(message);
return false;
}
}
@Override
public String getName() {
return "Small Cursor Window Allocation Test";
}
}