Commit Graph
116 Commits
Author SHA1 Message Date
Rodrigo Kumpera 0ac61b03fc [corlib] Fix UnicodeEncoding GetMaxByteCount and GetMaxCharCount to return the same values as .net. 2014-10-01 15:11:20 -04:00
Marcos Henrich 3d332ac26d Added UTF8EncodingTest.EncodingFallback.
EncodingFallback tests for multiple invalid inputs the unknownBytes that are given to the DecoderFallback.
2014-09-02 22:55:52 +08:00
Marcos Henrich 60aa49b35b Added class EncodingTester that can be used to test fallbacks.
EncodingTester is a testing helper class with a method TestDecoderFallback that makes DecoderFalback testing  easier.
2014-09-02 22:42:54 +08:00
Marcos Henrich 97e5bfb498 Test Encoder.Convert and UTF8Encoder.Convert behaviors.
Added class ExposedEncoder to test the virtual method Encoder.Convert behavior.
Test UTF8Encoder.Convert override.
2014-08-04 15:26:53 +01:00
Martin Potter 1b318701b9 Fixing bugs in UTF8Encoding's GetMaxByteCount and GetMaxCharCount.
The previous implementation of GetMaxByteCount has two bugs: it incorrectly took into account the byte order mark and it was taking the max of a byte count (3) and a character count (EncoderFallback.MaxCharCount). This could result in returning the max number of bytes required to convert a string that was less than the number bytes used when converting the string.

GetMaxCharCount did not previously take into account DecoderFallback.MaxCharCount or the fact that there may still be part of a surrogate pair left on the buffer from a previous call to convert.

I removed the #if NET_2_0 conditionals and NotWorking category since these methods now return results consistent with Microsoft's implementation. I also added two simple tests for custom EncoderFallback and DecoderFallback cases.

This commit is licensed under MIT/X11.
2013-10-13 14:37:45 -07:00
Atsushi Eno 132a16ca07 Revert "Merge pull request #622 from killabytenow/master"
This reverts commit 392bae3c45, reversing
changes made to 61cd9ee8b6.
2013-07-13 23:56:59 +09:00
Gerardo García Peña 2e6266606a Reverted changes of commit 6ad7f75a37 2013-07-11 23:52:35 +02:00
Gerardo García Peña 9d55be425d An #if has been negated (bugfix) 2013-07-10 11:26:26 +02:00
Gerardo García Peña 04ffec1684 Added new test for checking EncoderFallbackException exception behaviour. 2013-07-09 16:22:37 +02:00
Gerardo García Peña ef205e5df2 Added new test for checking DecoderFallbackException exception behaviour. 2013-07-08 23:31:06 +02:00
Gerardo García Peña 6ad7f75a37 in test SufficientByteArray() when !NET_2_0 unexpected exceptions should be forwarded. 2013-05-23 08:43:13 +02:00
Gerardo García Peña d624211706 MS.NET implementation returns 1000 not 625. 2013-05-21 13:43:23 +02:00
Gerardo García Peña 05643bef22 MS.NET implementation returns 1000 not 625. 2013-05-21 12:26:49 +02:00
Rodrigo Kumpera abe9dc6206 Revert "Fix object::GetType when remoting is enabled."
This reverts commit 93e2d1dc48.
2013-03-01 10:54:09 -05:00
Rodrigo Kumpera 93e2d1dc48 Fix object::GetType when remoting is enabled. 2013-03-01 10:52:03 -05:00
Martin Potter 643d8b8b3a System.Text.Decoder throws ArgumentOutOfRangeException when it should not. Fixes Bug #10789
Similar to previously reported bug #6404, according to the documentation at http://msdn.microsoft.com/en-us/library/h6w985hz.aspx, System.Text.Encoder throws ArgumentOutOfRangeExceptions when it should not. From the documentation, an ArgumentOutOfRangeException should be thrown when:

charIndex, charCount, byteIndex, or byteCount is less than zero.
-or-
The length of chars - charIndex is less than charCount.
-or-
The length of bytes - byteIndex is less than byteCount.

To reproduce, run the following code:

