3
# Copyright (C) 2007 Mark Lee <avant-wn@lazymalevolence.com>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
# Author : Mark Lee <avant-wn@lazymalevolence.com>
27
sys.stderr.write(err + '\n')
29
def test_option_bool(client):
30
print '* set bool...',
33
client.set_bool(GROUP, 'bool', val)
34
except Exception, err:
38
print '* get bool...',
41
val = client.get_bool(GROUP, 'bool')
42
except Exception, err:
51
def test_option_float(client):
52
print '* set float...',
55
client.set_float(GROUP, 'float', val)
56
except Exception, err:
60
print '* get float...',
63
val = client.get_float(GROUP, 'float')
64
except Exception, err:
73
def test_option_int(client):
77
client.set_int(GROUP, 'int', val)
78
except Exception, err:
85
val = client.get_int(GROUP, 'int')
86
except Exception, err:
95
def test_option_string(client):
96
print '* set string...',
99
client.set_string(GROUP, 'str', val)
100
except Exception, err:
104
print '* get string...',
107
val = client.get_string(GROUP, 'str')
108
except Exception, err:
117
def check_lists(list_get, list_set):
119
if len(list_get) != len(list_set):
122
list_len = len(list_set)
123
for i in range(list_len):
124
if list_get[i] != list_set[i]:
125
print_err('The lists differ at list index %s: get="%s", set="%s"' % (i, list_get[i], list_set[i]))
129
def test_option_list_bool(client):
130
print '* set list (bool)...',
131
list_set = [True, False, True]
133
client.set_list(GROUP, 'list_bool', awn.CONFIG_LIST_BOOL, list_set)
134
except Exception, err:
138
print '* get list (bool)...',
140
list_get = client.get_list(GROUP, 'list_bool', awn.CONFIG_LIST_BOOL)
141
except Exception, err:
145
return check_lists(list_get, list_set)
147
def test_option_list_float(client):
148
print '* set list (float)...',
149
list_set = [0.2, 0.4, 0.6]
151
client.set_list(GROUP, 'list_float', awn.CONFIG_LIST_FLOAT, list_set)
152
except Exception, err:
156
print '* get list (float)...',
158
list_get = client.get_list(GROUP, 'list_float', awn.CONFIG_LIST_FLOAT)
159
except Exception, err:
163
return check_lists(list_get, list_set)
165
def test_option_list_int(client):
166
print '* set list (int)...',
169
client.set_list(GROUP, 'list_int', awn.CONFIG_LIST_INT, list_set)
170
except Exception, err:
174
print '* get list (int)...',
176
list_get = client.get_list(GROUP, 'list_int', awn.CONFIG_LIST_INT)
177
except Exception, err:
181
return check_lists(list_get, list_set)
183
def test_option_list_string(client):
184
print '* set list (string)...',
185
list_set = ['One', 'Two', 'Three']
187
client.set_list(GROUP, 'list_str', awn.CONFIG_LIST_STRING, list_set)
188
except Exception, err:
192
print '* get list (string)...',
194
list_get = client.get_list(GROUP, 'list_str', awn.CONFIG_LIST_STRING)
195
except Exception, err:
199
return check_lists(list_get, list_set)
201
def test_option_types(client):
203
retval |= test_option_bool(client)
204
retval |= test_option_float(client)
205
retval |= test_option_int(client)
206
retval |= test_option_string(client)
207
retval |= test_option_list_bool(client)
208
retval |= test_option_list_float(client)
209
retval |= test_option_list_int(client)
210
retval |= test_option_list_string(client)
213
def test_awn_config():
215
print 'Main config client'
216
client = awn.Config()
219
retval |= test_option_types(client)
222
def test_applet_config():
224
print 'Applet config client'
225
client = awn.Config('test')
228
retval |= test_option_types(client)
233
retval |= test_awn_config()
234
retval |= test_applet_config()
237
if __name__ == '__main__':