|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 """ |
|
18 Script for generating expected data for the tests where output |
|
19 is written to a file. |
|
20 """ |
|
21 |
|
22 import os, unittest |
|
23 import __init__ |
|
24 |
|
25 from testautomation.utils import hex_to_bindata |
|
26 |
|
27 from hcrplugin.hcrrepository import HcrRepository, HcrRecord |
|
28 from hcrplugin.hcr_writer import HcrWriter |
|
29 from hcrplugin import hcr_exceptions |
|
30 |
|
31 def generate_repository(file_path, records): |
|
32 dir = os.path.dirname(file_path) |
|
33 if dir != '' and not os.path.exists(dir): |
|
34 os.makedirs(dir) |
|
35 |
|
36 writer = HcrWriter() |
|
37 repo = HcrRepository(records) |
|
38 f = open(file_path, "wb") |
|
39 try: f.write(writer.get_repository_bindata(repo)) |
|
40 finally: f.close() |
|
41 |
|
42 print "Generated '%s' with %d records" % (file_path, len(records)) |
|
43 |
|
44 def generate_expected_data(): |
|
45 records = [] |
|
46 category = 0x10001234 |
|
47 records.append(HcrRecord(HcrRecord.VALTYPE_INT32, 0, category, 0)) |
|
48 records.append(HcrRecord(HcrRecord.VALTYPE_INT32, 0, category, 1)) |
|
49 records.append(HcrRecord(HcrRecord.VALTYPE_INT32, 0, category, 2)) |
|
50 |
|
51 generate_repository("generated/expected/project/hcr.dat", records) |
|
52 |
|
53 # -------------------------------------------------------------- |
|
54 |
|
55 records = [] |
|
56 category = 0x10001234 |
|
57 records.append(HcrRecord(HcrRecord.VALTYPE_INT8, 125, category, 0)) |
|
58 records.append(HcrRecord(HcrRecord.VALTYPE_UINT32, 4000000000, category, 1)) |
|
59 records.append(HcrRecord(HcrRecord.VALTYPE_ARRAY_INT32, [-1, -20, -300, -4000, -50000], category, 2)) |
|
60 records.append(HcrRecord(HcrRecord.VALTYPE_BIN_DATA, hex_to_bindata('00112233 DEADBEEF CAFE 50'), category, 3)) |
|
61 |
|
62 category = 0x20001234 |
|
63 records.append(HcrRecord(HcrRecord.VALTYPE_LIN_ADDR, 0x10203040, category, 0)) |
|
64 records.append(HcrRecord(HcrRecord.VALTYPE_INT64, 1234567890123456789, category, 1)) |
|
65 records.append(HcrRecord(HcrRecord.VALTYPE_ARRAY_UINT32, [1, 20, 300, 4000, 50000], category, 2)) |
|
66 records.append(HcrRecord(HcrRecord.VALTYPE_TEXT8, u'100\u20ac', category, 3)) |
|
67 |
|
68 category = 0x30001234 |
|
69 records.append(HcrRecord(HcrRecord.VALTYPE_BOOL, False, category, 0)) |
|
70 |
|
71 generate_repository("generated/expected/multifile_project/hcr.dat", records) |
|
72 |
|
73 if __name__ == "__main__": |
|
74 generate_expected_data() |