Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / bug-705140.cs
1 using System;
2
3
4 namespace BufferTest
5 {
6         class Test
7         {
8                 const byte TotalLength = 32;
9
10                 public static byte Expected (byte dest, byte src, int len, byte i)
11                 {
12                         if (i >= dest && i < dest + len)
13                                 return (byte) (src + (i - dest));
14                         else
15                                 return i;
16                 }
17
18                 public static bool TestMove (byte dest, byte src, int len)
19                 {
20                         byte[] array = new byte [TotalLength];
21                         for (byte i = 0; i < TotalLength; ++i)
22                                 array [i] = i;
23                         Buffer.BlockCopy (array, src, array, dest, len);
24                         for (byte i = 0; i < TotalLength; ++i)
25                         {
26                                 if (array [i] != Expected (dest, src, len, i)) {
27                                         Console.WriteLine ("when copying " + len + " from " + src + " to " + dest + ": expected ");
28                                         for (byte j = 0; j < TotalLength; ++j)
29                                                 Console.Write ("" + Expected (dest, src, len, j) + " ");
30                                         Console.WriteLine ();
31                                         Console.WriteLine ("got");
32                                         for (byte j = 0; j < TotalLength; ++j)
33                                                 Console.Write ("" + array [j] + " ");
34                                         Console.WriteLine ();
35                                         return false;
36                                 }
37                         }
38                         return true;
39                 }
40
41                 public static int Main (string[] args)
42                 {
43                         bool failed = false;
44                         for (byte i = 0; i < TotalLength; ++i) {
45                                 for (byte j = 0; j < TotalLength; ++j) {
46                                         byte max = (byte) (TotalLength - Math.Max (i, j));
47                                         for (byte l = 0; l < max; ++l) {
48                                                 if (!TestMove (i, j, l))
49                                                         failed = true;
50                                         }
51                                 }
52                         }
53
54                         return failed ? 1 : 0;
55                 }
56         }
57 }