Add some cppunit-based tests for BTextView.
Note that this does not reproduce #8447. I could not get more precise details from involved people about how to reproduce this, and the patch was already applied anyway, so I'm stopping my investigation for now. Feel free to complete this with more test cases.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "bdeskbar/DeskbarTest.h"
|
#include "bdeskbar/DeskbarTest.h"
|
||||||
#include "bpolygon/PolygonTest.h"
|
#include "bpolygon/PolygonTest.h"
|
||||||
#include "bregion/RegionTest.h"
|
#include "bregion/RegionTest.h"
|
||||||
|
#include "btextview/TextViewTest.h"
|
||||||
//#include "bwidthbuffer/WidthBufferTest.h"
|
//#include "bwidthbuffer/WidthBufferTest.h"
|
||||||
#include "GraphicsDefsTest.h"
|
#include "GraphicsDefsTest.h"
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ getTestSuite()
|
|||||||
suite->addTest("BDeskbar", DeskbarTestSuite());
|
suite->addTest("BDeskbar", DeskbarTestSuite());
|
||||||
suite->addTest("BPolygon", PolygonTestSuite());
|
suite->addTest("BPolygon", PolygonTestSuite());
|
||||||
suite->addTest("BRegion", RegionTestSuite());
|
suite->addTest("BRegion", RegionTestSuite());
|
||||||
|
suite->addTest("BTextView", TextViewTestSuite());
|
||||||
//suite->addTest("_BWidthBuffer_", WidthBufferTestSuite());
|
//suite->addTest("_BWidthBuffer_", WidthBufferTestSuite());
|
||||||
suite->addTest("GraphicsDefs", GraphicsDefsTestSuite());
|
suite->addTest("GraphicsDefs", GraphicsDefsTestSuite());
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) bbitmap ] ;
|
|||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ;
|
||||||
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) btextview ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) bwindowstack ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) bwindowstack ] ;
|
||||||
|
|
||||||
SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ;
|
SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ;
|
||||||
@@ -49,6 +50,8 @@ UnitTestLib libinterfacetest.so
|
|||||||
RegionIntersect.cpp
|
RegionIntersect.cpp
|
||||||
RegionOffsetBy.cpp
|
RegionOffsetBy.cpp
|
||||||
|
|
||||||
|
TextViewTest.cpp
|
||||||
|
|
||||||
: be [ TargetLibstdc++ ]
|
: be [ TargetLibstdc++ ]
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -164,7 +167,7 @@ SimpleTest SetBorderScrollViewTest :
|
|||||||
;
|
;
|
||||||
|
|
||||||
SimpleTest TextViewTest :
|
SimpleTest TextViewTest :
|
||||||
TextViewTest.cpp
|
TextViewTestManual.cpp
|
||||||
: be [ TargetLibsupc++ ]
|
: be [ TargetLibsupc++ ]
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -174,7 +177,8 @@ SimpleTest WindowStackTest :
|
|||||||
;
|
;
|
||||||
|
|
||||||
SEARCH on [ FGristFiles
|
SEARCH on [ FGristFiles
|
||||||
ScrollView.cpp CheckBox.cpp ChannelSlider.cpp ChannelControl.cpp Slider.cpp Control.cpp
|
ScrollView.cpp CheckBox.cpp ChannelSlider.cpp ChannelControl.cpp
|
||||||
|
Slider.cpp Control.cpp
|
||||||
] = [ FDirName $(HAIKU_TOP) src kits interface ] ;
|
] = [ FDirName $(HAIKU_TOP) src kits interface ] ;
|
||||||
|
|
||||||
SubInclude HAIKU_TOP src tests kits interface bprintjob ;
|
SubInclude HAIKU_TOP src tests kits interface bprintjob ;
|
||||||
|
|||||||
+155
-162
@@ -1,162 +1,155 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
|
* Copyright 2009, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <GroupLayout.h>
|
#include <GroupLayout.h>
|
||||||
#include <GroupLayoutBuilder.h>
|
#include <GroupLayoutBuilder.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
const static uint32 kMsgAlignLeft = 'alle';
|
const static uint32 kMsgAlignLeft = 'alle';
|
||||||
const static uint32 kMsgAlignCenter = 'alce';
|
const static uint32 kMsgAlignCenter = 'alce';
|
||||||
const static uint32 kMsgAlignRight = 'alri';
|
const static uint32 kMsgAlignRight = 'alri';
|
||||||
|
|
||||||
|
|
||||||
class Window : public BWindow {
|
class Window : public BWindow {
|
||||||
public:
|
public:
|
||||||
Window();
|
Window();
|
||||||
|
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BTextControl* fTextControl;
|
BTextControl* fTextControl;
|
||||||
BTextView* fTextView;
|
BTextView* fTextView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
Window::Window()
|
Window::Window()
|
||||||
: BWindow(BRect(100, 100, 800, 500), "TextView-Test",
|
: BWindow(BRect(100, 100, 800, 500), "TextView-Test",
|
||||||
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||||
{
|
{
|
||||||
fTextControl = new BTextControl("text-contr-O",
|
fTextControl = new BTextControl("text-contr-O",
|
||||||
"a single line of text - (c) Conglom-O", NULL);
|
"a single line of text - (c) Conglom-O", NULL);
|
||||||
fTextView = new BTextView("text-O");
|
fTextView = new BTextView("text-O");
|
||||||
BScrollView* scrollView = new BScrollView("scroll-O", fTextView, 0, true,
|
BScrollView* scrollView = new BScrollView("scroll-O", fTextView, 0, true,
|
||||||
true, B_FANCY_BORDER);
|
true, B_FANCY_BORDER);
|
||||||
|
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
|
||||||
.Add(fTextControl)
|
.Add(fTextControl)
|
||||||
.Add(scrollView)
|
.Add(scrollView)
|
||||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
|
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
|
||||||
.Add(new BButton("Align Left", new BMessage(kMsgAlignLeft)))
|
.Add(new BButton("Align Left", new BMessage(kMsgAlignLeft)))
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(new BButton("Align Center", new BMessage(kMsgAlignCenter)))
|
.Add(new BButton("Align Center", new BMessage(kMsgAlignCenter)))
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(new BButton("Align Right", new BMessage(kMsgAlignRight)))
|
.Add(new BButton("Align Right", new BMessage(kMsgAlignRight)))
|
||||||
)
|
)
|
||||||
.SetInsets(5, 5, 5, 5)
|
.SetInsets(5, 5, 5, 5)
|
||||||
);
|
);
|
||||||
|
|
||||||
// generate some lines of content
|
// generate some lines of content
|
||||||
const int32 kLineCount = 10;
|
const int32 kLineCount = 10;
|
||||||
const int32 kLineNoSize = 6;
|
const int32 kLineNoSize = 6;
|
||||||
BString line = ": just some text here - nothing special to see\n";
|
BString line = ": just some text here - nothing special to see\n";
|
||||||
BString format = BString("%*d") << line;
|
BString format = BString("%*d") << line;
|
||||||
BString content;
|
BString content;
|
||||||
int32 lineLength = line.Length() + kLineNoSize;
|
int32 lineLength = line.Length() + kLineNoSize;
|
||||||
int32 contentLength = lineLength * kLineCount;
|
int32 contentLength = lineLength * kLineCount;
|
||||||
char* currLine = content.LockBuffer(contentLength);
|
char* currLine = content.LockBuffer(contentLength);
|
||||||
if (currLine) {
|
if (currLine) {
|
||||||
int32 lineNo = 0;
|
int32 lineNo = 0;
|
||||||
for ( ; lineNo < kLineCount; currLine += lineLength)
|
for ( ; lineNo < kLineCount; currLine += lineLength)
|
||||||
sprintf(currLine, format.String(), kLineNoSize, lineNo++);
|
sprintf(currLine, format.String(), kLineNoSize, lineNo++);
|
||||||
content.UnlockBuffer(contentLength);
|
content.UnlockBuffer(contentLength);
|
||||||
}
|
}
|
||||||
fTextView->SetInsets(2,2,2,2);
|
fTextView->SetInsets(2,2,2,2);
|
||||||
fTextView->SetText(content.String());
|
fTextView->SetText(content.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Window::QuitRequested()
|
Window::QuitRequested()
|
||||||
{
|
{
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Window::MessageReceived(BMessage *message)
|
Window::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgAlignLeft:
|
case kMsgAlignLeft:
|
||||||
fTextControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
|
fTextControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
|
||||||
fTextView->SetAlignment(B_ALIGN_LEFT);
|
fTextView->SetAlignment(B_ALIGN_LEFT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgAlignCenter:
|
case kMsgAlignCenter:
|
||||||
fTextControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_CENTER);
|
fTextControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_CENTER);
|
||||||
fTextView->SetAlignment(B_ALIGN_CENTER);
|
fTextView->SetAlignment(B_ALIGN_CENTER);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgAlignRight:
|
case kMsgAlignRight:
|
||||||
fTextControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
|
fTextControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
|
||||||
fTextView->SetAlignment(B_ALIGN_RIGHT);
|
fTextView->SetAlignment(B_ALIGN_RIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
class Application : public BApplication {
|
class Application : public BApplication {
|
||||||
public:
|
public:
|
||||||
Application();
|
Application();
|
||||||
|
|
||||||
virtual void ReadyToRun(void);
|
virtual void ReadyToRun(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Application::Application()
|
Application::Application()
|
||||||
: BApplication("application/x-vnd.haiku-test")
|
: BApplication("application/x-vnd.haiku-test")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Application::ReadyToRun(void)
|
Application::ReadyToRun(void)
|
||||||
{
|
{
|
||||||
BWindow *window = new Window();
|
BWindow *window = new Window();
|
||||||
window->Show();
|
window->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Application app;
|
Application app;
|
||||||
|
|
||||||
const int kExpectedTextViewSize = 356;
|
app.Run();
|
||||||
if (sizeof(BTextView) != kExpectedTextViewSize) {
|
return 0;
|
||||||
fprintf(stderr, "sizeof(BTextView) is %ld instead of %d!\n",
|
}
|
||||||
sizeof(BTextView), kExpectedTextViewSize);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
app.Run();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <TextView.h>
|
||||||
|
|
||||||
|
class TextViewTestcase: public TestCase {
|
||||||
|
public:
|
||||||
|
void
|
||||||
|
SizeTest()
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT_EQUAL(356, sizeof(BTextView));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GetTextTest()
|
||||||
|
{
|
||||||
|
BApplication app("application/x-vnd.Haiku-interfacekit-textviewtest");
|
||||||
|
BRect textRect(0, 0, 100, 100);
|
||||||
|
BTextView* v = new BTextView(textRect, "test", textRect, 0, 0);
|
||||||
|
v->SetText("Initial text");
|
||||||
|
v->Insert(8, "(inserted) ", 10);
|
||||||
|
char buffer[12];
|
||||||
|
v->GetText(2, 11, buffer);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(BString("itial (inse"), buffer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Test*
|
||||||
|
TextViewTestSuite()
|
||||||
|
{
|
||||||
|
TestSuite *testSuite = new TestSuite();
|
||||||
|
|
||||||
|
testSuite->addTest(new CppUnit::TestCaller<TextViewTestcase>(
|
||||||
|
"BTextView_Size", &TextViewTestcase::SizeTest));
|
||||||
|
testSuite->addTest(new CppUnit::TestCaller<TextViewTestcase>(
|
||||||
|
"BTextView_GetText", &TextViewTestcase::GetTextTest));
|
||||||
|
|
||||||
|
return testSuite;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _text_view_test_h_
|
||||||
|
#define _text_view_test_h_
|
||||||
|
|
||||||
|
class CppUnit::Test;
|
||||||
|
|
||||||
|
CppUnit::Test *TextViewTestSuite();
|
||||||
|
|
||||||
|
#endif // text_view_test_h_
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user