diff options
author | Thays Grazia <thaystg@gmail.com> | 2019-11-07 17:22:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-07 17:22:25 +0300 |
commit | 4bdacea237f2ae7ed444e0336dad503d9a0535ac (patch) | |
tree | 32adaf90ec8ffb35386ee1f1ea2a6c6789888ef8 /samples | |
parent | 3c84633c7c2d51b2629c8fbbbae77111edb976c3 (diff) |
[embed] Assert when call mono_runtime_object_init (#17589)
* Fix assert when calling externally call mono_runtime_object_init, mono_object_get_domain, mono_string_to_utf8
* Adding samples/embed as unit-test
Diffstat (limited to 'samples')
-rw-r--r-- | samples/embed/test-invoke.c | 34 | ||||
-rw-r--r-- | samples/embed/test.cs | 8 | ||||
-rw-r--r-- | samples/embed/teste.c | 35 |
3 files changed, 58 insertions, 19 deletions
diff --git a/samples/embed/test-invoke.c b/samples/embed/test-invoke.c index 791c8afffb7..42df4003cfd 100644 --- a/samples/embed/test-invoke.c +++ b/samples/embed/test-invoke.c @@ -1,4 +1,7 @@ +#ifndef _TESTCASE_ #include <mono/jit/jit.h> +#endif + #include <mono/metadata/object.h> #include <mono/metadata/environment.h> #include <mono/metadata/assembly.h> @@ -16,9 +19,9 @@ * We show how to create objects and invoke methods and set fields in them. * Compile with: * gcc -Wall -o test-invoke test-invoke.c `pkg-config --cflags --libs mono-2` -lm - * mcs invoke.cs + * mcs -out:test-embed-invoke-cs.exe invoke.cs * Run with: - * ./test-invoke invoke.exe + * ./test-invoke */ static void @@ -317,16 +320,31 @@ static void main_function (MonoDomain *domain, const char *file, int argc, char create_object (domain, mono_assembly_get_image (assembly)); } +#ifdef _TESTCASE_ +#ifdef __cplusplus +extern "C" +#endif +int +test_mono_embed_invoke_main (void); + int -main (int argc, char* argv[]) { +test_mono_embed_invoke_main (void) +{ +#else +int +main (void) +{ +#endif + MonoDomain *domain; + int argc = 2; + char *argv[] = { + (char*)"test-embed-invoke.exe", + (char*)"test-embed-invoke-cs.exe", + NULL + }; const char *file; int retval; - - if (argc < 2){ - fprintf (stderr, "Please provide an assembly to load\n"); - return 1; - } file = argv [1]; /* diff --git a/samples/embed/test.cs b/samples/embed/test.cs index 3283006d8b3..fcca03b54a4 100644 --- a/samples/embed/test.cs +++ b/samples/embed/test.cs @@ -5,7 +5,11 @@ class MonoEmbed { [MethodImplAttribute(MethodImplOptions.InternalCall)] extern static string gimme(); - static void Main() { - Console.WriteLine (gimme ()); + static int Main () + { + System.Console.WriteLine(gimme ()); + if (gimme ().Equals("All your monos are belong to us!")) + return 0; + return 100; } } diff --git a/samples/embed/teste.c b/samples/embed/teste.c index 069749e128a..a3e1445aa4b 100644 --- a/samples/embed/teste.c +++ b/samples/embed/teste.c @@ -1,4 +1,7 @@ +#ifndef _TESTCASE_ #include <mono/jit/jit.h> +#endif + #include <mono/metadata/environment.h> #include <mono/utils/mono-publib.h> #include <mono/metadata/mono-config.h> @@ -8,9 +11,9 @@ * Very simple mono embedding example. * Compile with: * gcc -o teste teste.c `pkg-config --cflags --libs mono-2` -lm - * mcs test.cs + * mcs -out:test-embed.exe test.cs * Run with: - * ./teste test.exe + * ./teste */ static MonoString* @@ -41,16 +44,30 @@ static void* custom_malloc(size_t bytes) return malloc(bytes); } +#ifdef _TESTCASE_ +#ifdef __cplusplus +extern "C" +#endif +int +test_mono_embed_main (void); + int -main(int argc, char* argv[]) { +test_mono_embed_main (void) { +#else +int +main (void) { +#endif + MonoDomain *domain; + int argc = 2; + char *argv[] = { + (char*)"test-mono-embed.exe", + (char*)"test-embed.exe", + NULL + }; const char *file; int retval; - - if (argc < 2){ - fprintf (stderr, "Please provide an assembly to load\n"); - return 1; - } + file = argv [1]; MonoAllocatorVTable mem_vtable = { MONO_ALLOCATOR_VTABLE_VERSION, custom_malloc, NULL, NULL, NULL }; @@ -71,7 +88,7 @@ main(int argc, char* argv[]) { * We add our special internal call, so that C# code * can call us back. */ - mono_add_internal_call ("MonoEmbed::gimme", gimme); + mono_add_internal_call ("MonoEmbed::gimme", (const void *)gimme); main_function (domain, file, argc - 1, argv + 1); |