summaryrefslogtreecommitdiff
path: root/test/test_cerbero_build_filesprovider.py
blob: fdd36d5aa54df281a6adce983ee90244d62bb1c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# cerbero - a multi-platform build system for Open Source software
# Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import shutil
import unittest
import tempfile

from cerbero.build import filesprovider
from cerbero.config import Platform, License
from test.test_build_common import add_files
from test.test_common import DummyConfig


class Config(DummyConfig):

    def __init__(self, tmp, platform):
        self.prefix = tmp
        self.target_platform = platform


class FilesProvider(filesprovider.FilesProvider):

    files_misc = ['README', 'libexec/gstreamer-0.10/pluginsloader%(bext)s']
    files_libs = ['libgstreamer-0.10']
    files_bins = ['gst-launch']
    files_devel = ['include/gstreamer.h']
    licenses_devel = [License.LGPL]
    platform_files_bins = {
            Platform.WINDOWS: ['windows'],
            Platform.LINUX: ['linux']}
    platform_files_libs = {
            Platform.WINDOWS: ['libgstreamer-win32'],
            Platform.LINUX: ['libgstreamer-x11']}


class PackageTest(unittest.TestCase):

    def setUp(self):
        self.tmp = tempfile.mkdtemp()
        win32config = Config(self.tmp, Platform.WINDOWS)
        linuxconfig = Config(self.tmp, Platform.LINUX)
        self.win32recipe = FilesProvider(win32config)
        self.linuxrecipe = FilesProvider(linuxconfig)

        self.winbin = ['bin/gst-launch.exe', 'bin/windows.exe']
        self.linuxbin = ['bin/gst-launch', 'bin/linux']
        self.winlib = ['bin/libgstreamer-0.10.dll', 'bin/libgstreamer-win32.dll']
        self.linuxlib = ['lib/libgstreamer-0.10.so.1', 'lib/libgstreamer-x11.so.1']
        self.winmisc = ['README', 'libexec/gstreamer-0.10/pluginsloader.exe']
        self.linuxmisc = ['README', 'libexec/gstreamer-0.10/pluginsloader']
        devfiles = ['include/gstreamer.h', 'lib/libgstreamer-0.10.a',
                    'lib/libgstreamer-0.10.la']

        self.windevfiles = devfiles + ['lib/libgstreamer-win32.a',
                'lib/libgstreamer-win32.la', 'lib/libgstreamer-win32.dll.a',
                'lib/libgstreamer-win32.def', 'lib/gstreamer-win32.lib',
                'lib/libgstreamer-0.10.dll.a', 'lib/libgstreamer-0.10.def',
                'lib/gstreamer-0.10.lib']
        self.lindevfiles = devfiles + ['lib/libgstreamer-0.10.so',
                'lib/libgstreamer-x11.a', 'lib/libgstreamer-x11.la',
                'lib/libgstreamer-x11.so']

    def tearDown(self):
        shutil.rmtree(self.tmp)

    def testFilesCategories(self):
        self.assertEqual(sorted(['bins', 'libs', 'misc', 'devel']),
                self.win32recipe._files_categories())

    def testListBinaries(self):
        self.assertEqual(self.win32recipe.files_list_by_category('bins'),
                sorted(self.winbin))
        self.assertEqual(self.linuxrecipe.files_list_by_category('bins'),
                sorted(self.linuxbin))

    def testListLibraries(self):
        add_files(self.tmp)
        self.assertEqual(self.win32recipe.files_list_by_category('libs'),
                sorted(self.winlib))
        self.assertEqual(self.linuxrecipe.files_list_by_category('libs'),
                sorted(self.linuxlib))

    def testDevelFiles(self):
        add_files(self.tmp)
        self.assertEqual(self.win32recipe.devel_files_list(),
                sorted(self.windevfiles))
        self.assertEqual(self.linuxrecipe.devel_files_list(),
                sorted(self.lindevfiles))

    def testDistFiles(self):
        win32files = self.winlib + self.winbin + self.winmisc
        linuxfiles = self.linuxlib + self.linuxbin + self.linuxmisc
        add_files(self.tmp)
        self.assertEqual(self.win32recipe.dist_files_list(), sorted(win32files))
        self.assertEqual(self.linuxrecipe.dist_files_list(), sorted(linuxfiles))

    def testGetAllFiles(self):
        win32files = self.winlib + self.winbin + self.winmisc + self.windevfiles
        linuxfiles = self.linuxlib + self.linuxbin + self.linuxmisc + self.lindevfiles
        add_files(self.tmp)
        self.assertEqual(self.win32recipe.files_list(), sorted(win32files))
        self.assertEqual(self.linuxrecipe.files_list(), sorted(linuxfiles))