aztec_test.go 5.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package aztec
  2. import (
  3. "testing"
  4. )
  5. func encodeTest(t *testing.T, data, wanted string) {
  6. result, err := Encode([]byte(data), DEFAULT_EC_PERCENT, DEFAULT_LAYERS)
  7. if err != nil {
  8. t.Error(err)
  9. } else {
  10. ac, ok := result.(*aztecCode)
  11. if !ok {
  12. t.Error("returned barcode is no aztec code...")
  13. } else if draw := ac.string(); draw != wanted {
  14. t.Errorf("Invalid Barcode returned:\n%s", draw)
  15. }
  16. }
  17. }
  18. func Test_Encode1(t *testing.T) {
  19. encodeTest(t, "This is an example Aztec symbol for Wikipedia.",
  20. "X X X X X X X X \n"+
  21. "X X X X X X X X X X \n"+
  22. "X X X X X X X X X X X \n"+
  23. "X X X X X X X X X X X \n"+
  24. " X X X X X X X X X X X \n"+
  25. " X X X X X X X X X X X X X \n"+
  26. " X X X X X X X X X X X X \n"+
  27. "X X X X X X X X X X X X X X X X \n"+
  28. "X X X X X X X X X X X \n"+
  29. "X X X X X X X X X X X X X X X X \n"+
  30. "X X X X X X X X X X \n"+
  31. "X X X X X X X X X X \n"+
  32. " X X X X X X X X X X \n"+
  33. " X X X X X X X X X X X X X X X X X X \n"+
  34. " X X X X X X X X X X X X \n"+
  35. " X X X X X X X X X X X X X X X X \n"+
  36. " X X X X X X X X X X X \n"+
  37. " X X X X X X X X \n"+
  38. " X X X X X X X X X X X X X X X X \n"+
  39. " X X X X X X X X X X X X \n"+
  40. " X X X \n"+
  41. " X X X X X X X X X X \n"+
  42. " X X X X X X X X X X \n")
  43. }
  44. func Test_Encode2(t *testing.T) {
  45. encodeTest(t, "Aztec Code is a public domain 2D matrix barcode symbology"+
  46. " of nominally square symbols built on a square grid with a "+
  47. "distinctive square bullseye pattern at their center.",
  48. " X X X X X X X X X X X X X X X \n"+
  49. " X X X X X X X X X X X X X X X \n"+
  50. " X X X X X X X X X X X X X X X X X X X \n"+
  51. "X X X X X X X X X X X X X X \n"+
  52. "X X X X X X X X X X X X X X X X X X X X X \n"+
  53. " X X X X X X X X X X X X X X X X \n"+
  54. "X X X X X X X X X X X X X X X X X X X X \n"+
  55. " X X X X X X X X X X X X X X X X X X X X X X \n"+
  56. "X X X X X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  57. " X X X X X X X X X X X X X X X X X X X X \n"+
  58. " X X X X X X X X X X X X X X X X X X X X \n"+
  59. " X X X X X X X X X X X X X X X X X X X X X X X \n"+
  60. "X X X X X X X X X X X X X X X X X X X X X \n"+
  61. " X X X X X X X X X X X X X X X \n"+
  62. " X X X X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  63. " X X X X X X X X X X X \n"+
  64. " X X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  65. " X X X X X X X X X X X X X X X \n"+
  66. "X X X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  67. "X X X X X X X X X X X X X X X X X X X X \n"+
  68. "X X X X X X X X X X X X X X X X X X X X X \n"+
  69. " X X X X X X X X X X X X \n"+
  70. " X X X X X X X X X X X X X X X X X X X X X X X \n"+
  71. "X X X X X X X X X X X X X X X X X \n"+
  72. " X X X X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  73. " X X X X X X X X X X X X X X X X \n"+
  74. " X X X X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  75. " X X X X X X X X X X X X X X X X X \n"+
  76. "X X X X X X X X X X X X X X X X X \n"+
  77. "X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  78. " X X X X X X X X X X X X X X X X X X X X \n"+
  79. "X X X X X X X X X X X X X X X \n"+
  80. " X X X X X X X X X X X X X X X X X X X X X X X X X \n"+
  81. " X X X X X X X X X X X X X X X X X \n"+
  82. "X X X X X X X X X X X X X X X X X X \n"+
  83. "X X X X X X X X X X X X X X X X X X X X X X X \n"+
  84. "X X X X X X X X X X X X X X X X X X X X X \n"+
  85. "X X X X X X X X X X X X X X X X \n"+
  86. "X X X X X X X X X X X X X X X X X X X X X \n"+
  87. " X X X X X X X X X X X X X X X X \n"+
  88. "X X X X X X X X X X X X X \n")
  89. }