From 8dd5c3f974dbad5cd672c44d2c746126d8e09ebb Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 22 Feb 2008 22:30:34 +0000 Subject: [PATCH] Refactored BWidthBuffer test into something more useful. Looks like the class has some problems (hangs while calculating width of lines inside termcap, cf bug #1690 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24070 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/interface/Jamfile | 13 +-- src/tests/kits/interface/WidthBufferTest.cpp | 89 +++++++++++++++++++ .../bwidthbuffer/WidthBufferSimpleTest.cpp | 82 ----------------- .../bwidthbuffer/WidthBufferSimpleTest.h | 19 ---- .../bwidthbuffer/WidthBufferTest.cpp | 14 --- .../interface/bwidthbuffer/WidthBufferTest.h | 8 -- 6 files changed, 96 insertions(+), 129 deletions(-) create mode 100644 src/tests/kits/interface/WidthBufferTest.cpp delete mode 100644 src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.cpp delete mode 100644 src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.h delete mode 100644 src/tests/kits/interface/bwidthbuffer/WidthBufferTest.cpp delete mode 100644 src/tests/kits/interface/bwidthbuffer/WidthBufferTest.h diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile index f774df5423..5f00788ed7 100644 --- a/src/tests/kits/interface/Jamfile +++ b/src/tests/kits/interface/Jamfile @@ -11,7 +11,6 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) bbitmap ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bdeskbar ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bpolygon ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) bregion ] ; -SEARCH_SOURCE += [ FDirName $(SUBDIR) bwidthbuffer ] ; SEARCH_SOURCE += [ FDirName $(TOP) src kits interface ] ; @@ -48,11 +47,7 @@ UnitTestLib libinterfacetest.so RegionInclude.cpp RegionIntersect.cpp RegionOffsetBy.cpp - - #_BWidthBuffer_ - WidthBufferTest.cpp - WidthBufferSimpleTest.cpp - + : be $(TARGET_LIBSTDC++) ; @@ -128,6 +123,12 @@ Application MenuTriggerTest : : be ; + +SimpleTest WidthBufferTest : + WidthBufferTest.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/WidthBufferTest.cpp b/src/tests/kits/interface/WidthBufferTest.cpp new file mode 100644 index 0000000000..8856c9ffa8 --- /dev/null +++ b/src/tests/kits/interface/WidthBufferTest.cpp @@ -0,0 +1,89 @@ +/* +** Copyright 2008, Stefano Ceccherini (stefano.ceccherini@gmail.com). +** All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + +#include +#include + +#include +#include + +#include + + +class App : public BApplication { +public: + App(); + ~App(); + virtual void ReadyToRun(); + +private: + _BWidthBuffer_ *fWidthBuffer; + thread_id fThread; + + int32 TesterFunc(); + static int32 _thread(void *data); + +}; + + +int main() +{ + App app; + app.Run(); + return 0; +} + + +App::App() + :BApplication("application/x-vnd-WidthBufferTest") +{ + fWidthBuffer = new _BWidthBuffer_; + fThread = spawn_thread(App::_thread, "widthbuffer tester", + B_NORMAL_PRIORITY, this); +} + + +void +App::ReadyToRun() +{ + resume_thread(fThread); +} + + +App::~App() +{ + status_t status; + wait_for_thread(fThread, &status); + delete fWidthBuffer; +} + + +int32 +App::TesterFunc() +{ + FILE *file = fopen("/boot/beos/etc/termcap", "r"); + if (file != NULL) { + char buffer[512]; + while (fgets(buffer, 512, file)) { + float width = fWidthBuffer->StringWidth(buffer, 0, + strlen(buffer), be_plain_font); + printf("string: %s, width: %f\n", buffer, width); + } + fclose(file); + } + + PostMessage(B_QUIT_REQUESTED); + + return 0; +} + + +int32 +App::_thread(void *data) +{ + return static_cast(data)->TesterFunc(); +} + diff --git a/src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.cpp b/src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.cpp deleted file mode 100644 index b545714511..0000000000 --- a/src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "WidthBufferSimpleTest.h" -#include "cppunit/TestCaller.h" - -#include -#include - -#include - -// Needed because it isn't available in beos headers -double round(float n) -{ - int32 tmp = (int32)floor(n + 0.5); - return (double)tmp; -} - - -WidthBufferSimpleTest::WidthBufferSimpleTest(std::string name) : - BTestCase(name) -{ - fWidthBuffer = new _BWidthBuffer_; -} - - - -WidthBufferSimpleTest::~WidthBufferSimpleTest() -{ - delete fWidthBuffer; -} - - -void -WidthBufferSimpleTest::PerformTest(void) -{ - const char *str = "Something"; - const char *str2 = "Some Text"; - const char *longString = "ABCDEFGHIJKLMNOPQRSTUVYXWZ abcdefghijklmnopqrstuvwyxz"; - - // Some charachters which takes more than one byte - const char *str3 = "30u8g 2342 42nfrç°S£^GF°W§|£^?£ç$£!1ààà'ì"; - - const BFont *font = be_plain_font; - - // We use round() here because the width returned by - // _BWidthBuffer_::StringWidth() isn't _exactly_ the same - // as the one returned by BFont::StringWidth(); - float width = fWidthBuffer->StringWidth(str, 0, strlen(str), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(str)); - - width = fWidthBuffer->StringWidth(str2, 0, strlen(str2), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(str2)); - - width = fWidthBuffer->StringWidth(longString, 0, strlen(longString), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(longString)); - - // pass the first string again, it should be completely cached - // in _BWidthBuffer_'s hash table - width = fWidthBuffer->StringWidth(str, 0, strlen(str), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(str)); - - width = fWidthBuffer->StringWidth(str3, 0, strlen(str3), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(str3)); - - // choose a different font and ask the same strings as before - font = be_fixed_font; - width = fWidthBuffer->StringWidth(longString, 0, strlen(longString), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(longString)); - - width = fWidthBuffer->StringWidth(str, 0, strlen(str), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(str)); - - width = fWidthBuffer->StringWidth(str2, 0, strlen(str2), font); - CPPUNIT_ASSERT(round(width) == font->StringWidth(str2)); -} - - -CppUnit::Test *WidthBufferSimpleTest::suite(void) -{ - typedef CppUnit::TestCaller - WidthBufferSimpleTestCaller; - - return(new WidthBufferSimpleTestCaller("_BWidthBuffer_::Simple Test", &WidthBufferSimpleTest::PerformTest)); -} diff --git a/src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.h b/src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.h deleted file mode 100644 index 14337faa9d..0000000000 --- a/src/tests/kits/interface/bwidthbuffer/WidthBufferSimpleTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __WidthBufferSIMPLETest_H -#define __WidthBufferSIMPLETest_H - -#include "TestCase.h" -#include - -class WidthBufferSimpleTest : public BTestCase -{ -public: - static Test *suite(void); - void PerformTest(void); - WidthBufferSimpleTest(std::string name = ""); - virtual ~WidthBufferSimpleTest(); - -private: - _BWidthBuffer_ *fWidthBuffer; -}; - -#endif diff --git a/src/tests/kits/interface/bwidthbuffer/WidthBufferTest.cpp b/src/tests/kits/interface/bwidthbuffer/WidthBufferTest.cpp deleted file mode 100644 index 65a3b901e3..0000000000 --- a/src/tests/kits/interface/bwidthbuffer/WidthBufferTest.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "cppunit/Test.h" -#include "cppunit/TestSuite.h" -#include "WidthBufferTest.h" -#include "WidthBufferSimpleTest.h" - - -CppUnit::Test *WidthBufferTestSuite() -{ - CppUnit::TestSuite *testSuite = new CppUnit::TestSuite(); - - testSuite->addTest(WidthBufferSimpleTest::suite()); - - return testSuite; -} diff --git a/src/tests/kits/interface/bwidthbuffer/WidthBufferTest.h b/src/tests/kits/interface/bwidthbuffer/WidthBufferTest.h deleted file mode 100644 index 6954d8f3e4..0000000000 --- a/src/tests/kits/interface/bwidthbuffer/WidthBufferTest.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __WIDTHBUFFER_TEST_H -#define __WIDTHBUFFER_TEST_H - -class CppUnit::Test; - -CppUnit::Test *WidthBufferTestSuite(); - -#endif __WIDTHBUFFER_TEST_H