| 1 |
|
| 2 |
package decoder |
| 3 |
|
| 4 |
import ( |
| 5 |
"reflect" |
| 6 |
"testing" |
| 7 |
) |
| 8 |
|
| 9 |
type portIsConnectedTest struct { |
| 10 |
arg1 uint32 |
| 11 |
expected bool |
| 12 |
} |
| 13 |
|
| 14 |
var portIsConnectedTests = []portIsConnectedTest{ |
| 15 |
portIsConnectedTest{0x20000000, true}, |
| 16 |
portIsConnectedTest{0xC0000000, true}, |
| 17 |
portIsConnectedTest{0x40000000, false}, |
| 18 |
} |
| 19 |
|
| 20 |
func TestPortIsConnected(t *testing.T) { |
| 21 |
for _, test := range portIsConnectedTests { |
| 22 |
output := PortIsConnected(test.arg1) |
| 23 |
if output != test.expected { |
| 24 |
t.Errorf("Expected %v, received %v", test.expected, output) |
| 25 |
} |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
type decodeTest struct { |
| 30 |
arg1 uint32 |
| 31 |
expected Fields[uint32] |
| 32 |
} |
| 33 |
|
| 34 |
var decodeTests = []decodeTest{ |
| 35 |
decodeTest{0xe23d1a0e, Fields[uint32]{0x3, 0x22, 0x3, 0xd, 0x1, 0xa, 0x0, 0xe}}, |
| 36 |
decodeTest{0x66a8a2e4, Fields[uint32]{0x1, 0x26, 0xa, 0x8, 0xa, 0x2, 0xe, 0x4}}, |
| 37 |
decodeTest{0x2e00a164, Fields[uint32]{0x0, 0x2e, 0x0, 0x0, 0xa, 0x1, 0x6, 0x4}}, |
| 38 |
decodeTest{0x3b83dfe9, Fields[uint32]{0x0, 0x3b, 0x8, 0x3, 0xd, 0xf, 0xe, 0x9}}, |
| 39 |
decodeTest{0x51708701, Fields[uint32]{0x1, 0x11, 0x7, 0x0, 0x8, 0x7, 0x0, 0x1}}, |
| 40 |
} |
| 41 |
|
| 42 |
func TestDecode(t *testing.T) { |
| 43 |
for _, test := range decodeTests { |
| 44 |
output := Decode(test.arg1) |
| 45 |
if !reflect.DeepEqual(output, test.expected) { |
| 46 |
t.Errorf("Expected %v, received %v", test.expected, output) |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
type toHumanReadableTest struct { |
| 52 |
arg1 uint32 |
| 53 |
expected Fields[string] |
| 54 |
} |
| 55 |
|
| 56 |
var toHumanReadableTests = []toHumanReadableTest{ |
| 57 |
toHumanReadableTest{0xe23d1a0e, Fields[string]{ |
| 58 |
"AZALIA_JACK_AND_INTEGRATED", |
| 59 |
"AZALIA_SEPARATE_CHASSIS | AZALIA_FRONT", |
| 60 |
"AZALIA_CD", |
| 61 |
"0xd", |
| 62 |
"AZALIA_BLACK", |
| 63 |
"AZALIA_JACK_PRESENCE_DETECT | 0xa", |
| 64 |
"0", |
| 65 |
"14", |
| 66 |
}}, |
| 67 |
|
| 68 |
toHumanReadableTest{0x57708701, Fields[string]{ |
| 69 |
"AZALIA_NC", |
| 70 |
"AZALIA_RISER", |
| 71 |
"AZALIA_MODEM_HANDSET_SIDE", |
| 72 |
"AZALIA_TYPE_UNKNOWN", |
| 73 |
"AZALIA_PURPLE", |
| 74 |
"AZALIA_NO_JACK_PRESENCE_DETECT | 0x6", |
| 75 |
"0", |
| 76 |
"1", |
| 77 |
}}, |
| 78 |
|
| 79 |
toHumanReadableTest{0x2e00a164, Fields[string]{ |
| 80 |
"AZALIA_JACK", |
| 81 |
"AZALIA_SEPARATE_CHASSIS | 0xe", |
| 82 |
"AZALIA_LINE_OUT", |
| 83 |
"AZALIA_TYPE_UNKNOWN", |
| 84 |
"0xa", |
| 85 |
"AZALIA_NO_JACK_PRESENCE_DETECT", |
| 86 |
"6", |
| 87 |
"4", |
| 88 |
}}, |
| 89 |
|
| 90 |
toHumanReadableTest{0x80949653, Fields[string]{ |
| 91 |
"AZALIA_INTEGRATED", |
| 92 |
"AZALIA_EXTERNAL_PRIMARY_CHASSIS", |
| 93 |
"AZALIA_AUX", |
| 94 |
"AZALIA_RCA", |
| 95 |
"AZALIA_PINK", |
| 96 |
"AZALIA_JACK_PRESENCE_DETECT | 0x6", |
| 97 |
"5", |
| 98 |
"3", |
| 99 |
}}, |
| 100 |
} |
| 101 |
|
| 102 |
func TestToHumanReadable(t *testing.T) { |
| 103 |
for _, test := range toHumanReadableTests { |
| 104 |
output := ToHumanReadable(Decode(test.arg1)) |
| 105 |
if output != test.expected { |
| 106 |
t.Errorf("Expected %v, received %v", test.expected, output) |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
type configToVerbsTest struct { |
| 112 |
arg1 uint32 |
| 113 |
arg2 uint32 |
| 114 |
arg3 uint32 |
| 115 |
expected [4]uint32 |
| 116 |
} |
| 117 |
|
| 118 |
var configToVerbsTests = []configToVerbsTest{ |
| 119 |
configToVerbsTest{ |
| 120 |
0, 0x19, 0x1cc3efde, |
| 121 |
[4]uint32{0x01971cde, 0x01971def, 0x01971ec3, 0x01971f1c}, |
| 122 |
}, |
| 123 |
configToVerbsTest{ |
| 124 |
9, 0x4e, 0x913ddc4c, |
| 125 |
[4]uint32{0x94e71c4c, 0x94e71ddc, 0x94e71e3d, 0x94e71f91}, |
| 126 |
}, |
| 127 |
configToVerbsTest{ |
| 128 |
12, 0xf4, 0x4193db3a, |
| 129 |
[4]uint32{0xcf471c3a, 0xcf471ddb, 0xcf471e93, 0xcf471f41}, |
| 130 |
}, |
| 131 |
configToVerbsTest{ |
| 132 |
7, 0xb7, 0x0c39e09a, |
| 133 |
[4]uint32{0x7b771c9a, 0x7b771de0, 0x7b771e39, 0x7b771f0c}, |
| 134 |
}, |
| 135 |
configToVerbsTest{ |
| 136 |
3, 0x5a, 0x24c04c66, |
| 137 |
[4]uint32{0x35a71c66, 0x35a71d4c, 0x35a71ec0, 0x35a71f24}, |
| 138 |
}, |
| 139 |
} |
| 140 |
|
| 141 |
func TestConfigToVerbs(t *testing.T) { |
| 142 |
for _, test := range configToVerbsTests { |
| 143 |
output := ConfigToVerbs(test.arg1, test.arg2, test.arg3) |
| 144 |
if output != test.expected { |
| 145 |
t.Errorf("Expected %#08x, received %#08x", test.expected, output) |
| 146 |
} |
| 147 |
} |
| 148 |
} |