f959e2647f0902607996437dca075dbc91c318bf
[platform/framework/web/crosswalk.git] / src / third_party / chromite / lib / upgrade_table_unittest.py
1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Unit tests for the upgrade_table module."""
7
8 import os
9 import sys
10
11 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(
12     os.path.abspath(__file__)))))
13
14 from chromite.lib import cros_test_lib
15 from chromite.lib import upgrade_table as utable
16
17 # pylint: disable=W0212,R0904
18 class UpgradeTableTest(cros_test_lib.TestCase):
19   """Unittests for UpgradeTable."""
20   ARCH = 'some-arch'
21   NAME = 'some-name'
22
23   def _CreateTable(self, upgrade_mode, arch=ARCH, name=NAME):
24     return utable.UpgradeTable(arch, upgrade=upgrade_mode, name=name)
25
26   def testGetArch(self):
27     t1 = self._CreateTable(True, arch='arch1')
28     self.assertEquals(t1.GetArch(), 'arch1')
29     t2 = self._CreateTable(False, arch='arch2')
30     self.assertEquals(t2.GetArch(), 'arch2')
31
32   def _AssertEqualsAfterArchSub(self, arch, table_col_name,
33                                 static_table_col_name):
34     self.assertEquals(table_col_name,
35                       static_table_col_name.replace('ARCH', arch))
36
37   def testColumnNameArchSubstitute(self):
38     arch = 'foobar'
39     t1 = self._CreateTable(True, arch=arch)
40
41     # Some column names are independent of ARCH.
42     self.assertEquals(t1.COL_PACKAGE, utable.UpgradeTable.COL_PACKAGE)
43     self.assertEquals(t1.COL_SLOT, utable.UpgradeTable.COL_SLOT)
44     self.assertEquals(t1.COL_OVERLAY, utable.UpgradeTable.COL_OVERLAY)
45     self.assertEquals(t1.COL_TARGET, utable.UpgradeTable.COL_TARGET)
46
47     # Other column names require ARCH substitution.
48     self._AssertEqualsAfterArchSub(arch, t1.COL_CURRENT_VER,
49                                    utable.UpgradeTable.COL_CURRENT_VER)
50     self._AssertEqualsAfterArchSub(arch, t1.COL_STABLE_UPSTREAM_VER,
51                                    utable.UpgradeTable.COL_STABLE_UPSTREAM_VER)
52     self._AssertEqualsAfterArchSub(arch, t1.COL_LATEST_UPSTREAM_VER,
53                                    utable.UpgradeTable.COL_LATEST_UPSTREAM_VER)
54     self._AssertEqualsAfterArchSub(arch, t1.COL_STATE,
55                                    utable.UpgradeTable.COL_STATE)
56     self._AssertEqualsAfterArchSub(arch, t1.COL_DEPENDS_ON,
57                                    utable.UpgradeTable.COL_DEPENDS_ON)
58     self._AssertEqualsAfterArchSub(arch, t1.COL_USED_BY,
59                                    utable.UpgradeTable.COL_USED_BY)
60     self._AssertEqualsAfterArchSub(arch, t1.COL_UPGRADED,
61                                    utable.UpgradeTable.COL_UPGRADED)
62
63   def testColumnExistence(self):
64     t1 = self._CreateTable(False)
65     t2 = self._CreateTable(True)
66
67     # All these columns should be in both tables, with same name.
68     cols = [t1.COL_PACKAGE,
69             t1.COL_SLOT,
70             t1.COL_OVERLAY,
71             t1.COL_CURRENT_VER,
72             t1.COL_STABLE_UPSTREAM_VER,
73             t1.COL_LATEST_UPSTREAM_VER,
74             t1.COL_STATE,
75             t1.COL_DEPENDS_ON,
76             t1.COL_USED_BY,
77             t1.COL_TARGET,
78             ]
79
80     for col in cols:
81       self.assertTrue(t1.HasColumn(col))
82       self.assertTrue(t2.HasColumn(col))
83
84     # The UPGRADED column should only be in the table with upgrade_mode=True.
85     col = t1.COL_UPGRADED
86     self.assertFalse(t1.HasColumn(col))
87     self.assertTrue(t2.HasColumn(col))
88
89 if __name__ == "__main__":
90   cros_test_lib.main()