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
99using namespace entt ::literals;
1010
@@ -93,6 +93,17 @@ TEST_CASE("Register struct and convert it to a protocol value", "[meta,design-te
9393class 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
98109TEST_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 &¶m1 = 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