2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / tests / unsafe-1.cs
old mode 100755 (executable)
new mode 100644 (file)
index c54d891..aa1f15e
@@ -1,3 +1,5 @@
+// Compiler options: -unsafe
+
 //
 // Tests unsafe operators.  address-of, dereference, member access
 //
@@ -99,6 +101,61 @@ unsafe class X {
                        return 105;
                return 0;
        }
+
+       static int TestPtrArithmetic ()
+       {
+               char [] array = new char [10];
+               char *pb;
+
+               array [5] = 'j';
+               fixed (char *pa = array){
+                       pb = pa + 1;
+
+
+                       //
+                       // This one tests pointer element access
+                       //
+                       if (pa [5] != 'j')
+                               return 199;
+                       
+                       Console.WriteLine ("V: " + (pb - pa));
+                       if ((pb - pa) != 1)
+                               return 200;
+
+                       pb++;
+
+                       if (pb == pa)
+                               return 201;
+                       if (pb < pa)
+                               return 202;
+                       if (pa > pb)
+                               return 203;
+                       if (pa >= pb)
+                               return 204;
+                       if (pb <= pa)
+                               return 205;
+                       pb = pb - 2;
+                       if (pb != pa){
+                               Console.WriteLine ("VV: " + (pb - pa));
+                               return 206;
+                       }
+               }
+
+               return 0;
+       }
+
+       static int TestMultiple ()
+       {
+               char [] array = new char [10];
+               int count = 0;
+               
+               fixed (char *pa = array, pb = array){
+                       count++;
+               }
+               if (count != 1)
+                       return 300;
+               return 0;
+       }
        
        static int Main ()
        {
@@ -112,6 +169,12 @@ unsafe class X {
 
                if ((v = TestPtrAssign ()) != 0)
                        return v;
+
+               if ((v = TestPtrArithmetic ()) != 0)
+                       return v;
+
+               if ((v = TestMultiple ()) != 0)
+                       return v;
                
                Console.WriteLine ("Ok");
                return 0;