1// go-qrcode 2// Copyright 2014 Tom Harwood 3/* 4 Amendments Thu, 2017-December-14: 5 - test integration (go test -v) 6 - idiomatic go code 7*/ 8package qrcode 9 10import ( 11 "fmt" 12 "image/color" 13 "os" 14 "testing" 15) 16 17func TestExampleEncode(t *testing.T) { 18 if png, err := Encode("https://example.org", Medium, 256); err != nil { 19 t.Errorf("Error: %s", err.Error()) 20 } else { 21 fmt.Printf("PNG is %d bytes long", len(png)) 22 } 23} 24 25func TestExampleWriteFile(t *testing.T) { 26 filename := "example.png" 27 if err := WriteFile("https://example.org", Medium, 256, filename); err != nil { 28 if err = os.Remove(filename); err != nil { 29 t.Errorf("Error: %s", err.Error()) 30 } 31 } 32} 33 34func TestExampleEncodeWithColourAndWithoutBorder(t *testing.T) { 35 q, err := New("https://example.org", Medium) 36 if err != nil { 37 t.Errorf("Error: %s", err) 38 return 39 } 40 41 // Optionally, disable the QR Code border. 42 q.DisableBorder = true 43 44 // Optionally, set the colours. 45 q.ForegroundColor = color.RGBA{R: 0x33, G: 0x33, B: 0x66, A: 0xff} 46 q.BackgroundColor = color.RGBA{R: 0xef, G: 0xef, B: 0xef, A: 0xff} 47 48 err = q.WriteFile(256, "example2.png") 49 if err != nil { 50 t.Errorf("Error: %s", err) 51 return 52 } 53} 54