2005-02-13 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Sat, 12 Feb 2005 23:19:37 +0000 (23:19 -0000)
committerZoltan Varga <vargaz@gmail.com>
Sat, 12 Feb 2005 23:19:37 +0000 (23:19 -0000)
* pinvoke13.cs libtest.c: Add/correct tests for pinvoke name mangling.

svn path=/trunk/mono/; revision=40566

mono/tests/ChangeLog
mono/tests/libtest.c
mono/tests/pinvoke13.cs

index dee65402e92dffc961ae8ff3d73161c072f35c7a..db8750bca5f62be335f97655cfb117ca7f8cd05d 100644 (file)
@@ -1,3 +1,7 @@
+2005-02-13  Zoltan Varga  <vargaz@freemail.hu>
+
+       * pinvoke13.cs libtest.c: Add/correct tests for pinvoke name mangling.
+
 2005-02-05  Zoltan Varga  <vargaz@freemail.hu>
 
        * libtest.c: Mark all exported functions STDCALL.
index 45294507660f3c4cb44f0e53b55b65c6f2ec5e84..db53140498cb820f639191f58c23643fd1b2a36f 100644 (file)
@@ -851,61 +851,72 @@ mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
        return (ret != 0);
 }
 
-STDCALL int 
-HexDump(char *data)
+STDCALL int
+NameManglingAnsi (char *data)
 {
-       int i, res = 0;
-       char *p;
-
-       printf ("HEXDUMP DEFAULT VERSION\n");
-
-       p = data;
-       for (i=0; i < 8; ++i)
-       {
-               res += *p;
-               printf("%0x ", (int) *(p++));
-       }
-       putchar('\n');
+       return data [0] + data [1] + data [2];
+}
 
-       return res;
+STDCALL int
+NameManglingAnsiA (char *data)
+{
+       g_assert_not_reached ();
 }
 
-STDCALL int 
-HexDumpA(char *data)
+STDCALL int
+NameManglingAnsiW (char *data)
 {
-       int i, res = 0;
-       char *p;
+       g_assert_not_reached ();
+}
 
-       printf ("HEXDUMP ANSI VERSION\n");
+STDCALL int
+NameManglingAnsi2A (char *data)
+{
+       return data [0] + data [1] + data [2];
+}
 
-       p = data;
-       for (i=0; i < 8; ++i)
-       {
-               res += *p;
-               printf("%0x ", (int) *(p++));
-       }
-       putchar('\n');
+STDCALL int
+NameManglingAnsi2W (char *data)
+{
+       g_assert_not_reached ();
+}
 
-       return res + 100000;
+STDCALL int
+NameManglingUnicode (char *data)
+{
+       g_assert_not_reached ();
 }
 
-STDCALL int 
-HexDump1W(char *data)
+STDCALL int
+NameManglingUnicodeW (char *data)
 {
-       int i, res = 0;
-       char *p;
+       return data [0] + data [1] + data [2];
+}
 
-       printf ("HEXDUMP UNICODE VERSION\n");
+STDCALL int
+NameManglingUnicode2 (char *data)
+{
+       return data [0] + data [1] + data [2];
+}
 
-       p = data;
-       for (i=0; i < 8; ++i)
-       {
-               res += *p;
-               printf("%0x ", (int) *(p++));
-       }
-       putchar('\n');
+STDCALL int
+NameManglingAutoW (char *data)
+{
+#ifdef WIN32
+       return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
+#else
+       g_assert_not_reached ();
+#endif
+}
 
-       return res + 1000000;
+STDCALL int
+NameManglingAuto (char *data)
+{
+#ifndef WIN32
+       return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
+#else
+       g_assert_not_reached ();
+#endif
 }
 
 typedef int (STDCALL *intcharFunc)(const char*);
index 6a2a9cf38bfcb9ccaa06a05090577898ee1b5f49..ef2142a305444b818998b1d44c24698ab833ec4a 100644 (file)
@@ -1,40 +1,58 @@
+//
+// pinvoke13.cs
+//
+//   Tests for pinvoke name mangling
+//
 using System;
 using System.Runtime.InteropServices;
 
-public class DumpTest
+public class Tests
 {
-       /* this should call HexDumpA with ANSI encoded string */
+       /*
+        * These tests exercise the search order associated with the different charset values.
+        */
+
+       /* This should call NameManglingAnsi */
        [DllImport("libtest", CharSet=CharSet.Ansi)]
-       private static extern int HexDump (string data);
+       private static extern int NameManglingAnsi (string data);
+
+       /* This should call NameManglingAnsi2A */
+       [DllImport ("libtest", CharSet=CharSet.Ansi)]
+       private static extern int NameManglingAnsi2 (string data);
 
-       /* this should call HexDump default version with Unicode string */
-       [DllImport("libtest", EntryPoint="HexDump", CharSet=CharSet.Unicode)]
-       private static extern int HexDump2(string data);
+       /* This should call NameManglingUnicodeW */
+       [DllImport ("libtest", CharSet=CharSet.Unicode)]
+       private static extern int NameManglingUnicode (string data);
 
-       /* this should call HexDump1W with unicode encoding */
-       [DllImport("libtest", CharSet=CharSet.Unicode)]
-       private static extern int HexDump1(string data);
+       /* This should call NameManglingUnicode2 */
+       [DllImport ("libtest", CharSet=CharSet.Unicode)]
+       private static extern int NameManglingUnicode2 (string data);
 
-       public static int Main()
-       {
+       /* This should call NameManglingAutoW under windows, and NameManglingAuto under unix */
+       [DllImport ("libtest", CharSet=CharSet.Auto)]
+       private static extern int NameManglingAuto (string s);
+
+       public static int Main (String[] args) {
                int res;
-               
-               res = HexDump ("First test");
-               Console.WriteLine (res);
-               if (res != 100769)
-                       return 1;
 
-               res = HexDump2 ("First test");
-               Console.WriteLine (res);
-               if (res != 404)
+               res = NameManglingAnsi ("ABC");
+               if (res != 198)
+                       return 1;
+               res = NameManglingAnsi ("ABC");
+               if (res != 198)
                        return 2;
-
-               res = HexDump1 ("First test");
-               Console.WriteLine (res);
-               if (res != 1000404)
+               res = NameManglingUnicode ("ABC");
+               if (res != 131)
                        return 3;
+               res = NameManglingUnicode ("ABC");
+               if (res != 131)
+                       return 4;
 
-               return 0;               
+               res = NameManglingAuto ("ABC");
+               if (res != 0)
+                       return 5;
+               
+               return 0;
        }
 }