• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3echo "srcdir: $srcdir"
4echo "scanner: $WAYLAND_SCANNER"
5echo "test_data_dir: $TEST_DATA_DIR"
6echo "test_output_dir: $TEST_OUTPUT_DIR"
7echo "pwd: $PWD"
8echo "sed: $SED"
9
10RETCODE=0
11
12hard_fail() {
13	echo "$@" "ERROR"
14	exit 99
15}
16
17fail() {
18	echo "$@" "FAIL"
19	RETCODE=1
20}
21
22mkdir -p "$TEST_OUTPUT_DIR" || hard_fail "setup"
23
24generate_and_compare() {
25	echo
26	echo "Testing $1 generation: $2 -> $3"
27
28	"$WAYLAND_SCANNER" $1 < "$TEST_DATA_DIR/$2" > "$TEST_OUTPUT_DIR/$3" || \
29		hard_fail "$2 -> $3"
30
31	"$SED" -i -e 's/Generated by wayland-scanner [0-9.]*/SCANNER TEST/' \
32		"$TEST_OUTPUT_DIR/$3" || hard_fail "$2 -> $3"
33
34	diff -q "$TEST_DATA_DIR/$3" "$TEST_OUTPUT_DIR/$3" && \
35		echo "$2 -> $3 PASS" || \
36		fail "$2 -> $3"
37}
38
39verify_error() {
40	echo
41	echo "Checking that reading $1 gives an error on line $3"
42
43	[ -f "$TEST_DATA_DIR/$1" ] || hard_fail "$1 not present"
44
45	# Confirm failure error code
46	"$WAYLAND_SCANNER" server-header < "$TEST_DATA_DIR/$1" >/dev/null 2>"$TEST_OUTPUT_DIR/$2" && \
47		fail "$1 return code check"
48
49	# Verify that an error is produced at the correct line
50	grep -q "<stdin>:$3: error:" "$TEST_OUTPUT_DIR/$2" && echo "$1 PASS" || fail "$1 line number check"
51}
52
53generate_and_compare "code" "example.xml" "example-code.c"
54generate_and_compare "client-header" "example.xml" "example-client.h"
55generate_and_compare "server-header" "example.xml" "example-server.h"
56
57generate_and_compare "code" "small.xml" "small-code.c"
58generate_and_compare "client-header" "small.xml" "small-client.h"
59generate_and_compare "server-header" "small.xml" "small-server.h"
60
61generate_and_compare "-c code" "small.xml" "small-code-core.c"
62generate_and_compare "-c client-header" "small.xml" "small-client-core.h"
63generate_and_compare "-c server-header" "small.xml" "small-server-core.h"
64
65# The existing "code" must produce result identical to "public-code"
66generate_and_compare "code" "small.xml" "small-code.c"
67generate_and_compare "public-code" "small.xml" "small-code.c"
68generate_and_compare "private-code" "small.xml" "small-private-code.c"
69
70verify_error "bad-identifier-arg.xml" "bad-identifier-arg.log" 7
71verify_error "bad-identifier-entry.xml" "bad-identifier-entry.log" 8
72verify_error "bad-identifier-enum.xml" "bad-identifier-enum.log" 6
73verify_error "bad-identifier-event.xml" "bad-identifier-event.log" 6
74verify_error "bad-identifier-interface.xml" "bad-identifier-interface.log" 3
75verify_error "bad-identifier-protocol.xml" "bad-identifier-protocol.log" 2
76verify_error "bad-identifier-request.xml" "bad-identifier-request.log" 6
77
78exit $RETCODE
79