diff --git a/src/tests/add-ons/translators/TranslatorTestAddOn.cpp b/src/tests/add-ons/translators/TranslatorTestAddOn.cpp index 5652023905..d687f1747a 100644 --- a/src/tests/add-ons/translators/TranslatorTestAddOn.cpp +++ b/src/tests/add-ons/translators/TranslatorTestAddOn.cpp @@ -1,11 +1,50 @@ -#include -#include +// TranslatorTestAddOn.cpp + +#include +#include "TranslatorTestAddOn.h" // ##### Include headers for your tests here ##### #include "bmptranslator/BMPTranslatorTest.h" #include "stxttranslator/STXTTranslatorTest.h" #include "tifftranslator/TIFFTranslatorTest.h" +// helper function used by multiple tests to +// determine if the given streams are exactly +// the same +bool +CompareStreams(BPositionIO &a, BPositionIO &b) +{ + off_t alen = 0, blen = 0; + uint8 *abuf = NULL, *bbuf = NULL; + + a.Seek(0, SEEK_END); + alen = a.Position(); + b.Seek(0, SEEK_END); + blen = b.Position(); + + if (alen != blen) + return false; + + bool bresult = false; + abuf = new uint8[alen]; + bbuf = new uint8[blen]; + if (a.ReadAt(0, abuf, alen) == alen) { + if (b.ReadAt(0, bbuf, blen) == blen) { + if (memcmp(abuf, bbuf, alen) == 0) + bresult = true; + else + bresult = false; + } + } + + delete[] abuf; + abuf = NULL; + delete[] bbuf; + bbuf = NULL; + + return bresult; +} + BTestSuite * getTestSuite() { diff --git a/src/tests/add-ons/translators/TranslatorTestAddOn.h b/src/tests/add-ons/translators/TranslatorTestAddOn.h new file mode 100644 index 0000000000..7a296116b9 --- /dev/null +++ b/src/tests/add-ons/translators/TranslatorTestAddOn.h @@ -0,0 +1,12 @@ +// TranslatorTestAddOn.h + +#ifndef TRANSLATOR_TEST_ADD_ON_H +#define TRANSLATOR_TEST_ADD_ON_H + +#include +#include +#include + +bool CompareStreams(BPositionIO &a, BPositionIO &b); + +#endif // #ifndef TRANSLATOR_TEST_ADD_ON_H