Merge pull request #2314 from lambdageek/dev/local-handles
[mono.git] / mono / unit-tests / test-mono-handle.c
1 /*
2  * test-mono-handle: tests for MonoHandle and MonoHandleArena
3  *
4  * Authors:
5  *   Aleksey Kliger <aleksey@xamarin.com>
6  *
7  * Copyright 2015 Xamarin, Inc. (www.xamarin.com)
8  */
9
10 #include <config.h>
11 #include <glib.h>
12 #include <mono/metadata/handle.h>
13 #include <mono/metadata/handle-private.h>
14
15 static void
16 test1_arena_size ()
17 {
18         for (gsize i = 1; i < 10; ++i) {
19                 gsize sz = mono_handle_arena_size(i);
20                 g_assert(sz >= i*sizeof(MonoHandle));
21         }
22 }
23
24 static void
25 test2_arena_push_pop ()
26 {
27         MonoHandleArena *top = NULL;
28
29         const int n_handles = 3;
30         MonoHandleArena *new_arena1 = g_malloc0 (mono_handle_arena_size (n_handles));
31         mono_handle_arena_stack_push (&top, new_arena1, n_handles);
32
33         MonoHandleArena *new_arena2 = g_malloc0 (mono_handle_arena_size (n_handles));
34
35         mono_handle_arena_stack_push (&top, new_arena2, n_handles);
36
37         g_assert (top == new_arena2);
38
39         mono_handle_arena_stack_pop (&top, new_arena2, n_handles);
40
41         g_free (new_arena2);
42
43         g_assert (top == new_arena1);
44
45         mono_handle_arena_stack_pop (&top, new_arena1, n_handles);
46
47         g_assert (top == NULL);
48         
49         g_free (new_arena1);
50 }
51
52
53
54 int
55 main (int argc, const char* argv[])
56 {
57         test1_arena_size ();
58         
59         test2_arena_push_pop ();
60
61         return 0;
62 }