Some tests for _BWidthBuffer_
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7017 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "bdeskbar/DeskbarTest.h"
|
||||
#include "bpolygon/PolygonTest.h"
|
||||
#include "bregion/RegionTest.h"
|
||||
#include "bwidthbuffer/WidthBufferTest.h"
|
||||
|
||||
BTestSuite* getTestSuite() {
|
||||
BTestSuite *suite = new BTestSuite("Interface");
|
||||
@@ -15,6 +16,7 @@ BTestSuite* getTestSuite() {
|
||||
suite->addTest("BDeskbar", DeskbarTestSuite());
|
||||
suite->addTest("BPolygon", PolygonTestSuite());
|
||||
suite->addTest("BRegion", RegionTestSuite());
|
||||
suite->addTest("_BWidthBuffer_", WidthBufferTestSuite());
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
SubDir OBOS_TOP src tests kits interface ;
|
||||
|
||||
UsePrivateHeaders interface ;
|
||||
|
||||
# Let Jam know where to find some of our source files
|
||||
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 ] ;
|
||||
|
||||
@@ -37,6 +40,10 @@ CommonTestLib libinterfacetest.so
|
||||
RegionIntersect.cpp
|
||||
RegionOffsetBy.cpp
|
||||
|
||||
#_BWidthBuffer_
|
||||
WidthBufferTest.cpp
|
||||
WidthBufferSimpleTest.cpp
|
||||
|
||||
: <boot!home!config!lib>libopenbeos.so
|
||||
be stdc++.r4
|
||||
: be stdc++.r4
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "WidthBufferSimpleTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
|
||||
#include <Application.h>
|
||||
#include <Font.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// 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<WidthBufferSimpleTest>
|
||||
WidthBufferSimpleTestCaller;
|
||||
|
||||
return(new WidthBufferSimpleTestCaller("_BWidthBuffer_::Simple Test", &WidthBufferSimpleTest::PerformTest));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef __WidthBufferSIMPLETest_H
|
||||
#define __WidthBufferSIMPLETest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <WidthBuffer.h>
|
||||
|
||||
class WidthBufferSimpleTest : public BTestCase
|
||||
{
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
WidthBufferSimpleTest(std::string name = "");
|
||||
virtual ~WidthBufferSimpleTest();
|
||||
|
||||
private:
|
||||
_BWidthBuffer_ *fWidthBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef __WIDTHBUFFER_TEST_H
|
||||
#define __WIDTHBUFFER_TEST_H
|
||||
|
||||
class CppUnit::Test;
|
||||
|
||||
CppUnit::Test *WidthBufferTestSuite();
|
||||
|
||||
#endif __WIDTHBUFFER_TEST_H
|
||||
Reference in New Issue
Block a user