Skip to content

Commit

Permalink
Interface Kit tests: add test for BTextControl.
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
pulkomandy committed Oct 1, 2014
1 parent a8f520f commit 48ea56b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tests/kits/interface/InterfaceKitTestAddon.cpp
Expand Up @@ -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"
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/tests/kits/interface/Jamfile
Expand Up @@ -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 ] ;

Expand Down Expand Up @@ -50,6 +51,7 @@ UnitTestLib libinterfacetest.so
RegionIntersect.cpp
RegionOffsetBy.cpp

TextControlTest.cpp
TextViewTest.cpp

: be [ TargetLibstdc++ ]
Expand Down
11 changes: 11 additions & 0 deletions src/tests/kits/interface/TextViewTestManual.cpp
Expand Up @@ -6,6 +6,7 @@

#include <Application.h>
#include <Button.h>
#include <ControlLook.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <ScrollView.h>
Expand Down Expand Up @@ -44,13 +45,23 @@ 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);

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)))
Expand Down
39 changes: 39 additions & 0 deletions src/tests/kits/interface/btextcontrol/TextControlTest.cpp
@@ -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;
}
10 changes: 10 additions & 0 deletions 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_


0 comments on commit 48ea56b

Please sign in to comment.