-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiscTests.java
More file actions
60 lines (53 loc) · 2.13 KB
/
MiscTests.java
File metadata and controls
60 lines (53 loc) · 2.13 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
package com.almworks.sqlite4java;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Locale;
public class MiscTests extends SQLiteTestFixture {
public MiscTests() {
super(false);
}
public void testAdjustingLibPath() throws IOException {
String jar = tempName("sqlite4java.jar");
File jarFile = new File(jar);
new RandomAccessFile(jarFile, "rw").close();
assertTrue(jarFile.exists());
jarFile.deleteOnExit();
String dir = jarFile.getParentFile().getPath();
char c = File.pathSeparatorChar;
String url = "jar:file:" + jar + "!/sqlite/Internal.class";
assertEquals(dir, Internal.getDefaultLibPath(null, url));
assertEquals(dir, Internal.getDefaultLibPath("xxx", url));
assertEquals(dir, Internal.getDefaultLibPath("xxx" + c + c + "yyy" + c, url));
assertNull(Internal.getDefaultLibPath("xxx" + File.pathSeparatorChar + File.pathSeparatorChar + dir, url));
assertEquals(dir, Internal.getDefaultLibPath(dir + "x", url));
assertNull(Internal.getDefaultLibPath(dir, url));
}
public void testCreatingDatabaseInNonExistingDirectory() {
String dir = tempName("newDir");
File db = new File(dir, "db");
SQLiteConnection c = new SQLiteConnection(db);
try {
c.open(true);
fail("created a connection to db in a non-existing directory");
} catch (SQLiteException e) {
assertTrue(e.getMessage().toLowerCase(Locale.US).contains("file"));
}
}
public void testJarSuffix() throws IOException {
String jar = tempName("sqlite4java.jar");
File jarFile = new File(jar);
new RandomAccessFile(jarFile, "rw").close();
assertTrue(jarFile.exists());
jarFile.deleteOnExit();
String url = "jar:file:" + jar + "!/sqlite/Internal.class";
assertNull(Internal.getVersionSuffix(url));
jar = tempName("sqlite4java-0.1999-SNAPSHOT.jar");
jarFile = new File(jar);
new RandomAccessFile(jarFile, "rw").close();
assertTrue(jarFile.exists());
jarFile.deleteOnExit();
url = "jar:file:" + jar + "!/sqlite/Internal.class";
assertEquals("-0.1999-SNAPSHOT", Internal.getVersionSuffix(url));
}
}