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