1313#include < AUI/Util/UIBuildingHelpers.h>
1414#include < AUI/View/AText.h>
1515#include < AUI/View/AScrollArea.h>
16+ #include < gmock/gmock.h>
1617
1718using namespace ass ;
1819using namespace declarative ;
@@ -22,31 +23,18 @@ class UIText: public testing::UITest {
2223public:
2324 ~UIText () override = default ;
2425
25- protected:
26- void SetUp () override {
27- UITest::SetUp ();
28-
29-
30- auto window = _new<AWindow>();
31- window->setContents (Centered {
32- mText
33- });
34- window->pack ();
35- window->show ();
36- uitest::frame ();
37- }
38-
39- _<AText> mText = AText::fromString(" Привет мир\n вторая строка" );
40-
41-
42- void TearDown () override {
43- UITest::TearDown ();
44- }
4526};
4627
4728
4829TEST_F (UIText, Contents) {
49- auto & entries = mText ->mEngine .entries ();
30+ auto window = _new<AWindow>();
31+ auto text = AText::fromString (" Привет мир\n вторая строка" );
32+ window->setContents (Centered {
33+ text
34+ });
35+ window->pack ();
36+ window->show ();
37+ auto & entries = text->mEngine .entries ();
5038 ASSERT_EQ (entries.size (), 7 );
5139 EXPECT_EQ (AString::fromUtf32 (_cast<AText::WordEntry>(entries[0 ])->getWord ()), " Привет" );
5240 EXPECT_NE (_cast<aui::detail::WhitespaceEntry>(entries[1 ]), nullptr );
@@ -56,3 +44,82 @@ TEST_F(UIText, Contents) {
5644 EXPECT_NE (_cast<aui::detail::WhitespaceEntry>(entries[5 ]), nullptr );
5745 EXPECT_EQ (AString::fromUtf32 (_cast<aui::detail::WordEntry>(entries[6 ])->getWord ()), " строка" );
5846}
47+
48+ namespace {
49+
50+ class ViewMock : public ALabel {
51+ public:
52+ ViewMock (): ALabel(" Test" ) {
53+
54+ }
55+ void setPosition (glm::ivec2 position) override {
56+ if (getPosition () == position) {
57+ return ;
58+ }
59+ ALabel::setPosition (position);
60+ setPosition2 (position.x , position.y );
61+ }
62+
63+ MOCK_METHOD (void , setPosition2, (int x, int y));
64+ };
65+ }
66+
67+ TEST_F (UIText, Basic) {
68+ auto w = _new<AWindow>();
69+ auto mock = _new<ViewMock>();
70+
71+ EXPECT_CALL (
72+ *mock,
73+ setPosition2 (testing::AllOf (testing::Ge (25 ), testing::Le (35 )), testing::AllOf (testing::Ge (0 ), testing::Le (5 )))).Times (1 );
74+
75+ w->setContents (Centered {
76+ AText::fromItems ({
77+ " Hello" , mock, " World" , " Test"
78+ }) AUI_OVERRIDE_STYLE {
79+ FixedSize { 200_dp }
80+ },
81+ });
82+ w->pack ();
83+ w->show ();
84+ }
85+
86+ TEST_F (UIText, Visibility) {
87+ auto w = _new<AWindow>();
88+ _<AView> label = Label { " Hello" };
89+ auto mock = _new<ViewMock>();
90+
91+ testing::InSequence s;
92+
93+ EXPECT_CALL (
94+ *mock,
95+ setPosition2 (testing::AllOf (testing::Ge (25 ), testing::Le (35 )), testing::AllOf (testing::Ge (0 ), testing::Le (5 )))).Times (1 );
96+
97+ w->setContents (Centered {
98+ AText::fromItems ({
99+ label, mock,
100+ }) AUI_OVERRIDE_STYLE {
101+ FixedSize { 200_dp }
102+ },
103+ });
104+ w->pack ();
105+ w->show ();
106+
107+ saveScreenshot (" initial" );
108+
109+ EXPECT_CALL (
110+ *mock,
111+ setPosition2 (testing::AllOf (testing::Ge (0 ), testing::Le (5 )), testing::AllOf (testing::Ge (0 ), testing::Le (5 )))).Times (1 );
112+
113+ label->setVisibility (Visibility::GONE);
114+ uitest::frame ();
115+
116+ saveScreenshot (" label gone" );
117+
118+ EXPECT_CALL (
119+ *mock,
120+ setPosition2 (testing::AllOf (testing::Ge (25 ), testing::Le (35 )), testing::AllOf (testing::Ge (0 ), testing::Le (5 )))).Times (1 );
121+ label->setVisibility (Visibility::VISIBLE);
122+ uitest::frame ();
123+
124+ saveScreenshot (" label visible" );
125+ }
0 commit comments