aboutsummaryrefslogtreecommitdiffstats
path: root/runtests
blob: b2fb8616eec8a6fd2adffb3563e13b5a1849ea33 (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
#!/bin/bash

pulsemix=$1

if [[ -z $pulsemix ]]; then
  printf 'usage: %s path-to-pulsemix\n' "${0##*/}"
  exit 1
fi

if [[ ! -x $pulsemix ]]; then
  printf '==> ERROR: pulsemix binary not found at %s\n' "$pulsemix"
  exit 1
fi

testno=0 fail=0 pass=0

do_test() {
  local expected=$1 verb=$2 arg=$3 result=

  (( ++testno ))

  result=$("$pulsemix" "$verb" -- ${arg+"$arg"} 2>/dev/null)
  if [[ $result != $expected ]]; then
    printf '==> test %d FAIL: expected %s, got %s\n' "$testno" "$expected" "$result"
    (( ++fail ))
  else
    (( ++pass ))
  fi
}

# volume
do_test 50 'set-volume' 50
do_test 10 'decrease' 40
do_test 0 'decrease' 9001
do_test 0 'get-volume'
do_test 50 'increase' 50
do_test '' 'set-volume'
do_test '' 'increase' foo
do_test '' 'decrease' bar

# balance
do_test 30 'set-balance' 30
do_test 30 'get-balance'
do_test 100 'set-balance' 9001
do_test -5 'adj-balance' -105
do_test 45 'adj-balance' 50
do_test 100 'adj-balance' 9001
do_test 0 'set-balance' 0

if (( ! fail )); then
  printf '==> All %d tests successful\n' "$testno"
else
  printf '==> %d/%d tests failed\n' "$fail" "$testno"
  exit 1
fi