Translation update done using Pootle.
[gammu.git] / tests / gen_sms_tests.py
blob2e74513750174e315a45dc5c30cca63c9575cc75
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # vim: expandtab sw=4 ts=4 sts=4:
4 '''
5 Gammu SMS backup generator.
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import os
28 # Work in both common location when this can be executed:
29 try:
30 os.chdir('tests/at-sms-encode/')
31 except OSError:
32 os.chdir('at-sms-encode/')
34 # Numbers we're going to test
35 NUMBERS = [
36 '1234',
37 '800123456',
38 '+420800123456',
39 '+41761234567',
42 # Text parts we're going to test
43 TEXTS = [
44 '123456',
45 'Zkouška sirén',
46 'This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.',
49 TEMPLATE = '''
50 [SMSBackup000]
51 SMSC = "%s"
52 State = %s
53 Number = "%s"
54 Coding = %s
55 Folder = %d
56 '''
58 STATES = [
59 'Read',
60 'Read',
61 'Sent',
63 CODINGS = [
64 'Default',
65 'Unicode',
68 def write_text(f, text):
69 '''
70 Writes text splitted and encoded in same way as Gammu does it for SMS backups.
71 '''
72 encoded = text.encode('UTF-16-BE').encode('HEX')
73 line = 0
74 while len(encoded) > 0:
75 f.write('Text%02d = %s\n' % (line, encoded[:200]))
76 encoded = encoded[200:]
77 line = line + 1
79 def generate_message(index, folder, coding, smscnum, num, text):
80 '''
81 Generates single message file.
82 '''
83 f = file('%02d.backup' % index, 'w')
84 f.write(TEMPLATE % (
85 NUMBERS[smscnum],
86 STATES[folder],
87 NUMBERS[num],
88 CODINGS[coding],
89 folder
91 if folder > 1:
92 f.write('Sent = 20070605T135630\n')
93 write_text(f, TEXTS[text])
94 f.close()
96 def generate():
97 '''
98 Generates test data based on NUMBERS and TEXTS variables.
99 '''
100 index = 1
102 for smscnum in range(len(NUMBERS)):
103 for num in range(len(NUMBERS)):
104 for text in range(len(TEXTS)):
105 for coding in range(len(CODINGS)):
106 for folder in [1, 2]:
107 generate_message(index,
108 folder,
109 coding,
110 smscnum,
111 num,
112 text)
113 index = index + 1
115 if __name__ == '__main__':
116 generate()