#598
This commit is contained in:
Gert-Jan Timmer 2018-07-03 15:56:06 +02:00
parent eef0bf0ebb
commit ac2e8f35da
3 changed files with 49 additions and 7 deletions

View File

@ -1,6 +0,0 @@
-tags=sqlite_userauth
-cover
-race

View File

@ -238,5 +238,4 @@ func TestExtendedErrorCodes_Unique(t *testing.T) {
extended, expected)
}
}
}

View File

@ -9,12 +9,61 @@ package sqlite3
import (
"database/sql"
"fmt"
"reflect"
"regexp"
"strings"
"testing"
)
func TestInvalidFunctionRegistration(t *testing.T) {
afn := "func"
zeroArgsFn := func(a bool) {}
nonErrorArgsFn := func(a bool) (int, int) { return 0, 0 }
sql.Register(fmt.Sprintf("sqlite3-%s-afn", t.Name()), &SQLiteDriver{
ConnectHook: func(conn *SQLiteConn) error {
if err := conn.RegisterFunc("afn", afn, true); err != nil {
return err
}
return nil
},
})
sql.Register(fmt.Sprintf("sqlite3-%s-zeroArgsFn", t.Name()), &SQLiteDriver{
ConnectHook: func(conn *SQLiteConn) error {
if err := conn.RegisterFunc("zeroArgsFn", zeroArgsFn, true); err != nil {
return err
}
return nil
},
})
sql.Register(fmt.Sprintf("sqlite3-%s-nonErrorArgsFn", t.Name()), &SQLiteDriver{
ConnectHook: func(conn *SQLiteConn) error {
if err := conn.RegisterFunc("nonErrorArgsFn", nonErrorArgsFn, true); err != nil {
return err
}
return nil
},
})
for _, s := range []string{"sqlite3-%s-afn", "sqlite3-%s-zeroArgsFn", "sqlite3-%s-nonErrorArgsFn"} {
db, err := sql.Open(fmt.Sprintf(s, t.Name()), ":memory:")
if err != nil {
t.Fatal("Failed to open database:", err)
}
defer db.Close()
if err := db.Ping(); err == nil {
t.Fatal("Expected error from RegisterFunc")
}
}
}
func TestFunctionRegistration(t *testing.T) {
addi8_16_32 := func(a int8, b int16) int32 { return int32(a) + int32(b) }
addi64 := func(a, b int64) int64 { return a + b }