From 90ba955b6362b3bb894b033f2bce921c4bae7096 Mon Sep 17 00:00:00 2001 From: matzon Date: Tue, 13 Aug 2002 15:12:17 +0000 Subject: [PATCH] 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 --- .../kits/translation/BitmapStreamTest.cpp | 164 +++++------------- src/tests/kits/translation/BitmapStreamTest.h | 34 ++-- .../translation/TranslationKitTestAddon.cpp | 2 + 3 files changed, 61 insertions(+), 139 deletions(-) diff --git a/src/tests/kits/translation/BitmapStreamTest.cpp b/src/tests/kits/translation/BitmapStreamTest.cpp index 0622ece42f..ee8cf1bc4e 100644 --- a/src/tests/kits/translation/BitmapStreamTest.cpp +++ b/src/tests/kits/translation/BitmapStreamTest.cpp @@ -34,11 +34,17 @@ #include #include #include +#include + +/* cppunit framework */ +#include +#include +#include /** * 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::Initialize Test", &BitmapStreamTest::InitializeTest)); + suite->addTest(new CppUnit::TestCaller("BitmapStreamTest::Constructor Test", &BitmapStreamTest::ConstructorTest)); + suite->addTest(new CppUnit::TestCaller("BitmapStreamTest::DetachBitmap Test", &BitmapStreamTest::DetachBitmapTest)); + suite->addTest(new CppUnit::TestCaller("BitmapStreamTest::Position Test", &BitmapStreamTest::PositionTest)); + suite->addTest(new CppUnit::TestCaller("BitmapStreamTest::ReadAt Test", &BitmapStreamTest::ReadAtTest)); + suite->addTest(new CppUnit::TestCaller("BitmapStreamTest::Seek Test", &BitmapStreamTest::SeekTest)); + suite->addTest(new CppUnit::TestCaller("BitmapStreamTest::SetSize Test", &BitmapStreamTest::SetSizeTest)); + suite->addTest(new CppUnit::TestCaller("BitmapStreamTest::WriteAt Test", &BitmapStreamTest::WriteAtTest)); + suite->addTest(new CppUnit::TestCaller("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() { } \ No newline at end of file diff --git a/src/tests/kits/translation/BitmapStreamTest.h b/src/tests/kits/translation/BitmapStreamTest.h index 04b1c2d863..a99752cd26 100644 --- a/src/tests/kits/translation/BitmapStreamTest.h +++ b/src/tests/kits/translation/BitmapStreamTest.h @@ -36,34 +36,32 @@ #include #include -class BitmapStreamTest { +/** CppUnit support */ +#include + +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 \ No newline at end of file diff --git a/src/tests/kits/translation/TranslationKitTestAddon.cpp b/src/tests/kits/translation/TranslationKitTestAddon.cpp index b852f8a7c0..7787badda9 100644 --- a/src/tests/kits/translation/TranslationKitTestAddon.cpp +++ b/src/tests/kits/translation/TranslationKitTestAddon.cpp @@ -1,9 +1,11 @@ #include #include #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; }