Skip to content

Commit

Permalink
Add qfontmetrics test
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Mar 15, 2024
1 parent 781bd5b commit 0fa3bbf
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/qt_types_standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ add_executable(${APP_NAME}
cpp/qcoreapplication.h
cpp/qdate.h
cpp/qdatetime.h
cpp/qfontmetrics.h
cpp/qguiapplication.h
cpp/qhash.h
cpp/qline.h
Expand Down
2 changes: 2 additions & 0 deletions tests/qt_types_standalone/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "qcoreapplication.h"
#include "qdate.h"
#include "qdatetime.h"
#include "qfontmetrics.h"
#include "qguiapplication.h"
#include "qhash.h"
#include "qline.h"
Expand Down Expand Up @@ -92,6 +93,7 @@ main(int argc, char* argv[])
runTest(QScopedPointer<QObject>(new QVector3DTest));
runTest(QScopedPointer<QObject>(new QVector4DTest));
runTest(QScopedPointer<QObject>(new QPolygonTest));
runTest(QScopedPointer<QObject>(new QFontMetricsTest));

return status;
}
34 changes: 34 additions & 0 deletions tests/qt_types_standalone/cpp/qfontmetrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// clang-format off
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// clang-format on
// SPDX-FileContributor: Laurent Montel <laurent.montel@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

#include <QtGui/QFontMetrics>
#include <QtGui/QFont>
#include <QtTest/QTest>

#include "cxx-qt-gen/qfontmetrics.cxx.h"

class QFontMetricsTest : public QObject
{
Q_OBJECT

private Q_SLOTS:
void construct()
{
}
void clone()
{
QFont f;
f.setBold(true);
f.setPointSize(30);
const auto m = QFontMetrics(f);

const auto c = clone_qfontmetrics(m);
QCOMPARE(m.ascent(), c.ascent());
QCOMPARE(m.height(), c.height());
}
};
1 change: 1 addition & 0 deletions tests/qt_types_standalone/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn main() {
.file("src/qcoreapplication.rs")
.file("src/qdate.rs")
.file("src/qdatetime.rs")
.file("src/qfontmetrics.rs")
.file("src/qguiapplication.rs")
.file("src/qhash.rs")
.file("src/qline.rs")
Expand Down
1 change: 1 addition & 0 deletions tests/qt_types_standalone/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod qcolor;
mod qcoreapplication;
mod qdate;
mod qdatetime;
mod qfontmetrics;
mod qguiapplication;
mod qhash;
mod qline;
Expand Down
23 changes: 23 additions & 0 deletions tests/qt_types_standalone/rust/src/qfontmetrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// SPDX-FileContributor: Laurent Montel <laurent.montel@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

use cxx_qt_lib::QFontMetrics;

#[cxx::bridge]
mod qfontmetrics_cxx {
unsafe extern "C++" {
include!("cxx-qt-lib/qfontmetrics.h");

type QFontMetrics = cxx_qt_lib::QFontMetrics;
}

extern "Rust" {
fn clone_qfontmetrics(f: &QFontMetrics) -> QFontMetrics;
}
}

fn clone_qfontmetrics(p: &QFontMetrics) -> QFontMetrics {
p.clone()
}

0 comments on commit 0fa3bbf

Please sign in to comment.