Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
vm_tools: Fixes sommelier autogen issues
Browse files Browse the repository at this point in the history
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 <[email protected]>
Auto-Submit: Justin Huang <[email protected]>
Commit-Queue: Chloe Pelling <[email protected]>
Reviewed-by: Chloe Pelling <[email protected]>
  • Loading branch information
Justin Huang authored and Chromeos LUCI committed Apr 13, 2023
1 parent 8180f85 commit 74d15b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions gen-shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions gen/mock-protocol-shim.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down
6 changes: 3 additions & 3 deletions gen/protocol-shim.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}(
Expand All @@ -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 -%}
};
Expand Down

0 comments on commit 74d15b3

Please sign in to comment.