From f57313518ec2611d2c0bb3c6615e6f964dea9c60 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sun, 5 Apr 2009 22:28:54 +0000 Subject: [PATCH] * added a test for BTextView which exposes a couple of problems with large contents git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29956 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/interface/Jamfile | 5 + src/tests/kits/interface/TextViewTest.cpp | 109 ++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/tests/kits/interface/TextViewTest.cpp diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile index d4695fca59..c1076427a8 100644 --- a/src/tests/kits/interface/Jamfile +++ b/src/tests/kits/interface/Jamfile @@ -147,6 +147,11 @@ SimpleTest SetBorderScrollViewTest : : be ; +SimpleTest TextViewTest : + TextViewTest.cpp + : be + ; + SEARCH on [ FGristFiles ScrollView.cpp CheckBox.cpp ChannelSlider.cpp ChannelControl.cpp Slider.cpp Control.cpp ] = [ FDirName $(HAIKU_TOP) src kits interface ] ; diff --git a/src/tests/kits/interface/TextViewTest.cpp b/src/tests/kits/interface/TextViewTest.cpp new file mode 100644 index 0000000000..be7c533426 --- /dev/null +++ b/src/tests/kits/interface/TextViewTest.cpp @@ -0,0 +1,109 @@ +/* + * Copyright 2009, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include +#include + +#include + + +class Window : public BWindow { + public: + Window(); + + virtual bool QuitRequested(); +}; + + +// #pragma mark - + + +Window::Window() + : BWindow(BRect(100, 100, 800, 500), "TextView-Test", + B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +{ + BRect rect = Bounds().InsetByCopy(20, 20); + + BTextView* textView = new BTextView(rect, "text-o-mo", + rect.OffsetToCopy(0, 0), B_FOLLOW_ALL); + + BScrollView* scrollView = new BScrollView("scroll-o-mo", textView, + B_FOLLOW_ALL_SIDES, 0, true, true); + AddChild(scrollView); + + printf("starting to prepare content ... [%Ld]\n", system_time()); + + // generate a million lines of content + const int32 kLineCount = 1000000; + const int32 kLineNoSize = 6; + BString line + = ": you should see a pretty large text in this textview ...\n"; + BString format = BString("%*d") << line; + BString content; + int32 lineLength = line.Length() + kLineNoSize; + int32 contentLength = lineLength * kLineCount; + char* currLine = content.LockBuffer(contentLength); + if (currLine) { + int32 lineNo = 0; + char buf[10]; + for ( ; lineNo < kLineCount; currLine += lineLength) + sprintf(currLine, format.String(), kLineNoSize, lineNo++); + content.UnlockBuffer(contentLength); + } + printf("setting content ... [%Ld]\n", system_time()); + textView->SetText(content.String()); + printf("done. [%Ld]\n", system_time()); +} + + +bool +Window::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +// #pragma mark - + + +class Application : public BApplication { + public: + Application(); + + virtual void ReadyToRun(void); +}; + + +Application::Application() + : BApplication("application/x-vnd.haiku-test") +{ +} + + +void +Application::ReadyToRun(void) +{ + BWindow *window = new Window(); + window->Show(); +} + + +// #pragma mark - + + +int +main(int argc, char **argv) +{ + Application app; + + app.Run(); + return 0; +} +