int charsUsed, bytesUsed;
bool completed;
byte[] bytes = new byte[4096];
char[] chars = new char[4096];
System.Text.Encoding.UTF8.GetDecoder().Convert(bytes, 0, 0, chars, 4096, 0, false, out bytesUsed, out charsUsed, out completed);

Expected:

The code runs, charsUsed equals zero, bytesUsed equals zero and completed is true.

Actual:

Mono throws an ArgumentOutOfRangeException for charIndex.

There are also other behavioral differences between Mono and Microsoft's implementation for the GetChars(Byte[], Int32, Int32, Char[], Int32, Boolean) method, such as:

byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes, 0, 0, chars, 10, false);

On Mono, this results in an ArgumentOutOfRangeException for charIndex, where for Microsoft charactersWritten = 0.

Similarly:

byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes, 0, 4096, chars, 10, false);

On Mono, this results in the same ArgumentOutOfRangeException for charIndex, where Microsoft throws and ArgumentException. since "chars does not have enough capacity from charIndex to the end of the array to accommodate the resulting characters."
2013-03-01 05:05:34 -08:00
Martin Potter 7ca2aa01d7 UTF8Decoder.GetChars(Byte[], Int32, Int32, Char[], Int32, Boolean) can write past end of char[]. Fixes Bug#10788
UTF8Decoder.GetChars(Byte[], Int32, Int32, Char[], Int32, Boolean) eventually calls into UTF8Encoding.InternalGetChars, which does not perform any bounds checking on the passed in char* until after the first byte > 0x80 is encountered. For instance:

byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes,
0, 4096, chars, 9, false);

