Beispiel #1
0
func Test_open(t *testing.T) {
	mgc, _ := open()
	defer func() {
		value := reflect.ValueOf(mgc).Elem().FieldByName("magic")
		value.Interface().(*magic).close()
	}()

	func(v interface{}) {
		if _, ok := v.(*Magic); !ok {
			t.Fatalf("not a Magic type: %s", reflect.TypeOf(v).String())
		}
	}(mgc)

	magic := reflect.ValueOf(mgc).Elem().FieldByName("magic").Elem()
	path := magic.FieldByName("path")
	cookie := magic.FieldByName("cookie").Elem().UnsafeAddr()

	if path.Kind() != reflect.Slice || path.Len() > 0 {
		t.Errorf("value given {%v ?}, want {%v %d}",
			path.Kind(), reflect.Slice, 0)
	}

	if reflect.ValueOf(cookie).Kind() != reflect.Uintptr || cookie <= 0 {
		t.Errorf("value given {%v 0x%x}, want {%v > %d}",
			reflect.ValueOf(cookie).Kind(),
			cookie, reflect.Uintptr, 0)
	}
}
Beispiel #2
0
func Test_destroy(t *testing.T) {
	mgc, _ := open()
	mgc.destroy()

	magic := reflect.ValueOf(mgc).Elem().FieldByName("magic").Elem()
	path := magic.FieldByName("path")
	cookie := magic.FieldByName("cookie").Elem()

	if path.Kind() != reflect.Slice || path.Len() > 0 {
		t.Errorf("value given {%v ?}, want {%v %d}",
			path.Kind(), reflect.Slice, 0)
	}

	// Should be NULL (at C level) as magic_close() will free underlying Magic database.
	if ok := cookie.IsValid(); ok {
		t.Errorf("value given %v, want %v", ok, false)
	}
}