Revision 441:cbce1fd3b1b7 test/unit/lib/redmine/export
| test/unit/lib/redmine/export/pdf_test.rb | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 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 |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../../../../test_helper', __FILE__)
|
|
| 19 |
require 'iconv' |
|
| 20 |
|
|
| 21 |
class PdfTest < ActiveSupport::TestCase |
|
| 22 |
include Redmine::I18n |
|
| 23 |
|
|
| 24 |
def test_fix_text_encoding_nil |
|
| 25 |
set_language_if_valid 'ja' |
|
| 26 |
assert_equal 'CP932', l(:general_pdf_encoding) |
|
| 27 |
if RUBY_VERSION < '1.9' |
|
| 28 |
ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') |
|
| 29 |
end |
|
| 30 |
assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, nil) |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
def test_rdm_pdf_iconv_cannot_convert_ja_cp932 |
|
| 34 |
set_language_if_valid 'ja' |
|
| 35 |
assert_equal 'CP932', l(:general_pdf_encoding) |
|
| 36 |
if RUBY_VERSION < '1.9' |
|
| 37 |
ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') |
|
| 38 |
end |
|
| 39 |
utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b" |
|
| 40 |
utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" |
|
| 41 |
utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" |
|
| 42 |
if utf8_txt_1.respond_to?(:force_encoding) |
|
| 43 |
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1) |
|
| 44 |
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_2) |
|
| 45 |
txt_3 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_3) |
|
| 46 |
assert_equal "?\x91\xd4", txt_1 |
|
| 47 |
assert_equal "?\x91\xd4?", txt_2 |
|
| 48 |
assert_equal "??\x91\xd4?", txt_3 |
|
| 49 |
assert_equal "ASCII-8BIT", txt_1.encoding.to_s |
|
| 50 |
assert_equal "ASCII-8BIT", txt_2.encoding.to_s |
|
| 51 |
assert_equal "ASCII-8BIT", txt_3.encoding.to_s |
|
| 52 |
else |
|
| 53 |
assert_equal "???\x91\xd4", |
|
| 54 |
Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1) |
|
| 55 |
assert_equal "???\x91\xd4???", |
|
| 56 |
Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_2) |
|
| 57 |
assert_equal "??????\x91\xd4???", |
|
| 58 |
Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_3) |
|
| 59 |
end |
|
| 60 |
end |
|
| 61 |
|
|
| 62 |
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en |
|
| 63 |
set_language_if_valid 'en' |
|
| 64 |
assert_equal 'UTF-8', l(:general_pdf_encoding) |
|
| 65 |
str1 = "Texte encod\xe9 en ISO-8859-1" |
|
| 66 |
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
|
| 67 |
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
|
| 68 |
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
|
| 69 |
if RUBY_VERSION < '1.9' |
|
| 70 |
ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') |
|
| 71 |
end |
|
| 72 |
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str1) |
|
| 73 |
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str2) |
|
| 74 |
if txt_1.respond_to?(:force_encoding) |
|
| 75 |
assert_equal "ASCII-8BIT", txt_1.encoding.to_s |
|
| 76 |
assert_equal "ASCII-8BIT", txt_2.encoding.to_s |
|
| 77 |
end |
|
| 78 |
assert_equal "Texte encod? en ISO-8859-1", txt_1 |
|
| 79 |
assert_equal "?a?b?c?d?e test", txt_2 |
|
| 80 |
end |
|
| 81 |
|
|
| 82 |
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja |
|
| 83 |
set_language_if_valid 'ja' |
|
| 84 |
assert_equal 'CP932', l(:general_pdf_encoding) |
|
| 85 |
str1 = "Texte encod\xe9 en ISO-8859-1" |
|
| 86 |
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
|
| 87 |
str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
|
|
| 88 |
str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
|
|
| 89 |
if RUBY_VERSION < '1.9' |
|
| 90 |
ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') |
|
| 91 |
end |
|
| 92 |
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str1) |
|
| 93 |
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str2) |
|
| 94 |
if txt_1.respond_to?(:force_encoding) |
|
| 95 |
assert_equal "ASCII-8BIT", txt_1.encoding.to_s |
|
| 96 |
assert_equal "ASCII-8BIT", txt_2.encoding.to_s |
|
| 97 |
end |
|
| 98 |
assert_equal "Texte encod? en ISO-8859-1", txt_1 |
|
| 99 |
assert_equal "?a?b?c?d?e test", txt_2 |
|
| 100 |
end |
|
| 101 |
end |
|
Also available in: Unified diff