Adding test that shows that B_TRUNCATE_BEGINNING mode is essentially broken.

Worse yet for a small enough length it actually crashes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35379 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2010-02-01 13:39:06 +00:00
parent d66b223341
commit 8806dfd057
2 changed files with 70 additions and 0 deletions
+5
View File
@@ -117,6 +117,11 @@ SimpleTest SliderTest :
: be $(TARGET_LIBSUPC++)
;
SimpleTest TruncateString :
TruncateString.cpp
: be $(TARGET_LIBSUPC++)
;
SimpleTest MenuBeginningTest :
MenuBeginningTest.cpp
: be $(TARGET_LIBSUPC++)
@@ -0,0 +1,65 @@
#include <stdio.h>
#include <SupportDefs.h>
#include <Application.h>
#include <String.h>
#include <View.h>
#include <Window.h>
class TruncateView : public BView {
public:
TruncateView(BRect frame)
: BView(frame, "TruncateView", B_FOLLOW_ALL, B_WILL_DRAW)
{
}
void Draw(BRect updateRect)
{
const float kSpacing = 20.0;
const float kTopOffset = kSpacing + 5;
const uint32 kTruncateModes[]
= { B_TRUNCATE_BEGINNING, B_TRUNCATE_MIDDLE, B_TRUNCATE_END };
const uint32 kTruncateModeCount
= sizeof(kTruncateModes) / sizeof(kTruncateModes[0]);
BString theString("ö-ä-ü");
BPoint point(10, kTopOffset);
BString truncated;
for (float length = 25; length < 50; length += 5) {
SetHighColor(255, 0, 0);
StrokeRect(BRect(point.x, point.y - kSpacing, point.x + length,
point.y + kSpacing * (kTruncateModeCount - 1)));
SetHighColor(0, 0, 0);
for (uint32 i = 0; i < kTruncateModeCount; i++) {
truncated = theString;
TruncateString(&truncated, kTruncateModes[i], length);
DrawString(truncated.String(), point);
point.y += kSpacing;
}
point.x += length + kSpacing;
point.y = kTopOffset;
}
}
};
int
main(int argc, char *argv[])
{
BApplication app("application/x-vnd.Haiku-TruncateString");
BRect frame(200, 200, 600, 400);
BWindow *window = new BWindow(frame, "TruncateString", B_TITLED_WINDOW,
B_QUIT_ON_WINDOW_CLOSE);
TruncateView *view = new TruncateView(frame.OffsetToSelf(0, 0));
window->AddChild(view);
window->Show();
app.Run();
return 0;
}