Debian Codegraph @

tests/scripts/test-proxy

raw
1 #!/bin/bash
2 # GDBus++ - glib2 GDBus C++ wrapper
3 #
4 # SPDX-License-Identifier: AGPL-3.0-only
5 #
6 # Copyright (C) OpenVPN Inc <[email protected]>
7 # Copyright (C) David Sommerseth <[email protected]>
8 #
9
10 set -eu
11
12 ##
13 # @file tests/scripts/test-proxy
14 #
15 # @brief Runs several tests using the tests/test_proxy.cpp
16 # D-Bus proxy client.
17 #
18 # This tests requires the tests/simple-service.cpp test service
19 # to be running
20
21 FAILED_RESULT=0
22
23 run_proxy()
24 {
25 DEFAULT_ARGS="-E -d net.openvpn.gdbuspp.test.simple"
26 echo ">> Running proxy test: ${BUILD_DIR:-.}/test_proxy ${DEFAULT_ARGS} $@"
27 ${BUILD_DIR:-.}/test_proxy -q ${DEFAULT_ARGS} "$@"
28 if [ $? -ne 0 ]; then
29 echo ">> ## Result: FAIL"
30 FAILED_RESULT=$(($FAILED_RESULT + 1))
31 else
32 echo ">> Result: Pass"
33 fi
34 echo ""
35 }
36
37
38 MAIN_PATH="-p /gdbuspp/tests/simple1"
39 METHODS_PATH="$MAIN_PATH/methods"
40 PROPS_PATH="$MAIN_PATH/properties"
41
42 # Test introspection
43 run_proxy $MAIN_PATH -Q
44
45 # Test calling D-Bus methods
46 run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m MethodNoArgs
47 run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m StringLength -t s -v "A small test string" -X "(i)" -x "(19,)"
48
49 # Test creating child objects and introspect it
50 run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m CreateSimpleObject -t s -v proxy_test -X "(o)" -x "('/gdbuspp/tests/simple1/childs/proxy_test',)"
51 run_proxy $MAIN_PATH/childs/proxy_test -Q
52 run_proxy $MAIN_PATH/childs/proxy_test -i gdbuspp.test.simple1.child -m GetMyName -X '(s)' -x "('proxy_test',)"
53 run_proxy $MAIN_PATH/childs/proxy_test -i gdbuspp.test.simple1.child -g my_path -X "o" -x "'/gdbuspp/tests/simple1/childs/proxy_test'"
54 run_proxy $MAIN_PATH/childs/proxy_test -i gdbuspp.test.simple1.child -m RemoveMe
55
56 run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m CreateSimpleObject -t s -v proxy_test2 -X "(o)" -x "('/gdbuspp/tests/simple1/childs/proxy_test2',)"
57 run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m RemoveSimpleObject -t s -v proxy_test2
58
59 # Test querying properties - simple types
60 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g bool_val -X "b" -x "true"
61 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g int_val -X "i" -x "-345"
62 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g long_val -X "x" -x "9223372036854775807"
63 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g uint_val -X "u" -x "123"
64 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g ulonglong_val -X "t" -x "18446744073709551615"
65 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g string_val -X "s" -x "'Initial string'"
66
67 # Test querying properties - array types
68 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g int_array -X "ai" -x "[-10, 3, 16, 9388]"
69 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g uint_array -X "au" -x "[0, 15, 16, 31, 32, 65534, 65535]"
70 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g string_array -X "as" -x "['line 1', 'line 2', 'line 3']"
71
72 # Test querying properties - struct type
73 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex -X "(bis)" -x "(true, 98877, 'Initial complex string value')"
74
75 # Test setting properties - just taking a selection here (test-simple-servce-1 will test all)
76 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s bool_val -t "b" -v "false"
77 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g bool_val -X "b" -x "false"
78 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s bool_val -t "b" -v "true"
79
80 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s string_val -t "s" -v "Modified by test-proxy"
81 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g string_val -X "s" -x "'Modified by test-proxy'"
82 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s string_val -t "s" -v "Initial string"
83
84 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s complex -t bis -v false -v -34977 -v "Complex string modified by test-proxy"
85 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex -X "(bis)" -x "(false, -34977, 'Complex string modified by test-proxy')"
86 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex_readonly -X "(bis)" -x "(false, -34977, 'Complex string modified by test-proxy')"
87 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s complex -t bis -v true -v 98877 -v "Initial complex string value"
88 run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex_readonly -X "(bis)" -x "(true, 98877, 'Initial complex string value')"
89
90
91 echo "Test failed: $FAILED_RESULT"
92 if [ $FAILED_RESULT -gt 0 ]; then
93 exit 1
94 fi