1 -- test script for wslua utility functions
3 local testlib
= require("testlib")
7 local RESET_PREF
= "reset"
18 --------------------------
20 -- Note: This tests expects some specific default values
21 testlib
.testing("get_preference")
23 success
= pcall(get_preference
)
24 testlib
.test(GET_PREF
,"get_preference-empty-0", not success
)
25 testlib
.test(GET_PREF
,"get_preference-empty-1",get_preference("") == nil)
26 testlib
.test(GET_PREF
,"get_preference-unknown-0",get_preference("g") == nil)
27 testlib
.test(GET_PREF
,"get_preference-unknown-1",get_preference("gui") == nil)
28 testlib
.test(GET_PREF
,"get_preference-unknown-2",get_preference("gui.") == nil)
29 testlib
.test(GET_PREF
,"get_preference-unknown-3",get_preference("gui.ask") == nil)
30 testlib
.test(GET_PREF
,"get_preference-unknown-4",get_preference("ugi.ask_unsaved") == nil)
31 testlib
.test(GET_PREF
,"get_preference-uint-0",get_preference("gui.fileopen.preview") == 3)
32 testlib
.test(GET_PREF
,"get_preference-bool-0",get_preference("gui.ask_unsaved") == true)
33 testlib
.test(GET_PREF
,"get_preference-bool-1",get_preference("gui.interfaces_show_hidden") == false)
34 -- gui.console_open is persistent (in the Windows registry) and for that
35 -- reason does not have a default value.
36 console_open
= get_preference("gui.console_open")
37 testlib
.test(GET_PREF
,"get_preference-enum-0",console_open
== "NEVER" or console_open
== "AUTOMATIC" or console_open
== "ALWAYS")
38 testlib
.test(GET_PREF
,"get_preference-string-0",get_preference("gui.window_title") == "")
39 testlib
.test(GET_PREF
,"get_preference-range-0",get_preference("http.tls.port") == "443")
40 success
= pcall(get_preference
, "user_dlt.encaps_table")
41 testlib
.test(GET_PREF
,"get_preference-uat-0", not success
)
43 --------------------------
45 testlib
.testing("set_preference")
47 success
= pcall(set_preference
)
48 testlib
.test(SET_PREF
,"set_preference-empty-0", not success
)
49 testlib
.test(SET_PREF
,"set_preference-empty-1",set_preference("") == nil)
50 testlib
.test(SET_PREF
,"set_preference-unknown-0",set_preference("g") == nil)
51 testlib
.test(SET_PREF
,"set_preference-unknown-1",set_preference("gui") == nil)
52 testlib
.test(SET_PREF
,"set_preference-unknown-2",set_preference("gui.") == nil)
53 testlib
.test(SET_PREF
,"set_preference-unknown-3",set_preference("gui.ask") == nil)
54 testlib
.test(SET_PREF
,"set_preference-unknown-4",set_preference("ugi.ask_unsaved") == nil)
55 success
= pcall(set_preference
,"gui.fileopen.preview")
56 testlib
.test(SET_PREF
,"set_preference-uint-0", not success
)
57 success
= pcall(set_preference
,"gui.fileopen.preview",true)
58 testlib
.test(SET_PREF
,"set_preference-uint-1", not success
)
59 success
= pcall(set_preference
,"gui.fileopen.preview","string")
60 testlib
.test(SET_PREF
,"set_preference-uint-2", not success
)
61 testlib
.test(SET_PREF
,"set_preference-uint-3",set_preference("gui.fileopen.preview",3) == false)
62 testlib
.test(SET_PREF
,"set_preference-uint-4",set_preference("gui.fileopen.preview",42) == true)
63 testlib
.test(SET_PREF
,"set_preference-uint-4-get",get_preference("gui.fileopen.preview") == 42)
64 success
= pcall(set_preference
,"gui.ask_unsaved")
65 testlib
.test(SET_PREF
,"set_preference-bool-0", not success
)
66 success
= pcall(set_preference
,"gui.ask_unsaved",42)
67 testlib
.test(SET_PREF
,"set_preference-bool-1", not success
)
68 success
= pcall(set_preference
,"gui.ask_unsaved","string")
69 testlib
.test(SET_PREF
,"set_preference-bool-2", not success
)
70 testlib
.test(SET_PREF
,"set_preference-bool-3",set_preference("gui.ask_unsaved", true) == false)
71 testlib
.test(SET_PREF
,"set_preference-bool-4",set_preference("gui.ask_unsaved", false) == true)
72 success
= pcall(set_preference
,"gui.console_open")
73 testlib
.test(SET_PREF
,"set_preference-enum-0", not success
)
74 success
= pcall(set_preference
,"gui.console_open",true)
75 testlib
.test(SET_PREF
,"set_preference-enum-1", not success
)
76 -- false means unchanged
77 testlib
.test(SET_PREF
,"set_preference-enum-2",set_preference("gui.console_open",console_open
) == false)
78 success
= pcall(set_preference
,"gui.window_title")
79 testlib
.test(SET_PREF
,"set_preference-string-0", not success
)
80 success
= pcall(set_preference
,"gui.window_title",true)
81 testlib
.test(SET_PREF
,"set_preference-string-1", not success
)
82 testlib
.test(SET_PREF
,"set_preference-string-2",set_preference("gui.window_title","Title") == true)
83 testlib
.test(SET_PREF
,"set_preference-string-2-get",get_preference("gui.window_title") == "Title")
84 testlib
.test(SET_PREF
,"set_preference-string-3",set_preference("gui.window_title","Title") == false)
85 testlib
.test(SET_PREF
,"set_preference-string-4",set_preference("gui.window_title","") == true)
86 testlib
.test(SET_PREF
,"set_preference-string-4-get",get_preference("gui.window_title") == "")
87 testlib
.test(SET_PREF
,"set_preference-string-5",set_preference("gui.window_title","") == false)
88 success
= pcall(set_preference
,"http.tls.port")
89 testlib
.test(SET_PREF
,"set_preference-range-0", not success
)
90 success
= pcall(set_preference
,"http.tls.port","65536") -- Number too big
91 testlib
.test(SET_PREF
,"set_preference-range-1", not success
)
92 success
= pcall(set_preference
,"http.tls.port","http") -- Syntax error
93 testlib
.test(SET_PREF
,"set_preference-range-2", not success
)
94 testlib
.test(SET_PREF
,"set_preference-range-3",set_preference("http.tls.port","443") == false)
95 testlib
.test(SET_PREF
,"set_preference-range-4",set_preference("http.tls.port","443-444") == true)
96 testlib
.test(SET_PREF
,"set_preference-range-4-get",get_preference("http.tls.port") == "443-444")
97 testlib
.test(SET_PREF
,"set_preference-range-5",set_preference("http.tls.port","443-444") == false)
98 testlib
.test(SET_PREF
,"set_preference-range-6",set_preference("http.tls.port","443,444") == true) -- XXX - Returns "changed" because ranges_are_equal is false, 1 range of 2 vs 2 ranges of 1
99 testlib
.test(SET_PREF
,"set_preference-range-7",set_preference("http.tls.port","443,444") == false)
100 success
= pcall(set_preference
, "user_dlt.encaps_table")
101 testlib
.test(SET_PREF
,"set_preference-uat-0", not success
)
103 --------------------------
105 testlib
.testing("reset_preference")
107 success
= pcall(set_preference
)
108 testlib
.test(RESET_PREF
,"reset_preference-empty-0", not success
)
109 testlib
.test(RESET_PREF
,"reset_preference-empty-1",reset_preference("") == nil)
110 testlib
.test(RESET_PREF
,"reset_preference-unknown-0",reset_preference("unknown") == nil)
111 testlib
.test(RESET_PREF
,"reset_preference-uint-0",reset_preference("gui.fileopen.preview") == true)
112 testlib
.test(RESET_PREF
,"reset_preference-uint-0-get",get_preference("gui.fileopen.preview") == 3)
113 testlib
.test(RESET_PREF
,"reset_preference-bool-0",reset_preference("gui.ask_unsaved") == true)
114 testlib
.test(RESET_PREF
,"reset_preference-bool-0-get",get_preference("gui.ask_unsaved") == true)
115 testlib
.test(RESET_PREF
,"reset_preference-string-0",reset_preference("gui.window_title") == true)
116 testlib
.test(RESET_PREF
,"reset_preference-string-0-get",get_preference("gui.window_title") == "")
117 testlib
.test(RESET_PREF
,"reset_preference-range-0",reset_preference("http.tls.port") == true)
118 testlib
.test(RESET_PREF
,"reset_preference-range-0-get",get_preference("http.tls.port") == "443")