blob: e2fbb950b0ba4bb17ec64103db29d952bc0cd4cb [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001# Copyright (C) 2017-2018 Wind River Systems, Inc.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License version 2 as
5# published by the Free Software Foundation.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10# See the GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program; if not, write to the Free Software
14# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
16import unittest
17import tempfile
18import os
19import bb
20
21from layerindexlib.tests.common import LayersTest
22
23import logging
24
25class LayerIndexObjectsTest(LayersTest):
26 def setUp(self):
27 from layerindexlib import LayerIndexObj, Branch, LayerItem, LayerBranch, LayerDependency, Recipe, Machine, Distro
28
29 LayersTest.setUp(self)
30
31 self.index = LayerIndexObj()
32
33 branchId = 0
34 layerItemId = 0
35 layerBranchId = 0
36 layerDependencyId = 0
37 recipeId = 0
38 machineId = 0
39 distroId = 0
40
41 self.index.branches = {}
42 self.index.layerItems = {}
43 self.index.layerBranches = {}
44 self.index.layerDependencies = {}
45 self.index.recipes = {}
46 self.index.machines = {}
47 self.index.distros = {}
48
49 branchId += 1
50 self.index.branches[branchId] = Branch(self.index)
51 self.index.branches[branchId].define_data(branchId,
52 'test_branch', 'bb_test_branch')
53 self.index.branches[branchId].lockData()
54
55 layerItemId +=1
56 self.index.layerItems[layerItemId] = LayerItem(self.index)
57 self.index.layerItems[layerItemId].define_data(layerItemId,
58 'test_layerItem', vcs_url='git://git_test_url/test_layerItem')
59 self.index.layerItems[layerItemId].lockData()
60
61 layerBranchId +=1
62 self.index.layerBranches[layerBranchId] = LayerBranch(self.index)
63 self.index.layerBranches[layerBranchId].define_data(layerBranchId,
64 'test_collection', '99', layerItemId,
65 branchId)
66
67 recipeId += 1
68 self.index.recipes[recipeId] = Recipe(self.index)
69 self.index.recipes[recipeId].define_data(recipeId, 'test_git.bb',
70 'recipes-test', 'test', 'git',
71 layerBranchId)
72
73 machineId += 1
74 self.index.machines[machineId] = Machine(self.index)
75 self.index.machines[machineId].define_data(machineId,
76 'test_machine', 'test_machine',
77 layerBranchId)
78
79 distroId += 1
80 self.index.distros[distroId] = Distro(self.index)
81 self.index.distros[distroId].define_data(distroId,
82 'test_distro', 'test_distro',
83 layerBranchId)
84
85 layerItemId +=1
86 self.index.layerItems[layerItemId] = LayerItem(self.index)
87 self.index.layerItems[layerItemId].define_data(layerItemId, 'test_layerItem 2',
88 vcs_url='git://git_test_url/test_layerItem')
89
90 layerBranchId +=1
91 self.index.layerBranches[layerBranchId] = LayerBranch(self.index)
92 self.index.layerBranches[layerBranchId].define_data(layerBranchId,
93 'test_collection_2', '72', layerItemId,
94 branchId, actual_branch='some_other_branch')
95
96 layerDependencyId += 1
97 self.index.layerDependencies[layerDependencyId] = LayerDependency(self.index)
98 self.index.layerDependencies[layerDependencyId].define_data(layerDependencyId,
99 layerBranchId, 1)
100
101 layerDependencyId += 1
102 self.index.layerDependencies[layerDependencyId] = LayerDependency(self.index)
103 self.index.layerDependencies[layerDependencyId].define_data(layerDependencyId,
104 layerBranchId, 1, required=False)
105
106 def test_branch(self):
107 branch = self.index.branches[1]
108 self.assertEqual(branch.id, 1)
109 self.assertEqual(branch.name, 'test_branch')
110 self.assertEqual(branch.short_description, 'test_branch')
111 self.assertEqual(branch.bitbake_branch, 'bb_test_branch')
112
113 def test_layerItem(self):
114 layerItem = self.index.layerItems[1]
115 self.assertEqual(layerItem.id, 1)
116 self.assertEqual(layerItem.name, 'test_layerItem')
117 self.assertEqual(layerItem.summary, 'test_layerItem')
118 self.assertEqual(layerItem.description, 'test_layerItem')
119 self.assertEqual(layerItem.vcs_url, 'git://git_test_url/test_layerItem')
120 self.assertEqual(layerItem.vcs_web_url, None)
121 self.assertIsNone(layerItem.vcs_web_tree_base_url)
122 self.assertIsNone(layerItem.vcs_web_file_base_url)
123 self.assertIsNotNone(layerItem.updated)
124
125 layerItem = self.index.layerItems[2]
126 self.assertEqual(layerItem.id, 2)
127 self.assertEqual(layerItem.name, 'test_layerItem 2')
128 self.assertEqual(layerItem.summary, 'test_layerItem 2')
129 self.assertEqual(layerItem.description, 'test_layerItem 2')
130 self.assertEqual(layerItem.vcs_url, 'git://git_test_url/test_layerItem')
131 self.assertIsNone(layerItem.vcs_web_url)
132 self.assertIsNone(layerItem.vcs_web_tree_base_url)
133 self.assertIsNone(layerItem.vcs_web_file_base_url)
134 self.assertIsNotNone(layerItem.updated)
135
136 def test_layerBranch(self):
137 layerBranch = self.index.layerBranches[1]
138 self.assertEqual(layerBranch.id, 1)
139 self.assertEqual(layerBranch.collection, 'test_collection')
140 self.assertEqual(layerBranch.version, '99')
141 self.assertEqual(layerBranch.vcs_subdir, '')
142 self.assertEqual(layerBranch.actual_branch, 'test_branch')
143 self.assertIsNotNone(layerBranch.updated)
144 self.assertEqual(layerBranch.layer_id, 1)
145 self.assertEqual(layerBranch.branch_id, 1)
146 self.assertEqual(layerBranch.layer, self.index.layerItems[1])
147 self.assertEqual(layerBranch.branch, self.index.branches[1])
148
149 layerBranch = self.index.layerBranches[2]
150 self.assertEqual(layerBranch.id, 2)
151 self.assertEqual(layerBranch.collection, 'test_collection_2')
152 self.assertEqual(layerBranch.version, '72')
153 self.assertEqual(layerBranch.vcs_subdir, '')
154 self.assertEqual(layerBranch.actual_branch, 'some_other_branch')
155 self.assertIsNotNone(layerBranch.updated)
156 self.assertEqual(layerBranch.layer_id, 2)
157 self.assertEqual(layerBranch.branch_id, 1)
158 self.assertEqual(layerBranch.layer, self.index.layerItems[2])
159 self.assertEqual(layerBranch.branch, self.index.branches[1])
160
161 def test_layerDependency(self):
162 layerDependency = self.index.layerDependencies[1]
163 self.assertEqual(layerDependency.id, 1)
164 self.assertEqual(layerDependency.layerbranch_id, 2)
165 self.assertEqual(layerDependency.layerbranch, self.index.layerBranches[2])
166 self.assertEqual(layerDependency.layer_id, 2)
167 self.assertEqual(layerDependency.layer, self.index.layerItems[2])
168 self.assertTrue(layerDependency.required)
169 self.assertEqual(layerDependency.dependency_id, 1)
170 self.assertEqual(layerDependency.dependency, self.index.layerItems[1])
171 self.assertEqual(layerDependency.dependency_layerBranch, self.index.layerBranches[1])
172
173 layerDependency = self.index.layerDependencies[2]
174 self.assertEqual(layerDependency.id, 2)
175 self.assertEqual(layerDependency.layerbranch_id, 2)
176 self.assertEqual(layerDependency.layerbranch, self.index.layerBranches[2])
177 self.assertEqual(layerDependency.layer_id, 2)
178 self.assertEqual(layerDependency.layer, self.index.layerItems[2])
179 self.assertFalse(layerDependency.required)
180 self.assertEqual(layerDependency.dependency_id, 1)
181 self.assertEqual(layerDependency.dependency, self.index.layerItems[1])
182 self.assertEqual(layerDependency.dependency_layerBranch, self.index.layerBranches[1])
183
184 def test_recipe(self):
185 recipe = self.index.recipes[1]
186 self.assertEqual(recipe.id, 1)
187 self.assertEqual(recipe.layerbranch_id, 1)
188 self.assertEqual(recipe.layerbranch, self.index.layerBranches[1])
189 self.assertEqual(recipe.layer_id, 1)
190 self.assertEqual(recipe.layer, self.index.layerItems[1])
191 self.assertEqual(recipe.filename, 'test_git.bb')
192 self.assertEqual(recipe.filepath, 'recipes-test')
193 self.assertEqual(recipe.fullpath, 'recipes-test/test_git.bb')
194 self.assertEqual(recipe.summary, "")
195 self.assertEqual(recipe.description, "")
196 self.assertEqual(recipe.section, "")
197 self.assertEqual(recipe.pn, 'test')
198 self.assertEqual(recipe.pv, 'git')
199 self.assertEqual(recipe.license, "")
200 self.assertEqual(recipe.homepage, "")
201 self.assertEqual(recipe.bugtracker, "")
202 self.assertEqual(recipe.provides, "")
203 self.assertIsNotNone(recipe.updated)
204 self.assertEqual(recipe.inherits, "")
205
206 def test_machine(self):
207 machine = self.index.machines[1]
208 self.assertEqual(machine.id, 1)
209 self.assertEqual(machine.layerbranch_id, 1)
210 self.assertEqual(machine.layerbranch, self.index.layerBranches[1])
211 self.assertEqual(machine.layer_id, 1)
212 self.assertEqual(machine.layer, self.index.layerItems[1])
213 self.assertEqual(machine.name, 'test_machine')
214 self.assertEqual(machine.description, 'test_machine')
215 self.assertIsNotNone(machine.updated)
216
217 def test_distro(self):
218 distro = self.index.distros[1]
219 self.assertEqual(distro.id, 1)
220 self.assertEqual(distro.layerbranch_id, 1)
221 self.assertEqual(distro.layerbranch, self.index.layerBranches[1])
222 self.assertEqual(distro.layer_id, 1)
223 self.assertEqual(distro.layer, self.index.layerItems[1])
224 self.assertEqual(distro.name, 'test_distro')
225 self.assertEqual(distro.description, 'test_distro')
226 self.assertIsNotNone(distro.updated)