i2creg_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package i2creg
  2. import (
  3. "prod2u6400-uartkit/internal/protocol"
  4. "testing"
  5. )
  6. func TestSetAllTransactions(t *testing.T) {
  7. s := protocol.SetAll{}
  8. for i := range s.Front {
  9. s.Front[i] = 20
  10. }
  11. for i := range s.Rear {
  12. s.Rear[i] = 20
  13. }
  14. s.Front[3], s.Rear[3] = 30, 10
  15. for i := 18; i < 24; i++ {
  16. s.PTC[i] = 100
  17. }
  18. ts_, err := SetAllTransactions(s)
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. if len(ts_) != 2 || ts_[0].Address7 != Address7 {
  23. t.Fatalf("transactions=%+v", ts_)
  24. }
  25. if len(ts_[0].Write) != 34 || ts_[0].Write[0] != 1 || ts_[0].Write[1] != 0 {
  26. t.Fatalf("staging write=%x", ts_[0].Write)
  27. }
  28. if len(ts_[1].Write) != 3 || ts_[1].Write[0] != 0 || ts_[1].Write[1] != 0x10 || ts_[1].Write[2] != 1 {
  29. t.Fatalf("command write=%x", ts_[1].Write)
  30. }
  31. }
  32. func TestSnapshotReads(t *testing.T) {
  33. ts_, err := SnapshotReads(201, 64)
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. if len(ts_) != 4 || ts_[0].Write[0] != 2 || ts_[0].Write[1] != 0 {
  38. t.Fatalf("reads=%+v", ts_)
  39. }
  40. if ts_[3].ReadLength != 9 || !ts_[3].RepeatedStart {
  41. t.Fatalf("last=%+v", ts_[3])
  42. }
  43. }