|
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 import unittest |
|
18 import os, shutil |
|
19 import sys |
|
20 import __init__ |
|
21 |
|
22 from testautomation.utils import hex_to_bindata |
|
23 |
|
24 from hcrplugin import hcr_header |
|
25 from hcrplugin.hcr_exceptions import InvalidHcrHeaderError |
|
26 |
|
27 |
|
28 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
29 |
|
30 |
|
31 class TestHCRHeader(unittest.TestCase): |
|
32 def test_hcr_header_dumps_empty(self): |
|
33 hcrh = hcr_header.HcrHeader() |
|
34 self.assertEquals(len(hcrh.dumps()), 32) |
|
35 expected_data = hex_to_bindata( |
|
36 "48435266 0000 0000 00000000 00000000"+\ |
|
37 "00000000 000000000000000000000000") |
|
38 self.assertEquals(hcrh.dumps(), expected_data) |
|
39 |
|
40 def test_hcr_header_loads_empty(self): |
|
41 hcrh = hcr_header.HcrHeader() |
|
42 try: |
|
43 hcrh.loads('') |
|
44 self.fail('parsing of empty string succeeded?') |
|
45 except InvalidHcrHeaderError: |
|
46 pass |
|
47 |
|
48 def test_hcr_header_loads_invalid_signature(self): |
|
49 hcrh = hcr_header.HcrHeader() |
|
50 try: |
|
51 hcrh.loads(32*' ') |
|
52 self.fail('parsing of empty string succeeded?') |
|
53 except InvalidHcrHeaderError: |
|
54 pass |
|
55 |
|
56 def test_hcr_header_loads_zero(self): |
|
57 hcrh = hcr_header.HcrHeader() |
|
58 header_data = hex_to_bindata( |
|
59 "48435266 0000 0000 00000000 00000000"+\ |
|
60 "00000000 000000000000000000000000") |
|
61 hcrh.loads(header_data) |
|
62 self.assertEquals(hcrh.version, 0) |
|
63 self.assertEquals(hcrh.flags, 0) |
|
64 self.assertEquals(hcrh.nrecords, 0) |
|
65 self.assertEquals(hcrh.lsd_offset, 0) |
|
66 self.assertEquals(hcrh.lsd_size, 0) |
|
67 |
|
68 def test_hcr_header_dumps_some_data(self): |
|
69 hcrh = hcr_header.HcrHeader() |
|
70 hcrh.version = 5 |
|
71 hcrh.flags = 6 |
|
72 hcrh.nrecords = 10 |
|
73 hcrh.lsd_offset = 18 |
|
74 hcrh.lsd_size = 32 |
|
75 expected_data = hex_to_bindata( |
|
76 "48435266 0500 0600 0A000000 12000000"+\ |
|
77 "20000000 000000000000000000000000") |
|
78 self.assertEquals(hcrh.dumps(), expected_data) |
|
79 |
|
80 def test_hcr_header_loads_some_data(self): |
|
81 hcrh = hcr_header.HcrHeader() |
|
82 header_data = hex_to_bindata( |
|
83 "48435266 0500 0600 0A000000 12000000"+\ |
|
84 "20000000 000000000000000000000000") |
|
85 hcrh.loads(header_data) |
|
86 self.assertEquals(hcrh.version, 5) |
|
87 self.assertEquals(hcrh.flags, 6) |
|
88 self.assertEquals(hcrh.nrecords, 10) |
|
89 self.assertEquals(hcrh.lsd_offset, 18) |
|
90 self.assertEquals(hcrh.lsd_size, 32) |