Commit dd971ca9 authored by gwenn's avatar gwenn

Improves tests coverage.

parent eb69bb64
...@@ -32,6 +32,10 @@ func TestBlob(t *testing.T) { ...@@ -32,6 +32,10 @@ func TestBlob(t *testing.T) {
content := []byte("Clob") content := []byte("Clob")
n, err := bw.Write(content) n, err := bw.Write(content)
checkNoError(t, err, "blob write error: %s") checkNoError(t, err, "blob write error: %s")
//bw.Close()
err = bw.Reopen(rowid)
checkNoError(t, err, "blob reopen error: %s")
bw.Close() bw.Close()
br, err := db.NewBlobReader("main", "test", "content", rowid) br, err := db.NewBlobReader("main", "test", "content", rowid)
...@@ -52,6 +56,9 @@ func TestBlob(t *testing.T) { ...@@ -52,6 +56,9 @@ func TestBlob(t *testing.T) {
n, err = br.Read(content[10:]) n, err = br.Read(content[10:])
assert(t, "error expected", n == 0 && err == io.EOF) assert(t, "error expected", n == 0 && err == io.EOF)
err = br.Reopen(rowid)
checkNoError(t, err, "blob reopen error: %s")
br.Close() br.Close()
} }
......
...@@ -145,6 +145,9 @@ func TestSumFunction(t *testing.T) { ...@@ -145,6 +145,9 @@ func TestSumFunction(t *testing.T) {
err = db.OneValue("select mysum(i) from (select 2 as i union all select 2)", &i) err = db.OneValue("select mysum(i) from (select 2 as i union all select 2)", &i)
checkNoError(t, err, "couldn't execute statement: %s") checkNoError(t, err, "couldn't execute statement: %s")
assertEquals(t, "expected %d but got %v", 4, i) assertEquals(t, "expected %d but got %v", 4, i)
err = db.CreateAggregateFunction("mysum", 1, nil, nil, nil, nil)
checkNoError(t, err, "couldn't unregister function: %s")
} }
func randomFill(db *Conn, n int) { func randomFill(db *Conn, n int) {
......
...@@ -55,6 +55,9 @@ func TestColumns(t *testing.T) { ...@@ -55,6 +55,9 @@ func TestColumns(t *testing.T) {
} }
column := columns[2] column := columns[2]
assertEquals(t, "wrong column name: %q <> %q", "int_num", column.Name) assertEquals(t, "wrong column name: %q <> %q", "int_num", column.Name)
columns, err = db.Columns("main", "test")
checkNoError(t, err, "error listing columns: %s")
} }
func TestColumn(t *testing.T) { func TestColumn(t *testing.T) {
...@@ -67,6 +70,9 @@ func TestColumn(t *testing.T) { ...@@ -67,6 +70,9 @@ func TestColumn(t *testing.T) {
assertEquals(t, "wrong column name: %q <> %q", "id", column.Name) assertEquals(t, "wrong column name: %q <> %q", "id", column.Name)
assert(t, "expecting primary key flag to be true", column.Pk) assert(t, "expecting primary key flag to be true", column.Pk)
assert(t, "expecting autoinc flag to be false", !column.Autoinc) assert(t, "expecting autoinc flag to be false", !column.Autoinc)
column, err = db.Column("main", "test", "id")
checkNoError(t, err, "error getting column metadata: %s")
} }
func TestForeignKeys(t *testing.T) { func TestForeignKeys(t *testing.T) {
......
...@@ -535,8 +535,12 @@ func (c *Conn) Close() error { ...@@ -535,8 +535,12 @@ func (c *Conn) Close() error {
// EnableLoadExtension enables or disables extension loading. // EnableLoadExtension enables or disables extension loading.
// (See http://sqlite.org/c3ref/enable_load_extension.html) // (See http://sqlite.org/c3ref/enable_load_extension.html)
func (c *Conn) EnableLoadExtension(b bool) { func (c *Conn) EnableLoadExtension(b bool) error {
C.sqlite3_enable_load_extension(c.db, btocint(b)) rv := C.sqlite3_enable_load_extension(c.db, btocint(b))
if rv == C.SQLITE_OK {
return nil
}
return c.error(rv, "Conn.EnableLoadExtension")
} }
// LoadExtension loads an extension // LoadExtension loads an extension
...@@ -560,8 +564,12 @@ func (c *Conn) LoadExtension(file string, proc ...string) error { ...@@ -560,8 +564,12 @@ func (c *Conn) LoadExtension(file string, proc ...string) error {
// EnableSharedCache enables or disables shared pager cache // EnableSharedCache enables or disables shared pager cache
// (See http://sqlite.org/c3ref/enable_shared_cache.html) // (See http://sqlite.org/c3ref/enable_shared_cache.html)
func EnableSharedCache(b bool) { func EnableSharedCache(b bool) error {
C.sqlite3_enable_shared_cache(btocint(b)) rv := C.sqlite3_enable_shared_cache(btocint(b))
if rv == C.SQLITE_OK {
return nil
}
return Errno(rv)
} }
// Must is a helper that wraps a call to a function returning (bool, os.Error) // Must is a helper that wraps a call to a function returning (bool, os.Error)
......
...@@ -56,6 +56,11 @@ func TestOpen(t *testing.T) { ...@@ -56,6 +56,11 @@ func TestOpen(t *testing.T) {
checkNoError(t, db.Close(), "Error closing database: %s") checkNoError(t, db.Close(), "Error closing database: %s")
} }
func TestOpenFailure(t *testing.T) {
db, err := Open("doesnotexist.sqlite", OpenReadOnly)
assert(t, "open failure expected", db == nil && err != nil)
}
func TestEnableFKey(t *testing.T) { func TestEnableFKey(t *testing.T) {
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
...@@ -96,6 +101,10 @@ func TestTransaction(t *testing.T) { ...@@ -96,6 +101,10 @@ func TestTransaction(t *testing.T) {
t.Fatalf("Error expected (transaction cannot be nested)") t.Fatalf("Error expected (transaction cannot be nested)")
} }
checkNoError(t, db.Commit(), "Error while commiting transaction: %s") checkNoError(t, db.Commit(), "Error while commiting transaction: %s")
checkNoError(t, db.BeginTransaction(Immediate), "Error while beginning immediate transaction: %s")
checkNoError(t, db.Commit(), "Error while commiting transaction: %s")
checkNoError(t, db.BeginTransaction(Exclusive), "Error while beginning immediate transaction: %s")
checkNoError(t, db.Commit(), "Error while commiting transaction: %s")
} }
func TestSavepoint(t *testing.T) { func TestSavepoint(t *testing.T) {
...@@ -205,14 +214,27 @@ func TestConnInitialState(t *testing.T) { ...@@ -205,14 +214,27 @@ func TestConnInitialState(t *testing.T) {
assert(t, "readonly expected to be unset by default", !readonly) assert(t, "readonly expected to be unset by default", !readonly)
} }
func TestReadonlyMisuse(t *testing.T) {
db := open(t)
defer checkClose(db, t)
_, err := db.Readonly("doesnotexist")
assert(t, "error expected", err != nil)
err.Error()
}
func TestConnSettings(t *testing.T) { func TestConnSettings(t *testing.T) {
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
db.EnableLoadExtension(false) err := db.EnableLoadExtension(false)
err := db.SetRecursiveTriggers("main", true) checkNoError(t, err, "EnableLoadExtension error: %s")
err = db.SetRecursiveTriggers("main", true)
checkNoError(t, err, "SetRecursiveTriggers error: %s") checkNoError(t, err, "SetRecursiveTriggers error: %s")
} }
func TestComplete(t *testing.T) {
assert(t, "expected complete statement", Complete("select 1;"))
}
func assertEquals(t *testing.T, format string, expected, actual interface{}) { func assertEquals(t *testing.T, format string, expected, actual interface{}) {
if expected != actual { if expected != actual {
t.Errorf(format, expected, actual) t.Errorf(format, expected, actual)
......
...@@ -19,6 +19,24 @@ func init() { ...@@ -19,6 +19,24 @@ func init() {
if err != nil { if err != nil {
panic(fmt.Sprintf("cannot activate mem status: '%s'", err)) panic(fmt.Sprintf("cannot activate mem status: '%s'", err))
} }
err = ConfigUri(true)
if err != nil {
panic(fmt.Sprintf("cannot activate uri handling: '%s'", err))
}
err = ConfigLog(func(d interface{}, err error, msg string) {
fmt.Printf("%s: %s, %s\n", d, err, msg)
}, "SQLITE")
if err != nil {
panic(fmt.Sprintf("couldn't config log: '%s'", err))
}
err = ConfigLog(nil, "")
if err != nil {
panic(fmt.Sprintf("couldn't unset logger: '%s'", err))
}
err = EnableSharedCache(false)
if err != nil {
panic(fmt.Sprintf("couldn't disable shared cache: '%s'", err))
}
} }
func trace(d interface{}, sql string) { func trace(d interface{}, sql string) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment