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:
matzon
2002-08-13 15:12:17 +00:00
parent fa883a5924
commit 90ba955b63
3 changed files with 61 additions and 139 deletions
+43 -121
View File
@@ -34,11 +34,17 @@
#include <stdio.h> #include <stdio.h>
#include <TranslatorRoster.h> #include <TranslatorRoster.h>
#include <Application.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 * Default constructor - no work
*/ */
BitmapStreamTest::BitmapStreamTest() { BitmapStreamTest::BitmapStreamTest(std::string name) : BTestCase(name) {
} }
/** /**
@@ -47,185 +53,101 @@ BitmapStreamTest::BitmapStreamTest() {
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 * Initializes the test
*
* @return B_OK if initialization went ok, B_ERROR if not
*/ */
status_t BitmapStreamTest::Initialize() { void BitmapStreamTest::InitializeTest() {
//aquire default roster //aquire default roster
roster = BTranslatorRoster::Default(); roster = BTranslatorRoster::Default();
if(roster == NULL) { CPPUNIT_ASSERT(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;
} }
/**
* 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: * Tests:
* BBitmapStream(BBitmap *map = NULL) * BBitmapStream(BBitmap *map = NULL)
*
* @return B_OK if everything went ok, B_ERROR if not
*/ */
status_t BitmapStreamTest::ConstructorTest() { void BitmapStreamTest::ConstructorTest() {
return B_OK;
} }
/** /**
* Tests: * Tests:
* status_t DetachBitmap(BBitmap **outMap) * 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); BFile file("./data/images/image.gif", B_READ_ONLY);
if(file.InitCheck() != B_OK) { CPPUNIT_ASSERT(file.InitCheck() == B_OK);
return B_ERROR;
}
NextSubTest();
BBitmapStream stream; BBitmapStream stream;
BBitmap* result = NULL; BBitmap* result = NULL;
if (roster->Translate(&file, NULL, NULL, &stream, B_TRANSLATOR_BITMAP) < B_OK) { roster = BTranslatorRoster::Default();
return B_ERROR; CPPUNIT_ASSERT(roster->Translate(&file, NULL, NULL, &stream, B_TRANSLATOR_BITMAP) == B_OK);
}
stream.DetachBitmap(&result); stream.DetachBitmap(&result);
CPPUNIT_ASSERT(result != NULL);
if(result != NULL) { if(result != NULL) {
return B_OK; delete result;
} }
return B_ERROR;
} }
/** /**
* Tests: * Tests:
* off_t Position() const * off_t Position() const
*
* @return B_OK if everything went ok, B_ERROR if not
*/ */
status_t BitmapStreamTest::Position() { void BitmapStreamTest::PositionTest() {
return B_OK;
} }
/** /**
* Tests: * Tests:
* ssize_t ReadAt(off_t pos, void *buffer, size_t *size) * 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() { void BitmapStreamTest::ReadAtTest() {
return B_OK;
} }
/** /**
* Tests: * Tests:
* off_t Seek(off_t position, uint32 whence) * off_t Seek(off_t position, uint32 whence)
*
* @return B_OK if everything went ok, B_ERROR if not
*/ */
status_t BitmapStreamTest::Seek() { void BitmapStreamTest::SeekTest() {
return B_OK;
} }
/** /**
* Tests: * Tests:
* status_t SetSize(off_t size) const * status_t SetSize(off_t size) const
*
* @return B_OK if everything went ok, B_ERROR if not
*/ */
status_t BitmapStreamTest::SetSize() { void BitmapStreamTest::SetSizeTest() {
return B_OK;
} }
/** /**
* Tests: * Tests:
* ssize_t WriteAt(off_t pos, const void *data, size_t *size) * 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() { void BitmapStreamTest::WriteAtTest() {
return B_OK;
} }
/** /**
* Tests: * Tests:
* off_t Size() const * off_t Size() const
*
* @return B_OK if everything went ok, B_ERROR if not
*/ */
status_t BitmapStreamTest::Size() { void BitmapStreamTest::SizeTest() {
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");
}
} }
+16 -18
View File
@@ -36,34 +36,32 @@
#include <BitmapStream.h> #include <BitmapStream.h>
#include <File.h> #include <File.h>
class BitmapStreamTest { /** CppUnit support */
#include <TestCase.h>
class BitmapStreamTest : public BTestCase {
public: public:
BitmapStreamTest(); BitmapStreamTest(std::string name = "");
~BitmapStreamTest(); ~BitmapStreamTest();
status_t Initialize(); /* cppunit suite function prototype */
status_t Perform(); static CppUnit::Test* Suite();
inline void setVerbose(bool verbose) { this->verbose = verbose; };
//actual tests //actual tests
status_t ConstructorTest(); void InitializeTest();
status_t DetachBitmap(); void ConstructorTest();
status_t Position(); void DetachBitmapTest();
status_t ReadAt(); void PositionTest();
status_t Seek(); void ReadAtTest();
status_t SetSize(); void SeekTest();
status_t WriteAt(); void SetSizeTest();
status_t Size(); void WriteAtTest();
void SizeTest();
private: private:
void Debug(char* string);
/** default roster used when performing tests */ /** default roster used when performing tests */
BTranslatorRoster* roster; BTranslatorRoster* roster;
/** File to read from */ /** File to read from */
BFile* file; BFile* file;
/** Whether or not to output test info */
bool verbose;
}; };
#endif #endif
@@ -1,9 +1,11 @@
#include <TestSuite.h> #include <TestSuite.h>
#include <TestSuiteAddon.h> #include <TestSuiteAddon.h>
#include "TranslatorRosterTest.h" #include "TranslatorRosterTest.h"
#include "BitmapStreamTest.h"
BTestSuite* getTestSuite() { BTestSuite* getTestSuite() {
BTestSuite *suite = new BTestSuite("TranslatorRosterTest suite"); BTestSuite *suite = new BTestSuite("TranslatorRosterTest suite");
suite->addTest("TranslatorRosterTest", TranslatorRosterTest::Suite()); suite->addTest("TranslatorRosterTest", TranslatorRosterTest::Suite());
suite->addTest("BitmapStreamTest", BitmapStreamTest::Suite());
return suite; return suite;
} }