Skip to content

Commit e049269

Browse files
committed
experiment how to get the protocol types to the qt methods
1 parent 4de5f5f commit e049269

File tree

7 files changed

+78
-5
lines changed

7 files changed

+78
-5
lines changed

libs/probeqt/rpc/create_snapshot.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ exec::task<void> CreateScreenshotRpcHandler::operator()(CreateScreenshotRPC &rpc
2626
grpc::Status{grpc::StatusCode::NOT_FOUND, fmt::format("could not find {}", request.object_id())});
2727
co_return;
2828
}
29-
auto expected_image = co_await stdexec::on(QtStdExec::qThreadAsScheduler(QCoreApplication::instance()->thread()),
30-
take_snapshot(*object));
29+
auto expected_image = co_await stdexec::starts_on(
30+
QtStdExec::qThreadAsScheduler(QCoreApplication::instance()->thread()), take_snapshot(*object));
3131
if (expected_image.has_value())
3232
{
3333
constexpr std::int64_t k4Mb = 4000000;

libs/protocol/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ asio_grpc_protobuf_generate(
1212
"${proto_inc_dir}/keyboard.proto"
1313
"${proto_inc_dir}/mouse.proto"
1414
"${proto_inc_dir}/types.proto"
15+
"${proto_inc_dir}/methods.proto"
1516
)
1617

1718
add_library(quite_protocol_proto STATIC)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
syntax = "proto3";
2+
3+
package quite.proto;
4+
5+
import "quite/proto/types.proto";
6+
7+
message MethodCall {
8+
string method_name = 1;
9+
repeated Value arguments = 2;
10+
};
11+
12+
message MethodReturnValue {
13+
optional Value value = 1;
14+
}

libs/protocol/quite/proto/probe.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "quite/proto/common.proto";
55
import "quite/proto/keyboard.proto";
66
import "quite/proto/mouse.proto";
77
import "quite/proto/types.proto";
8+
import "quite/proto/methods.proto";
89

910
service ProbeService {
1011
rpc Exit(ExitRequest) returns (ExitReponse) {}
@@ -16,6 +17,8 @@ service ProbeService {
1617
rpc CreateScreenshot(ScreenshotRequest) returns (stream ImageResponse) {};
1718

1819
rpc GetViews(GetViewsRequest) returns (GetViewsResponse) {};
20+
21+
rpc InvokeMethod(MethodCallRequest) returns (MethodCallResponse) {};
1922
}
2023

2124
message ExitRequest {};
@@ -77,3 +80,12 @@ message GetViewsRequest {
7780
message GetViewsResponse {
7881
repeated uint64 object_id = 1;
7982
}
83+
84+
message MethodCallRequest {
85+
uint64 object_id = 1;
86+
MethodCall method_call = 2;
87+
}
88+
89+
message MethodCallResponse {
90+
MethodReturnValue return_value = 1;
91+
}

python/quite/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
quite - the (q)t (ui) (te)sting framework. See https://github.com/mathisloge/ng-quite
2+
quite - a ui testing framework. See https://github.com/mathisloge/ng-quite
33
"""
44

55
from __future__ import annotations

python/quite/_quite.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
quite - the (q)t (ui) (te)sting framework. See https://github.com/mathisloge/ng-quite
2+
quite - a ui testing framework. See https://github.com/mathisloge/ng-quite
33
"""
44

55
from __future__ import annotations

test/meta/test_object_registry.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <QObject>
2-
#include <atomic>
32
#include <catch2/catch_test_macros.hpp>
43
#include <entt/meta/factory.hpp>
54
#include <fmt/base.h>
65
#include <qmetaobject.h>
76
#include <quite/proto/types.pb.h>
7+
#include <value_converters.hpp>
88

99
using namespace entt::literals;
1010

@@ -93,6 +93,17 @@ TEST_CASE("Register struct and convert it to a protocol value", "[meta,design-te
9393
class MyOwnClass : public QObject
9494
{
9595
Q_OBJECT
96+
97+
public Q_SLOTS:
98+
quint64 compute(quint64 val1, quint8 val2)
99+
{
100+
return val1 + val2;
101+
}
102+
103+
quint64 compute(float val1, qint8 val2)
104+
{
105+
return val1 * val2;
106+
}
96107
};
97108

98109
TEST_CASE("API DESIGN META RUNTIME")
@@ -102,4 +113,39 @@ TEST_CASE("API DESIGN META RUNTIME")
102113
kMetaType.metaObject()->method(0).parameterType(0);
103114
}
104115

116+
TEST_CASE("Test meta method call")
117+
{
118+
quite::probe::register_converters();
119+
120+
MyOwnClass test_obj{};
121+
122+
QByteArray normalized_signature = QMetaObject::normalizedSignature("compute(float, qint8)");
123+
const auto *meta_object = test_obj.metaObject();
124+
int method_index = meta_object->indexOfMethod(normalized_signature);
125+
126+
for (int i = 0; i < meta_object->methodCount(); i++)
127+
{
128+
qDebug() << meta_object->method(i).name();
129+
}
130+
131+
QMetaMethod method = test_obj.metaObject()->method(method_index);
132+
REQUIRE(method.isValid());
133+
134+
auto &&param1 = method.parameterMetaType(0);
135+
136+
double initial_val{5};
137+
REQUIRE(QMetaType::canConvert(QMetaType::fromType<double>(), QMetaType::fromType<float>()));
138+
auto *val1 = param1.create();
139+
QMetaType::convert(QMetaType::fromType<double>(), &initial_val, param1, val1);
140+
QMetaMethodArgument arg3{.metaType = param1.iface(), .name = param1.name(), .data = val1};
141+
142+
qDebug() << arg3.metaType << arg3.name << arg3.data;
143+
144+
quint64 result{};
145+
auto infoke_result = method.invoke(&test_obj, Qt::DirectConnection, qReturnArg(result), arg3, qint8{5});
146+
147+
REQUIRE(infoke_result);
148+
REQUIRE(result == 25);
149+
}
150+
105151
#include "test_object_registry.moc"

0 commit comments

Comments
 (0)