Created structures to make it much easier to test BAlert's various options.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11162 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ea9716dc6e
commit
855c5b57b8
@ -3,24 +3,250 @@
|
||||
#include <cppunit/Test.h>
|
||||
#include <cppunit/TestCaller.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Application.h>
|
||||
#include <Alert.h>
|
||||
#include <Point.h>
|
||||
#include <TextView.h>
|
||||
#include <Button.h>
|
||||
#include <Rect.h>
|
||||
|
||||
#define ASSERT_DEQUAL(x,y) CPPUNIT_ASSERT_DOUBLES_EQUAL((x),(y),0.01)
|
||||
|
||||
// Required by CPPUNIT_ASSERT_EQUAL(rgb_color, rgb_color)
|
||||
bool operator==(const rgb_color &left, const rgb_color &right)
|
||||
{
|
||||
if (left.red == right.red && left.green == right.green &&
|
||||
left.blue == right.blue && left.alpha == right.alpha)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
// Required by CPPUNIT_ASSERT_EQUAL(rgb_color, rgb_color)
|
||||
ostream &operator<<(ostream &stream, const rgb_color &clr)
|
||||
{
|
||||
return stream << "rgb_color(" << clr.red << ", " <<
|
||||
clr.green << ", " << clr.blue << ", " << clr.alpha << ")";
|
||||
}
|
||||
|
||||
// For storing expected state of windows or views.
|
||||
struct GuiInfo {
|
||||
const char* label;
|
||||
float width;
|
||||
float height;
|
||||
BPoint topleft;
|
||||
};
|
||||
|
||||
// For storing all the information required to create and
|
||||
// verify the state of a BAlert object.
|
||||
class AlertTestInfo {
|
||||
public:
|
||||
AlertTestInfo(AlertTest *pTest);
|
||||
~AlertTestInfo();
|
||||
|
||||
void SetWinInfo(const GuiInfo &winInfo);
|
||||
void SetTextViewInfo(const GuiInfo &textInfo);
|
||||
void SetButtonInfo(int32 btn, const GuiInfo &btnInfo);
|
||||
|
||||
void SetButtonWidthMode(button_width widthMode);
|
||||
void SetButtonSpacingMode(button_spacing spacingMode);
|
||||
void SetAlertType(alert_type alertType);
|
||||
|
||||
void GuiInfoTest();
|
||||
|
||||
private:
|
||||
AlertTest* fTest;
|
||||
GuiInfo fWinInfo;
|
||||
GuiInfo fTextInfo;
|
||||
GuiInfo fButtonInfo[3];
|
||||
int32 fButtonCount;
|
||||
button_width fWidthMode;
|
||||
button_spacing fSpacingMode;
|
||||
alert_type fAlertType;
|
||||
};
|
||||
|
||||
AlertTestInfo::AlertTestInfo(AlertTest *pTest)
|
||||
{
|
||||
memset(this, 0, sizeof(AlertTestInfo));
|
||||
|
||||
fTest = pTest;
|
||||
fWidthMode = B_WIDTH_AS_USUAL;
|
||||
fSpacingMode = B_EVEN_SPACING;
|
||||
fAlertType = B_INFO_ALERT;
|
||||
}
|
||||
|
||||
AlertTestInfo::~AlertTestInfo()
|
||||
{
|
||||
fTest = NULL;
|
||||
fButtonCount = 0;
|
||||
}
|
||||
|
||||
void
|
||||
AlertTestInfo::SetWinInfo(const GuiInfo &winInfo)
|
||||
{
|
||||
fWinInfo = winInfo;
|
||||
}
|
||||
|
||||
void
|
||||
AlertTestInfo::SetTextViewInfo(const GuiInfo &textInfo)
|
||||
{
|
||||
fTextInfo = textInfo;
|
||||
}
|
||||
|
||||
void
|
||||
AlertTestInfo::SetButtonInfo(int32 btn, const GuiInfo &btnInfo)
|
||||
{
|
||||
if (btn < 0 || btn > 2 || btn > fButtonCount) {
|
||||
CPPUNIT_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
fButtonInfo[btn] = btnInfo;
|
||||
if (btn == fButtonCount && fButtonCount < 3)
|
||||
fButtonCount++;
|
||||
}
|
||||
|
||||
void
|
||||
AlertTestInfo::SetButtonWidthMode(button_width widthMode)
|
||||
{
|
||||
fWidthMode = widthMode;
|
||||
}
|
||||
|
||||
void
|
||||
AlertTestInfo::SetButtonSpacingMode(button_spacing spacingMode)
|
||||
{
|
||||
fSpacingMode = spacingMode;
|
||||
}
|
||||
|
||||
void
|
||||
AlertTestInfo::SetAlertType(alert_type alertType)
|
||||
{
|
||||
fAlertType = alertType;
|
||||
}
|
||||
|
||||
void
|
||||
AlertTestInfo::GuiInfoTest()
|
||||
{
|
||||
fTest->NextSubTest();
|
||||
// Dummy application object required to create Window objects.
|
||||
BApplication app("application/x-vnd.Haiku-interfacekit_alerttest");
|
||||
BAlert *pAlert = new BAlert(
|
||||
fWinInfo.label,
|
||||
fTextInfo.label,
|
||||
fButtonInfo[0].label,
|
||||
fButtonInfo[1].label,
|
||||
fButtonInfo[2].label,
|
||||
fWidthMode,
|
||||
fSpacingMode,
|
||||
fAlertType
|
||||
);
|
||||
CPPUNIT_ASSERT(pAlert);
|
||||
|
||||
// Alert Window Width/Height
|
||||
fTest->NextSubTest();
|
||||
ASSERT_DEQUAL(fWinInfo.width, pAlert->Bounds().Width());
|
||||
ASSERT_DEQUAL(fWinInfo.height, pAlert->Bounds().Height());
|
||||
|
||||
// [k] MasterView
|
||||
fTest->NextSubTest();
|
||||
BView *masterView = pAlert->ChildAt(0);
|
||||
CPPUNIT_ASSERT(masterView);
|
||||
|
||||
// [k] MasterView Color
|
||||
fTest->NextSubTest();
|
||||
CPPUNIT_ASSERT_EQUAL(ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||
masterView->ViewColor());
|
||||
|
||||
// Test all the buttons
|
||||
BButton *btns[3] = { NULL };
|
||||
for (int32 i = 0; i < 3; i++) {
|
||||
fTest->NextSubTest();
|
||||
btns[i] = pAlert->ButtonAt(i);
|
||||
|
||||
if (i >= fButtonCount) {
|
||||
// If there is should be no button at this index
|
||||
CPPUNIT_ASSERT_EQUAL((BButton*)NULL, btns[i]);
|
||||
} else {
|
||||
// If there should be a button at this index
|
||||
CPPUNIT_ASSERT(btns[i]);
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
strcmp(fButtonInfo[i].label, btns[i]->Label()) == 0);
|
||||
|
||||
ASSERT_DEQUAL(fButtonInfo[i].width, btns[i]->Bounds().Width());
|
||||
|
||||
ASSERT_DEQUAL(fButtonInfo[i].height, btns[i]->Bounds().Height());
|
||||
|
||||
BPoint pt = btns[i]->ConvertToParent(BPoint(0, 0));
|
||||
ASSERT_DEQUAL(fButtonInfo[i].topleft.x, pt.x);
|
||||
ASSERT_DEQUAL(fButtonInfo[i].topleft.y, pt.y);
|
||||
|
||||
if (i == fButtonCount - 1) {
|
||||
// Default button
|
||||
CPPUNIT_ASSERT_EQUAL(true, btns[i]->IsDefault());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [k] TextView
|
||||
fTest->NextSubTest();
|
||||
BTextView *textView = pAlert->TextView();
|
||||
CPPUNIT_ASSERT(textView);
|
||||
|
||||
// [k] TextView ViewColor()
|
||||
fTest->NextSubTest();
|
||||
CPPUNIT_ASSERT_EQUAL(ui_color(B_PANEL_BACKGROUND_COLOR), textView->ViewColor());
|
||||
|
||||
// [k] TextView IsEditable()
|
||||
fTest->NextSubTest();
|
||||
CPPUNIT_ASSERT_EQUAL(false, textView->IsEditable());
|
||||
|
||||
// [k] TextView IsSelectable()
|
||||
fTest->NextSubTest();
|
||||
CPPUNIT_ASSERT_EQUAL(false, textView->IsSelectable());
|
||||
|
||||
// [k] TextView DoesWordWrap()
|
||||
fTest->NextSubTest();
|
||||
CPPUNIT_ASSERT_EQUAL(true, textView->DoesWordWrap());
|
||||
|
||||
// TextView Text
|
||||
fTest->NextSubTest();
|
||||
CPPUNIT_ASSERT(strcmp(fTextInfo.label, textView->Text()) == 0);
|
||||
|
||||
// TextView Width/Height
|
||||
fTest->NextSubTest();
|
||||
ASSERT_DEQUAL(fTextInfo.width, textView->Bounds().Width());
|
||||
ASSERT_DEQUAL(fTextInfo.height, textView->Bounds().Height());
|
||||
|
||||
// TextView Position
|
||||
fTest->NextSubTest();
|
||||
BPoint pt = textView->ConvertToParent(BPoint(0, 0));
|
||||
ASSERT_DEQUAL(fTextInfo.topleft.x, pt.x);
|
||||
ASSERT_DEQUAL(fTextInfo.topleft.y, pt.y);
|
||||
|
||||
delete pAlert;
|
||||
pAlert = NULL;
|
||||
}
|
||||
|
||||
// Suite
|
||||
CppUnit::Test *
|
||||
AlertTest::Suite()
|
||||
{
|
||||
CppUnit::TestSuite *suite = new CppUnit::TestSuite();
|
||||
typedef CppUnit::TestCaller<AlertTest> TC;
|
||||
|
||||
suite->addTest(
|
||||
new TC("Alert empty_empty_UW_ES_IA",
|
||||
&AlertTest::empty_empty_UW_ES_IA));
|
||||
|
||||
suite->addTest(
|
||||
new TC("Alert OK_X_UW_ES_IA",
|
||||
&AlertTest::OK_X_UW_ES_IA));
|
||||
|
||||
suite->addTest(
|
||||
new TC("Alert ControlMetricsTest",
|
||||
&AlertTest::ControlMetricsTest));
|
||||
new TC("Alert OK_60X_UW_ES_IA",
|
||||
&AlertTest::OK_60X_UW_ES_IA));
|
||||
|
||||
return suite;
|
||||
}
|
||||
@ -39,54 +265,91 @@ AlertTest::tearDown()
|
||||
BTestCase::tearDown();
|
||||
}
|
||||
|
||||
// Test state of controls in the BAlert's window
|
||||
void
|
||||
AlertTest::ControlMetricsTest()
|
||||
AlertTest::empty_empty_UW_ES_IA()
|
||||
{
|
||||
NextSubTest();
|
||||
// Dummy application object required to create Window objects.
|
||||
BApplication app("application/x-vnd.Haiku-interfacekit_alerttest");
|
||||
BAlert *pAlert = new BAlert(
|
||||
"alert1",
|
||||
"X",
|
||||
"OK", NULL, NULL,
|
||||
B_WIDTH_AS_USUAL, // widthStyle
|
||||
B_EVEN_SPACING,
|
||||
B_INFO_ALERT // alert_type
|
||||
);
|
||||
CPPUNIT_ASSERT(pAlert);
|
||||
AlertTestInfo ati(this);
|
||||
GuiInfo wi, ti, bi;
|
||||
wi.label = "alert1";
|
||||
wi.width = 310.0f;
|
||||
wi.height = 64.0f;
|
||||
ati.SetWinInfo(wi);
|
||||
|
||||
// Only button0 should be available
|
||||
NextSubTest();
|
||||
CPPUNIT_ASSERT_EQUAL((BButton*)NULL, pAlert->ButtonAt(1));
|
||||
CPPUNIT_ASSERT_EQUAL((BButton*)NULL, pAlert->ButtonAt(2));
|
||||
BButton *pBtn0 = pAlert->ButtonAt(0);
|
||||
CPPUNIT_ASSERT(pBtn0);
|
||||
ti.label = "";
|
||||
ti.width = 245.0f;
|
||||
ti.height = 13.0f;
|
||||
ti.topleft.Set(55.0f, 6.0f);
|
||||
ati.SetTextViewInfo(ti);
|
||||
|
||||
NextSubTest();
|
||||
CPPUNIT_ASSERT(strcmp(pBtn0->Label(), "OK") == 0);
|
||||
bi.label = "";
|
||||
bi.width = 75.0f;
|
||||
bi.height = 30.0f;
|
||||
bi.topleft.Set(229.0f, 28.0f);
|
||||
ati.SetButtonInfo(0, bi);
|
||||
|
||||
// Width / Height
|
||||
NextSubTest();
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(75, pBtn0->Bounds().Width(), 0.01);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(30, pBtn0->Bounds().Height(), 0.01);
|
||||
ati.SetButtonWidthMode(B_WIDTH_AS_USUAL);
|
||||
ati.SetButtonSpacingMode(B_EVEN_SPACING);
|
||||
ati.SetAlertType(B_INFO_ALERT);
|
||||
|
||||
// Horizontal / Vertical position
|
||||
NextSubTest();
|
||||
BPoint pt = pBtn0->ConvertToParent(BPoint(0, 0));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(229, pt.x, 0.01);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(28, pt.y, 0.01);
|
||||
ati.GuiInfoTest();
|
||||
}
|
||||
|
||||
void
|
||||
AlertTest::OK_X_UW_ES_IA()
|
||||
{
|
||||
AlertTestInfo ati(this);
|
||||
GuiInfo wi, ti, bi;
|
||||
wi.label = "alert1";
|
||||
wi.width = 310.0f;
|
||||
wi.height = 64.0f;
|
||||
ati.SetWinInfo(wi);
|
||||
|
||||
// TextView
|
||||
NextSubTest();
|
||||
BTextView *textView = pAlert->TextView();
|
||||
CPPUNIT_ASSERT(textView);
|
||||
ti.label = "X";
|
||||
ti.width = 245.0f;
|
||||
ti.height = 13.0f;
|
||||
ti.topleft.Set(55.0f, 6.0f);
|
||||
ati.SetTextViewInfo(ti);
|
||||
|
||||
NextSubTest();
|
||||
CPPUNIT_ASSERT(strcmp(textView->Text(), "X") == 0);
|
||||
bi.label = "OK";
|
||||
bi.width = 75.0f;
|
||||
bi.height = 30.0f;
|
||||
bi.topleft.Set(229.0f, 28.0f);
|
||||
ati.SetButtonInfo(0, bi);
|
||||
|
||||
delete pAlert;
|
||||
pAlert = NULL;
|
||||
ati.SetButtonWidthMode(B_WIDTH_AS_USUAL);
|
||||
ati.SetButtonSpacingMode(B_EVEN_SPACING);
|
||||
ati.SetAlertType(B_INFO_ALERT);
|
||||
|
||||
ati.GuiInfoTest();
|
||||
}
|
||||
|
||||
void
|
||||
AlertTest::OK_60X_UW_ES_IA()
|
||||
{
|
||||
AlertTestInfo ati(this);
|
||||
GuiInfo wi, ti, bi;
|
||||
wi.label = "alert1";
|
||||
wi.width = 310.0f;
|
||||
wi.height = 77.0f;
|
||||
ati.SetWinInfo(wi);
|
||||
|
||||
ti.label = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
|
||||
ti.width = 245.0f;
|
||||
ti.height = 26.0f;
|
||||
ti.topleft.Set(55.0f, 6.0f);
|
||||
ati.SetTextViewInfo(ti);
|
||||
|
||||
bi.label = "OK";
|
||||
bi.width = 75.0f;
|
||||
bi.height = 30.0f;
|
||||
bi.topleft.Set(229.0f, 41.0f);
|
||||
ati.SetButtonInfo(0, bi);
|
||||
|
||||
ati.SetButtonWidthMode(B_WIDTH_AS_USUAL);
|
||||
ati.SetButtonSpacingMode(B_EVEN_SPACING);
|
||||
ati.SetAlertType(B_INFO_ALERT);
|
||||
|
||||
ati.GuiInfoTest();
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
#include <TestCase.h>
|
||||
#include <TestShell.h>
|
||||
|
||||
#define TEXT_MIME_STRING "text/plain"
|
||||
#define STXT_MIME_STRING "text/x-vnd.Be-stxt"
|
||||
|
||||
class CppUnit::Test;
|
||||
|
||||
class AlertTest : public BTestCase {
|
||||
@ -24,7 +21,32 @@ public:
|
||||
//------------------------------------------------------------
|
||||
// Test functions
|
||||
//------------------------------------------------------------
|
||||
void ControlMetricsTest();
|
||||
//
|
||||
// For conciseness, the test function names are made of codes
|
||||
// which indicate which BAlert construtor options are chosen.
|
||||
//
|
||||
// The format is:
|
||||
//
|
||||
// btn0[_btn1[_btn2]]_msg_widthMode_spacingMode_alertType
|
||||
//
|
||||
// where: btn# is the label of the button for that index,
|
||||
// msg is the alert message
|
||||
// widthMode is the button_width setting:
|
||||
// UW = B_WIDTH_AS_USUAL
|
||||
// WW = B_WIDTH_FROM_WIDEST
|
||||
// LW = B_WIDTH_FROM_LABEL
|
||||
// spacingMode is the button_spacing setting:
|
||||
// ES = B_EVEN_SPACING
|
||||
// OS = B_OFFSET_SPACING
|
||||
// alertType specifies the icon displayed on the alert:
|
||||
// EA = B_EMPTY_ALERT
|
||||
// IA = B_INFO_ALERT
|
||||
// LA = B_IDEA_ALERT
|
||||
// WA = B_WARNING_ALERT
|
||||
// SA = B_STOP_ALERT
|
||||
void empty_empty_UW_ES_IA();
|
||||
void OK_X_UW_ES_IA();
|
||||
void OK_60X_UW_ES_IA();
|
||||
};
|
||||
|
||||
#endif // ALERT_TEST_H
|
||||
|
Loading…
Reference in New Issue
Block a user