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)
This commit is contained in:
Adrien Destugues 2014-10-01 11:32:18 +02:00
parent a8f520f2a8
commit 48ea56bf32
5 changed files with 64 additions and 0 deletions

View File

@ -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());

View File

@ -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++ ]

View File

@ -6,6 +6,7 @@
#include <Application.h>
#include <Button.h>
#include <ControlLook.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <ScrollView.h>
@ -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)))

View File

@ -0,0 +1,39 @@
#include "../common.h"
#include <Application.h>
#include <String.h>
#include <TextControl.h>
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<TextControlTestcase>(
"BTextControl_Size", &TextControlTestcase::SizeTest));
testSuite->addTest(new CppUnit::TestCaller<TextControlTestcase>(
"BTextControl_GetText", &TextControlTestcase::GetTextTest));
return testSuite;
}

View File

@ -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_