This repository has been archived on 2024-08-25. You can view files and clone it, but cannot push or open issues or pull requests.
2017-09-19 12:17:25 +01:00
|
|
|
package captcha
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-09-20 02:51:27 +01:00
|
|
|
"image/color"
|
2017-09-19 12:17:25 +01:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewCaptcha(t *testing.T) {
|
2017-09-20 02:51:27 +01:00
|
|
|
New(36, 12)
|
2017-09-19 12:17:25 +01:00
|
|
|
data, err := New(150, 50)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
data.WriteTo(buf)
|
|
|
|
}
|
2017-09-20 02:51:27 +01:00
|
|
|
|
|
|
|
func TestNewCaptchaOptions(t *testing.T) {
|
|
|
|
New(100, 34, func(options *Options) {
|
|
|
|
options.BackgroundColor = color.Opaque
|
|
|
|
options.CharPreset = "1234567890"
|
|
|
|
options.CurveNumber = 0
|
|
|
|
options.TextLength = 6
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCovNilFontError(t *testing.T) {
|
|
|
|
temp := ttfFont
|
|
|
|
ttfFont = nil
|
|
|
|
|
|
|
|
_, err := New(150, 50)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expect to get nil font error")
|
|
|
|
}
|
|
|
|
|
|
|
|
ttfFont = temp
|
|
|
|
}
|