configurationengine/source/plugins/symbian/ConeCRMLPlugin/CRMLPlugin/tests/unittest_crml_model.py
author m2lahtel
Tue, 10 Aug 2010 14:29:28 +0300
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
permissions -rw-r--r--
ConE 1.2.11 release
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
import unittest
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
from cone.public import api, exceptions
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
from CRMLPlugin.crml_model import *
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
class TestCrmlAccess(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
    def test_create_access_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
        acc = CrmlAccess()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
        self.assertEquals(acc.cap_rd, None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
        self.assertEquals(acc.cap_wr, None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
        self.assertEquals(acc.sid_rd, None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
        self.assertEquals(acc.sid_wr, None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
        acc = CrmlAccess(cap_rd='AlwaysPass', cap_wr='WriteUserData', sid_rd='0x12345678', sid_wr='0x87654321')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
        self.assertEquals(acc.cap_rd, 'AlwaysPass')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
        self.assertEquals(acc.cap_wr, 'WriteUserData')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
        self.assertEquals(acc.sid_rd, '0x12345678')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
        self.assertEquals(acc.sid_wr, '0x87654321')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
    def test_clone_access_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
        acc1 = CrmlAccess(cap_rd='AlwaysPass', cap_wr='WriteUserData', sid_rd='0x12345678', sid_wr='0x87654321')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
        acc2 = acc1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
        self.assertFalse(acc1 is acc2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
        self.assertTrue(acc1 == acc2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
        self.assertFalse(acc1 != acc2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    def test_compare_access_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
        acc1 = CrmlAccess(cap_rd='AlwaysPass', cap_wr='WriteUserData', sid_rd='0x12345678', sid_wr='0x87654321')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
        acc2 = acc1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
        self.assertTrue(acc1 == acc2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
        self.assertFalse(acc1 != acc2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
        def check(attrname, value):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
            acc2 = acc1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
            setattr(acc1, attrname, value)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
            self.assertFalse(acc1 == acc2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
            self.assertTrue(acc1 != acc2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        # Check that changing each individual attribute makes the comparison fail
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
        check('cap_rd', 'ReadDeviceData')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
        check('cap_wr', 'WriteDeviceData')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
        check('sid_rd', '0x11223344')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
        check('sid_wr', '0x44332211')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
        subkeys = [
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
            CrmlKeyRangeSubKey(ref='Sub1', name='Sub-key 1', type='int', int='0x1'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
            CrmlKeyRangeSubKey(ref='Sub2', name='Sub-key 2', type='real', int='0x2'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
            CrmlKeyRangeSubKey(ref='Sub3', name='Sub-key 3', type='string', int='0x3'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
        ]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
        self.keyrange = CrmlKeyRange(
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
            first_int   = '0x10000000',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
            last_int    = '0x1FFFFFFF',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
            first_index = 2,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
            index_bits  = 0x0ff0,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
            backup      = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
            read_only   = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
            access      = CrmlAccess(cap_rd='ReadUserData'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
            subkeys     = subkeys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
    def test_create_keyrange_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
        self.assertRaises(ValueError, CrmlKeyRange)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
        self.assertRaises(ValueError, CrmlKeyRange, first_int='0x10')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
        self.assertRaises(ValueError, CrmlKeyRange, last_int='0x1F')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
        keyrange = CrmlKeyRange(first_int='0x10', last_int='0x1F')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
class TestCrmlRepository(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    86
        keys = [
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
            CrmlSimpleKey(ref='Foo.Bar', int='0x1'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
            CrmlBitmaskKey(int='0x2', bits=[CrmlBit(ref='Foo.Bit1', index=1),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
                                            CrmlBit(ref='Foo.Bit2', index=2),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
                                            CrmlBit(ref='Foo.Bit4', index=4, invert=True)]),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
            CrmlKeyRange(first_int='0x10000000', last_int='0x1FFFFFFF', ref="Foo.Seq",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
                         subkeys=[CrmlKeyRangeSubKey(ref='Sub1', name='Sub-key 1', type='int', int='0x1'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
                                  CrmlKeyRangeSubKey(ref='Sub2', name='Sub-key 2', type='real', int='0x2')]),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
        ]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
        self.repo = CrmlRepository(
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    97
            uid_value   = '0x10203040',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
            uid_name    = 'KCrUidTest',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    99
            owner       = '0x11223344',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   100
            backup      = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   101
            rfs         = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   102
            version     = '2',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
            access      = CrmlAccess(cap_rd='ReadUserData'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   104
            keys        = keys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   105
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   106
    def test_create_empty_repo(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   107
        repo = CrmlRepository()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   108
        self.assertEquals(repo.get_refs(), [])
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   109
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   110
    def test_create_repo_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   111
        repo = CrmlRepository()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   112
        self.assertEquals(repo.uid_value,   None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   113
        self.assertEquals(repo.uid_name,    None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   114
        self.assertEquals(repo.owner,       None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   115
        self.assertEquals(repo.backup,      False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   116
        self.assertEquals(repo.rfs,         False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   117
        self.assertEquals(repo.access,      CrmlAccess())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   118
        self.assertEquals(repo.keys,        [])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   119
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   120
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   121
        keys = [
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   122
            CrmlSimpleKey(ref='Foo.Bar', int='0x1'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   123
            CrmlBitmaskKey(int='0x2', bits=[CrmlBit(ref='Foo.Bit1', index=1),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   124
                                            CrmlBit(ref='Foo.Bit2', index=2),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   125
                                            CrmlBit(ref='Foo.Bit4', index=4, invert=True)]),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   126
            CrmlKeyRange(first_int='0x10000000', last_int='0x1FFFFFFF', ref="Foo.Seq",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   127
                         subkeys=[CrmlKeyRangeSubKey(ref='Sub1', name='Sub-key 1', type='int', int='0x1'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   128
                                  CrmlKeyRangeSubKey(ref='Sub2', name='Sub-key 2', type='real', int='0x2')]),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   129
        ]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   130
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   131
        repo = self.repo
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   132
        self.assertEquals(repo.uid_value,   '0x10203040')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   133
        self.assertEquals(repo.uid_name,    'KCrUidTest')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   134
        self.assertEquals(repo.owner,       '0x11223344')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   135
        self.assertEquals(repo.backup,      True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   136
        self.assertEquals(repo.rfs,         True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   137
        self.assertEquals(repo.version,     '2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   138
        self.assertEquals(repo.access,      CrmlAccess(cap_rd='ReadUserData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   139
        self.assertEquals(repo.keys,        keys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   140
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   141
    def test_clone_repo_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   142
        repo1 = self.repo
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   143
        repo2 = repo1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   144
        self.assertFalse(repo1 is repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   145
        self.assertTrue(repo1 == repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   146
        self.assertFalse(repo1 != repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   147
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   148
        # Assert that the keys have been deep-copied
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   149
        self.assertFalse(repo1.keys is repo2.keys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   150
        self.assertEquals(repo1.keys, repo2.keys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   151
        for i in xrange(len(repo1.keys)):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   152
            self.assertFalse(repo1.keys[i] is repo2.keys[i])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   153
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   154
    def test_compare_repo_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   155
        repo1 = CrmlRepository()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   156
        repo2 = repo1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   157
        self.assertTrue(repo1 == repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   158
        self.assertFalse(repo1 != repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   159
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   160
        def check(attrname, value):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   161
            repo1 = self.repo
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   162
            repo2 = repo1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   163
            setattr(repo2, attrname, value)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   164
            self.assertFalse(repo1 == repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   165
            self.assertTrue(repo1 != repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   166
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   167
        # Check that changing each individual attribute makes the comparison fail
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   168
        check('uid_value',  '0xbaadf00d')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   169
        check('uid_name',   'KFooUid')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   170
        check('owner',      '0xbeef')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   171
        check('backup',     False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   172
        check('rfs',        False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   173
        check('access',     CrmlAccess(cap_wr='WriteUserData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   174
        check('keys',       ['foo'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   175
        check('version',    '3')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   176
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   177
        def check2(mod_func):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   178
            repo1 = self.repo
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   179
            repo2 = repo1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   180
            mod_func(repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   181
            self.assertFalse(repo1 == repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   182
            self.assertTrue(repo1 != repo2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   183
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   184
        # Check that changing the keys makes the comparison fail
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   185
        check2(lambda r: setattr(r.keys[0], 'name', 'foo'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   186
        check2(lambda r: setattr(r.keys[1], 'type', 'binary'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   187
        check2(lambda r: setattr(r.keys[2], 'index_bits', 0x00ffff00))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   188
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   189
    def test_get_repo_refs(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   190
        self.assertEquals([], CrmlRepository(uid_value='0x1').get_refs())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   191
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   192
        expected = ['Foo.Bar',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   193
                    'Foo.Bit1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   194
                    'Foo.Bit2',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   195
                    'Foo.Bit4',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   196
                    'Foo.Seq',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   197
                    'Foo.Seq.Sub1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   198
                    'Foo.Seq.Sub2']
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   199
        self.assertEquals(sorted(expected), sorted(self.repo.get_refs()))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   200
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   201
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   202
class TestCrmlSimpleKey(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   203
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   204
        self.key = CrmlSimpleKey(
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   205
            ref         = 'Foo.Bar',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   206
            name        = 'Foobar',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   207
            int         = '0x1020',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   208
            type        = 'real',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   209
            backup      = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   210
            read_only   = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   211
            access      = CrmlAccess(cap_rd='ReadUserData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   212
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   213
    def test_create_key_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   214
        # Not specifying ref or index should make the constructor fail
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   215
        self.assertRaises(ValueError, CrmlSimpleKey)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   216
        self.assertRaises(ValueError, CrmlSimpleKey, ref='Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   217
        self.assertRaises(ValueError, CrmlSimpleKey, int='0x1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   218
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   219
        key = CrmlSimpleKey(ref='Foo.Bar', int='0x1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   220
        self.assertEquals(key.ref,          'Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   221
        self.assertEquals(key.name,         None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   222
        self.assertEquals(key.int,          '0x1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   223
        self.assertEquals(key.type,         'int')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   224
        self.assertEquals(key.backup,       False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   225
        self.assertEquals(key.read_only,    False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   226
        self.assertEquals(key.access,       CrmlAccess())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   227
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   228
        key = self.key
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   229
        self.assertEquals(key.ref,          'Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   230
        self.assertEquals(key.name,         'Foobar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   231
        self.assertEquals(key.int,          '0x1020')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   232
        self.assertEquals(key.type,         'real')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   233
        self.assertEquals(key.backup,       True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   234
        self.assertEquals(key.read_only,    True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   235
        self.assertEquals(key.access,       CrmlAccess(cap_rd='ReadUserData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   236
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   237
    def test_clone_key_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   238
        key1 = self.key
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   239
        key2 = key1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   240
        self.assertFalse(key1 is key2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   241
        self.assertTrue(key1 == key2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   242
        self.assertFalse(key1 != key2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   243
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   244
    def test_compare_key_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   245
        def check(attrname, value):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   246
            key1 = self.key
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   247
            key2 = key1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   248
            setattr(key2, attrname, value)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   249
            self.assertFalse(key1 == key2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   250
            self.assertTrue(key1 != key2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   251
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   252
        # Check that changing each individual attribute makes the comparison fail
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   253
        check('ref',        'Foo.Bar.Baz')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   254
        check('name',       'Testing')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   255
        check('int',        'KFooUid')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   256
        check('type',       'selection')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   257
        check('backup',     False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   258
        check('read_only',  False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   259
        check('access',     CrmlAccess(cap_wr='WriteUserData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   260
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   261
    def test_get_key_refs(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   262
        self.assertEquals(['Foo.Bar'], self.key.get_refs())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   263
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   264
class TestCrmlBit(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   265
    def test_create_bit_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   266
        # Not specifying ref or index should make the constructor fail
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   267
        self.assertRaises(ValueError, CrmlBit)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   268
        self.assertRaises(ValueError, CrmlBit, ref='Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   269
        self.assertRaises(ValueError, CrmlBit, index='3')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   270
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   271
        bit = CrmlBit(ref='Foo.Bar', index=1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   272
        self.assertEquals(bit.ref,      'Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   273
        self.assertEquals(bit.index,    1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   274
        self.assertEquals(bit.invert,   False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   275
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   276
        bit = CrmlBit(ref='Foo.Bar.Baz', index=2, invert=True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   277
        self.assertEquals(bit.ref,      'Foo.Bar.Baz')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   278
        self.assertEquals(bit.index,    2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   279
        self.assertEquals(bit.invert,   True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   280
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   281
    def test_clone_bit_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   282
        bit1 = CrmlBit(ref='Foo.Bar.Baz', index=2, invert=True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   283
        bit2 = bit1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   284
        self.assertFalse(bit1 is bit2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   285
        self.assertTrue(bit1 == bit2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   286
        self.assertFalse(bit1 != bit2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   287
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   288
    def test_compare_bit_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   289
        bit1 = CrmlBit(ref='Foo.Bar.Baz', index=2, invert=True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   290
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   291
        def check(attrname, value):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   292
            bit2 = bit1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   293
            setattr(bit1, attrname, value)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   294
            self.assertFalse(bit1 == bit2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   295
            self.assertTrue(bit1 != bit2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   296
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   297
        check('ref',    'Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   298
        check('index',  5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   299
        check('invert', False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   300
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   301
class TestCrmlBitmaskKey(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   302
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   303
        bits = [
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   304
            CrmlBit(ref='Foo.Bit1', index=1),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   305
            CrmlBit(ref='Foo.Bit2', index=2),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   306
            CrmlBit(ref='Foo.Bit4', index=4, invert=True),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   307
        ]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   308
        self.bm = CrmlBitmaskKey(
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   309
            int         = '0x500',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   310
            type        = 'int',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   311
            backup      = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   312
            read_only   = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   313
            access      = CrmlAccess(cap_rd='ReadUserData'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   314
            bits        = bits)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   315
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   316
    def test_create_bitmask_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   317
        self.assertRaises(ValueError, CrmlBitmaskKey)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   318
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   319
        bm = CrmlBitmaskKey(int='0x2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   320
        self.assertEquals(bm.int,       '0x2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   321
        self.assertEquals(bm.type,      'int')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   322
        self.assertEquals(bm.backup,    False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   323
        self.assertEquals(bm.read_only, False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   324
        self.assertEquals(bm.access,    CrmlAccess())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   325
        self.assertEquals(bm.bits,      [])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   326
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   327
        bm = self.bm
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   328
        self.assertEquals(bm.int,       '0x500')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   329
        self.assertEquals(bm.type,      'int')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   330
        self.assertEquals(bm.backup,    True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   331
        self.assertEquals(bm.read_only, True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   332
        self.assertEquals(bm.access,    CrmlAccess(cap_rd='ReadUserData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   333
        self.assertEquals(bm.bits,      [CrmlBit(ref='Foo.Bit1', index=1),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   334
                                         CrmlBit(ref='Foo.Bit2', index=2),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   335
                                         CrmlBit(ref='Foo.Bit4', index=4, invert=True)])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   336
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   337
    def test_clone_bitmask_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   338
        bm1 = self.bm
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   339
        bm2 = bm1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   340
        self.assertFalse(bm1 is bm2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   341
        self.assertTrue(bm1 == bm2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   342
        self.assertFalse(bm1 != bm2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   343
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   344
        # Assert that the bits have been deep-copied
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   345
        self.assertFalse(bm1.bits is bm2.bits)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   346
        self.assertEquals(bm1.bits, bm2.bits)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   347
        for i in xrange(len(bm1.bits)):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   348
            self.assertFalse(bm1.bits[i] is bm2.bits[i])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   349
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   350
    def test_compare_bitmask_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   351
        def check(attrname, value):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   352
            bm1 = self.bm
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   353
            bm2 = bm1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   354
            setattr(bm2, attrname, value)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   355
            self.assertFalse(bm1 == bm2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   356
            self.assertTrue(bm1 != bm2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   357
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   358
        check('int',        '0x600')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   359
        check('type',       'binary')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   360
        check('backup',     False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   361
        check('read_only',  False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   362
        check('access',     CrmlAccess(cap_rd='ReadDeviceData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   363
        check('bits',       [CrmlBit(ref='Foo.Bit7', index=7),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   364
                             CrmlBit(ref='Foo.Bit9', index=9)])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   365
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   366
    def test_get_bitmask_refs(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   367
        self.assertEquals([], CrmlBitmaskKey(int='0x1').get_refs())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   368
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   369
        expected = ['Foo.Bit1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   370
                    'Foo.Bit2',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   371
                    'Foo.Bit4',]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   372
        self.assertEquals(sorted(expected), sorted(self.bm.get_refs()))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   373
 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   374
class TestCrmlKeyRangeSubKey(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   375
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   376
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   377
        self.subkey = CrmlKeyRangeSubKey(ref='Foo.Bar', name='Foobar', type='int', int='0x1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   378
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   379
    def test_create_subkey_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   380
        self.assertRaises(ValueError, CrmlKeyRangeSubKey)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   381
        self.assertRaises(ValueError, CrmlKeyRangeSubKey, ref='Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   382
        self.assertRaises(ValueError, CrmlKeyRangeSubKey, type='int')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   383
        self.assertRaises(ValueError, CrmlKeyRangeSubKey, int='0x1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   384
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   385
        subkey = self.subkey
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   386
        self.assertEquals(subkey.ref,   'Foo.Bar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   387
        self.assertEquals(subkey.name,  'Foobar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   388
        self.assertEquals(subkey.type,  'int')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   389
        self.assertEquals(subkey.int,   '0x1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   390
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   391
    def test_clone_subkey_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   392
        subkey1 = self.subkey
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   393
        subkey2 = subkey1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   394
        self.assertFalse(subkey1 is subkey2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   395
        self.assertTrue(subkey1 == subkey2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   396
        self.assertFalse(subkey1 != subkey2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   397
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   398
    def test_compare_subkey_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   399
        def check(attrname, value):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   400
            subkey1 = self.subkey
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   401
            subkey2 = subkey1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   402
            setattr(subkey2, attrname, value)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   403
            self.assertFalse(subkey1 == subkey2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   404
            self.assertTrue(subkey1 != subkey2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   405
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   406
        check('ref',    'Foo.Bar.Baz')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   407
        check('name',   'Test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   408
        check('int',    '0x2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   409
        check('type',   'binary')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   410
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   411
class TestCrmlKeyRange(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   412
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   413
        subkeys = [
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   414
            CrmlKeyRangeSubKey(ref='Sub1', name='Sub-key 1', type='int', int='0x1'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   415
            CrmlKeyRangeSubKey(ref='Sub2', name='Sub-key 2', type='real', int='0x2'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   416
            CrmlKeyRangeSubKey(ref='Sub3', name='Sub-key 3', type='string', int='0x3'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   417
        ]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   418
        self.keyrange = CrmlKeyRange(
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   419
            ref         = 'Foo.Seq',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   420
            first_int   = '0x10000000',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   421
            last_int    = '0x1FFFFFFF',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   422
            first_index = 2,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   423
            index_bits  = 0x0ff0,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   424
            backup      = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   425
            read_only   = True,
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   426
            access      = CrmlAccess(cap_rd='ReadUserData'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   427
            subkeys     = subkeys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   428
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   429
    def test_create_keyrange_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   430
        self.assertRaises(ValueError, CrmlKeyRange)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   431
        self.assertRaises(ValueError, CrmlKeyRange, first_int='0x10')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   432
        self.assertRaises(ValueError, CrmlKeyRange, last_int='0x1F')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   433
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   434
        keyrange = CrmlKeyRange(first_int='0x10', last_int='0x1F')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   435
        self.assertEquals(keyrange.first_int,   '0x10')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   436
        self.assertEquals(keyrange.last_int,    '0x1F')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   437
        self.assertEquals(keyrange.first_index, 0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   438
        self.assertEquals(keyrange.index_bits,  None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   439
        self.assertEquals(keyrange.backup,      False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   440
        self.assertEquals(keyrange.read_only,   False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   441
        self.assertEquals(keyrange.access,      CrmlAccess())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   442
        self.assertEquals(keyrange.subkeys,     [])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   443
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   444
        keyrange = self.keyrange
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   445
        self.assertEquals(keyrange.first_int,   '0x10000000')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   446
        self.assertEquals(keyrange.last_int,    '0x1FFFFFFF')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   447
        self.assertEquals(keyrange.first_index, 2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   448
        self.assertEquals(keyrange.index_bits,  0x0ff0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   449
        self.assertEquals(keyrange.backup,      True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   450
        self.assertEquals(keyrange.read_only,   True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   451
        self.assertEquals(keyrange.access,      CrmlAccess(cap_rd='ReadUserData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   452
        self.assertEquals(keyrange.subkeys,     [
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   453
            CrmlKeyRangeSubKey(ref='Sub1', name='Sub-key 1', type='int', int='0x1'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   454
            CrmlKeyRangeSubKey(ref='Sub2', name='Sub-key 2', type='real', int='0x2'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   455
            CrmlKeyRangeSubKey(ref='Sub3', name='Sub-key 3', type='string', int='0x3')])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   456
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   457
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   458
    def test_clone_keyrange_object(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   459
        keyrange1 = self.keyrange
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   460
        keyrange2 = keyrange1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   461
        self.assertFalse(keyrange1 is keyrange2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   462
        self.assertTrue(keyrange1 == keyrange2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   463
        self.assertFalse(keyrange1 != keyrange2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   464
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   465
        # Assert that the sub-keys have been deep-copied
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   466
        self.assertFalse(keyrange1.subkeys is keyrange2.subkeys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   467
        self.assertEquals(keyrange1.subkeys, keyrange2.subkeys)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   468
        for i in xrange(len(keyrange1.subkeys)):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   469
            self.assertFalse(keyrange1.subkeys[i] is keyrange2.subkeys[i])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   470
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   471
    def test_compare_keyrange_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   472
        def check(attrname, value):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   473
            keyrange1 = self.keyrange
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   474
            keyrange2 = keyrange1.copy()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   475
            setattr(keyrange2, attrname, value)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   476
            self.assertFalse(keyrange1 == keyrange2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   477
            self.assertTrue(keyrange1 != keyrange2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   478
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   479
        check('first_int',      '0x20000000')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   480
        check('last_int',       '0x2FFFFFFF')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   481
        check('first_index',    3)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   482
        check('index_bits',     0xf00)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   483
        check('backup',         False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   484
        check('read_only',      False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   485
        check('access',         CrmlAccess(cap_rd='ReadDeviceData'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   486
        check('subkeys',        [
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   487
            CrmlKeyRangeSubKey(ref='Sub0x100', name='Sub-key 0x100', type='string', int='0x100'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   488
            CrmlKeyRangeSubKey(ref='Sub0x200', name='Sub-key 0x200', type='binary', int='0x200')])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   489
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   490
    def test_get_keyrange_refs(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   491
        self.assertEquals([], CrmlKeyRange(first_int='0x1', last_int='0x2').get_refs())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   492
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   493
        expected = ['Foo.Seq',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   494
                    'Foo.Seq.Sub1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   495
                    'Foo.Seq.Sub2',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   496
                    'Foo.Seq.Sub3',]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   497
        self.assertEquals(sorted(expected), sorted(self.keyrange.get_refs()))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   498
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   499
if __name__ == "__main__":
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   500
    unittest.main()