@@ -1,52 +1,55 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class PdfTest < ActiveSupport::TestCase |
|
20 | class PdfTest < ActiveSupport::TestCase | |
21 | include Redmine::I18n |
|
21 | include Redmine::I18n | |
22 |
|
22 | |||
23 | def test_fix_text_encoding_nil |
|
23 | def test_fix_text_encoding_nil | |
24 | set_language_if_valid 'ja' |
|
24 | set_language_if_valid 'ja' | |
25 | pdf = Redmine::Export::PDF::IFPDF.new('ja') |
|
25 | pdf = Redmine::Export::PDF::IFPDF.new('ja') | |
26 | assert pdf |
|
26 | assert pdf | |
27 | assert_equal '', pdf.fix_text_encoding(nil) |
|
27 | assert_equal '', pdf.fix_text_encoding(nil) | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def test_fix_text_encoding_cannot_convert_ja_cp932 |
|
30 | def test_fix_text_encoding_cannot_convert_ja_cp932 | |
31 | pdf = Redmine::Export::PDF::IFPDF.new('ja') |
|
31 | pdf = Redmine::Export::PDF::IFPDF.new('ja') | |
32 | assert pdf |
|
32 | assert pdf | |
33 | utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b" |
|
33 | utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b" | |
34 | utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" |
|
34 | utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" | |
35 | utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" |
|
35 | utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" | |
36 | if utf8_txt_1.respond_to?(:force_encoding) |
|
36 | if utf8_txt_1.respond_to?(:force_encoding) | |
37 | assert_equal "?\x91\xd4", |
|
37 | txt_1 = pdf.fix_text_encoding(utf8_txt_1) | |
38 |
|
|
38 | txt_2 = pdf.fix_text_encoding(utf8_txt_2) | |
39 | assert_equal "?\x91\xd4?", |
|
39 | txt_3 = pdf.fix_text_encoding(utf8_txt_3) | |
40 | pdf.fix_text_encoding(utf8_txt_2) |
|
40 | assert_equal "?\x91\xd4", txt_1 | |
41 |
assert_equal "? |
|
41 | assert_equal "?\x91\xd4?", txt_2 | |
42 | pdf.fix_text_encoding(utf8_txt_3) |
|
42 | assert_equal "??\x91\xd4?", txt_3 | |
|
43 | assert_equal "ASCII-8BIT", txt_1.encoding.to_s | |||
|
44 | assert_equal "ASCII-8BIT", txt_2.encoding.to_s | |||
|
45 | assert_equal "ASCII-8BIT", txt_3.encoding.to_s | |||
43 | else |
|
46 | else | |
44 | assert_equal "???\x91\xd4", |
|
47 | assert_equal "???\x91\xd4", | |
45 | pdf.fix_text_encoding(utf8_txt_1) |
|
48 | pdf.fix_text_encoding(utf8_txt_1) | |
46 | assert_equal "???\x91\xd4???", |
|
49 | assert_equal "???\x91\xd4???", | |
47 | pdf.fix_text_encoding(utf8_txt_2) |
|
50 | pdf.fix_text_encoding(utf8_txt_2) | |
48 | assert_equal "??????\x91\xd4???", |
|
51 | assert_equal "??????\x91\xd4???", | |
49 | pdf.fix_text_encoding(utf8_txt_3) |
|
52 | pdf.fix_text_encoding(utf8_txt_3) | |
50 | end |
|
53 | end | |
51 | end |
|
54 | end | |
52 | end |
|
55 | end |
General Comments 0
You need to be logged in to leave comments.
Login now