Skip TypedReferenceTest fixture for WASM as it causes a runtime abort (#12124)
[mono-project.git] / mono / unit-tests / test-mono-string.c
blob438263fb801b708d6e9321e1885e5d2c510855a3
1 /*
2 * test-mono-string.c: Unit test for runtime MonoString* manipulation.
3 */
5 #include "config.h"
6 #include <stdio.h>
7 #include "metadata/object-internals.h"
8 #include "mini/jit.h"
10 static int
11 new_string_ok (void)
13 ERROR_DECL (error);
14 MonoString *s = mono_string_new_checked (mono_domain_get (), "abcd", error);
15 static const gunichar2 u16s[] = { 0x61, 0x62, 0x63, 0x64, 0 }; /* u16 "abcd" */
16 mono_error_assert_ok (error);
17 gunichar2* c = mono_string_chars_internal (s);
19 g_assert (c != NULL && !memcmp (&u16s, c, sizeof (u16s)));
20 return 0;
23 static int
24 new_string_utf8 (void)
26 ERROR_DECL (error);
27 const gunichar2 snowman = 0x2603;
28 static const unsigned char bytes[] = { 0xE2, 0x98, 0x83, 0x00 }; /* U+2603 NUL */
29 MonoString *s = mono_string_new_checked (mono_domain_get (), (const char*)bytes, error);
30 mono_error_assert_ok (error);
31 gunichar2* c = mono_string_chars_internal (s);
32 g_assert (c != NULL &&
33 (c[0] == snowman) &&
34 (c[1] == 0));
35 return 0;
38 static int
39 new_string_conv_err (void)
41 ERROR_DECL (error);
42 static const unsigned char bytes[] = { 'a', 0xFC, 'b', 'c', 0 };
43 MonoString G_GNUC_UNUSED *s = mono_string_new_checked (mono_domain_get (), (const char*)bytes, error);
44 g_assert (!mono_error_ok (error));
45 const char *msg = mono_error_get_message (error);
46 g_assert (msg != NULL);
47 fprintf (stderr, "(expected) error message was: \"%s\"", msg);
48 mono_error_cleanup (error);
49 return 0;
52 #ifdef __cplusplus
53 extern "C"
54 #endif
55 int
56 test_mono_string_main (void);
58 int
59 test_mono_string_main (void)
62 mono_jit_init_version ("test-mono-string", "v4.0.30319");
64 int res = 0;
66 res += new_string_ok ();
67 res += new_string_utf8 ();
68 res += new_string_conv_err ();
70 return res;