From 74d15b342b413e566c0e5232d7e05631d09b8ea1 Mon Sep 17 00:00:00 2001 From: Justin Huang Date: Tue, 11 Apr 2023 15:28:40 +1000 Subject: [PATCH] vm_tools: Fixes sommelier autogen issues When writing the xdg-shell tests turns out there's a bunch of issues with the mock generation. This fixes them. BUG=b:255439799 TEST=meson build && ninja -C build && build/sommelier_test Change-Id: I685e7a04b676cdcda6cb1439f36ad365660c88a7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/4399943 Tested-by: Justin Huang Auto-Submit: Justin Huang Commit-Queue: Chloe Pelling Reviewed-by: Chloe Pelling --- gen-shim.py | 6 +++--- gen/mock-protocol-shim.h.jinja2 | 9 ++++++--- gen/protocol-shim.h.jinja2 | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gen-shim.py b/gen-shim.py index 46c4c14..89d1fb4 100755 --- a/gen-shim.py +++ b/gen-shim.py @@ -58,9 +58,9 @@ def CppTypeForWaylandType(xml_type_string: str, interface: str) -> str: elif xml_type_string == "string": return "const char *" elif xml_type_string == "object": - return f"struct {interface} *" + return f"struct {interface}*" elif xml_type_string == "array": - return "struct wl_array *" + return "struct wl_array*" else: raise ValueError(f"Invalid Type conversion: {xml_type_string}") @@ -78,7 +78,7 @@ def GetRequestReturnType(arguments: List[object]) -> str: for arg in arguments: if arg.attrib["type"] == "new_id": if "interface" in arg.attrib: - return f"struct {arg.attrib['interface']} *" + return f"struct {arg.attrib['interface']}*" else: return "void *" return "void" diff --git a/gen/mock-protocol-shim.h.jinja2 b/gen/mock-protocol-shim.h.jinja2 index 1d5b8ac..dd252b5 100644 --- a/gen/mock-protocol-shim.h.jinja2 +++ b/gen/mock-protocol-shim.h.jinja2 @@ -9,13 +9,16 @@ #include "{{ protocol.name_hyphen }}-shim.h" {%- for interface in protocol.interfaces %} -class Mock{{interface.name}} { +class Mock{{ interface.name }} : public {{ interface.name }} { public: + MOCK_METHOD(void, set_user_data, (struct {{ interface.name_underscore }}* {{ interface.name_underscore }}, void* user_data), (override)); + MOCK_METHOD(void*, get_user_data, (struct {{ interface.name_underscore }}* {{ interface.name_underscore }}), (override)); + {%- for method in interface.methods %} - MOCK_METHOD({{ method.ret }}, {{ method.name }}, ({% for arg in method.args %}{{ arg.type }} {{ arg.name }}{% if not loop.last %},{% endif %}{% endfor %}), (override)); + MOCK_METHOD({{ method.ret }}, {{ method.name }}, (struct {{ interface.name_underscore }}* {{ interface.name_underscore }}{% for arg in method.args %}, {{ arg.type }} {{ arg.name }}{% endfor %}), (override)); {% endfor -%} {%- for event in interface.events %} - MOCK_METHOD(void, {{ event.name }}, ({% for arg in event.args %}{{ arg.type }} {{ arg.name }}{% if not loop.last %},{% endif %}{% endfor %}), (override)); + MOCK_METHOD(void, send_{{ event.name }}, (struct wl_resource* resource{% for arg in event.args %}, {{ arg.type }} {{ arg.name }}{% endfor %}), (override)); {% endfor -%} }; {% endfor -%} diff --git a/gen/protocol-shim.h.jinja2 b/gen/protocol-shim.h.jinja2 index 943635b..a560956 100644 --- a/gen/protocol-shim.h.jinja2 +++ b/gen/protocol-shim.h.jinja2 @@ -23,9 +23,9 @@ class {{ interface.name }} { {# Logic comes from wayland scanner -#} {# Stub logic -> https://chromium.googlesource.com/external/wayland/wayland/+/refs/heads/master/src/scanner.c#1007 -#} - virtual void set_user_data(struct {{ interface.name_underscore }} *{{ interface.name_underscore}}, void *user_data); + virtual void set_user_data(struct {{ interface.name_underscore }}* {{ interface.name_underscore}}, void* user_data); - virtual void* get_user_data(struct {{ interface.name_underscore }} *{{ interface.name_underscore }}); + virtual void* get_user_data(struct {{ interface.name_underscore }}* {{ interface.name_underscore }}); {%- for method in interface.methods %} virtual {{ method.ret }} {{ method.name }}( @@ -36,7 +36,7 @@ class {{ interface.name }} { {# Event logic -> https://chromium.googlesource.com/external/wayland/wayland/+/refs/heads/master/src/scanner.c#1074 -#} {%- for event in interface.events %} virtual void send_{{ event.name }}( - struct wl_resource * resource{% for arg in event.args %}, + struct wl_resource* resource{% for arg in event.args %}, {{ arg.type }} {{arg.name}}{% endfor %}); {% endfor -%} };