Make primitive types more precise and add test
parent
75d5406943
commit
8949026c63
|
@ -114,7 +114,7 @@ extern "C" {
|
||||||
Fibonacci::Private* fibonacci_new(Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*));
|
Fibonacci::Private* fibonacci_new(Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*));
|
||||||
void fibonacci_free(Fibonacci::Private*);
|
void fibonacci_free(Fibonacci::Private*);
|
||||||
quint32 fibonacci_input_get(const Fibonacci::Private*);
|
quint32 fibonacci_input_get(const Fibonacci::Private*);
|
||||||
void fibonacci_input_set(Fibonacci::Private*, uint);
|
void fibonacci_input_set(Fibonacci::Private*, quint32);
|
||||||
quint64 fibonacci_result_get(const Fibonacci::Private*);
|
quint64 fibonacci_result_get(const Fibonacci::Private*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -484,8 +484,8 @@ extern "C" {
|
||||||
float processes_data_cpu_usage(const Processes::Private*, quintptr);
|
float processes_data_cpu_usage(const Processes::Private*, quintptr);
|
||||||
quint64 processes_data_memory(const Processes::Private*, quintptr);
|
quint64 processes_data_memory(const Processes::Private*, quintptr);
|
||||||
void processes_data_name(const Processes::Private*, quintptr, QString*, qstring_set);
|
void processes_data_name(const Processes::Private*, quintptr, QString*, qstring_set);
|
||||||
uint processes_data_pid(const Processes::Private*, quintptr);
|
quint32 processes_data_pid(const Processes::Private*, quintptr);
|
||||||
uint processes_data_uid(const Processes::Private*, quintptr);
|
quint32 processes_data_uid(const Processes::Private*, quintptr);
|
||||||
void processes_sort(Processes::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
void processes_sort(Processes::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
|
|
||||||
int processes_row_count(const Processes::Private*, quintptr, bool);
|
int processes_row_count(const Processes::Private*, quintptr, bool);
|
||||||
|
@ -1182,7 +1182,7 @@ quint32 Fibonacci::input() const
|
||||||
{
|
{
|
||||||
return fibonacci_input_get(m_d);
|
return fibonacci_input_get(m_d);
|
||||||
}
|
}
|
||||||
void Fibonacci::setInput(uint v) {
|
void Fibonacci::setInput(quint32 v) {
|
||||||
fibonacci_input_set(m_d, v);
|
fibonacci_input_set(m_d, v);
|
||||||
}
|
}
|
||||||
quint64 Fibonacci::result() const
|
quint64 Fibonacci::result() const
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
explicit Fibonacci(QObject *parent = nullptr);
|
explicit Fibonacci(QObject *parent = nullptr);
|
||||||
~Fibonacci();
|
~Fibonacci();
|
||||||
quint32 input() const;
|
quint32 input() const;
|
||||||
void setInput(uint v);
|
void setInput(quint32 v);
|
||||||
quint64 result() const;
|
quint64 result() const;
|
||||||
signals:
|
signals:
|
||||||
void inputChanged();
|
void inputChanged();
|
||||||
|
|
10
src/cpp.cpp
10
src/cpp.cpp
|
@ -579,10 +579,12 @@ public:
|
||||||
for (auto f: o.functions) {
|
for (auto f: o.functions) {
|
||||||
h << " Q_INVOKABLE " << f.type.name << " " << f.name << "(";
|
h << " Q_INVOKABLE " << f.type.name << " " << f.name << "(";
|
||||||
for (auto a = f.args.begin(); a < f.args.end(); a++) {
|
for (auto a = f.args.begin(); a < f.args.end(); a++) {
|
||||||
h << QString("%1 %2%3").arg(a->type.cppSetType, a->name, a + 1 < f.args.end() ? ", " : "");
|
if (a != f.args.begin()) {
|
||||||
|
h << ", ";
|
||||||
|
}
|
||||||
|
h << QString("%1 %2").arg(a->type.cppSetType, a->name);
|
||||||
}
|
}
|
||||||
h << QString(")%1;")
|
h << QString(")%1;").arg(f.mut ? "" : " const");
|
||||||
.arg(f.mut ? "" : " const");
|
|
||||||
h << endl;
|
h << endl;
|
||||||
}
|
}
|
||||||
if (baseType(o) == "QAbstractItemModel") {
|
if (baseType(o) == "QAbstractItemModel") {
|
||||||
|
@ -739,7 +741,7 @@ void writeFunctionCDecl(QTextStream& cpp, const Function& f, const QString& lcna
|
||||||
} else if (a->type.name == "QByteArray") {
|
} else if (a->type.name == "QByteArray") {
|
||||||
cpp << ", const char*, int";
|
cpp << ", const char*, int";
|
||||||
} else {
|
} else {
|
||||||
cpp << ", " << a->type.rustType;
|
cpp << ", " << a->type.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the return type is QString or QByteArray, append a pointer to the
|
// If the return type is QString or QByteArray, append a pointer to the
|
||||||
|
|
|
@ -68,8 +68,8 @@ QList<BindingTypeProperties>& bindingTypeProperties() {
|
||||||
f.append({
|
f.append({
|
||||||
.type = BindingType::UInt16,
|
.type = BindingType::UInt16,
|
||||||
.name = "quint16",
|
.name = "quint16",
|
||||||
.cppSetType = "uint",
|
.cppSetType = "quint16",
|
||||||
.cSetType = "uint",
|
.cSetType = "quint16",
|
||||||
.rustType = "u16",
|
.rustType = "u16",
|
||||||
.rustTypeInit = "0"
|
.rustTypeInit = "0"
|
||||||
});
|
});
|
||||||
|
@ -84,8 +84,8 @@ QList<BindingTypeProperties>& bindingTypeProperties() {
|
||||||
f.append({
|
f.append({
|
||||||
.type = BindingType::UInt32,
|
.type = BindingType::UInt32,
|
||||||
.name = "quint32",
|
.name = "quint32",
|
||||||
.cppSetType = "uint",
|
.cppSetType = "quint32",
|
||||||
.cSetType = "uint",
|
.cSetType = "quint32",
|
||||||
.rustType = "u32",
|
.rustType = "u32",
|
||||||
.rustTypeInit = "0"
|
.rustTypeInit = "0"
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,6 +30,12 @@ impl PersonTrait for Person {
|
||||||
self.user_name = format!("{}{}", self.user_name, self.user_name);
|
self.user_name = format!("{}{}", self.user_name, self.user_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn append(&mut self, suffix: String, amount: u32) {
|
||||||
|
for _ in 0..amount {
|
||||||
|
self.user_name += &suffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn greet(&self, name: String) -> String {
|
fn greet(&self, name: String) -> String {
|
||||||
format!("Hello {}, my name is {}, how is it going?", name, self.user_name)
|
format!("Hello {}, my name is {}, how is it going?", name, self.user_name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ pub trait PersonTrait {
|
||||||
fn emit(&self) -> &PersonEmitter;
|
fn emit(&self) -> &PersonEmitter;
|
||||||
fn user_name(&self) -> &str;
|
fn user_name(&self) -> &str;
|
||||||
fn set_user_name(&mut self, value: String);
|
fn set_user_name(&mut self, value: String);
|
||||||
|
fn append(&mut self, suffix: String, amount: u32) -> ();
|
||||||
fn double_name(&mut self) -> ();
|
fn double_name(&mut self) -> ();
|
||||||
fn greet(&self, name: String) -> String;
|
fn greet(&self, name: String) -> String;
|
||||||
fn quote(&self, prefix: String, suffix: String) -> String;
|
fn quote(&self, prefix: String, suffix: String) -> String;
|
||||||
|
@ -95,6 +96,15 @@ pub extern "C" fn person_user_name_set(ptr: *mut Person, v: *const c_ushort, len
|
||||||
o.set_user_name(s);
|
o.set_user_name(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn person_append(ptr: *mut Person, suffix_str: *const c_ushort, suffix_len: c_int, amount: u32) -> () {
|
||||||
|
let mut suffix = String::new();
|
||||||
|
set_string_from_utf16(&mut suffix, suffix_str, suffix_len);
|
||||||
|
let o = unsafe { &mut *ptr };
|
||||||
|
let r = o.append(suffix, amount);
|
||||||
|
r
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn person_double_name(ptr: *mut Person) -> () {
|
pub extern "C" fn person_double_name(ptr: *mut Person) -> () {
|
||||||
let o = unsafe { &mut *ptr };
|
let o = unsafe { &mut *ptr };
|
||||||
|
|
|
@ -30,6 +30,7 @@ private slots:
|
||||||
void testStringFunction();
|
void testStringFunction();
|
||||||
void testSimpleFunction();
|
void testSimpleFunction();
|
||||||
void testVoidFunction();
|
void testVoidFunction();
|
||||||
|
void testAppendFunction();
|
||||||
void testQuoteFunction();
|
void testQuoteFunction();
|
||||||
void testQuoteBytesFunction();
|
void testQuoteBytesFunction();
|
||||||
};
|
};
|
||||||
|
@ -61,6 +62,17 @@ void TestRustObject::testVoidFunction()
|
||||||
QCOMPARE(person.userName(), QString("KonqiKonqi"));
|
QCOMPARE(person.userName(), QString("KonqiKonqi"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestRustObject::testAppendFunction()
|
||||||
|
{
|
||||||
|
// GIVEN
|
||||||
|
Person person;
|
||||||
|
person.setUserName("Konqi");
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
person.append("!", 3);
|
||||||
|
QCOMPARE(person.userName(), QString("Konqi!!!"));
|
||||||
|
}
|
||||||
|
|
||||||
void TestRustObject::testQuoteFunction()
|
void TestRustObject::testQuoteFunction()
|
||||||
{
|
{
|
||||||
// GIVEN
|
// GIVEN
|
||||||
|
|
|
@ -30,6 +30,20 @@
|
||||||
"mut": true,
|
"mut": true,
|
||||||
"arguments": []
|
"arguments": []
|
||||||
},
|
},
|
||||||
|
"append": {
|
||||||
|
"return": "void",
|
||||||
|
"mut": true,
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"name": "suffix",
|
||||||
|
"type": "QString"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "amount",
|
||||||
|
"type": "quint32"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"vowelsInName": {
|
"vowelsInName": {
|
||||||
"return": "quint8",
|
"return": "quint8",
|
||||||
"arguments": []
|
"arguments": []
|
||||||
|
|
|
@ -17,6 +17,7 @@ extern "C" {
|
||||||
void person_free(Person::Private*);
|
void person_free(Person::Private*);
|
||||||
void person_user_name_get(const Person::Private*, QString*, qstring_set);
|
void person_user_name_get(const Person::Private*, QString*, qstring_set);
|
||||||
void person_user_name_set(Person::Private*, const ushort *str, int len);
|
void person_user_name_set(Person::Private*, const ushort *str, int len);
|
||||||
|
void person_append(Person::Private*, const ushort*, int, quint32);
|
||||||
void person_double_name(Person::Private*);
|
void person_double_name(Person::Private*);
|
||||||
void person_greet(const Person::Private*, const ushort*, int, QString*, qstring_set);
|
void person_greet(const Person::Private*, const ushort*, int, QString*, qstring_set);
|
||||||
void person_quote(const Person::Private*, const ushort*, int, const ushort*, int, QString*, qstring_set);
|
void person_quote(const Person::Private*, const ushort*, int, const ushort*, int, QString*, qstring_set);
|
||||||
|
@ -53,6 +54,10 @@ QString Person::userName() const
|
||||||
void Person::setUserName(const QString& v) {
|
void Person::setUserName(const QString& v) {
|
||||||
person_user_name_set(m_d, reinterpret_cast<const ushort*>(v.data()), v.size());
|
person_user_name_set(m_d, reinterpret_cast<const ushort*>(v.data()), v.size());
|
||||||
}
|
}
|
||||||
|
void Person::append(const QString& suffix, quint32 amount)
|
||||||
|
{
|
||||||
|
return person_append(m_d, suffix.utf16(), suffix.size(), amount);
|
||||||
|
}
|
||||||
void Person::doubleName()
|
void Person::doubleName()
|
||||||
{
|
{
|
||||||
return person_double_name(m_d);
|
return person_double_name(m_d);
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
~Person();
|
~Person();
|
||||||
QString userName() const;
|
QString userName() const;
|
||||||
void setUserName(const QString& v);
|
void setUserName(const QString& v);
|
||||||
|
Q_INVOKABLE void append(const QString& suffix, quint32 amount);
|
||||||
Q_INVOKABLE void doubleName();
|
Q_INVOKABLE void doubleName();
|
||||||
Q_INVOKABLE QString greet(const QString& name) const;
|
Q_INVOKABLE QString greet(const QString& name) const;
|
||||||
Q_INVOKABLE QString quote(const QString& prefix, const QString& suffix) const;
|
Q_INVOKABLE QString quote(const QString& prefix, const QString& suffix) const;
|
||||||
|
|
|
@ -80,10 +80,10 @@ extern "C" {
|
||||||
bool list_set_data_optional_string_none(List::Private*, int);
|
bool list_set_data_optional_string_none(List::Private*, int);
|
||||||
void list_data_string(const List::Private*, int, QString*, qstring_set);
|
void list_data_string(const List::Private*, int, QString*, qstring_set);
|
||||||
bool list_set_data_string(List::Private*, int, const ushort* s, int len);
|
bool list_set_data_string(List::Private*, int, const ushort* s, int len);
|
||||||
uint list_data_u16(const List::Private*, int);
|
quint16 list_data_u16(const List::Private*, int);
|
||||||
bool list_set_data_u16(List::Private*, int, uint);
|
bool list_set_data_u16(List::Private*, int, quint16);
|
||||||
uint list_data_u32(const List::Private*, int);
|
quint32 list_data_u32(const List::Private*, int);
|
||||||
bool list_set_data_u32(List::Private*, int, uint);
|
bool list_set_data_u32(List::Private*, int, quint32);
|
||||||
quint64 list_data_u64(const List::Private*, int);
|
quint64 list_data_u64(const List::Private*, int);
|
||||||
bool list_set_data_u64(List::Private*, int, quint64);
|
bool list_set_data_u64(List::Private*, int, quint64);
|
||||||
quint8 list_data_u8(const List::Private*, int);
|
quint8 list_data_u8(const List::Private*, int);
|
||||||
|
|
|
@ -146,9 +146,9 @@ extern "C" {
|
||||||
void object_string_get(const Object::Private*, QString*, qstring_set);
|
void object_string_get(const Object::Private*, QString*, qstring_set);
|
||||||
void object_string_set(Object::Private*, const ushort *str, int len);
|
void object_string_set(Object::Private*, const ushort *str, int len);
|
||||||
quint16 object_u16_get(const Object::Private*);
|
quint16 object_u16_get(const Object::Private*);
|
||||||
void object_u16_set(Object::Private*, uint);
|
void object_u16_set(Object::Private*, quint16);
|
||||||
quint32 object_u32_get(const Object::Private*);
|
quint32 object_u32_get(const Object::Private*);
|
||||||
void object_u32_set(Object::Private*, uint);
|
void object_u32_set(Object::Private*, quint32);
|
||||||
quint64 object_u64_get(const Object::Private*);
|
quint64 object_u64_get(const Object::Private*);
|
||||||
void object_u64_set(Object::Private*, quint64);
|
void object_u64_set(Object::Private*, quint64);
|
||||||
quint8 object_u8_get(const Object::Private*);
|
quint8 object_u8_get(const Object::Private*);
|
||||||
|
@ -320,14 +320,14 @@ quint16 Object::u16() const
|
||||||
{
|
{
|
||||||
return object_u16_get(m_d);
|
return object_u16_get(m_d);
|
||||||
}
|
}
|
||||||
void Object::setU16(uint v) {
|
void Object::setU16(quint16 v) {
|
||||||
object_u16_set(m_d, v);
|
object_u16_set(m_d, v);
|
||||||
}
|
}
|
||||||
quint32 Object::u32() const
|
quint32 Object::u32() const
|
||||||
{
|
{
|
||||||
return object_u32_get(m_d);
|
return object_u32_get(m_d);
|
||||||
}
|
}
|
||||||
void Object::setU32(uint v) {
|
void Object::setU32(quint32 v) {
|
||||||
object_u32_set(m_d, v);
|
object_u32_set(m_d, v);
|
||||||
}
|
}
|
||||||
quint64 Object::u64() const
|
quint64 Object::u64() const
|
||||||
|
|
|
@ -63,9 +63,9 @@ public:
|
||||||
QString string() const;
|
QString string() const;
|
||||||
void setString(const QString& v);
|
void setString(const QString& v);
|
||||||
quint16 u16() const;
|
quint16 u16() const;
|
||||||
void setU16(uint v);
|
void setU16(quint16 v);
|
||||||
quint32 u32() const;
|
quint32 u32() const;
|
||||||
void setU32(uint v);
|
void setU32(quint32 v);
|
||||||
quint64 u64() const;
|
quint64 u64() const;
|
||||||
void setU64(quint64 v);
|
void setU64(quint64 v);
|
||||||
quint8 u8() const;
|
quint8 u8() const;
|
||||||
|
|
Loading…
Reference in New Issue