Commit 440c681f authored by gwenn's avatar gwenn

Improves tests and benches.

parent 2927f44c
......@@ -47,7 +47,7 @@ func BenchmarkValuesScan(b *testing.B) {
if Must(cs.Next()) {
cs.ScanValues(values)
}
panicOnError(b, cs.Reset())
/*panicOnError(b, */ cs.Reset() /*)*/
}
}
......@@ -70,9 +70,9 @@ func BenchmarkScan(b *testing.B) {
var sstr string
if Must(cs.Next()) {
panicOnError(b, cs.Scan(&fnum, &inum, &sstr))
/*panicOnError(b, */ cs.Scan(&fnum, &inum, &sstr) /*)*/
}
panicOnError(b, cs.Reset())
/*panicOnError(b, */ cs.Reset() /*)*/
}
}
......@@ -95,20 +95,33 @@ func BenchmarkNamedScan(b *testing.B) {
var sstr string
if Must(cs.Next()) {
panicOnError(b, cs.NamedScan("float_num", &fnum, "int_num", &inum, "a_string", &sstr))
/*panicOnError(b, */ cs.NamedScan("float_num", &fnum, "int_num", &inum, "a_string", &sstr) /*)*/
}
panicOnError(b, cs.Reset())
/*panicOnError(b, */ cs.Reset() /*)*/
}
}
func BenchmarkInsert(b *testing.B) {
b.StopTimer()
db, err := Open(":memory:")
panicOnError(b, err)
defer db.Close()
fill(b, db, b.N)
panicOnError(b, db.Exec("DROP TABLE IF EXISTS test"))
panicOnError(b, db.Exec("CREATE TABLE test (id INTEGER PRIMARY KEY NOT NULL, float_num REAL, int_num INTEGER, a_string TEXT)"))
s, err := db.Prepare("INSERT INTO test (float_num, int_num, a_string) VALUES (?, ?, ?)")
panicOnError(b, err)
defer s.Finalize()
b.StartTimer()
panicOnError(b, db.Begin())
for i := 0; i < b.N; i++ {
/*panicOnError(b, */ s.Exec(float64(i)*float64(3.14), i, "hello") /*)*/
}
panicOnError(b, db.Commit())
}
func BenchmarkNamedInsert(b *testing.B) {
b.StopTimer()
db, err := Open(":memory:")
panicOnError(b, err)
defer db.Close()
......@@ -120,9 +133,10 @@ func BenchmarkNamedInsert(b *testing.B) {
panicOnError(b, err)
defer s.Finalize()
b.StartTimer()
panicOnError(b, db.Begin())
for i := 0; i < b.N; i++ {
panicOnError(b, s.NamedBind(":f", float64(i)*float64(3.14), ":i", i, ":s", "hello"))
/*panicOnError(b, */ s.NamedBind(":f", float64(i)*float64(3.14), ":i", i, ":s", "hello") /*)*/
Must(s.Next())
}
panicOnError(b, db.Commit())
......
......@@ -367,3 +367,20 @@ func TestInsertMisuse(t *testing.T) {
_, err = is.Insert()
assert(t, "missing bind parameters expected", err != nil)
}
func TestScanValues(t *testing.T) {
db := open(t)
defer checkClose(db, t)
s, err := db.Prepare("SELECT 1, null, 0")
checkNoError(t, err, "prepare error: %s")
defer checkFinalize(s, t)
if !Must(s.Next()) {
t.Fatal("no result")
}
values := make([]interface{}, 3)
s.ScanValues(values)
assertEquals(t, "expected %v but got %v", int64(1), values[0])
assertEquals(t, "expected %v but got %v", nil, values[1])
assertEquals(t, "expected %v but got %v", int64(0), values[2])
}
......@@ -128,3 +128,12 @@ func TestTrace(t *testing.T) {
func TestLog(t *testing.T) {
Log(0, "One message")
}
func TestMemory(t *testing.T) {
used := MemoryUsed()
assert(t, "memory used", used >= 0)
highwater := MemoryHighwater(false)
assert(t, "memory highwater", highwater >= 0)
limit := SoftHeapLimit()
assert(t, "soft heap limit positive", limit >= 0)
}
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