[DllImport("libtest")]
public static extern int mono_test_marshal_variant_out_safearray_4dim_vt_int ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
- public static int Main() {
+ [DllImport ("libtest")]
+ public static extern bool mono_cominterop_is_supported ();
+
+ public static int Main ()
+ {
+
+ bool isWindows = !(((int)Environment.OSVersion.Platform == 4) ||
+ ((int)Environment.OSVersion.Platform == 128));
- bool isWindows = !(((int)Environment.OSVersion.Platform == 4) ||
- ((int)Environment.OSVersion.Platform == 128));
- if (isWindows) {
+ if (mono_cominterop_is_supported ())
+ {
#region BSTR Tests
string str;
if (mono_test_marshal_bstr_in ("mono_test_marshal_bstr_in") != 0)
return 1;
if (mono_test_marshal_bstr_out (out str) != 0 || str != "mono_test_marshal_bstr_out")
- return 2;
- if (mono_test_marshal_bstr_in_null (null) != 0)
- return 1;
- if (mono_test_marshal_bstr_out_null (out str) != 0 || str != null)
- return 2;
+ return 2;
+ if (mono_test_marshal_bstr_in_null (null) != 0)
+ return 1;
+ if (mono_test_marshal_bstr_out_null (out str) != 0 || str != null)
+ return 2;
#endregion // BSTR Tests
#endregion // COM Callable Wrapper Tests
#region SAFEARRAY tests
+
+ if (isWindows) {
+ Array array;
+ if ((mono_test_marshal_variant_out_safearray_1dim_vt_bstr_empty(out array) != 0) || (array.Rank != 1) || (array.Length != 0))
+ return 62;
+
+ if ((mono_test_marshal_variant_out_safearray_1dim_vt_bstr (out array) != 0) || (array.Rank != 1) || (array.Length != 10))
+ return 63;
+ for (int i = 0; i < 10; ++i) {
+ if (i != Convert.ToInt32(array.GetValue (i)))
+ return 64;
+ }
- Array array;
- if ((mono_test_marshal_variant_out_safearray_1dim_vt_bstr_empty(out array) != 0) || (array.Rank != 1) || (array.Length != 0))
- return 62;
-
- if ((mono_test_marshal_variant_out_safearray_1dim_vt_bstr (out array) != 0) || (array.Rank != 1) || (array.Length != 10))
- return 63;
- for (int i = 0; i < 10; ++i) {
- if (i != Convert.ToInt32(array.GetValue (i)))
- return 64;
- }
-
- if ((mono_test_marshal_variant_out_safearray_2dim_vt_int (out array) != 0) || (array.Rank != 2))
- return 65;
- if ( (array.GetLowerBound (0) != 0) || (array.GetUpperBound (0) != 3)
- || (array.GetLowerBound (1) != 0) || (array.GetUpperBound (1) != 2))
- return 66;
- for (int i = array.GetLowerBound (0); i <= array.GetUpperBound (0); ++i)
- {
- for (int j = array.GetLowerBound (1); j <= array.GetUpperBound (1); ++j) {
- if ((i + 1) * 10 + (j + 1) != (int)array.GetValue (new long[] { i, j }))
- return 67;
+ if ((mono_test_marshal_variant_out_safearray_2dim_vt_int (out array) != 0) || (array.Rank != 2))
+ return 65;
+ if ( (array.GetLowerBound (0) != 0) || (array.GetUpperBound (0) != 3)
+ || (array.GetLowerBound (1) != 0) || (array.GetUpperBound (1) != 2))
+ return 66;
+ for (int i = array.GetLowerBound (0); i <= array.GetUpperBound (0); ++i)
+ {
+ for (int j = array.GetLowerBound (1); j <= array.GetUpperBound (1); ++j) {
+ if ((i + 1) * 10 + (j + 1) != (int)array.GetValue (new long[] { i, j }))
+ return 67;
+ }
}
- }
- if ((mono_test_marshal_variant_out_safearray_4dim_vt_int (out array) != 0) || (array.Rank != 4))
- return 68;
- if ( (array.GetLowerBound (0) != 15) || (array.GetUpperBound (0) != 24)
- || (array.GetLowerBound (1) != 20) || (array.GetUpperBound (1) != 22)
- || (array.GetLowerBound (2) != 5) || (array.GetUpperBound (2) != 10)
- || (array.GetLowerBound (3) != 12) || (array.GetUpperBound (3) != 18) )
- return 69;
-
- int index = 0;
- for (int i = array.GetLowerBound (3); i <= array.GetUpperBound (3); ++i) {
- for (int j = array.GetLowerBound (2); j <= array.GetUpperBound (2); ++j) {
- for (int k = array.GetLowerBound (1); k <= array.GetUpperBound (1); ++k) {
- for (int l = array.GetLowerBound (0); l <= array.GetUpperBound (0); ++l) {
- if (index != (int)array.GetValue (new long[] { l, k, j, i }))
- return 70;
- ++index;
+ if ((mono_test_marshal_variant_out_safearray_4dim_vt_int (out array) != 0) || (array.Rank != 4))
+ return 68;
+ if ( (array.GetLowerBound (0) != 15) || (array.GetUpperBound (0) != 24)
+ || (array.GetLowerBound (1) != 20) || (array.GetUpperBound (1) != 22)
+ || (array.GetLowerBound (2) != 5) || (array.GetUpperBound (2) != 10)
+ || (array.GetLowerBound (3) != 12) || (array.GetUpperBound (3) != 18) )
+ return 69;
+
+ int index = 0;
+ for (int i = array.GetLowerBound (3); i <= array.GetUpperBound (3); ++i) {
+ for (int j = array.GetLowerBound (2); j <= array.GetUpperBound (2); ++j) {
+ for (int k = array.GetLowerBound (1); k <= array.GetUpperBound (1); ++k) {
+ for (int l = array.GetLowerBound (0); l <= array.GetUpperBound (0); ++l) {
+ if (index != (int)array.GetValue (new long[] { l, k, j, i }))
+ return 70;
+ ++index;
+ }
}
}
}
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
}
+
+static gunichar2* marshal_bstr_alloc(const gchar* str)
+{
+#ifdef WIN32
+ gunichar2* ret = NULL;
+ gunichar2* temp = NULL;
+ temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
+ ret = SysAllocString (temp);
+ g_free (temp);
+ return ret;
+#else
+ gchar* ret = NULL;
+ int slen = strlen (str);
+ gunichar2* temp;
+ /* allocate len + 1 utf16 characters plus 4 byte integer for length*/
+ ret = g_malloc ((slen + 1) * sizeof(gunichar2) + sizeof(guint32));
+ if (ret == NULL)
+ return NULL;
+ temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
+ memcpy (ret + sizeof(guint32), temp, slen * sizeof(gunichar2));
+ * ((guint32 *) ret) = slen * sizeof(gunichar2);
+ ret [4 + slen * sizeof(gunichar2)] = 0;
+ ret [5 + slen * sizeof(gunichar2)] = 0;
+
+ return (gunichar2*)(ret + 4);
+#endif
+}
+
+LIBTEST_API int STDCALL
+mono_cominterop_is_supported ()
+{
+#if defined(TARGET_X86) || defined(TARGET_AMD64)
+ return 1;
+#endif
+ return 0;
+}
+
LIBTEST_API unsigned short* STDCALL
test_lpwstr_marshal (unsigned short* chars, long length)
{
* COM INTEROP TESTS
*/
-#ifdef WIN32
+#ifndef WIN32
+
+typedef struct {
+ guint16 vt;
+ guint16 wReserved1;
+ guint16 wReserved2;
+ guint16 wReserved3;
+ union {
+ gint64 llVal;
+ gint32 lVal;
+ guint8 bVal;
+ gint16 iVal;
+ float fltVal;
+ double dblVal;
+ gint16 boolVal;
+ gunichar2* bstrVal;
+ gint8 cVal;
+ guint16 uiVal;
+ guint32 ulVal;
+ guint64 ullVal;
+ struct {
+ gpointer pvRecord;
+ gpointer pRecInfo;
+ };
+ };
+} VARIANT;
+
+typedef enum {
+ VARIANT_TRUE = -1,
+ VARIANT_FALSE = 0
+} VariantBool;
+
+typedef enum {
+ VT_EMPTY = 0,
+ VT_NULL = 1,
+ VT_I2 = 2,
+ VT_I4 = 3,
+ VT_R4 = 4,
+ VT_R8 = 5,
+ VT_CY = 6,
+ VT_DATE = 7,
+ VT_BSTR = 8,
+ VT_DISPATCH = 9,
+ VT_ERROR = 10,
+ VT_BOOL = 11,
+ VT_VARIANT = 12,
+ VT_UNKNOWN = 13,
+ VT_DECIMAL = 14,
+ VT_I1 = 16,
+ VT_UI1 = 17,
+ VT_UI2 = 18,
+ VT_UI4 = 19,
+ VT_I8 = 20,
+ VT_UI8 = 21,
+ VT_INT = 22,
+ VT_UINT = 23,
+ VT_VOID = 24,
+ VT_HRESULT = 25,
+ VT_PTR = 26,
+ VT_SAFEARRAY = 27,
+ VT_CARRAY = 28,
+ VT_USERDEFINED = 29,
+ VT_LPSTR = 30,
+ VT_LPWSTR = 31,
+ VT_RECORD = 36,
+ VT_FILETIME = 64,
+ VT_BLOB = 65,
+ VT_STREAM = 66,
+ VT_STORAGE = 67,
+ VT_STREAMED_OBJECT = 68,
+ VT_STORED_OBJECT = 69,
+ VT_BLOB_OBJECT = 70,
+ VT_CF = 71,
+ VT_CLSID = 72,
+ VT_VECTOR = 4096,
+ VT_ARRAY = 8192,
+ VT_BYREF = 16384
+} VarEnum;
+
+void VariantInit(VARIANT* vt)
+{
+ vt->vt = VT_EMPTY;
+}
+
+typedef struct
+{
+ guint32 a;
+ guint16 b;
+ guint16 c;
+ guint8 d[8];
+} GUID;
+
+#define S_OK 0
+
+#endif
LIBTEST_API int STDCALL
-mono_test_marshal_bstr_in(BSTR bstr)
+mono_test_marshal_bstr_in(gunichar2* bstr)
{
- if (!wcscmp(bstr, L"mono_test_marshal_bstr_in"))
+ gint32 result = 0;
+ gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
+ result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
+ g_free(bstr_utf8);
+ if (result == 0)
return 0;
return 1;
}
LIBTEST_API int STDCALL
-mono_test_marshal_bstr_out(BSTR* bstr)
+mono_test_marshal_bstr_out(gunichar2** bstr)
{
- *bstr = SysAllocString(L"mono_test_marshal_bstr_out");
+ *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
return 0;
}
LIBTEST_API int STDCALL
-mono_test_marshal_bstr_in_null(BSTR bstr)
+mono_test_marshal_bstr_in_null(gunichar2* bstr)
{
if (!bstr)
return 0;
}
LIBTEST_API int STDCALL
-mono_test_marshal_bstr_out_null(BSTR* bstr)
+mono_test_marshal_bstr_out_null(gunichar2** bstr)
{
*bstr = NULL;
return 0;
LIBTEST_API int STDCALL
mono_test_marshal_variant_in_bstr(VARIANT variant)
{
- if (variant.vt == VT_BSTR && !wcscmp(variant.bstrVal, L"PI"))
+ gint32 result = 0;
+ gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
+ result = strcmp("PI", bstr_utf8);
+ g_free(bstr_utf8);
+
+ if (variant.vt == VT_BSTR && !result)
return 0;
return 1;
}
mono_test_marshal_variant_out_bstr(VARIANT* variant)
{
variant->vt = VT_BSTR;
- variant->bstrVal = SysAllocString(L"PI");
+ variant->bstrVal = marshal_bstr_alloc("PI");
return 0;
}
{
VARIANT vt;
vt.vt = VT_BSTR;
- vt.bstrVal = SysAllocString(L"PI");
+ vt.bstrVal = marshal_bstr_alloc("PI");
return func (VT_BSTR, vt);
}
mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
{
VARIANT vt;
+ gchar* bstr_utf8;
+ gint32 result = 0;
+
+
VariantInit (&vt);
func (VT_BSTR, &vt);
- if (vt.vt == VT_BSTR && !wcscmp(vt.bstrVal, L"PI"))
+ bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
+ result = strcmp("PI", bstr_utf8);
+ g_free(bstr_utf8);
+ if (vt.vt == VT_BSTR && !result)
return 0;
return 1;
}
int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
- int (STDCALL *LongIn)(MonoComObject* pUnk, LONGLONG a);
- int (STDCALL *ULongIn)(MonoComObject* pUnk, ULONGLONG a);
+ int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
+ int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
int m_ref;
};
-DEFINE_GUID(IID_ITest, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
-DEFINE_GUID(IID_IMonoUnknown, 0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
-DEFINE_GUID(IID_IMonoDispatch, 0x00020400, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
+static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
+static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
+static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
LIBTEST_API int STDCALL
MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
{
+
*ppv = NULL;
if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
*ppv = pUnk;
*ppv = pUnk;
return S_OK;
}
- return E_NOINTERFACE;
+ return 0x80004002; //E_NOINTERFACE;
}
LIBTEST_API int STDCALL
}
LIBTEST_API int STDCALL
-LongIn(MonoComObject* pUnk, LONGLONG a)
+LongIn(MonoComObject* pUnk, gint64 a)
{
return S_OK;
}
LIBTEST_API int STDCALL
-ULongIn(MonoComObject* pUnk, ULONGLONG a)
+ULongIn(MonoComObject* pUnk, guint64 a)
{
return S_OK;
}
return 0;
}
-
-#endif //NOT_YET
-
-
/*
* mono_method_get_unmanaged_thunk tests
*/
SAFEARRAY *pSA;
SAFEARRAYBOUND dimensions [1];
long i;
- wchar_t buffer [20];
+ gchar buffer [20];
HRESULT hr = S_OK;
long indices [1];
VARIANT vOut;
VariantInit (&vOut);
vOut.vt = VT_BSTR;
- _ltow (i,buffer,10);
- vOut.bstrVal= SysAllocString (buffer);
+ _ltoa (i,buffer,10);
+ vOut.bstrVal= marshal_bstr_alloc (buffer);
indices [0] = i;
if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
VariantClear (&vOut);