File: settings.sh.in

package info (click to toggle)
libcddb 1.3.2-6
  • links: PTS
  • area: main
  • in suites: bullseye, buster
  • size: 2,276 kB
  • sloc: sh: 10,946; ansic: 4,721; makefile: 44
file content (187 lines) | stat: -rw-r--r-- 3,747 bytes parent folder | download | duplicates (5)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/sh
# @configure_input@
#
# $Id: settings.sh.in,v 1.11 2006/10/15 10:07:50 airborne Exp $

# location of the example program used in the tests
CDDB_QUERY='@abs_top_builddir@/examples/cddb_query -q'

# location of local test cache
CDDB_CACHE='@abs_srcdir@/testcache'

# location of test data
CDDB_DATA='@abs_srcdir@/testdata'

# library built with iconv support?
WITH_ICONV='@with_iconv@'

# name of temporary file for result data
TMP_FILE='./result.tmp'

# test result return codes
SUCCESS=0
FAILURE=1
SKIPPED=77

# libcddb/cddb_query error codes
DISC_NOT_FOUND=12

# counters for number of succeeded/failed/skipped/total tests
CNT_SUCCESS=0
CNT_FAIL=0
CNT_SKIP=0

start_test()
{
    MSG=$*
    printf '%s...' "${MSG}"
    RESULT=
}

fail()
{
    REASON=$*
    if test -z "$REASON"; then
        printf 'failed.\n'
    else
        printf 'failed (%s).\n' "${REASON}"
    fi
    CNT_FAIL=`expr $CNT_FAIL + 1`
    RESULT=${FAILURE}
}

success()
{
    printf 'ok.\n'
    CNT_SUCCESS=`expr $CNT_SUCCESS + 1`
    RESULT=${SUCCESS}
}

skip()
{
    REASON=$*
    if test -z "$REASON"; then
        printf 'skipped.\n'
    else
        printf 'skipped (%s).\n' "${REASON}"
    fi
    CNT_SKIP=`expr $CNT_SKIP + 1`
    RESULT=${SKIPPED}
}

finalize()
{
    rm $TMP_FILE > /dev/null 2>&1
    CNT_TOTAL=`expr $CNT_SUCCESS + $CNT_FAIL + $CNT_SKIP`
    echo "Results for $0"
    if [ $CNT_SUCCESS -gt 0 ]; then
        echo "  Succeeded: ${CNT_SUCCESS}/${CNT_TOTAL}"
    fi
    if [ $CNT_SKIP -gt 0 ]; then
        echo "  Skipped:   ${CNT_SKIP}/${CNT_TOTAL}"
    fi
    if [ $CNT_FAIL -gt 0 ]; then
        echo "  Failed:    ${CNT_FAIL}/${CNT_TOTAL}"
    fi
    if [ $CNT_FAIL -gt 0 ]; then
        exit $FAILURE
    elif [ $CNT_SUCCESS -gt 0 -o $CNT_SKIP -eq 0 ]; then
        exit $SUCCESS
    else
        exit $SKIPPED
    fi
}

cddb_query()
{
    rm $TMP_FILE > /dev/null 2>&1
    $CDDB_QUERY "$@" > $TMP_FILE
}

check_discid()
{
    DISCID_STR='CD disc ID is '
    RV=$1
    EXP_ID=$2
    if [ ${RV} -ne 0 ]; then
        fail 'cddb_query failed'
        return
    fi
    RET_ID=`cat $TMP_FILE | sed "/^${DISCID_STR}[0-9a-f]*\$/!d;s/${DISCID_STR}\([0-9a-f]*\)/\1/"`
    if [ ${RET_ID}x != ${EXP_ID}x ]; then
        fail 'result mismatch'
        return
    fi
    success
}

diff_res_exp()
{
    EXPECTED=$1
    diff $TMP_FILE $EXPECTED > /dev/null
    if [ $? -ne 0 ]; then
        fail 'result mismatch'
        return
    fi
    success
}

check_read()
{
    RV=$1
    DISC_ID=$2
    if [ ${RV} -ne 0 ]; then
        fail 'cddb_query failed'
        return
    fi
    EXP_READ="${CDDB_DATA}/${DISC_ID}.txt"
    diff_res_exp $EXP_READ
}

check_query()
{
    RV=$1
    if [ ${RV} -ne 0 ]; then
        fail 'cddb_query failed'
        return
    fi
    MATCH_COUNT='^Number of matches: \([0-9]*\)$'
    CNT=`grep "${MATCH_COUNT}" ${TMP_FILE} | sed "s/${MATCH_COUNT}/\1/"`
    if test -z "$CNT"; then
        fail 'number of matches not found'
        return
    fi
    if test $CNT -eq 0; then
        fail 'number of matches not found'
        return
    fi
    # check whether all $CNT entries are present
    # XXX: check for category, disc ID and title ?!?
    I=1
    while test $I -le $CNT; do
        grep "Match $I" $TMP_FILE > /dev/null 2>&1
        if test $? -ne 0; then
            fail "entry $I missing, $CNT expected"
            return
        fi
        I=`expr $I + 1`
    done
    # make sure there are not more matches than $CNT
    grep "Match $I" $TMP_FILE > /dev/null 2>&1
    if test $? -eq 0; then
        fail "entry $I present, $CNT expected"
        return
    fi
    success
}

check_not_found()
{
    RV=$1
    DISC_ID=$2
    if [ $RV -ne $DISC_NOT_FOUND ]; then
        fail
        return
    fi
    success
}