blob: 0bfe6010935bb22ff76e3f28a2565f82aabc5dee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package pm_test
import (
"testing"
"reflect"
"sort"
"pinmap/pm"
)
type testChip struct {
name string
nodes []string
adc string
gc string
gp int
i2c string
}
func (c *testChip) Name() string {
return c.name
}
func (c *testChip) EnabledNodes() []string {
return c.nodes
}
func (c *testChip) Adc(pin string) string {
return c.adc
}
func (c *testChip) Gpio(pin string) (string, int) {
return c.gc, c.gp
}
func (c *testChip) I2c(pin string) string {
return c.i2c
}
func TestName(t *testing.T) {
n1 := "Test1"
n2 := "Test2"
tc1 := &testChip{name: n1}
tc2 := &testChip{name: n2}
pm.RegisterChip(tc1)
pm.RegisterChip(tc2)
if pm.FindChip(n1) != tc1 {
t.Errorf("Did not match tc1")
}
if pm.FindChip(n2) != tc2 {
t.Errorf("Did not match tc2")
}
chips := pm.Chips()
sort.Strings(chips)
exp := []string{n1, n2}
if !reflect.DeepEqual(exp, chips) {
t.Errorf("Expected %v, got %v", exp, chips)
}
}
|