X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Ftests%2Flibtest.c;h=f65b779e2838eeb9176ce9847f90802e268cbdf1;hb=b3aa48281e8c3c3aeb525ededa0653bcb668a25b;hp=1f2930da9655300e0a32a48da28c4f7ec9d69bd1;hpb=d43ea3ac56e86e4bb683037c7d895b4c30eeb253;p=mono.git diff --git a/mono/tests/libtest.c b/mono/tests/libtest.c index 1f2930da965..f65b779e283 100644 --- a/mono/tests/libtest.c +++ b/mono/tests/libtest.c @@ -889,12 +889,12 @@ mono_test_marshal_return_delegate (SimpleDelegate delegate) return delegate; } -typedef int DelegateByrefDelegate (void *); +typedef int (STDCALL *DelegateByrefDelegate) (void *); LIBTEST_API int STDCALL mono_test_marshal_delegate_ref_delegate (DelegateByrefDelegate del) { - int (*ptr) (int i); + int (STDCALL *ptr) (int i); del (&ptr); @@ -1243,7 +1243,7 @@ mono_test_marshal_stringbuilder_ref (char **s) * C/C++ standard and the runtime. */ typedef struct { -#if !defined(__GNUC__) || (defined(TARGET_WIN32) && defined(TARGET_AMD64)) +#if !defined(__GNUC__) || defined(TARGET_WIN32) char a; #endif } EmptyStruct; @@ -7220,3 +7220,202 @@ mono_return_double_array4 (double_array4 sa4, int addend) { return sa4; } +typedef struct { + int array [3]; +} FixedArrayStruct; + +LIBTEST_API int STDCALL +mono_test_marshal_fixed_array (FixedArrayStruct s) +{ + return s.array [0] + s.array [1] + s.array [2]; +} + +const int NSTRINGS = 6; +//test strings +const char *utf8Strings[] = { + "Managed", + "Sîne klâwen durh die wolken sint geslagen" , + "काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम्", + "我能吞下玻璃而不伤身体", + "ღმერთსი შემვედრე,შემვედრე, ნუთუ კვლა დამხსნას შემვედრე,სოფლისა შემვედრე, შემვედრე,შემვედრე,შემვედრე,შრომასა, ცეცხლს, წყალსა და მიწასა, ჰაერთა თანა მრომასა; მომცნეს ფრთენი და აღვფრინდე, მივჰხვდე მას ჩემსა ნდომასა, დღისით და ღამით ვჰხედვიდე მზისა ელვათა კრთომაასაშემვედრე,შემვედრე,", + "Τη γλώσσα μου έδωσαν ελληνική", +"\0" +}; + +LIBTEST_API char * +build_return_string(const char* pReturn) +{ + char *ret = 0; + if (pReturn == 0 || *pReturn == 0) + return ret; + + size_t strLength = strlen(pReturn); + ret = (char *)(malloc(sizeof(char)* (strLength + 1))); + memset(ret, '\0', strLength + 1); + strncpy(ret, pReturn, strLength); + return ret; +} + +LIBTEST_API char * +StringParameterInOut(/*[In,Out]*/ char *s, int index) +{ + // return a copy + return build_return_string(s); +} + +LIBTEST_API void +StringParameterRefOut(/*out*/ char **s, int index) +{ + char *pszTextutf8 = (char*)utf8Strings[index]; + size_t strLength = strlen(pszTextutf8); + *s = (char *)(malloc(sizeof(char)* (strLength + 1))); + memcpy(*s, pszTextutf8, strLength); + (*s)[strLength] = '\0'; +} + +LIBTEST_API void +StringParameterRef(/*ref*/ char **s, int index) +{ + char *pszTextutf8 = (char*)utf8Strings[index]; + size_t strLength = strlen(pszTextutf8); + // do byte by byte validation of in string + size_t szLen = strlen(*s); + for (size_t i = 0; i < szLen; i++) + { + if ((*s)[i] != pszTextutf8[i]) + { + printf("[in] managed string do not match native string\n"); + abort (); + } + } + + if (*s) + { + free(*s); + } + // overwrite the orginal + *s = (char *)(malloc(sizeof(char)* (strLength + 1))); + memcpy(*s, pszTextutf8, strLength); + (*s)[strLength] = '\0'; +} + +LIBTEST_API void +StringBuilderParameterInOut(/*[In,Out] StringBuilder*/ char *s, int index) +{ + // if string.empty + if (s == 0 || *s == 0) + return; + + char *pszTextutf8 = (char*)utf8Strings[index]; + + // do byte by byte validation of in string + size_t szLen = strlen(s); + for (size_t i = 0; i < szLen; i++) + { + if (s[i] != pszTextutf8[i]) + { + printf("[in] managed string do not match native string\n"); + abort (); + } + } + + // modify the string inplace + size_t outLen = strlen(pszTextutf8); + for (size_t i = 0; i < outLen; i++) { + s[i] = pszTextutf8[i]; + } + s[outLen] = '\0'; +} + +//out string builder +LIBTEST_API void +StringBuilderParameterOut(/*[Out] StringBuilder*/ char *s, int index) +{ + char *pszTextutf8 = (char*)utf8Strings[index]; + + printf ("SBPO: Receiving %s\n", s); + // modify the string inplace + size_t outLen = strlen(pszTextutf8); + for (size_t i = 0; i < outLen; i++) { + s[i] = pszTextutf8[i]; + } + s[outLen] = '\0'; +} + +LIBTEST_API char * +StringParameterOut(/*[Out]*/ char *s, int index) +{ + // return a copy + return build_return_string(s); +} + +// Utf8 field +typedef struct FieldWithUtf8 +{ + char *pFirst; + int index; +}FieldWithUtf8; + +//utf8 struct field +LIBTEST_API void +TestStructWithUtf8Field(struct FieldWithUtf8 fieldStruct) +{ + char *pszManagedutf8 = fieldStruct.pFirst; + int stringIndex = fieldStruct.index; + char *pszNative = 0; + size_t outLen = 0; + + if (pszManagedutf8 == 0 || *pszManagedutf8 == 0) + return; + + pszNative = (char*)utf8Strings[stringIndex]; + + outLen = strlen(pszNative); + // do byte by byte comparision + for (size_t i = 0; i < outLen; i++) + { + if (pszNative[i] != pszManagedutf8[i]) + { + printf("Native and managed string do not match.\n"); + abort (); + } + } +} + +typedef void (* Callback2)(char *text, int index); + +LIBTEST_API void +Utf8DelegateAsParameter(Callback2 managedCallback) +{ + for (int i = 0; i < NSTRINGS; ++i) + { + char *pszNative = 0; + pszNative = (char*)utf8Strings[i]; + managedCallback(pszNative, i); + } +} + + +LIBTEST_API char* +StringBuilderParameterReturn(int index) +{ + char *pszTextutf8 = (char*)utf8Strings[index]; + size_t strLength = strlen(pszTextutf8); + char * ret = (char *)(malloc(sizeof(char)* (strLength + 1))); + memcpy(ret, pszTextutf8, strLength); + ret[strLength] = '\0'; + + return ret; +} + +LIBTEST_API int STDCALL +mono_test_marshal_pointer_array (int *arr[]) +{ + int i; + + for (i = 0; i < 10; ++i) { + if (*arr [i] != -1) + return 1; + } + return 0; +}