File: test-proxy

package info (click to toggle)
gdbuspp 3-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,116 kB
  • sloc: cpp: 9,462; python: 477; sh: 215; makefile: 5
file content (94 lines) | stat: -rwxr-xr-x 4,381 bytes parent folder | download | duplicates (2)
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
#!/bin/bash
#  GDBus++ - glib2 GDBus C++ wrapper
#
#  SPDX-License-Identifier: AGPL-3.0-only
#
#  Copyright (C)  OpenVPN Inc <sales@openvpn.net>
#  Copyright (C)  David Sommerseth <davids@openvpn.net>
#

set -eu

##
# @file tests/scripts/test-proxy
#
# @brief Runs several tests using the tests/test_proxy.cpp
#        D-Bus proxy client.
#
#        This tests requires the tests/simple-service.cpp test service
#        to be running

FAILED_RESULT=0

run_proxy()
{
    DEFAULT_ARGS="-E -d net.openvpn.gdbuspp.test.simple"
    echo ">> Running proxy test: ${BUILD_DIR:-.}/test_proxy ${DEFAULT_ARGS} $@"
    ${BUILD_DIR:-.}/test_proxy -q ${DEFAULT_ARGS} "$@"
    if [ $? -ne 0 ]; then
        echo ">>     ## Result: FAIL"
        FAILED_RESULT=$(($FAILED_RESULT + 1))
    else
        echo ">>     Result: Pass"
    fi
    echo ""
}


MAIN_PATH="-p /gdbuspp/tests/simple1"
METHODS_PATH="$MAIN_PATH/methods"
PROPS_PATH="$MAIN_PATH/properties"

# Test introspection
run_proxy $MAIN_PATH -Q

# Test calling D-Bus methods
run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m MethodNoArgs
run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m StringLength -t s -v "A small test string" -X "(i)" -x "(19,)"

# Test creating child objects and introspect it
run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m CreateSimpleObject -t s -v proxy_test -X "(o)" -x "('/gdbuspp/tests/simple1/childs/proxy_test',)"
run_proxy $MAIN_PATH/childs/proxy_test -Q
run_proxy $MAIN_PATH/childs/proxy_test -i gdbuspp.test.simple1.child -m GetMyName -X '(s)' -x "('proxy_test',)"
run_proxy $MAIN_PATH/childs/proxy_test -i gdbuspp.test.simple1.child -g my_path -X "o" -x "'/gdbuspp/tests/simple1/childs/proxy_test'"
run_proxy $MAIN_PATH/childs/proxy_test -i gdbuspp.test.simple1.child -m RemoveMe

run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m CreateSimpleObject -t s -v proxy_test2 -X "(o)" -x "('/gdbuspp/tests/simple1/childs/proxy_test2',)"
run_proxy $METHODS_PATH -i gdbuspp.test.simple1 -m RemoveSimpleObject -t s -v proxy_test2

# Test querying properties - simple types
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g bool_val -X "b" -x "true"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g int_val -X "i" -x "-345"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g long_val -X "x" -x "9223372036854775807"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g uint_val -X "u" -x "123"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g ulonglong_val -X "t" -x "18446744073709551615"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g string_val -X "s" -x "'Initial string'"

# Test querying properties - array types
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g int_array -X "ai" -x "[-10, 3, 16, 9388]"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g uint_array -X "au" -x "[0, 15, 16, 31, 32, 65534, 65535]"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g string_array -X "as" -x "['line 1', 'line 2', 'line 3']"

# Test querying properties - struct type
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex -X "(bis)" -x "(true, 98877, 'Initial complex string value')"

# Test setting properties - just taking a selection here (test-simple-servce-1 will test all)
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s bool_val -t "b" -v "false"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g bool_val -X "b" -x "false"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s bool_val -t "b" -v "true"

run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s string_val -t "s" -v "Modified by test-proxy"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g string_val -X "s" -x "'Modified by test-proxy'"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s string_val -t "s" -v "Initial string"

run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s complex -t bis -v false -v -34977 -v "Complex string modified by test-proxy"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex -X "(bis)" -x "(false, -34977, 'Complex string modified by test-proxy')"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex_readonly -X "(bis)" -x "(false, -34977, 'Complex string modified by test-proxy')"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -s complex -t bis -v true -v 98877 -v "Initial complex string value"
run_proxy $PROPS_PATH -i gdbuspp.test.simple1 -g complex_readonly -X "(bis)" -x "(true, 98877, 'Initial complex string value')"


echo "Test failed: $FAILED_RESULT"
if [ $FAILED_RESULT -gt 0 ]; then
    exit 1
fi