alphanumeric_test.go 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package qr
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func makeString(length int, content string) string {
  7. res := ""
  8. for i := 0; i < length; i++ {
  9. res += content
  10. }
  11. return res
  12. }
  13. func Test_AlphaNumericEncoding(t *testing.T) {
  14. encode := AlphaNumeric.getEncoder()
  15. x, vi, err := encode("HELLO WORLD", M)
  16. if x == nil || vi == nil || vi.Version != 1 || bytes.Compare(x.GetBytes(), []byte{32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, 17, 236, 17, 236, 17}) != 0 {
  17. t.Errorf("\"HELLO WORLD\" failed to encode: %s", err)
  18. }
  19. x, vi, err = encode(makeString(4296, "A"), L)
  20. if x == nil || vi == nil || err != nil {
  21. t.Fail()
  22. }
  23. x, vi, err = encode(makeString(4297, "A"), L)
  24. if x != nil || vi != nil || err == nil {
  25. t.Fail()
  26. }
  27. x, vi, err = encode("ABc", L)
  28. if x != nil || vi != nil || err == nil {
  29. t.Fail()
  30. }
  31. x, vi, err = encode("hello world", M)
  32. if x != nil || vi != nil || err == nil {
  33. t.Error("\"hello world\" should not be encodable in alphanumeric mode")
  34. }
  35. }