will result in no errors and charactersWritten = 4096.
2013-02-28 16:26:02 -08:00
Marek Safar f0f4f4ae51 More mobile tests update 2013-02-14 13:06:49 +01:00
Marek Safar d6af35c68f Fix more mobile tests 2013-02-12 20:02:07 +01:00
Rodrigo Kumpera 1b92a4148c Since MOBILE implies NET_4_* now, take this into account and simplify our ifdefs. 2013-02-11 18:42:18 -05:00
Rodrigo Kumpera b96d05dac3 Kill the MOONLIGHT define in corlib. 2013-02-11 16:03:28 -05:00
Marek Safar afa79435aa Update for mobile profile 2013-02-07 16:34:21 +01:00
Martin Baulig cd8ca2f658 [corlib] Fix ASCIIEncoding with custom DecoderFallback.
Only pass one single byte to DecoderFallback.Fallback(),
throw if there's not enough space in the char array.
2012-12-22 05:14:25 +01:00
Zoltan Varga 2b3148f2a0 Add a workaround for #5432 to EncodingInfoTest. 2012-09-03 20:47:59 +02:00
Martin Potter e3d59a330e Updating System.Text.Encoder's Convert method bounds checking to be compliant with Microsoft's documentation. (http://msdn.microsoft.com/en-us/library/dh0797c4.aspx) 2012-08-05 21:18:33 -07:00
Marek Safar db7131d010 Change few Assertions to Asserts 2012-02-29 18:09:52 +00:00
Paolo Molaro 8397d2885e Fixed StringBuilder.Clear() to properly clear the cached string. 2011-11-22 12:04:05 +01:00
Miguel de Icaza 2852ed0b59 Update copyrights 2011-09-13 18:26:13 -04:00
Atsushi Eno 08d304aa03 Add test for bug #545. 2011-08-31 14:10:15 -07:00
Atsushi Eno f4aff310cf EncoderFallback support in UTF8Encoding. Fixed bug #565129 and regression in d961246.
Patch mostly by JB Evain.
2010-08-10 20:22:52 +09:00
Marek Habersack 7e0a0a69f0 Revert "EncoderFallback support in UTF8Encoding. Fixed bug #565129."
This reverts commit d961246014 because it breaks 2 tests in
System.Web on 2.0 and 4 on 4.0 profile.
2010-08-05 15:32:58 +02:00
atsushieno d961246014 EncoderFallback support in UTF8Encoding. Fixed bug #565129.
Patch mostly by JB Evain.
2010-08-04 15:32:54 +09:00
Sebastien Pouliot 07efc64d03 In System:
2009-10-27  Sebastien Pouliot  <[email protected]>

	* String.cs: Remove unused (and unneeded) internal call defs.
	Reduce duplication (and fix test) for Concat (object,object).
	Avoid allocating zero-length strings in the cases where the
	FX does not do so.

In Test/System.Text:
2009-10-27  Sebastien Pouliot  <[email protected]>

	* UnicodeEncodingTest.cs: Add test cases with an odd number of 
	bytes being used in GetString (it does not crash but it does not
	work like MS FX either).

In Test/System:
2009-10-27  Sebastien Pouliot  <[email protected]>

	* StringTest.cs: Add test case for methods that can return
	empty strings.

In System.Globalization:
2009-10-27  Sebastien Pouliot  <[email protected]>

	* TextInfo.cs: Avoid allocating zero-length strings in ToLower 
	and ToUpper methods


svn path=/trunk/mcs/; revision=144921
2009-10-27 23:42:55 +00:00
Gonzalo Paniagua Javier 32ce184cba 2009-09-12 Gonzalo Paniagua Javier <[email protected]>
* StringBuilderTest.cs: new test.


svn path=/trunk/mcs/; revision=141859
2009-09-13 02:44:02 +00:00
Miguel de Icaza 9afbbceb72 2009-07-28 Miguel de Icaza <[email protected]>
* UTF8Encoding.cs: Use Equals to compare the objects as the
	fallback objects do not overload operator ==.    The comparison
	was previously failing.

svn path=/trunk/mcs/; revision=138786
2009-07-28 05:04:08 +00:00
Gonzalo Paniagua Javier 885b9f9f7e 2009-07-26 Gonzalo Paniagua Javier <[email protected]>
* StringBuilderTest.cs: new overflow tests.


svn path=/trunk/mcs/; revision=138688
2009-07-26 16:27:07 +00:00
Robert Jordan a5b5163351 2009-06-26 Robert Jordan <[email protected]>
* UTF8EncodingTest.cs: Fix the NET_1_1 build.


svn path=/trunk/mcs/; revision=137012
2009-06-26 21:53:51 +00:00
Zoltan Varga 67b04fd53a 2009-06-26 Zoltan Varga <[email protected]>
* *.cs: Convert all tests to new-style nunit classes/methods. Add
	[Test] attributes to some tests which were missing them.

svn path=/trunk/mcs/; revision=136944
2009-06-26 11:16:10 +00:00
Gert Driesen 81ef506280 * UTF32EncodingTest.cs: Added tests for GetByteCount overloads.
svn path=/trunk/mcs/; revision=125864
2009-02-05 14:56:52 +00:00
Atsushi Eno 3ef06e62ed 2009-01-30 Atsushi Enomoto <[email protected]>
* UTF8Encoding.cs : surrogate characters are handled in 
	  InternalGetChars() but not in InternalGetCharCount().
	  Fixed bug #415628.

	* UTF8EncodingTest.cs : added test for bug #415628.

	* 415628.bin : new test resource.

	* Makefile: new resource, new EXTRA_DIST mess.


svn path=/trunk/mcs/; revision=125075
2009-01-30 12:13:56 +00:00
Jb Evain 37111e4f26 in System.Text:
2009-01-13  Jb Evain  <[email protected]>

	* Encoding.cs: when creating a ForwardingEncoder or a
	ForwardingDecoder, don't crash if the Encoding doesn't
	provide an EncoderFallback or a DecoderFallback.

in Test/System.Text:
2009-01-13  Jb Evain  <[email protected]>

	* EncoderTest.cs: Make sure we can get an encoder for a custom
	encoding.
	* DecoderTest.cs: ditto.

svn path=/trunk/mcs/; revision=123196
2009-01-13 15:25:45 +00:00
Atsushi Eno c12917a979 2008-04-09 Atsushi Enomoto <[email protected]>
* UTF7Encoding.cs :
	  Fixed misplaced leftOverSize reset in InternalGetCharCount().
	  Fixed base64 value for '+' (the value is actually unused though).

	* UTF7EncodingTest.cs : added test for broken GetCharCount() case.


svn path=/trunk/mcs/; revision=100197
2008-04-09 07:11:59 +00:00
Atsushi Eno 646393c59c 2007-12-27 Atsushi Enomoto <[email protected]>
* DecoderFallback.cs, EncoderFallback.cs, Encoding.cs :
	  the same "\uFFFD" fix for encoder fallback.
	  Reduced extra instantiation of those fallbacks.

	* EncoderReplacementFallbackTest.cs,
	  EncoderReplacementFallbackBufferTest.cs : encoder test for
	  "\uFFFD" replacement.


svn path=/trunk/mcs/; revision=91947
2007-12-27 16:04:57 +00:00
Atsushi Eno 1ab79d0289 2007-10-26 Atsushi Enomoto <[email protected]>
* UTF8EncodingTest.cs : looks like the issue is not fixed in .NET 1.x
	  and hence it looked like a regression. (It wasn't.)


svn path=/trunk/mcs/; revision=88248
2007-10-26 04:19:51 +00:00
Atsushi Eno f4071fef2b 2007-10-25 Atsushi Enomoto <[email protected]>
* DecoderReplacementFallbackBuffer.cs : Reset() should also reset the
	  input buffer. When fallback is not assigned, just return '\0'.
	* UnicodeEncoding.cs : handle throwOnInvalid .ctor argument.
	  Default replacement fallback buffer is now "\uFFFD".
	* UTF8Encoding.cs : couple of replacement buffer size fixes.
	  Default replacement fallback buffer is now "\uFFFD".
	* UTF32Encoding.cs : Default replacement is "\uFFFD" too here.
	  See http://support.microsoft.com/kb/940521/ for this change.

	* UnicodeEncodingTest.cs,
	  UTF8EncodingTest.cs,
	  DecoderReplacementFallbackBufferTest.cs,
	  DecoderReplacementFallbackTest.cs : default replacement buffer fix.
	  Added test for Reset() for replacement buffer.


svn path=/trunk/mcs/; revision=88150
2007-10-25 09:42:03 +00:00
Gert Driesen 797ad860d5 * UTF8Encoding.cs: IsMailNewsSave should return true. Fixes bug
#332515.
* UTF32Encoding.cs: IsBrowserSave returns false for both Big-Endian and
Little-Endian.
* TestEncoding.cs: Also make class available on 1.0 profile.
* EncodingTest.cs: Added tests for Is* properties.
* UTF7EncodingTest.cs: Added tests for Is* properties.
* UnicodeEncodingTest.cs: Added tests for Is* properties. Fixed 
line endings.
* UTF8EncodingTest.cs: Added tests for Is* properties. Spaces to
tabs. Numbered tests.
* ASCIIEncodingTest.cs: Added tests for Is* properties. No longer
derive from TestCase class. Spaces to tabs.    
* UTF32EncodingTest.cs: Added tests for Is* properties. No longer
derive from deprecated Assertion class.

svn path=/trunk/mcs/; revision=87593
2007-10-16 14:48:47 +00:00
Gert Driesen decc14ec8d * DecoderReplacementFallbackTest.cs: Fixed DontChangeReadOnlyCodePage-
DecoderFallback test to pass on systems where codepage 932 is valid.
Assert that exception is thrown by DecoderFallback property.
* EncoderReplacementFallbackTest.cs: Fixed DontChangeReadOnlyCodePage-
EncoderFallback test to pass on systems where codepage 932 is valid.
Assert that exception is thrown by EncoderFallback property.

svn path=/trunk/mcs/; revision=81463
2007-07-06 11:46:57 +00:00
Miguel de Icaza f082d34c15 Expect the proper exception
svn path=/trunk/mcs/; revision=75970
2007-04-19 22:18:28 +00:00
Marek Habersack 6e5bd19fbd 2007-04-19 Marek Habersack <[email protected]>
* DecoderReplacementFallbackTest.cs: expect the correct
	exception.


svn path=/trunk/mcs/; revision=75962
2007-04-19 16:20:42 +00:00
Eyal Alalouf 30c28c41d7 Mark tests as not working under TARGET_JVM
svn path=/trunk/mcs/; revision=74246
2007-03-14 10:47:05 +00:00