Patchwork [08/21] qapi: add test cases for generated free functions

login
register
mail settings
Submitter Luiz Capitulino
Date Sept. 28, 2011, 2:44 p.m.
Message ID <1317221085-5825-9-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/116802/
State New
Headers show

Comments

Luiz Capitulino - Sept. 28, 2011, 2:44 p.m.
From: Michael Roth <mdroth@linux.vnet.ibm.com>

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 test-qmp-commands.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
Anthony Liguori - Sept. 29, 2011, 12:51 p.m.
On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> From: Michael Roth<mdroth@linux.vnet.ibm.com>
>
> Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> ---
>   test-qmp-commands.c |   29 +++++++++++++++++++++++++++++
>   1 files changed, 29 insertions(+), 0 deletions(-)
>
> diff --git a/test-qmp-commands.c b/test-qmp-commands.c
> index f142cc6..7db38b6 100644
> --- a/test-qmp-commands.c
> +++ b/test-qmp-commands.c
> @@ -98,6 +98,34 @@ static void test_dispatch_cmd_io(void)
>       QDECREF(req);
>   }
>
> +/* test generated dealloc functions for generated types */
> +static void test_dealloc_types(void)
> +{
> +    UserDefOne *ud1test, *ud1a, *ud1b;
> +    UserDefOneList *ud1list;
> +
> +    ud1test = g_malloc0(sizeof(UserDefOne));
> +    ud1test->integer = 42;
> +    ud1test->string = strdup("hi there 42");
> +
> +    qapi_free_UserDefOne(ud1test);
> +
> +    ud1a = g_malloc0(sizeof(UserDefOne));
> +    ud1a->integer = 43;
> +    ud1a->string = strdup("hi there 43");
> +
> +    ud1b = g_malloc0(sizeof(UserDefOne));
> +    ud1b->integer = 44;
> +    ud1b->string = strdup("hi there 44");

Minor nit: this should be g_strdup.

Regards,

Anthony Liguori

> +
> +    ud1list = g_malloc0(sizeof(UserDefOneList));
> +    ud1list->value = ud1a;
> +    ud1list->next = g_malloc0(sizeof(UserDefOneList));
> +    ud1list->next->value = ud1b;
> +
> +    qapi_free_UserDefOneList(ud1list);
> +}
> +
>   int main(int argc, char **argv)
>   {
>       g_test_init(&argc,&argv, NULL);
> @@ -105,6 +133,7 @@ int main(int argc, char **argv)
>       g_test_add_func("/0.15/dispatch_cmd", test_dispatch_cmd);
>       g_test_add_func("/0.15/dispatch_cmd_error", test_dispatch_cmd_error);
>       g_test_add_func("/0.15/dispatch_cmd_io", test_dispatch_cmd_io);
> +    g_test_add_func("/0.15/dealloc_types", test_dealloc_types);
>
>       module_call_init(MODULE_INIT_QAPI);
>       g_test_run();

Patch

diff --git a/test-qmp-commands.c b/test-qmp-commands.c
index f142cc6..7db38b6 100644
--- a/test-qmp-commands.c
+++ b/test-qmp-commands.c
@@ -98,6 +98,34 @@  static void test_dispatch_cmd_io(void)
     QDECREF(req);
 }
 
+/* test generated dealloc functions for generated types */
+static void test_dealloc_types(void)
+{
+    UserDefOne *ud1test, *ud1a, *ud1b;
+    UserDefOneList *ud1list;
+
+    ud1test = g_malloc0(sizeof(UserDefOne));
+    ud1test->integer = 42;
+    ud1test->string = strdup("hi there 42");
+
+    qapi_free_UserDefOne(ud1test);
+
+    ud1a = g_malloc0(sizeof(UserDefOne));
+    ud1a->integer = 43;
+    ud1a->string = strdup("hi there 43");
+
+    ud1b = g_malloc0(sizeof(UserDefOne));
+    ud1b->integer = 44;
+    ud1b->string = strdup("hi there 44");
+
+    ud1list = g_malloc0(sizeof(UserDefOneList));
+    ud1list->value = ud1a;
+    ud1list->next = g_malloc0(sizeof(UserDefOneList));
+    ud1list->next->value = ud1b;
+
+    qapi_free_UserDefOneList(ud1list);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -105,6 +133,7 @@  int main(int argc, char **argv)
     g_test_add_func("/0.15/dispatch_cmd", test_dispatch_cmd);
     g_test_add_func("/0.15/dispatch_cmd_error", test_dispatch_cmd_error);
     g_test_add_func("/0.15/dispatch_cmd_io", test_dispatch_cmd_io);
+    g_test_add_func("/0.15/dealloc_types", test_dealloc_types);
 
     module_call_init(MODULE_INIT_QAPI);
     g_test_run();