fixed: converted BitmapStreamTest to unittest
added BitmapStreamTest to suite git-svn-id: file:///srv/svn/repos/haiku/trunk/current@741 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
fa883a5924
commit
90ba955b63
@ -34,11 +34,17 @@
|
||||
#include <stdio.h>
|
||||
#include <TranslatorRoster.h>
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
|
||||
/* cppunit framework */
|
||||
#include <cppunit/Test.h>
|
||||
#include <cppunit/TestCaller.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
|
||||
/**
|
||||
* Default constructor - no work
|
||||
*/
|
||||
BitmapStreamTest::BitmapStreamTest() {
|
||||
BitmapStreamTest::BitmapStreamTest(std::string name) : BTestCase(name) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,185 +53,101 @@ BitmapStreamTest::BitmapStreamTest() {
|
||||
BitmapStreamTest::~BitmapStreamTest() {
|
||||
}
|
||||
|
||||
CppUnit::Test*
|
||||
BitmapStreamTest::Suite() {
|
||||
/* create our suite */
|
||||
CppUnit::TestSuite *suite = new CppUnit::TestSuite("BitmapStreamTest Suite");
|
||||
|
||||
/* add suckers */
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::Initialize Test", &BitmapStreamTest::InitializeTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::Constructor Test", &BitmapStreamTest::ConstructorTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::DetachBitmap Test", &BitmapStreamTest::DetachBitmapTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::Position Test", &BitmapStreamTest::PositionTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::ReadAt Test", &BitmapStreamTest::ReadAtTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::Seek Test", &BitmapStreamTest::SeekTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::SetSize Test", &BitmapStreamTest::SetSizeTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::WriteAt Test", &BitmapStreamTest::WriteAtTest));
|
||||
suite->addTest(new CppUnit::TestCaller<BitmapStreamTest>("BitmapStreamTest::Size Test", &BitmapStreamTest::SizeTest));
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the test
|
||||
*
|
||||
* @return B_OK if initialization went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::Initialize() {
|
||||
void BitmapStreamTest::InitializeTest() {
|
||||
//aquire default roster
|
||||
roster = BTranslatorRoster::Default();
|
||||
if(roster == NULL) {
|
||||
Debug("Failed to create aquire default TranslatorRoster\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
//print version information
|
||||
if(verbose && roster != NULL) {
|
||||
int32 outCurVersion;
|
||||
int32 outMinVersion;
|
||||
long inAppVersion;
|
||||
const char* info = roster->Version(&outCurVersion, &outMinVersion, inAppVersion);
|
||||
printf("Default TranslatorRoster aquired. Version: %s\n", info);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
CPPUNIT_ASSERT(roster != NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the tests.
|
||||
* This will test ALL methods in BTranslatorRoster.
|
||||
*
|
||||
* @return B_OK if the whole test went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::Perform() {
|
||||
if(ConstructorTest() != B_OK) {
|
||||
Debug("ERROR: ConstructorTest did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
if(DetachBitmap() != B_OK) {
|
||||
Debug("ERROR: DetachBitmap did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
if(Position() != B_OK) {
|
||||
Debug("ERROR: Position did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
if(ReadAt() != B_OK) {
|
||||
Debug("ERROR: ReadAt did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
if(Seek() != B_OK) {
|
||||
Debug("ERROR: Seek did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
if(SetSize() != B_OK) {
|
||||
Debug("ERROR: SetSize did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
if(WriteAt() != B_OK) {
|
||||
Debug("ERROR: WriteAt did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
if(Size() != B_OK) {
|
||||
Debug("ERROR: Size did not complete successfully\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
/**
|
||||
* Tests:
|
||||
* BBitmapStream(BBitmap *map = NULL)
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::ConstructorTest() {
|
||||
return B_OK;
|
||||
void BitmapStreamTest::ConstructorTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests:
|
||||
* status_t DetachBitmap(BBitmap **outMap)
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::DetachBitmap() {
|
||||
void BitmapStreamTest::DetachBitmapTest() {
|
||||
BApplication app("application/x-vnd.OpenBeOS-translationkit_bitmapstreamtest");
|
||||
BFile file("./data/images/image.gif", B_READ_ONLY);
|
||||
if(file.InitCheck() != B_OK) {
|
||||
return B_ERROR;
|
||||
}
|
||||
CPPUNIT_ASSERT(file.InitCheck() == B_OK);
|
||||
|
||||
NextSubTest();
|
||||
BBitmapStream stream;
|
||||
BBitmap* result = NULL;
|
||||
if (roster->Translate(&file, NULL, NULL, &stream, B_TRANSLATOR_BITMAP) < B_OK) {
|
||||
return B_ERROR;
|
||||
}
|
||||
roster = BTranslatorRoster::Default();
|
||||
CPPUNIT_ASSERT(roster->Translate(&file, NULL, NULL, &stream, B_TRANSLATOR_BITMAP) == B_OK);
|
||||
stream.DetachBitmap(&result);
|
||||
|
||||
CPPUNIT_ASSERT(result != NULL);
|
||||
if(result != NULL) {
|
||||
return B_OK;
|
||||
delete result;
|
||||
}
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests:
|
||||
* off_t Position() const
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::Position() {
|
||||
return B_OK;
|
||||
void BitmapStreamTest::PositionTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests:
|
||||
* ssize_t ReadAt(off_t pos, void *buffer, size_t *size)
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::ReadAt() {
|
||||
return B_OK;
|
||||
void BitmapStreamTest::ReadAtTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests:
|
||||
* off_t Seek(off_t position, uint32 whence)
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::Seek() {
|
||||
return B_OK;
|
||||
void BitmapStreamTest::SeekTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests:
|
||||
* status_t SetSize(off_t size) const
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::SetSize() {
|
||||
return B_OK;
|
||||
void BitmapStreamTest::SetSizeTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests:
|
||||
* ssize_t WriteAt(off_t pos, const void *data, size_t *size)
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::WriteAt() {
|
||||
return B_OK;
|
||||
void BitmapStreamTest::WriteAtTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests:
|
||||
* off_t Size() const
|
||||
*
|
||||
* @return B_OK if everything went ok, B_ERROR if not
|
||||
*/
|
||||
status_t BitmapStreamTest::Size() {
|
||||
return B_OK;
|
||||
}
|
||||
/**
|
||||
* Prints debug information to stdout, if verbose is set to true
|
||||
*/
|
||||
void BitmapStreamTest::Debug(char* string) {
|
||||
if(verbose) {
|
||||
printf(string);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
BApplication app("application/x-vnd.OpenBeOS-translationkit_bitmapstreamtest");
|
||||
BitmapStreamTest test;
|
||||
test.setVerbose(true);
|
||||
test.Initialize();
|
||||
if(test.Perform() != B_OK) {
|
||||
printf("Tests did not complete successfully\n");
|
||||
} else {
|
||||
printf("All tests completed without errors\n");
|
||||
}
|
||||
void BitmapStreamTest::SizeTest() {
|
||||
}
|
@ -36,34 +36,32 @@
|
||||
#include <BitmapStream.h>
|
||||
#include <File.h>
|
||||
|
||||
class BitmapStreamTest {
|
||||
/** CppUnit support */
|
||||
#include <TestCase.h>
|
||||
|
||||
class BitmapStreamTest : public BTestCase {
|
||||
public:
|
||||
BitmapStreamTest();
|
||||
BitmapStreamTest(std::string name = "");
|
||||
~BitmapStreamTest();
|
||||
|
||||
status_t Initialize();
|
||||
status_t Perform();
|
||||
inline void setVerbose(bool verbose) { this->verbose = verbose; };
|
||||
/* cppunit suite function prototype */
|
||||
static CppUnit::Test* Suite();
|
||||
|
||||
//actual tests
|
||||
status_t ConstructorTest();
|
||||
status_t DetachBitmap();
|
||||
status_t Position();
|
||||
status_t ReadAt();
|
||||
status_t Seek();
|
||||
status_t SetSize();
|
||||
status_t WriteAt();
|
||||
status_t Size();
|
||||
void InitializeTest();
|
||||
void ConstructorTest();
|
||||
void DetachBitmapTest();
|
||||
void PositionTest();
|
||||
void ReadAtTest();
|
||||
void SeekTest();
|
||||
void SetSizeTest();
|
||||
void WriteAtTest();
|
||||
void SizeTest();
|
||||
private:
|
||||
void Debug(char* string);
|
||||
|
||||
/** default roster used when performing tests */
|
||||
BTranslatorRoster* roster;
|
||||
|
||||
/** File to read from */
|
||||
BFile* file;
|
||||
|
||||
/** Whether or not to output test info */
|
||||
bool verbose;
|
||||
};
|
||||
#endif
|
@ -1,9 +1,11 @@
|
||||
#include <TestSuite.h>
|
||||
#include <TestSuiteAddon.h>
|
||||
#include "TranslatorRosterTest.h"
|
||||
#include "BitmapStreamTest.h"
|
||||
|
||||
BTestSuite* getTestSuite() {
|
||||
BTestSuite *suite = new BTestSuite("TranslatorRosterTest suite");
|
||||
suite->addTest("TranslatorRosterTest", TranslatorRosterTest::Suite());
|
||||
suite->addTest("BitmapStreamTest", BitmapStreamTest::Suite());
|
||||
return suite;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user