|  | 
|  | 1 | +#include <gtest/gtest.h> | 
|  | 2 | +#include <QQmlEngine> | 
|  | 3 | +#include <QPushButton> | 
|  | 4 | +#include <QQuickItem> | 
|  | 5 | +#include <QSignalSpy> | 
|  | 6 | + | 
|  | 7 | +#include "internal/uiengine.h" | 
|  | 8 | + | 
|  | 9 | +using namespace scratchcpp::ui; | 
|  | 10 | + | 
|  | 11 | +TEST(UiEngineTest, Instance) | 
|  | 12 | +{ | 
|  | 13 | + ASSERT_TRUE(UiEngine::instance()); | 
|  | 14 | +} | 
|  | 15 | + | 
|  | 16 | +TEST(UiEngineTest, QmlEngine) | 
|  | 17 | +{ | 
|  | 18 | + UiEngine engine; | 
|  | 19 | + ASSERT_EQ(engine.qmlEngine(), nullptr); | 
|  | 20 | + | 
|  | 21 | + QQmlEngine qmlEngine; | 
|  | 22 | + engine.setQmlEngine(&qmlEngine); | 
|  | 23 | + ASSERT_EQ(engine.qmlEngine(), &qmlEngine); | 
|  | 24 | +} | 
|  | 25 | + | 
|  | 26 | +TEST(UiEngineTest, StandardButtonText) | 
|  | 27 | +{ | 
|  | 28 | + static const std::vector<QDialogButtonBox::StandardButton> buttons = { | 
|  | 29 | + QDialogButtonBox::Ok, QDialogButtonBox::Open, QDialogButtonBox::Save, | 
|  | 30 | + QDialogButtonBox::Cancel, QDialogButtonBox::Close, QDialogButtonBox::Discard, | 
|  | 31 | + QDialogButtonBox::Apply, QDialogButtonBox::Reset, QDialogButtonBox::RestoreDefaults, | 
|  | 32 | + QDialogButtonBox::Help, QDialogButtonBox::SaveAll, QDialogButtonBox::Yes, | 
|  | 33 | + QDialogButtonBox::YesToAll, QDialogButtonBox::No, QDialogButtonBox::NoToAll, | 
|  | 34 | + QDialogButtonBox::Abort, QDialogButtonBox::Retry, QDialogButtonBox::Ignore | 
|  | 35 | + }; | 
|  | 36 | + | 
|  | 37 | + UiEngine engine; | 
|  | 38 | + QDialogButtonBox dialogButtonBox; | 
|  | 39 | + | 
|  | 40 | + for (QDialogButtonBox::StandardButton button : buttons) { | 
|  | 41 | + dialogButtonBox.addButton(button); | 
|  | 42 | + ASSERT_EQ(engine.standardButtonText(button), dialogButtonBox.button(button)->text()); | 
|  | 43 | + ASSERT_FALSE(engine.standardButtonText(button).isEmpty()); | 
|  | 44 | + } | 
|  | 45 | +} | 
|  | 46 | + | 
|  | 47 | +TEST(UiEngineTest, ActiveFocusItem) | 
|  | 48 | +{ | 
|  | 49 | + UiEngine engine; | 
|  | 50 | + QSignalSpy spy(&engine, &UiEngine::activeFocusItemChanged); | 
|  | 51 | + ASSERT_EQ(engine.activeFocusItem(), nullptr); | 
|  | 52 | + | 
|  | 53 | + QQuickItem item; | 
|  | 54 | + engine.setActiveFocusItem(&item); | 
|  | 55 | + ASSERT_EQ(engine.activeFocusItem(), &item); | 
|  | 56 | + ASSERT_EQ(spy.count(), 1); | 
|  | 57 | +} | 
0 commit comments