Skip to content

Commit

Permalink
Add some tests for QByteArray conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Aug 10, 2024
1 parent a4338db commit e4576f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/python/test_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ PYBIND11_MODULE(qt, m)
return QString::number(value);
});

// QByteArray
m.def("create_qbytearray_from_raw", [](const char* raw) {
return QByteArray(raw);
});
m.def("get_qbytearray_length", [](const QByteArray& data) {
return data.size();
});

// QStringList

m.def("qstringlist_join", [](QStringList const& values, QString const& sep) {
Expand Down
10 changes: 9 additions & 1 deletion tests/python/test_qt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from PyQt6.QtCore import QDateTime, Qt
import struct

from PyQt6.QtCore import QByteArray, QDateTime, Qt

import mobase_tests.qt as m

Expand All @@ -23,6 +25,12 @@ def test_qstring():
assert m.consume_qstring_with_emoji("🌎") == 2


def test_qbytearray():
arr = m.create_qbytearray_from_raw("hello world!")
assert isinstance(arr, QByteArray)
assert m.get_qbytearray_length(arr) == 12


def test_qstringlist():
assert m.qstringlist_join([""], "--") == ""
assert m.qstringlist_join(["a", "b"], "") == "ab"
Expand Down
6 changes: 6 additions & 0 deletions typings/mobase_tests/qt.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ __all__ = [
"SimpleEnum",
"consume_qstring_with_emoji",
"create_qstring_with_emoji",
"create_qbytearray_from_raw",
"get_qbytearray_length",
"qbytearray_to_longlong",
"datetime_from_string",
"datetime_to_string",
"int_to_qstring",
Expand Down Expand Up @@ -92,6 +95,9 @@ def qflags_explode(arg0: int) -> tuple[int, bool, bool, bool]: ...
def qmap_to_length(arg0: dict[str, str]) -> dict[str, int]: ...
def qstring_to_int(arg0: str) -> int: ...
def qstring_to_stdstring(arg0: str) -> str: ...
def create_qbytearray_from_raw(arg0: str | bytes) -> PyQt6.QtCore.QByteArray: ...
def get_qbytearray_length(arg0: PyQt6.QtCore.QByteArray) -> int: ...
def qbytearray_to_longlong(arg0: PyQt6.QtCore.QByteArray) -> int: ...
def qstringlist_at(arg0: typing.Sequence[str], arg1: int) -> str: ...
def qstringlist_join(arg0: typing.Sequence[str], arg1: str) -> str: ...
def qvariant_bool() -> MoVariant: ...
Expand Down

0 comments on commit e4576f6

Please sign in to comment.