blob: a0e8160253f6d7a619176f33a9a7e1f273f20b60 [file] [log] [blame]
Ned Nguyenbf081d02018-12-18 16:41:31 -07001# -*- coding: utf-8 -*-
2# Copyright 2018 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"""Test gconv_strip."""
7
8from __future__ import print_function
9
10import os
11
12from chromite.lib import cros_test_lib
13from chromite.lib import osutils
14from chromite.scripts import gconv_strip
15
16
17class GconvStriptTest(cros_test_lib.MockTempDirTestCase):
18 """Tests for gconv_strip script."""
19
20 def testMultipleStringMatch(self):
Mike Frysinger2d589a12019-08-25 14:15:12 -040021 self.assertEqual(
Ned Nguyenbf081d02018-12-18 16:41:31 -070022 gconv_strip.MultipleStringMatch(
23 ['hell', 'a', 'z', 'k', 'spec'],
24 'hello_from a very special place'),
25 [True, True, False, False, True])
26
27 def testModuleRewrite(self):
28 tmp_gconv_module = os.path.join(self.tempdir, 'gconv-modules')
29
30 data = """
31# from to module cost
32alias FOO charset_foo
33alias BAR charset_bar
34module charset_foo charset_bar UNUSED_MODULE
35
36# from to module cost
37alias CHAR_A charset_A
38alias EUROPE charset_B
39module charset_A charset_B USED_MODULE
40module charset_foo charset_A USED_MODULE
41"""
42 osutils.WriteFile(tmp_gconv_module, data)
43
44 gmods = gconv_strip.GconvModules(tmp_gconv_module)
45 gmods.Load()
46 self.PatchObject(gconv_strip.lddtree, 'ParseELF', return_value={})
Mike Frysinger9c927782019-10-14 02:48:48 -040047 class _StubStat(object):
48 st_size = 0
49 self.PatchObject(gconv_strip.os, 'lstat', return_value=_StubStat)
Ned Nguyenbf081d02018-12-18 16:41:31 -070050 self.PatchObject(gconv_strip.os, 'unlink')
51 gmods.Rewrite(['charset_A', 'charset_B'], dry_run=False)
52
53 expected = """
54# from to module cost
55alias FOO charset_foo
56
57# from to module cost
58alias CHAR_A charset_A
59alias EUROPE charset_B
60module charset_A charset_B USED_MODULE
61module charset_foo charset_A USED_MODULE
62"""
63
64 content = osutils.ReadFile(tmp_gconv_module)
Mike Frysinger2d589a12019-08-25 14:15:12 -040065 self.assertEqual(content, expected)