From 48ea56bf32984ba755591526b1f2a8ab82bc9eff Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 1 Oct 2014 11:32:18 +0200 Subject: [PATCH] Interface Kit tests: add test for BTextControl. * Only tests very basic functionality, and size of the class, which must not change for BeOS compatibility. * Also add "manual" test for disabled and invalid controls (just check it looks right) --- .../kits/interface/InterfaceKitTestAddon.cpp | 2 + src/tests/kits/interface/Jamfile | 2 + .../kits/interface/TextViewTestManual.cpp | 11 ++++++ .../btextcontrol/TextControlTest.cpp | 39 +++++++++++++++++++ .../interface/btextcontrol/TextControlTest.h | 10 +++++ 5 files changed, 64 insertions(+) create mode 100644 src/tests/kits/interface/btextcontrol/TextControlTest.cpp create mode 100644 src/tests/kits/interface/btextcontrol/TextControlTest.h diff --git a/src/tests/kits/interface/InterfaceKitTestAddon.cpp b/src/tests/kits/interface/InterfaceKitTestAddon.cpp index da48c61c0f..f5a556f3a2 100644 --- a/src/tests/kits/interface/InterfaceKitTestAddon.cpp +++ b/src/tests/kits/interface/InterfaceKitTestAddon.cpp @@ -7,6 +7,7 @@ #include "bdeskbar/DeskbarTest.h" #include "bpolygon/PolygonTest.h" #include "bregion/RegionTest.h" +#include "btextcontrol/TextControlTest.h" #include "btextview/TextViewTest.h" //#include "bwidthbuffer/WidthBufferTest.h" #include "GraphicsDefsTest.h" @@ -23,6 +24,7 @@ getTestSuite() suite->addTest("BDeskbar", DeskbarTestSuite()); suite->addTest("BPolygon", PolygonTestSuite()); suite->addTest("BRegion", RegionTestSuite()); + suite->addTest("BTextControl", TextControlTestSuite()); suite->addTest("BTextView", TextViewTestSuite()); //suite->addTest("_BWidthBuffer_", WidthBufferTestSuite()); suite->addTest("GraphicsDefs", GraphicsDefsTestSuite()); diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile index 1e410595f9..f053deef39 100644 --- a/src/tests/kits/interface/Jamfile +++ b/src/tests/kits/interface/Jamfile @@ -11,6 +11,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) bbitmap ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) btextcontrol ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) btextview ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bwindowstack ] ; @@ -50,6 +51,7 @@ UnitTestLib libinterfacetest.so RegionIntersect.cpp RegionOffsetBy.cpp + TextControlTest.cpp TextViewTest.cpp : be [ TargetLibstdc++ ] diff --git a/src/tests/kits/interface/TextViewTestManual.cpp b/src/tests/kits/interface/TextViewTestManual.cpp index 0b1462593d..9bbc0404db 100644 --- a/src/tests/kits/interface/TextViewTestManual.cpp +++ b/src/tests/kits/interface/TextViewTestManual.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,14 @@ Window::Window() { fTextControl = new BTextControl("text-contr-O", "a single line of text - (c) Conglom-O", NULL); + + BTextControl* disabled = new BTextControl("disabled", + "I'm disabled: you can't edit me", NULL); + disabled->SetEnabled(false); + BTextControl* invalid = new BTextControl("invalid", + "I'm invalid: my border is red", NULL); + invalid->MarkAsInvalid(true); + fTextView = new BTextView("text-O"); BScrollView* scrollView = new BScrollView("scroll-O", fTextView, 0, true, true, B_FANCY_BORDER); @@ -51,6 +60,8 @@ Window::Window() SetLayout(new BGroupLayout(B_HORIZONTAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) .Add(fTextControl) + .Add(disabled) + .Add(invalid) .Add(scrollView) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .Add(new BButton("Align Left", new BMessage(kMsgAlignLeft))) diff --git a/src/tests/kits/interface/btextcontrol/TextControlTest.cpp b/src/tests/kits/interface/btextcontrol/TextControlTest.cpp new file mode 100644 index 0000000000..739f13c89f --- /dev/null +++ b/src/tests/kits/interface/btextcontrol/TextControlTest.cpp @@ -0,0 +1,39 @@ +#include "../common.h" + +#include +#include +#include + +class TextControlTestcase: public TestCase { +public: + void + SizeTest() + { + CPPUNIT_ASSERT_EQUAL(312, sizeof(BTextControl)); + } + + void + GetTextTest() + { + BApplication app("application/x-vnd.Haiku-interfacekit-textcontroltest"); + BRect textRect(0, 0, 100, 100); + BTextControl* v = new BTextControl(textRect, "test", 0, 0, 0); + v->SetText("Initial text"); + v->TextView()->Insert(8, "(inserted) ", 10); + CPPUNIT_ASSERT_EQUAL(BString("Initial (inserted)text"), v->Text()); + } +}; + + +Test* +TextControlTestSuite() +{ + TestSuite *testSuite = new TestSuite(); + + testSuite->addTest(new CppUnit::TestCaller( + "BTextControl_Size", &TextControlTestcase::SizeTest)); + testSuite->addTest(new CppUnit::TestCaller( + "BTextControl_GetText", &TextControlTestcase::GetTextTest)); + + return testSuite; +} diff --git a/src/tests/kits/interface/btextcontrol/TextControlTest.h b/src/tests/kits/interface/btextcontrol/TextControlTest.h new file mode 100644 index 0000000000..2c62902819 --- /dev/null +++ b/src/tests/kits/interface/btextcontrol/TextControlTest.h @@ -0,0 +1,10 @@ +#ifndef _text_control_test_h_ +#define _text_control_test_h_ + +class CppUnit::Test; + +CppUnit::Test *TextControlTestSuite(); + +#endif // text_control_test_h_ + +