Author: gert
Date: 2007-07-05 14:24:16 -0400 (Thu, 05 Jul 2007)
New Revision: 81419

Added:
   trunk/gert/standalone/bug81990/
   trunk/gert/standalone/bug81990/default.build
   trunk/gert/standalone/bug81990/libtest.c
   trunk/gert/standalone/bug81990/test.cs
Log:
Added test for bug #81990.


Added: trunk/gert/standalone/bug81990/default.build
===================================================================
--- trunk/gert/standalone/bug81990/default.build        2007-07-05 18:12:01 UTC 
(rev 81418)
+++ trunk/gert/standalone/bug81990/default.build        2007-07-05 18:24:16 UTC 
(rev 81419)
@@ -0,0 +1,84 @@
+<project name="bug81990" default="rebuild">
+       <target name="mono-1.0">
+               <property name="csc.defines" 
value="NET_1_0,NET_1_1,ONLY_1_1,MONO" />
+       </target>
+
+       <target name="mono-2.0">
+               <property name="csc.defines" 
value="NET_1_0,NET_1_1,NET_2_0,ONLY_2_0,MONO" />
+       </target>
+
+       <target name="net-1.1">
+               <property name="csc.defines" value="NET_1_0,NET_1_1,ONLY_1_1" />
+       </target>
+
+       <target name="net-2.0">
+               <property name="csc.defines" 
value="NET_1_0,NET_1_1,NET_2_0,ONLY_2_0" />
+       </target>
+
+       <property name="frameworks" value="mono-1.0,mono-2.0,net-1.1,net-2.0" />
+
+       <target name="clean">
+               <delete>
+                       <fileset>
+                               <include name="libtest.o" />
+                               <include name="libtest.so" />
+                               <include name="out" />
+                               <include name="test.exe" />
+                       </fileset>
+               </delete>
+       </target>
+
+       <target name="build">
+               <property name="original.targetframework" 
value="${nant.settings.currentframework}" />
+
+               <foreach property="framework" item="String" in="${frameworks}" 
delim=",">
+                       <if test="${framework::exists(framework)}">
+                               <property name="nant.settings.currentframework" 
value="${framework}" />
+                               <call 
target="${nant.settings.currentframework}" />
+                               <call target="run" />
+                               <call target="clean" />
+                       </if>
+               </foreach>
+
+               <property name="nant.settings.currentframework" 
value="${original.targetframework}" />
+       </target>
+
+       <target name="compile" if="${platform::is-unix()}">
+               <csc target="exe" define="${csc.defines}" output="test.exe" 
warnaserror="true" warninglevel="4">
+                       <sources>
+                               <include name="test.cs" />
+                       </sources>
+               </csc>
+               <exec program="gcc">
+                       <arg value="-g" />
+                       <arg value="-O0" />
+                       <arg value="-D&quot;_DEBUG&quot;" />
+                       <arg value="-D&quot;linux&quot;" />
+                       <arg value="-D&quot;_LINUX&quot;" />
+                       <arg value="-shared-libgcc" />
+                       <arg value="-fPIC" />
+                       <arg value="-c" />
+                       <arg value="-o" />
+                       <arg file="libtest.o" />
+                       <arg file="libtest.c" />
+               </exec>
+               <exec program="gcc">
+                       <arg value="-g" />
+                       <arg value="-shared-libgcc" />
+                       <arg value="-shared" />
+                       <arg value="-fPIC" />
+                       <arg value="-o" />
+                       <arg file="libtest.so" />
+                       <arg file="libtest.o" />
+               </exec>
+       </target>
+
+       <target name="run" depends="compile" if="${platform::is-unix()}">
+               <exec program="test.exe" managed="true" output="out" />
+               <fail unless="${file::exists('out')}">#1</fail>
+               <loadfile file="out" property="out" />
+               <fail 
unless="${string::index-of(out,'abcdefghijklmnopqrstuvwxyz|abcdefghijklmnopqrstuvwxyz|abcdefghijklmnopqrstuvwxyz')
 != -1}">#2</fail>
