| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package i2creg
- import (
- "prod2u6400-uartkit/internal/protocol"
- "testing"
- )
- func TestSetAllTransactions(t *testing.T) {
- s := protocol.SetAll{}
- for i := range s.Front {
- s.Front[i] = 20
- }
- for i := range s.Rear {
- s.Rear[i] = 20
- }
- s.Front[3], s.Rear[3] = 30, 10
- for i := 18; i < 24; i++ {
- s.PTC[i] = 100
- }
- ts_, err := SetAllTransactions(s)
- if err != nil {
- t.Fatal(err)
- }
- if len(ts_) != 2 || ts_[0].Address7 != Address7 {
- t.Fatalf("transactions=%+v", ts_)
- }
- if len(ts_[0].Write) != 34 || ts_[0].Write[0] != 1 || ts_[0].Write[1] != 0 {
- t.Fatalf("staging write=%x", ts_[0].Write)
- }
- if len(ts_[1].Write) != 3 || ts_[1].Write[0] != 0 || ts_[1].Write[1] != 0x10 || ts_[1].Write[2] != 1 {
- t.Fatalf("command write=%x", ts_[1].Write)
- }
- }
- func TestSnapshotReads(t *testing.T) {
- ts_, err := SnapshotReads(201, 64)
- if err != nil {
- t.Fatal(err)
- }
- if len(ts_) != 4 || ts_[0].Write[0] != 2 || ts_[0].Write[1] != 0 {
- t.Fatalf("reads=%+v", ts_)
- }
- if ts_[3].ReadLength != 9 || !ts_[3].RepeatedStart {
- t.Fatalf("last=%+v", ts_[3])
- }
- }
|