4d6f6809cc27357ed647d6dba20a998791383d6d
[profile/ivi/node-startup-controller.git] / tests / boot-manager / test-luc-handler
1 #!/bin/bash
2
3 #set -e
4
5 #function to compare the LastUserContext
6 # $1 is the context
7 # $2 is the path to the file to compare the context to
8 compare_luc()
9 {
10   ./gvariant-writer "$1" "$2"
11   diff -q "$luc_path" "$2"
12 }
13
14 # function to begin registration
15 begin()
16 {
17   gdbus call --system \
18     -d org.genivi.BootManager1 \
19     -o /org/genivi/BootManager1/BootManager \
20     -m org.genivi.BootManager1.BootManager.BeginLUCRegistration \
21      &> /dev/null
22 }
23
24 # function to make a registration call
25 register()
26 {
27   gdbus call --system \
28     -d org.genivi.BootManager1 \
29     -o /org/genivi/BootManager1/BootManager \
30     -m org.genivi.BootManager1.BootManager.RegisterWithLUC \
31     "$1" &> /dev/null
32 }
33
34 # function to begin registration
35 end()
36 {
37   gdbus call --system \
38     -d org.genivi.BootManager1 \
39     -o /org/genivi/BootManager1/BootManager \
40     -m org.genivi.BootManager1.BootManager.FinishLUCRegistration \
41      &> /dev/null
42 }
43
44
45 # function to fail with a reason
46 fail()
47 {
48   echo "ERROR: $1"
49   exit 1
50 }
51
52 rm -f temp
53 rm -f "$luc_path"
54
55
56 #Test a simple dictionary
57 begin
58 register "{0: ['app1.unit']}"
59 end
60 [ -z "$(compare_luc "{0: ['app1.unit']}" "temp")" ] \
61   || fail "Registration was not identical"
62
63 #Test whether RegisterWithLUC() writes by itself
64 register "{1: ['app2.service']}"
65 [ "$(compare_luc "{1: ['app2.service']}" "temp" )" ] \
66   || fail "Registration happened with only RegisterWithLUC() called"
67
68 #Test whether calling FinishLUCRegistration() by itself changes the file
69 end
70 [ -z "$(compare_luc "{0: ['app1.unit']}" "temp")" ] \
71   || fail "FinishLUCRegistration() without BeginLUCRegistration() changed the file"
72
73 #Test whether a complex dictionary works
74 dict="{0: ['app1.unit'], 1: ['app1.unit', 'app3.unit'], 2: ['app2.unit']}"
75 begin
76 register "$dict"
77 end
78 [ -z "$(compare_luc "$dict" "temp")" ] \
79   || fail "Failed to register a complex dictionary type"
80
81 #Test with multiple RegisterWithLUC() calls
82 dict="{0: ['app1.unit'], 1: ['app3.unit']}"
83 begin
84 register "{0: ['app1.unit']}"
85 register "{1: ['app3.unit']}"
86 end
87 [ -z "$(compare_luc "$dict" "temp")" ] \
88   || fail "Failed to register correctly when multiple calls are used"
89
90 #Test that using multiply RegisterWithLUC() calls changes the order of the apps
91 dict="{1: ['app2.unit', 'app1.unit']}"
92 begin
93 register "{1: ['app1.unit', 'app2.unit']}"
94 register "{1: ['app1.unit']}"
95 end
96 [ -z "$(compare_luc "$dict" "temp")" ] \
97   || fail "Failed to change the order of the apps on multiple RegisterWithLUC() calls"
98