Get-Service TeamViewer | Select-Object Status, Name, StartType
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -172,7 +173,7 @@ func TestPreparationHardErrorsNeverReset(t *testing.T) {
|
||||
{0x36, 0x32, 0x30, 0x30}, // Independent dispense error.
|
||||
{0x32, 0x31, 0x30, 0x30}, // Independent capture error.
|
||||
{0x34, 0x30, 0x30, 0x30}, // Command rejection alone.
|
||||
{0x30, 0x30, 0x30, 0x39}, // Unknown.
|
||||
{0x30, 0x30, 0x30, 0x40}, // Unknown.
|
||||
{0x32}, // Malformed.
|
||||
} {
|
||||
responses := prepareFailureResponses(0x32, 7)
|
||||
@@ -482,7 +483,7 @@ func TestPrepareCurrentCardRejectsFailureWithoutEncoderOrMovement(t *testing.T)
|
||||
},
|
||||
{
|
||||
name: "unknown status",
|
||||
response: cmdResp{status: []byte{0x30, 0x30, 0x30, 0x39}},
|
||||
response: cmdResp{status: []byte{0x30, 0x30, 0x30, 0x40}},
|
||||
wantError: "unknown dispenser status",
|
||||
},
|
||||
{
|
||||
@@ -696,3 +697,131 @@ func TestPrepareCardAtEncoderRequiresConfirmedEncoderState(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPositionFlags(t *testing.T) {
|
||||
for position := byte(0x30); position <= 0x3F; position++ {
|
||||
t.Run(fmt.Sprintf("%02X", position), func(t *testing.T) {
|
||||
st := status(position)
|
||||
wantEncoder := position&0x02 != 0
|
||||
wantEmpty := position&0x08 != 0
|
||||
if got := isAtEncoderPosition(st); got != wantEncoder {
|
||||
t.Errorf("isAtEncoderPosition(% X) = %t, want %t", st, got, wantEncoder)
|
||||
}
|
||||
if got := isCardWellEmpty(st); got != wantEmpty {
|
||||
t.Errorf("isCardWellEmpty(% X) = %t, want %t", st, got, wantEmpty)
|
||||
}
|
||||
if err := validateDispenserStatusData(st); err != nil {
|
||||
t.Errorf("validateDispenserStatusData(% X) = %v, want nil", st, err)
|
||||
}
|
||||
ready, err := preparationStatus("test", st, true)
|
||||
if ready != wantEncoder {
|
||||
t.Errorf("preparationStatus(% X) ready = %t, want %t", st, ready, wantEncoder)
|
||||
}
|
||||
wantEmptyError := wantEmpty && !wantEncoder
|
||||
if errors.Is(err, ErrCardWellEmpty) != wantEmptyError || (err != nil && !wantEmptyError) {
|
||||
t.Errorf("preparationStatus(% X) error = %v, want empty error %t", st, err, wantEmptyError)
|
||||
}
|
||||
wantStock := ""
|
||||
if wantEmpty {
|
||||
wantStock = "Card empty"
|
||||
}
|
||||
if got := stockTake(st); got != wantStock {
|
||||
t.Errorf("stockTake(% X) = %q, want %q", st, got, wantStock)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoderPositionPrecedesDiagnostics(t *testing.T) {
|
||||
for _, position := range []byte{0x32, 0x33, 0x36, 0x37, 0x3A, 0x3B, 0x3E, 0x3F} {
|
||||
for _, diagnostics := range [][]byte{
|
||||
{0x30, 0x30, 0x30},
|
||||
{0x32, 0x30, 0x30},
|
||||
{0x36, 0x30, 0x30},
|
||||
{0x34, 0x32, 0x32},
|
||||
{0x30, 0x31, 0x34},
|
||||
{0xFF, 0xFF, 0xFF},
|
||||
} {
|
||||
st := append(append([]byte(nil), diagnostics...), position)
|
||||
for _, operation := range []string{"current", "next"} {
|
||||
t.Run(fmt.Sprintf("%s/% X", operation, st), func(t *testing.T) {
|
||||
client, device := newSequenceTestClient(t, cmdResp{status: st})
|
||||
prepare := client.PrepareCurrentCard
|
||||
if operation == "next" {
|
||||
prepare = client.PrepareNextCard
|
||||
}
|
||||
if _, err := prepare(context.Background()); err != nil {
|
||||
t.Errorf("prepare(% X) = %v, want success", st, err)
|
||||
}
|
||||
want := []cmdType{cmdStatus}
|
||||
if !reflect.DeepEqual(device.commands, want) {
|
||||
t.Errorf("prepare(% X) commands = %v, want %v", st, device.commands, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCombinedEncoderPositionStopsRecovery(t *testing.T) {
|
||||
for _, afterReset := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("afterReset=%t", afterReset), func(t *testing.T) {
|
||||
count := 7 // Encoder confirmation at the recovery threshold, before RS.
|
||||
wantResets := 0
|
||||
if afterReset {
|
||||
count = 8 // Encoder confirmation on the fresh post-reset read.
|
||||
wantResets = 1
|
||||
}
|
||||
responses := append(prepareFailureResponses(0x32, count), cmdResp{status: []byte{0x36, 0x32, 0x34, 0x3F}})
|
||||
client, device := newSequenceTestClient(t, responses...)
|
||||
if _, err := client.PrepareCurrentCard(context.Background()); err != nil {
|
||||
t.Errorf("PrepareCurrentCard(combined encoder) = %v, want success", err)
|
||||
}
|
||||
if got := commandCount(device.commands, cmdReset); got != wantResets {
|
||||
t.Errorf("PrepareCurrentCard(combined encoder) RS count = %d, want %d", got, wantResets)
|
||||
}
|
||||
if got := commandCount(device.commands, cmdToEncoder); got != 1 {
|
||||
t.Errorf("PrepareCurrentCard(combined encoder) FC7 count = %d, want 1", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidPositionEncoding(t *testing.T) {
|
||||
for _, st := range [][]byte{nil, {0x30, 0x30, 0x30}, status(0x02), status(0x2F), status(0x40), status(0x72), status(0xFF)} {
|
||||
if isAtEncoderPosition(st) || isCardWellEmpty(st) {
|
||||
t.Errorf("invalid status % X confirmed encoder or empty, want neither", st)
|
||||
}
|
||||
if ready, err := preparationStatus("test", st, true); ready || err == nil {
|
||||
t.Errorf("preparationStatus(% X) = (%t, %v), want false and error", st, ready, err)
|
||||
}
|
||||
}
|
||||
st := []byte{0xFF, 0xFF, 0xFF, 0x37, 0xFF}
|
||||
if ready, err := preparationStatus("test", st, false); !ready || err != nil {
|
||||
t.Errorf("preparationStatus(% X) = (%t, %v), want encoder precedence", st, ready, err)
|
||||
}
|
||||
st = append(status(0x35), 0xFF)
|
||||
if ready, err := preparationStatus("test", st, true); ready || err == nil {
|
||||
t.Errorf("preparationStatus(% X) = (%t, %v), want malformed error", st, ready, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPositionDescriptions(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
position byte
|
||||
want string
|
||||
}{
|
||||
{0x30, ""},
|
||||
{0x31, "Card at pre-dispense position; "},
|
||||
{0x32, "Card at encoder position; "},
|
||||
{0x34, "Card at mouth position; "},
|
||||
{0x37, "Card at pre-dispense position; Card at encoder position; Card at mouth position; "},
|
||||
{0x39, "Card at pre-dispense position; Card empty; "},
|
||||
{0x3F, "Card at pre-dispense position; Card at encoder position; Card at mouth position; Card empty; "},
|
||||
{0x40, "Unknown status 0x40 at position 4; "},
|
||||
} {
|
||||
if got := statusDescription(status(test.position)); got != test.want {
|
||||
t.Errorf("statusDescription(position %X) = %q, want %q", test.position, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user