Ned Nguyen | bf081d0 | 2018-12-18 16:41:31 -0700 | [diff] [blame] | 1 | # -*- 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 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import cros_test_lib |
| 13 | from chromite.lib import osutils |
| 14 | from chromite.scripts import gconv_strip |
| 15 | |
| 16 | |
| 17 | class GconvStriptTest(cros_test_lib.MockTempDirTestCase): |
| 18 | """Tests for gconv_strip script.""" |
| 19 | |
| 20 | def testMultipleStringMatch(self): |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame] | 21 | self.assertEqual( |
Ned Nguyen | bf081d0 | 2018-12-18 16:41:31 -0700 | [diff] [blame] | 22 | 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 |
| 32 | alias FOO charset_foo |
| 33 | alias BAR charset_bar |
| 34 | module charset_foo charset_bar UNUSED_MODULE |
| 35 | |
| 36 | # from to module cost |
| 37 | alias CHAR_A charset_A |
| 38 | alias EUROPE charset_B |
| 39 | module charset_A charset_B USED_MODULE |
| 40 | module 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={}) |
| 47 | self.PatchObject(gconv_strip.os, 'lstat') |
| 48 | self.PatchObject(gconv_strip.os, 'unlink') |
| 49 | gmods.Rewrite(['charset_A', 'charset_B'], dry_run=False) |
| 50 | |
| 51 | expected = """ |
| 52 | # from to module cost |
| 53 | alias FOO charset_foo |
| 54 | |
| 55 | # from to module cost |
| 56 | alias CHAR_A charset_A |
| 57 | alias EUROPE charset_B |
| 58 | module charset_A charset_B USED_MODULE |
| 59 | module charset_foo charset_A USED_MODULE |
| 60 | """ |
| 61 | |
| 62 | content = osutils.ReadFile(tmp_gconv_module) |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame] | 63 | self.assertEqual(content, expected) |