+       </target>
+
+       <target name="rebuild" depends="clean, build" />
+</project>


Property changes on: trunk/gert/standalone/bug81990/default.build
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/gert/standalone/bug81990/libtest.c
===================================================================
--- trunk/gert/standalone/bug81990/libtest.c    2007-07-05 18:12:01 UTC (rev 
81418)
+++ trunk/gert/standalone/bug81990/libtest.c    2007-07-05 18:24:16 UTC (rev 
81419)
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+//
+// Define the interface for a callback function that will call from C++ into a 
C# function.
+// also allocate a static function pointer of that type to hold the function 
ptr
+//
+typedef unsigned short* (* SWIG_CSharpUTF16StringHelperCallback)(unsigned 
short*);
+static SWIG_CSharpUTF16StringHelperCallback stringCallback = NULL;
+
+//
+// export a registration function which the C# project will invoke to give us 
the callback 
+//
+void 
SWIGRegisterUTF16StringCallback_libtest(SWIG_CSharpUTF16StringHelperCallback 
callback)
+{
+   stringCallback = callback;
+}
+
+//
+// export a simple function that the C# project can call which will use the 
given callback function.
+//
+void my_test_func()
+{
+    //I'm going to create a utf16 string in the mono world.
+
+   unsigned short* ms;
+   unsigned short* ms2;
+   int x;
+
+   ms = malloc(27 * 2);
+   for (x=0; x<26; ++x)   
+   {
+       ms[x] = 'a' + x;
+   }
+   ms[26] = 0;
+
+   //
+   // print out the bytes before sending to the C# callback function
+   //
+   for (x=0; x<26; ++x)
+   {
+       printf("%c", ms[x]);
+   }
+   printf("|");
+
+   //
+   // Send the bytes to the C# callback function
+   //
+   ms2 = stringCallback(ms);
+
+   //
+   // print out the bytes after the C# callback function.  They will be 
destroyed by now 
+   //
+   x = 0;
+   while (ms2[x] != 0)
+   {
+       printf("%c", ms2[x]);
+       x++;
+   }
+}

Added: trunk/gert/standalone/bug81990/test.cs
===================================================================
--- trunk/gert/standalone/bug81990/test.cs      2007-07-05 18:12:01 UTC (rev 
81418)
+++ trunk/gert/standalone/bug81990/test.cs      2007-07-05 18:24:16 UTC (rev 
81419)
@@ -0,0 +1,36 @@
+using System;
+using System.Runtime.InteropServices;
+
+static class Program
+{
+       [STAThread]
+       static void Main ()
+       {
+               //
+               // Give a 'function pointer' of our static CreateWString 
function to the C library
+               //
+               SWIG_WStringDelegate wstringDelegate = new SWIG_WStringDelegate 
(CreateWString);
+               SWIGRegisterUTF16StringCallback_libtest (wstringDelegate);
+
+               //
+               // Invoke a function in the C library that will use the above 
registered CreateWString function pointer.
+               //
+               my_test_func ();
+       }
+
+       [return: MarshalAs (UnmanagedType.LPWStr)]
+       public delegate string SWIG_WStringDelegate ([MarshalAs 
(UnmanagedType.LPWStr)] string message);
+
+       [return: MarshalAs (UnmanagedType.LPWStr)]
+       public static string CreateWString ([MarshalAs (UnmanagedType.LPWStr)] 
string cString)
+       {
+               Console.Write (cString + "|");
+               return cString;
+       }
+
+       [DllImport ("libtest")]
+       public static extern void SWIGRegisterUTF16StringCallback_libtest 
(SWIG_WStringDelegate wstringDelegate);
+
+       [DllImport ("libtest")]
+       static extern void my_test_func ();
+}


Property changes on: trunk/gert/standalone/bug81990/test.cs
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to