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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
//
// DecoderReplacementFallbackBuffer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
using System;
using System.IO;
using System.Text;
using NUnit.Framework;
using Buffer = System.Text.DecoderReplacementFallbackBuffer;
namespace MonoTests.System.Text
{
[TestFixture]
public class DecoderReplacementFallbackBufferTest
{
private Buffer NewInstance ()
{
return new Buffer (new DecoderReplacementFallback ());
}
[Test]
public void FallbackEmptyDefault ()
{
Buffer b = NewInstance ();
Assert.IsTrue (b.Fallback (new byte [] {}, 0), "#0");
Assert.IsFalse (b.MovePrevious (), "#1");
Assert.AreEqual (1, b.Remaining, "#2");
Assert.AreEqual ('?', b.GetNextChar (), "#3");
Assert.AreEqual (0, b.Remaining, "#4");
// the string is already consumed.
Assert.AreEqual (char.MinValue, b.GetNextChar (), "#5");
}
[Test]
public void FallbackDefaultEncodingUTF8 ()
{
Buffer b = Encoding.UTF8.DecoderFallback.CreateFallbackBuffer () as Buffer;
Assert.IsTrue (b.Fallback (new byte [] {}, 0), "#1");
Assert.IsFalse (b.MovePrevious (), "#2");
Assert.AreEqual (1, b.Remaining, "#3");
Assert.AreEqual ('\uFFFD', b.GetNextChar (), "#4");
}
[Test]
public void FallbackEmptyForEncodingUTF8 ()
{
Buffer b = new DecoderReplacementFallbackBuffer (new DecoderReplacementFallback (String.Empty));
Assert.IsFalse (b.Fallback (new byte [] {}, 0), "#1");
Assert.IsFalse (b.MovePrevious (), "#2");
Assert.AreEqual (0, b.Remaining, "#3");
// the string does not exist.
Assert.AreEqual (char.MinValue, b.GetNextChar (), "#4");
}
[Test]
public void FallbackSequential ()
{
Buffer b = NewInstance ();
b.Fallback (new byte [] {}, 0);
b.GetNextChar ();
b.Fallback (new byte [] {}, 0);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FallbackRecursiveError ()
{
Buffer b = NewInstance ();
b.Fallback (new byte [] {}, 0);
b.Fallback (new byte [] {}, 0);
}
[Test]
[Category ("NotWorking")]
public void Iterate ()
{
Assert.AreEqual ('\0', Encoding.UTF8.DecoderFallback
.CreateFallbackBuffer ().GetNextChar (), "#1");
Buffer b = NewInstance ();
// Assert.AreEqual (1, b.Remaining, "#2");
// Assert.AreEqual ('?', b.GetNextChar (), "#3");
Assert.AreEqual (0, b.Remaining, "#4");
Assert.AreEqual ('\0', b.GetNextChar (), "#5");
// Assert.IsTrue (b.MovePrevious (), "#6");
// Assert.AreEqual (1, b.Remaining, "#7");
Assert.IsFalse (b.MovePrevious (), "#8");
// Assert.AreEqual ('?', b.GetNextChar (), "#9");
}
[Test]
public void Reset ()
{
DecoderReplacementFallback f = new DecoderReplacementFallback ("X");
DecoderReplacementFallbackBuffer b = new DecoderReplacementFallbackBuffer (f);
b.Fallback (new byte [0], 0);
Assert.AreEqual (1, b.Remaining, "#1");
b.Reset ();
Assert.AreEqual (0, b.Remaining, "#2");
b.Fallback (new byte [0], 0); // do not raise an error
b.Reset ();
Assert.AreEqual (0, (int) b.GetNextChar (), "#3");
}
}
}
|