// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package qr import ( "bytes" "image/png" "io/ioutil" "os" "testing" ) func Test2File(t *testing.T) { r, _ := Encode("http://www.baidu.com", L) fi, _ := os.OpenFile("C:\\Users\\admin\\Desktop\\2.png", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0x666) fi.Write(r.PNG()) } func TestPNG(t *testing.T) { c, err := Encode("http://www.baidu.com", H) if err != nil { t.Fatal(err) } pngdat := c.PNG() if true { ioutil.WriteFile("x.png", pngdat, 0666) } } func BenchmarkPNG(b *testing.B) { c, err := Encode("0123456789012345678901234567890123456789", L) if err != nil { panic(err) } var bytes []byte for i := 0; i < b.N; i++ { bytes = c.PNG() } b.SetBytes(int64(len(bytes))) } func BenchmarkImagePNG(b *testing.B) { c, err := Encode("0123456789012345678901234567890123456789", L) if err != nil { panic(err) } var buf bytes.Buffer for i := 0; i < b.N; i++ { buf.Reset() png.Encode(&buf, c.Image()) } b.SetBytes(int64(buf.Len())) }