-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadAllTests.java
More file actions
66 lines (65 loc) · 2.02 KB
/
LoadAllTests.java
File metadata and controls
66 lines (65 loc) · 2.02 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.almworks.sqlite4java;
public class LoadAllTests extends SQLiteConnectionFixture {
public void testInts() throws SQLiteException {
int COUNT = 1000;
SQLiteConnection sqlite = fileDb().open();
sqlite.exec("create table x (id integer not null primary key)");
sqlite.exec("begin");
SQLiteStatement st = sqlite.prepare("insert into x values(?)");
for (int i = 0; i < COUNT; i++) {
st.bind(1, i);
st.step();
st.reset();
}
st.dispose();
sqlite.exec("commit");
st = sqlite.prepare("select id from x order by (500-id)*(250-id)");
int[] buffer = new int[249];
int loaded = 0;
int count = 0;
int lastv = Integer.MIN_VALUE;
while ((loaded = st.loadInts(0, buffer, 0, buffer.length)) > 0) {
for (int i = 0; i < loaded; i++) {
int id = buffer[i];
int v = (int)(((long)(500 - id)) * (long)(250 - id));
if (v < lastv) {
assertTrue(lastv + " " + v, v >= lastv);
}
lastv = v;
count++;
}
}
assertEquals(COUNT, count);
}
public void testLongs() throws SQLiteException {
int COUNT = 1000;
SQLiteConnection sqlite = fileDb().open();
sqlite.exec("create table x (id integer not null primary key)");
sqlite.exec("begin");
SQLiteStatement st = sqlite.prepare("insert into x values(?)");
for (int i = 0; i < COUNT; i++) {
st.bind(1, (long)i);
st.step();
st.reset();
}
st.dispose();
sqlite.exec("commit");
st = sqlite.prepare("select id from x order by (500-id)*(250-id)");
long[] buffer = new long[249];
int loaded = 0;
int count = 0;
int lastv = Integer.MIN_VALUE;
while ((loaded = st.loadLongs(0, buffer, 0, buffer.length)) > 0) {
for (int i = 0; i < loaded; i++) {
long id = buffer[i];
int v = (int)(((long)(500 - id)) * (long)(250 - id));
if (v < lastv) {
assertTrue(lastv + " " + v, v >= lastv);
}
lastv = v;
count++;
}
}
assertEquals(COUNT, count);
}
}