| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
) |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
using System; |
| 30 |
using System.IO; |
| 31 |
using System.Text; |
| 32 |
using NUnit.Framework; |
| 33 |
|
| 34 |
using MonoTests.Helpers; |
| 35 |
|
| 36 |
namespace MonoTests.I18N.Rare |
| 37 |
{ |
| 38 |
[TestFixture] |
| 39 |
public class TestRare |
| 40 |
{ |
| 41 |
private global::I18N.Common.Manager Manager = global::I18N.Common.Manager.PrimaryManager; |
| 42 |
|
| 43 |
|
| 44 |
int[] cps = { 708, 852, 855, 857, 858, 862, 864, 866, 869 }; |
| 45 |
|
| 46 |
void AssertDecode (string utf8file, string decfile, int codepage) |
| 47 |
{ |
| 48 |
string decoded = null; |
| 49 |
byte [] encoded = null; |
| 50 |
using (StreamReader sr = new StreamReader (utf8file, |
| 51 |
Encoding.UTF8)) { |
| 52 |
decoded = sr.ReadToEnd (); |
| 53 |
} |
| 54 |
using (FileStream fs = File.OpenRead (decfile)) { |
| 55 |
encoded = new byte [fs.Length]; |
| 56 |
fs.Read (encoded, 0, (int) fs.Length); |
| 57 |
} |
| 58 |
Encoding enc = Manager.GetEncoding (codepage); |
| 59 |
char [] actual; |
| 60 |
|
| 61 |
Assert.AreEqual (decoded.Length, |
| 62 |
enc.GetCharCount (encoded, 0, encoded.Length), |
| 63 |
"GetCharCount(byte[], 0, len)"); |
| 64 |
actual = enc.GetChars (encoded, 0, encoded.Length); |
| 65 |
Assert.AreEqual (decoded.ToCharArray (), actual, |
| 66 |
"GetChars(byte[], 0, len)"); |
| 67 |
} |
| 68 |
|
| 69 |
[Test] |
| 70 |
[TestCaseSource (nameof (cps))] |
| 71 |
public void Ascii_Test_All(int cp) |
| 72 |
{ |
| 73 |
AssertDecode(TestResourceHelper.GetFullPathOfResource ("Test/texts/ascii-test.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/ascii-test.txt"), cp); |
| 74 |
} |
| 75 |
} |
| 76 |
} |