comparison test/unit/lib/redmine/export/pdf_test.rb @ 507:0c939c159af4 redmine-1.2

Update to Redmine 1.2.1 on 1.2-stable branch (Redmine SVN rev 6270)
author Chris Cannam
date Thu, 14 Jul 2011 10:32:19 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
441:cbce1fd3b1b7 507:0c939c159af4
22 include Redmine::I18n 22 include Redmine::I18n
23 23
24 def test_fix_text_encoding_nil 24 def test_fix_text_encoding_nil
25 set_language_if_valid 'ja' 25 set_language_if_valid 'ja'
26 assert_equal 'CP932', l(:general_pdf_encoding) 26 assert_equal 'CP932', l(:general_pdf_encoding)
27 if RUBY_VERSION < '1.9' 27 if RUBY_VERSION < '1.9'
28 ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') 28 if RUBY_PLATFORM == 'java'
29 ic = Iconv.new("SJIS", 'UTF-8')
30 else
31 ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8')
32 end
29 end 33 end
30 assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, nil) 34 assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, nil)
31 end 35 end
32 36
33 def test_rdm_pdf_iconv_cannot_convert_ja_cp932 37 def test_rdm_pdf_iconv_cannot_convert_ja_cp932
34 set_language_if_valid 'ja' 38 set_language_if_valid 'ja'
35 assert_equal 'CP932', l(:general_pdf_encoding) 39 assert_equal 'CP932', l(:general_pdf_encoding)
36 if RUBY_VERSION < '1.9' 40 if RUBY_VERSION < '1.9'
37 ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') 41 if RUBY_PLATFORM == 'java'
42 ic = Iconv.new("SJIS", 'UTF-8')
43 else
44 ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8')
45 end
38 end 46 end
39 utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b" 47 utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b"
40 utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" 48 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" 49 utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
42 if utf8_txt_1.respond_to?(:force_encoding) 50 if utf8_txt_1.respond_to?(:force_encoding)
47 assert_equal "?\x91\xd4?", txt_2 55 assert_equal "?\x91\xd4?", txt_2
48 assert_equal "??\x91\xd4?", txt_3 56 assert_equal "??\x91\xd4?", txt_3
49 assert_equal "ASCII-8BIT", txt_1.encoding.to_s 57 assert_equal "ASCII-8BIT", txt_1.encoding.to_s
50 assert_equal "ASCII-8BIT", txt_2.encoding.to_s 58 assert_equal "ASCII-8BIT", txt_2.encoding.to_s
51 assert_equal "ASCII-8BIT", txt_3.encoding.to_s 59 assert_equal "ASCII-8BIT", txt_3.encoding.to_s
60 elsif RUBY_PLATFORM == 'java'
61 assert_equal "??",
62 Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1)
63 assert_equal "???",
64 Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_2)
65 assert_equal "????",
66 Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_3)
52 else 67 else
53 assert_equal "???\x91\xd4", 68 assert_equal "???\x91\xd4",
54 Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1) 69 Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_1)
55 assert_equal "???\x91\xd4???", 70 assert_equal "???\x91\xd4???",
56 Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_2) 71 Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, utf8_txt_2)
85 str1 = "Texte encod\xe9 en ISO-8859-1" 100 str1 = "Texte encod\xe9 en ISO-8859-1"
86 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" 101 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
87 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding) 102 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
88 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding) 103 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
89 if RUBY_VERSION < '1.9' 104 if RUBY_VERSION < '1.9'
90 ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8') 105 if RUBY_PLATFORM == 'java'
106 ic = Iconv.new("SJIS", 'UTF-8')
107 else
108 ic = Iconv.new(l(:general_pdf_encoding), 'UTF-8')
109 end
91 end 110 end
92 txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str1) 111 txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str1)
93 txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str2) 112 txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_pdf_iconv(ic, str2)
94 if txt_1.respond_to?(:force_encoding) 113 if txt_1.respond_to?(:force_encoding)
95 assert_equal "ASCII-8BIT", txt_1.encoding.to_s 114 assert_equal "ASCII-8BIT", txt_1.encoding.to_s