unittests: Start simplifying test structure
* Rework ByteOrderTest and DateTimeTest to use autoregistration. * Functional changes in ByteOrderTest are confirmed in git history to be R5 compatibility fixes. This doesn't include B_ASCII_TYPE - it seems it has never been part of is_type_swapped(). * Autoregistered test names start with a number - this is because RTTI is used to create them. Disabling RTTI is not an option because CppUnit in our repo has a broken macro which always sets the name to "ATestFixtureType". This is probably fixed in newer CppUnit versions. Change-Id: I56ab5df6e998b6f47fca3c3458a56a761c1740a8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10266 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]> Reviewed-by: Kacper Kasper <[email protected]>
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include <LockerSyncObject.h>
|
#include <LockerSyncObject.h>
|
||||||
#include <cppunit/Exception.h>
|
#include <cppunit/Exception.h>
|
||||||
#include <cppunit/Test.h>
|
#include <cppunit/Test.h>
|
||||||
|
#include <cppunit/TestSuite.h>
|
||||||
#include <cppunit/TestListener.h>
|
#include <cppunit/TestListener.h>
|
||||||
#include <cppunit/TestResult.h>
|
#include <cppunit/TestResult.h>
|
||||||
#include <cppunit/TestResultCollector.h>
|
#include <cppunit/TestResultCollector.h>
|
||||||
@@ -61,6 +62,8 @@ public:
|
|||||||
// the list of tests via a call to AddTest(string
|
// the list of tests via a call to AddTest(string
|
||||||
status_t AddSuite(BTestSuite *kit);
|
status_t AddSuite(BTestSuite *kit);
|
||||||
|
|
||||||
|
status_t AddSuite(CppUnit::TestSuite *suite);
|
||||||
|
|
||||||
// This function is used to add test suites to the list of available
|
// This function is used to add test suites to the list of available
|
||||||
// tests. The test pointer may not be NULL. The name given is the name that
|
// tests. The test pointer may not be NULL. The name given is the name that
|
||||||
// will be presented when the program is run with "--list" as an argument.
|
// will be presented when the program is run with "--list" as an argument.
|
||||||
@@ -107,7 +110,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::map<std::string, CppUnit::Test*> TestMap;
|
typedef std::map<std::string, CppUnit::Test*> TestMap;
|
||||||
typedef std::map<std::string, BTestSuite*> SuiteMap;
|
typedef std::map<std::string, CppUnit::TestSuite*> SuiteMap;
|
||||||
|
|
||||||
VerbosityLevel fVerbosityLevel;
|
VerbosityLevel fVerbosityLevel;
|
||||||
std::set<std::string> fTestsToRun;
|
std::set<std::string> fTestsToRun;
|
||||||
|
|||||||
@@ -4,5 +4,6 @@
|
|||||||
class BTestSuite;
|
class BTestSuite;
|
||||||
|
|
||||||
extern "C" CPPUNIT_API BTestSuite* getTestSuite();
|
extern "C" CPPUNIT_API BTestSuite* getTestSuite();
|
||||||
|
extern "C" CPPUNIT_API const char* getTestSuiteName();
|
||||||
|
|
||||||
#endif // _beos_test_suite_addon_h_
|
#endif // _beos_test_suite_addon_h_
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
#include <cppunit/Portability.h>
|
#include <cppunit/Portability.h>
|
||||||
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
// Handy defines :-)
|
// Handy defines :-)
|
||||||
#define CHK CPPUNIT_ASSERT
|
#define CHK CPPUNIT_ASSERT
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace CppUnit {
|
|||||||
/** Auto-register the suite factory in the specified registry.
|
/** Auto-register the suite factory in the specified registry.
|
||||||
* \param name Name of the registry.
|
* \param name Name of the registry.
|
||||||
*/
|
*/
|
||||||
AutoRegisterSuite( const string &name )
|
AutoRegisterSuite( const std::string &name )
|
||||||
{
|
{
|
||||||
TestFactory *factory = new TestSuiteFactory<TestCaseType>();
|
TestFactory *factory = new TestSuiteFactory<TestCaseType>();
|
||||||
TestFactoryRegistry::getRegistry( name ).registerFactory( factory );
|
TestFactoryRegistry::getRegistry( name ).registerFactory( factory );
|
||||||
|
|||||||
@@ -97,7 +97,11 @@ namespace CppUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if __GNUC__ == 2
|
||||||
auto_ptr<TestSuite> m_suite;
|
auto_ptr<TestSuite> m_suite;
|
||||||
|
#else
|
||||||
|
std::unique_ptr<TestSuite> m_suite;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppUnit
|
} // namespace CppUnit
|
||||||
|
|||||||
@@ -4,20 +4,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ByteOrderTest.h"
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
|
|
||||||
#include <cppunit/TestCaller.h>
|
#include <TestCase.h>
|
||||||
#include <cppunit/TestSuite.h>
|
#include <TestSuiteAddon.h>
|
||||||
|
|
||||||
#include <TestUtils.h>
|
#include <TestUtils.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace CppUnit;
|
using CppUnit::TestFixture;
|
||||||
|
|
||||||
|
|
||||||
// ToDo: swap_int16() and friends don't really belong here as they are in libroot.so
|
// ToDo: swap_int16() and friends don't really belong here as they are in libroot.so
|
||||||
@@ -25,405 +22,267 @@ using namespace CppUnit;
|
|||||||
// long as they don't run on Haiku itself.
|
// long as they don't run on Haiku itself.
|
||||||
|
|
||||||
|
|
||||||
class Swap16Test : public BTestCase {
|
class ByteOrderTest : public TestFixture {
|
||||||
public:
|
CPPUNIT_TEST_SUITE(ByteOrderTest);
|
||||||
Swap16Test(std::string name = "");
|
|
||||||
|
CPPUNIT_TEST(Swap16_InputZero_RemainsZero);
|
||||||
static Test *suite(void);
|
CPPUNIT_TEST(Swap16_InputAscending_SwapsBytes);
|
||||||
void test(void);
|
CPPUNIT_TEST(Swap16_InputNegative_SwapsBytes);
|
||||||
};
|
CPPUNIT_TEST(Swap16_InputMixed_SwapsBytes);
|
||||||
|
|
||||||
|
CPPUNIT_TEST(Swap32_InputZero_RemainsZero);
|
||||||
Swap16Test::Swap16Test(std::string name)
|
CPPUNIT_TEST(Swap32_InputAscending_SwapsBytes);
|
||||||
: BTestCase(name)
|
CPPUNIT_TEST(Swap32_InputNegative_SwapsBytes);
|
||||||
{
|
CPPUNIT_TEST(Swap32_InputMixed_SwapsBytes);
|
||||||
}
|
|
||||||
|
CPPUNIT_TEST(Swap64_InputZero_RemainsZero);
|
||||||
|
CPPUNIT_TEST(Swap64_InputAscending_SwapsBytes);
|
||||||
Test *
|
CPPUNIT_TEST(Swap64_InputNegative_SwapsBytes);
|
||||||
Swap16Test::suite(void)
|
CPPUNIT_TEST(Swap64_InputMixed_SwapsBytes);
|
||||||
{
|
|
||||||
return new CppUnit::TestCaller<Swap16Test>("ByteOrderTest::Swap16Test", &Swap16Test::test);
|
CPPUNIT_TEST(SwapFloat_Roundtrip_ReturnsInput);
|
||||||
}
|
CPPUNIT_TEST(SwapDouble_Roundtrip_ReturnsInput);
|
||||||
|
|
||||||
|
CPPUNIT_TEST(SwapData_StringType_ReturnsBadValue);
|
||||||
void
|
CPPUNIT_TEST(SwapData_Int32TypeInputWithZeroLength_ReturnsOK);
|
||||||
Swap16Test::test(void)
|
CPPUNIT_TEST(SwapData_Int32TypeWithNullInputSwapAlways_ReturnsBadValue);
|
||||||
{
|
CPPUNIT_TEST(SwapData_Int32TypeWithNullInputSwapEndiannessToHost_ReturnsOK);
|
||||||
static int16 kNull = 0;
|
|
||||||
static int16 kAscending = 0x1234;
|
CPPUNIT_TEST(AlgorithmCheck);
|
||||||
static int16 kAscendingSwapped = 0x3412;
|
CPPUNIT_TEST(IsTypeSwapped);
|
||||||
static int16 kNegative = 0xfedc;
|
|
||||||
static int16 kNegativeSwapped = 0xdcfe;
|
CPPUNIT_TEST_SUITE_END();
|
||||||
static uint16 kMix = 0xfefd;
|
public:
|
||||||
static uint16 kMixSwapped = 0xfdfe;
|
void Swap16_InputZero_RemainsZero() {
|
||||||
|
uint16 input = 0;
|
||||||
CHK(kNull == __swap_int16(kNull));
|
CHK(input == __swap_int16(input));
|
||||||
CHK(kAscendingSwapped == __swap_int16(kAscending));
|
|
||||||
CHK(kNegativeSwapped == __swap_int16(kNegative));
|
|
||||||
CHK(kMixSwapped == __swap_int16(kMix));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
class Swap32Test : public BTestCase {
|
|
||||||
public:
|
|
||||||
Swap32Test(std::string name = "");
|
|
||||||
|
|
||||||
static Test *suite(void);
|
|
||||||
void test(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Swap32Test::Swap32Test(std::string name)
|
|
||||||
: BTestCase(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Test *
|
|
||||||
Swap32Test::suite(void)
|
|
||||||
{
|
|
||||||
return new CppUnit::TestCaller<Swap32Test>("ByteOrderTest::Swap32Test", &Swap32Test::test);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Swap32Test::test(void)
|
|
||||||
{
|
|
||||||
static int32 kNull = 0;
|
|
||||||
static int32 kAscending = 0x12345678;
|
|
||||||
static int32 kAscendingSwapped = 0x78563412;
|
|
||||||
static int32 kNegative = 0xfedcba98;
|
|
||||||
static int32 kNegativeSwapped = 0x98badcfe;
|
|
||||||
static uint32 kMix = 0xfefdfcfb;
|
|
||||||
static uint32 kMixSwapped = 0xfbfcfdfe;
|
|
||||||
|
|
||||||
CHK((uint32)kNull == __swap_int32(kNull));
|
|
||||||
CHK((uint32)kAscendingSwapped == __swap_int32(kAscending));
|
|
||||||
CHK((uint32)kNegativeSwapped == __swap_int32(kNegative));
|
|
||||||
CHK(kMixSwapped == __swap_int32(kMix));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
class Swap64Test : public BTestCase {
|
|
||||||
public:
|
|
||||||
Swap64Test(std::string name = "");
|
|
||||||
|
|
||||||
static Test *suite(void);
|
|
||||||
void test(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Swap64Test::Swap64Test(std::string name)
|
|
||||||
: BTestCase(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Test *
|
|
||||||
Swap64Test::suite(void)
|
|
||||||
{
|
|
||||||
return new CppUnit::TestCaller<Swap64Test>("ByteOrderTest::Swap64Test", &Swap64Test::test);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Swap64Test::test(void)
|
|
||||||
{
|
|
||||||
static int64 kNull = 0LL;
|
|
||||||
static int64 kAscending = 0x1234567890LL;
|
|
||||||
static int64 kAscendingSwapped = 0x0000009078563412LL;
|
|
||||||
static int64 kNegative = 0xfedcba9876543210LL;
|
|
||||||
static int64 kNegativeSwapped = 0x1032547698badcfeLL;
|
|
||||||
static uint64 kMix = 0xfefdLL;
|
|
||||||
static uint64 kMixSwapped = 0xfdfe000000000000LL;
|
|
||||||
|
|
||||||
CHK((uint64)kNull == __swap_int64(kNull));
|
|
||||||
CHK((uint64)kAscendingSwapped == __swap_int64(kAscending));
|
|
||||||
CHK((uint64)kNegativeSwapped == __swap_int64(kNegative));
|
|
||||||
CHK(kMixSwapped == __swap_int64(kMix));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
class SwapFloatTest : public BTestCase {
|
|
||||||
public:
|
|
||||||
SwapFloatTest(std::string name = "");
|
|
||||||
|
|
||||||
static Test *suite(void);
|
|
||||||
void test(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
SwapFloatTest::SwapFloatTest(std::string name)
|
|
||||||
: BTestCase(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Test *
|
|
||||||
SwapFloatTest::suite(void)
|
|
||||||
{
|
|
||||||
return new CppUnit::TestCaller<SwapFloatTest>("ByteOrderTest::SwapFloatTest", &SwapFloatTest::test);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SwapFloatTest::test(void)
|
|
||||||
{
|
|
||||||
const float kNumber = 1.125;
|
|
||||||
const float kNaN = NAN;
|
|
||||||
const float kInfinity = HUGE_VALF;
|
|
||||||
|
|
||||||
CHK(kNumber == __swap_float(__swap_float(kNumber)));
|
|
||||||
CHK(kNaN == __swap_float(__swap_float(kNaN)));
|
|
||||||
CHK(kInfinity == __swap_float(__swap_float(kInfinity)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
class SwapDoubleTest : public BTestCase {
|
|
||||||
public:
|
|
||||||
SwapDoubleTest(std::string name = "");
|
|
||||||
|
|
||||||
static Test *suite(void);
|
|
||||||
void test(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
SwapDoubleTest::SwapDoubleTest(std::string name)
|
|
||||||
: BTestCase(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Test *
|
|
||||||
SwapDoubleTest::suite(void)
|
|
||||||
{
|
|
||||||
return new CppUnit::TestCaller<SwapDoubleTest>("ByteOrderTest::SwapDoubleTest", &SwapDoubleTest::test);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SwapDoubleTest::test(void)
|
|
||||||
{
|
|
||||||
const double kNumber = 1.125;
|
|
||||||
const double kNaN = NAN;
|
|
||||||
const double kInfinity = HUGE_VAL;
|
|
||||||
|
|
||||||
CHK(kNumber == __swap_double(__swap_double(kNumber)));
|
|
||||||
CHK(kNaN == __swap_double(__swap_double(kNaN)));
|
|
||||||
CHK(kInfinity == __swap_double(__swap_double(kInfinity)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
class SwapDataTest : public BTestCase {
|
|
||||||
public:
|
|
||||||
SwapDataTest(std::string name = "");
|
|
||||||
|
|
||||||
static Test *suite(void);
|
|
||||||
void test(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
SwapDataTest::SwapDataTest(std::string name)
|
|
||||||
: BTestCase(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Test *
|
|
||||||
SwapDataTest::suite(void)
|
|
||||||
{
|
|
||||||
return new CppUnit::TestCaller<SwapDataTest>("ByteOrderTest::SwapDataTest", &SwapDataTest::test);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SwapDataTest::test(void)
|
|
||||||
{
|
|
||||||
// error checking
|
|
||||||
char string[4];
|
|
||||||
CHK(swap_data(B_STRING_TYPE, string, 4, B_SWAP_ALWAYS) == B_BAD_VALUE);
|
|
||||||
int32 num32 = 0;
|
|
||||||
CHK(swap_data(B_INT32_TYPE, &num32, 0, B_SWAP_ALWAYS) == B_BAD_VALUE);
|
|
||||||
CHK(swap_data(B_INT32_TYPE, NULL, 4, B_SWAP_ALWAYS) == B_BAD_VALUE);
|
|
||||||
#if B_HOST_IS_LENDIAN
|
|
||||||
CHK(swap_data(B_INT32_TYPE, NULL, 4, B_SWAP_HOST_TO_LENDIAN) == B_BAD_VALUE);
|
|
||||||
#else
|
|
||||||
CHK(swap_data(B_INT32_TYPE, NULL, 4, B_SWAP_HOST_TO_BENDIAN) == B_BAD_VALUE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// algorithm checking
|
|
||||||
#define TEST(type, source, target) \
|
|
||||||
memcpy(target, source, sizeof(source)); \
|
|
||||||
for (int32 i = 0; i < 4; i++) { \
|
|
||||||
if (B_HOST_IS_LENDIAN) { \
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_LENDIAN); \
|
|
||||||
CHK(!memcmp(target, source, sizeof(source))); \
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_LENDIAN_TO_HOST); \
|
|
||||||
CHK(!memcmp(target, source, sizeof(source))); \
|
|
||||||
\
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_BENDIAN); \
|
|
||||||
CHK(memcmp(target, source, sizeof(source))); \
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_BENDIAN_TO_HOST); \
|
|
||||||
CHK(!memcmp(target, source, sizeof(source))); \
|
|
||||||
} else if (B_HOST_IS_BENDIAN) { \
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_BENDIAN); \
|
|
||||||
CHK(!memcmp(target, source, sizeof(source))); \
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_BENDIAN_TO_HOST); \
|
|
||||||
CHK(!memcmp(target, source, sizeof(source))); \
|
|
||||||
\
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_LENDIAN); \
|
|
||||||
CHK(memcmp(target, source, sizeof(source))); \
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_LENDIAN_TO_HOST); \
|
|
||||||
CHK(!memcmp(target, source, sizeof(source))); \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_ALWAYS); \
|
|
||||||
CHK(memcmp(target, source, sizeof(source))); \
|
|
||||||
swap_data(type, target, sizeof(target), B_SWAP_ALWAYS); \
|
|
||||||
CHK(!memcmp(target, source, sizeof(source))); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint64 kArray64[] = {0x0123456789abcdefULL, 0x1234, 0x5678000000000000ULL, 0x0};
|
void Swap16_InputAscending_SwapsBytes() {
|
||||||
uint64 array64[4];
|
int16 input = 0x1234;
|
||||||
TEST(B_UINT64_TYPE, kArray64, array64);
|
uint16 expected = 0x3412;
|
||||||
|
CHK(expected == __swap_int16(input));
|
||||||
|
}
|
||||||
|
|
||||||
const uint32 kArray32[] = {0x12345678, 0x1234, 0x56780000, 0x0};
|
void Swap16_InputNegative_SwapsBytes() {
|
||||||
uint32 array32[4];
|
int16 input = 0xfedc;
|
||||||
TEST(B_UINT32_TYPE, kArray32, array32);
|
uint16 expected = 0xdcfe;
|
||||||
|
CHK(expected == __swap_int16(input));
|
||||||
|
}
|
||||||
|
|
||||||
const uint16 kArray16[] = {0x1234, 0x12, 0x3400, 0x0};
|
void Swap16_InputMixed_SwapsBytes() {
|
||||||
uint16 array16[4];
|
uint16 input = 0xfefd;
|
||||||
TEST(B_UINT16_TYPE, kArray16, array16);
|
uint16 expected = 0xfdfe;
|
||||||
|
CHK(expected == __swap_int16(input));
|
||||||
|
}
|
||||||
|
|
||||||
const float kArrayFloat[] = {3.4f, 0.0f, NAN, HUGE_VALF};
|
void Swap32_InputZero_RemainsZero() {
|
||||||
float arrayFloat[4];
|
uint32 input = 0;
|
||||||
TEST(B_FLOAT_TYPE, kArrayFloat, arrayFloat);
|
CHK(input == __swap_int32(input));
|
||||||
|
}
|
||||||
|
|
||||||
const double kArrayDouble[] = {3.42, 0.0, NAN, HUGE_VAL};
|
void Swap32_InputAscending_SwapsBytes() {
|
||||||
double arrayDouble[4];
|
int32 input = 0x12345678;
|
||||||
TEST(B_DOUBLE_TYPE, kArrayDouble, arrayDouble);
|
uint32 expected = 0x78563412;
|
||||||
|
CHK(expected == __swap_int32(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap32_InputNegative_SwapsBytes() {
|
||||||
|
int32 input = 0xfedcba98;
|
||||||
|
uint32 expected = 0x98badcfe;
|
||||||
|
CHK(expected == __swap_int32(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap32_InputMixed_SwapsBytes() {
|
||||||
|
uint32 input = 0xfefdfcfb;
|
||||||
|
uint32 expected = 0xfbfcfdfe;
|
||||||
|
CHK(expected == __swap_int32(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap64_InputZero_RemainsZero() {
|
||||||
|
uint64 input = 0;
|
||||||
|
CHK(input == __swap_int64(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap64_InputAscending_SwapsBytes() {
|
||||||
|
int64 input = 0x1234567890000000LL;
|
||||||
|
uint64 expected = 0x0000009078563412LL;
|
||||||
|
CHK(expected == __swap_int64(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap64_InputNegative_SwapsBytes() {
|
||||||
|
int64 input = 0xfedcba9876543210LL;
|
||||||
|
uint64 expected = 0x1032547698badcfeLL;
|
||||||
|
CHK(expected == __swap_int64(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap64_InputMixed_SwapsBytes() {
|
||||||
|
uint64 input = 0xfefdLL;
|
||||||
|
uint64 expected = 0xfdfe000000000000LL;
|
||||||
|
CHK(expected == __swap_int64(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapFloat_Roundtrip_ReturnsInput() {
|
||||||
|
const float kNumber = 1.125;
|
||||||
|
const float kNaN = NAN;
|
||||||
|
const float kInfinity = HUGE_VALF;
|
||||||
|
|
||||||
|
const float roundtrip = __swap_float(__swap_float(kNaN));
|
||||||
|
uint32 expectedNaN;
|
||||||
|
uint32 dataNaN;
|
||||||
|
memcpy(&dataNaN, &roundtrip, sizeof(float));
|
||||||
|
memcpy(&expectedNaN, &kNaN, sizeof(float));
|
||||||
|
|
||||||
|
CHK(kNumber == __swap_float(__swap_float(kNumber)));
|
||||||
|
CHK(expectedNaN == dataNaN); // NaN == NaN as floats returns false
|
||||||
|
CHK(kInfinity == __swap_float(__swap_float(kInfinity)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapDouble_Roundtrip_ReturnsInput() {
|
||||||
|
const double kNumber = 1.125;
|
||||||
|
const double kNaN = NAN;
|
||||||
|
const double kInfinity = HUGE_VAL;
|
||||||
|
|
||||||
|
const double roundtrip = __swap_double(__swap_double(kNaN));
|
||||||
|
uint64 expectedNaN;
|
||||||
|
uint64 dataNaN;
|
||||||
|
memcpy(&dataNaN, &roundtrip, sizeof(double));
|
||||||
|
memcpy(&expectedNaN, &kNaN, sizeof(double));
|
||||||
|
|
||||||
|
CHK(kNumber == __swap_double(__swap_double(kNumber)));
|
||||||
|
CHK(expectedNaN == dataNaN); // NaN == NaN as floats returns false
|
||||||
|
CHK(kInfinity == __swap_double(__swap_double(kInfinity)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapData_StringType_ReturnsBadValue() {
|
||||||
|
char str[4];
|
||||||
|
CHK(swap_data(B_STRING_TYPE, str, 4, B_SWAP_ALWAYS) == B_BAD_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapData_Int32TypeInputWithZeroLength_ReturnsOK() {
|
||||||
|
int32 num32 = 0;
|
||||||
|
CHK(swap_data(B_INT32_TYPE, &num32, 0, B_SWAP_ALWAYS) == B_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapData_Int32TypeWithNullInputSwapAlways_ReturnsBadValue() {
|
||||||
|
CHK(swap_data(B_INT32_TYPE, NULL, 4, B_SWAP_ALWAYS) == B_BAD_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapData_Int32TypeWithNullInputSwapEndiannessToHost_ReturnsOK() {
|
||||||
|
#if B_HOST_IS_LENDIAN
|
||||||
|
CHK(swap_data(B_INT32_TYPE, NULL, 4, B_SWAP_HOST_TO_LENDIAN) == B_OK);
|
||||||
|
#else
|
||||||
|
CHK(swap_data(B_INT32_TYPE, NULL, 4, B_SWAP_HOST_TO_BENDIAN) == B_OK);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlgorithmCheck() {
|
||||||
|
#define TEST(type, source, target) \
|
||||||
|
memcpy(target, source, sizeof(source)); \
|
||||||
|
for (int32 i = 0; i < 4; i++) { \
|
||||||
|
if (B_HOST_IS_LENDIAN) { \
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_LENDIAN); \
|
||||||
|
CHK(!memcmp(target, source, sizeof(source))); \
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_LENDIAN_TO_HOST); \
|
||||||
|
CHK(!memcmp(target, source, sizeof(source))); \
|
||||||
|
\
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_BENDIAN); \
|
||||||
|
CHK(memcmp(target, source, sizeof(source))); \
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_BENDIAN_TO_HOST); \
|
||||||
|
CHK(!memcmp(target, source, sizeof(source))); \
|
||||||
|
} else if (B_HOST_IS_BENDIAN) { \
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_BENDIAN); \
|
||||||
|
CHK(!memcmp(target, source, sizeof(source))); \
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_BENDIAN_TO_HOST); \
|
||||||
|
CHK(!memcmp(target, source, sizeof(source))); \
|
||||||
|
\
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_HOST_TO_LENDIAN); \
|
||||||
|
CHK(memcmp(target, source, sizeof(source))); \
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_LENDIAN_TO_HOST); \
|
||||||
|
CHK(!memcmp(target, source, sizeof(source))); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_ALWAYS); \
|
||||||
|
CHK(memcmp(target, source, sizeof(source))); \
|
||||||
|
swap_data(type, target, sizeof(target), B_SWAP_ALWAYS); \
|
||||||
|
CHK(!memcmp(target, source, sizeof(source))); \
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint64 kArray64[] = {0x0123456789abcdefULL, 0x1234, 0x5678000000000000ULL, 0x0};
|
||||||
|
uint64 array64[4];
|
||||||
|
TEST(B_UINT64_TYPE, kArray64, array64);
|
||||||
|
|
||||||
|
const uint32 kArray32[] = {0x12345678, 0x1234, 0x56780000, 0x0};
|
||||||
|
uint32 array32[4];
|
||||||
|
TEST(B_UINT32_TYPE, kArray32, array32);
|
||||||
|
|
||||||
|
const uint16 kArray16[] = {0x1234, 0x12, 0x3400, 0x0};
|
||||||
|
uint16 array16[4];
|
||||||
|
TEST(B_UINT16_TYPE, kArray16, array16);
|
||||||
|
|
||||||
|
const float kArrayFloat[] = {3.4f, 0.0f, NAN, HUGE_VALF};
|
||||||
|
float arrayFloat[4];
|
||||||
|
TEST(B_FLOAT_TYPE, kArrayFloat, arrayFloat);
|
||||||
|
|
||||||
|
const double kArrayDouble[] = {3.42, 0.0, NAN, HUGE_VAL};
|
||||||
|
double arrayDouble[4];
|
||||||
|
TEST(B_DOUBLE_TYPE, kArrayDouble, arrayDouble);
|
||||||
|
|
||||||
#undef TEST
|
#undef TEST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IsTypeSwapped()
|
||||||
// #pragma mark -
|
{
|
||||||
|
|
||||||
|
|
||||||
class IsTypeSwappedTest : public BTestCase {
|
|
||||||
public:
|
|
||||||
IsTypeSwappedTest(std::string name = "");
|
|
||||||
|
|
||||||
static Test *suite(void);
|
|
||||||
void test(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
IsTypeSwappedTest::IsTypeSwappedTest(std::string name)
|
|
||||||
: BTestCase(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Test *
|
|
||||||
IsTypeSwappedTest::suite(void)
|
|
||||||
{
|
|
||||||
return new CppUnit::TestCaller<IsTypeSwappedTest>("ByteOrderTest::IsTypeSwappedTest", &IsTypeSwappedTest::test);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
IsTypeSwappedTest::test(void)
|
|
||||||
{
|
|
||||||
#define IS_SWAPPED(x) CHK(is_type_swapped(x))
|
#define IS_SWAPPED(x) CHK(is_type_swapped(x))
|
||||||
#define NOT_SWAPPED(x) CHK(!is_type_swapped(x))
|
#define NOT_SWAPPED(x) CHK(!is_type_swapped(x))
|
||||||
|
|
||||||
IS_SWAPPED(B_ANY_TYPE);
|
NOT_SWAPPED(B_ANY_TYPE);
|
||||||
IS_SWAPPED(B_BOOL_TYPE);
|
IS_SWAPPED(B_BOOL_TYPE);
|
||||||
IS_SWAPPED(B_CHAR_TYPE);
|
IS_SWAPPED(B_CHAR_TYPE);
|
||||||
IS_SWAPPED(B_COLOR_8_BIT_TYPE);
|
IS_SWAPPED(B_COLOR_8_BIT_TYPE);
|
||||||
IS_SWAPPED(B_DOUBLE_TYPE);
|
IS_SWAPPED(B_DOUBLE_TYPE);
|
||||||
IS_SWAPPED(B_FLOAT_TYPE);
|
IS_SWAPPED(B_FLOAT_TYPE);
|
||||||
IS_SWAPPED(B_GRAYSCALE_8_BIT_TYPE);
|
IS_SWAPPED(B_GRAYSCALE_8_BIT_TYPE);
|
||||||
IS_SWAPPED(B_INT64_TYPE);
|
IS_SWAPPED(B_INT64_TYPE);
|
||||||
IS_SWAPPED(B_INT32_TYPE);
|
IS_SWAPPED(B_INT32_TYPE);
|
||||||
IS_SWAPPED(B_INT16_TYPE);
|
IS_SWAPPED(B_INT16_TYPE);
|
||||||
IS_SWAPPED(B_INT8_TYPE);
|
IS_SWAPPED(B_INT8_TYPE);
|
||||||
IS_SWAPPED(B_MESSAGE_TYPE);
|
IS_SWAPPED(B_MESSAGE_TYPE);
|
||||||
IS_SWAPPED(B_MESSENGER_TYPE);
|
IS_SWAPPED(B_MESSENGER_TYPE);
|
||||||
IS_SWAPPED(B_MIME_TYPE);
|
IS_SWAPPED(B_MIME_TYPE);
|
||||||
IS_SWAPPED(B_MONOCHROME_1_BIT_TYPE);
|
IS_SWAPPED(B_MONOCHROME_1_BIT_TYPE);
|
||||||
IS_SWAPPED(B_OBJECT_TYPE);
|
NOT_SWAPPED(B_OBJECT_TYPE);
|
||||||
IS_SWAPPED(B_OFF_T_TYPE);
|
IS_SWAPPED(B_OFF_T_TYPE);
|
||||||
IS_SWAPPED(B_PATTERN_TYPE);
|
IS_SWAPPED(B_PATTERN_TYPE);
|
||||||
IS_SWAPPED(B_POINTER_TYPE);
|
IS_SWAPPED(B_POINTER_TYPE);
|
||||||
IS_SWAPPED(B_POINT_TYPE);
|
IS_SWAPPED(B_POINT_TYPE);
|
||||||
IS_SWAPPED(B_RAW_TYPE);
|
NOT_SWAPPED(B_RAW_TYPE);
|
||||||
IS_SWAPPED(B_RECT_TYPE);
|
IS_SWAPPED(B_RECT_TYPE);
|
||||||
IS_SWAPPED(B_REF_TYPE);
|
IS_SWAPPED(B_REF_TYPE);
|
||||||
IS_SWAPPED(B_RGB_32_BIT_TYPE);
|
IS_SWAPPED(B_RGB_32_BIT_TYPE);
|
||||||
IS_SWAPPED(B_RGB_COLOR_TYPE);
|
IS_SWAPPED(B_RGB_COLOR_TYPE);
|
||||||
IS_SWAPPED(B_SIZE_T_TYPE);
|
IS_SWAPPED(B_SIZE_T_TYPE);
|
||||||
IS_SWAPPED(B_SSIZE_T_TYPE);
|
IS_SWAPPED(B_SSIZE_T_TYPE);
|
||||||
IS_SWAPPED(B_STRING_TYPE);
|
IS_SWAPPED(B_STRING_TYPE);
|
||||||
IS_SWAPPED(B_TIME_TYPE);
|
IS_SWAPPED(B_TIME_TYPE);
|
||||||
IS_SWAPPED(B_UINT64_TYPE);
|
IS_SWAPPED(B_UINT64_TYPE);
|
||||||
IS_SWAPPED(B_UINT32_TYPE);
|
IS_SWAPPED(B_UINT32_TYPE);
|
||||||
IS_SWAPPED(B_UINT16_TYPE);
|
IS_SWAPPED(B_UINT16_TYPE);
|
||||||
IS_SWAPPED(B_UINT8_TYPE);
|
IS_SWAPPED(B_UINT8_TYPE);
|
||||||
IS_SWAPPED(B_MEDIA_PARAMETER_TYPE);
|
NOT_SWAPPED(B_MEDIA_PARAMETER_TYPE);
|
||||||
IS_SWAPPED(B_MEDIA_PARAMETER_WEB_TYPE);
|
NOT_SWAPPED(B_MEDIA_PARAMETER_WEB_TYPE);
|
||||||
IS_SWAPPED(B_MEDIA_PARAMETER_GROUP_TYPE);
|
NOT_SWAPPED(B_MEDIA_PARAMETER_GROUP_TYPE);
|
||||||
IS_SWAPPED(B_ASCII_TYPE);
|
NOT_SWAPPED(B_ASCII_TYPE);
|
||||||
|
|
||||||
NOT_SWAPPED(' ');
|
NOT_SWAPPED(' ');
|
||||||
NOT_SWAPPED('0000');
|
NOT_SWAPPED('0000');
|
||||||
NOT_SWAPPED('1111');
|
NOT_SWAPPED('1111');
|
||||||
NOT_SWAPPED('aaaa');
|
NOT_SWAPPED('aaaa');
|
||||||
|
|
||||||
#undef IS_SWAPPED
|
#undef IS_SWAPPED
|
||||||
#undef NOT_SWAPPED
|
#undef NOT_SWAPPED
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
Test *
|
|
||||||
ByteOrderTestSuite()
|
|
||||||
{
|
|
||||||
TestSuite *testSuite = new TestSuite();
|
|
||||||
|
|
||||||
testSuite->addTest(new Swap16Test("__swap_int16()"));
|
|
||||||
testSuite->addTest(new Swap32Test("__swap_int32()"));
|
|
||||||
testSuite->addTest(new Swap64Test("__swap_int64()"));
|
|
||||||
testSuite->addTest(new SwapFloatTest("__swap_float()"));
|
|
||||||
testSuite->addTest(new SwapDoubleTest("__swap_double()"));
|
|
||||||
testSuite->addTest(new SwapDataTest("swap_data()"));
|
|
||||||
testSuite->addTest(new IsTypeSwappedTest("is_type_swapped()"));
|
|
||||||
|
|
||||||
return testSuite;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ByteOrderTest, getTestSuiteName());
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004-2010, Axel Dörfler, axeld@pinc-software.de.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
#ifndef _BYTE_ORDER_TEST_H_
|
|
||||||
#define _BYTE_ORDER_TEST_H_
|
|
||||||
|
|
||||||
|
|
||||||
#include "TestCase.h"
|
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test *ByteOrderTestSuite();
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _BYTE_ORDER_TEST_H_
|
|
||||||
@@ -3,31 +3,27 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "DateTimeTest.h"
|
|
||||||
|
|
||||||
#include <DateTime.h>
|
#include <DateTime.h>
|
||||||
|
|
||||||
#include <cppunit/TestSuite.h>
|
#include <TestCase.h>
|
||||||
|
#include <TestSuiteAddon.h>
|
||||||
|
#include <TestUtils.h>
|
||||||
|
|
||||||
|
|
||||||
class DateTimeTest : public BTestCase {
|
using CppUnit::TestFixture;
|
||||||
public:
|
|
||||||
DateTimeTest(std::string name = "");
|
|
||||||
|
|
||||||
void test(void);
|
|
||||||
|
class DateTimeTest : public TestFixture {
|
||||||
|
CPPUNIT_TEST_SUITE(DateTimeTest);
|
||||||
|
CPPUNIT_TEST(SetToMinusOne_IsValidAndReturnsCorrectProperties);
|
||||||
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
public:
|
||||||
|
void SetToMinusOne_IsValidAndReturnsCorrectProperties();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
DateTimeTest::DateTimeTest(std::string name)
|
|
||||||
:
|
|
||||||
BTestCase(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DateTimeTest::test()
|
DateTimeTest::SetToMinusOne_IsValidAndReturnsCorrectProperties()
|
||||||
{
|
{
|
||||||
BDateTime dateTime;
|
BDateTime dateTime;
|
||||||
|
|
||||||
@@ -44,12 +40,4 @@ DateTimeTest::test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test*
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(DateTimeTest, getTestSuiteName());
|
||||||
DateTimeTestSuite()
|
|
||||||
{
|
|
||||||
CppUnit::TestSuite* testSuite = new CppUnit::TestSuite();
|
|
||||||
|
|
||||||
testSuite->addTest(new DateTimeTest("BDateTime"));
|
|
||||||
|
|
||||||
return testSuite;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014, Haiku, Inc.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
#ifndef _DATE_TIME_TEST_H_
|
|
||||||
#define _DATE_TIME_TEST_H_
|
|
||||||
|
|
||||||
|
|
||||||
#include "TestCase.h"
|
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test *DateTimeTestSuite();
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _DATE_TIME_TEST_H_
|
|
||||||
@@ -10,10 +10,12 @@
|
|||||||
#include "bstring/StringTest.h"
|
#include "bstring/StringTest.h"
|
||||||
#include "bblockcache/BlockCacheTest.h"
|
#include "bblockcache/BlockCacheTest.h"
|
||||||
#include "bstopwatch/BStopWatchTest.h"
|
#include "bstopwatch/BStopWatchTest.h"
|
||||||
#include "ByteOrderTest.h"
|
|
||||||
#include "DateTimeTest.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
const char* getTestSuiteName() {
|
||||||
|
return "SupportKit";
|
||||||
|
}
|
||||||
|
|
||||||
BTestSuite *
|
BTestSuite *
|
||||||
getTestSuite()
|
getTestSuite()
|
||||||
{
|
{
|
||||||
@@ -22,14 +24,12 @@ getTestSuite()
|
|||||||
// ##### Add test suites here #####
|
// ##### Add test suites here #####
|
||||||
suite->addTest("BArchivable", ArchivableTestSuite());
|
suite->addTest("BArchivable", ArchivableTestSuite());
|
||||||
suite->addTest("BAutolock", AutolockTestSuite());
|
suite->addTest("BAutolock", AutolockTestSuite());
|
||||||
suite->addTest("BDateTime", DateTimeTestSuite());
|
|
||||||
suite->addTest("BLocker", LockerTestSuite());
|
suite->addTest("BLocker", LockerTestSuite());
|
||||||
suite->addTest("BMemoryIO", MemoryIOTestSuite());
|
suite->addTest("BMemoryIO", MemoryIOTestSuite());
|
||||||
suite->addTest("BMallocIO", MallocIOTestSuite());
|
suite->addTest("BMallocIO", MallocIOTestSuite());
|
||||||
suite->addTest("BString", StringTestSuite());
|
suite->addTest("BString", StringTestSuite());
|
||||||
suite->addTest("BBlockCache", BlockCacheTestSuite());
|
suite->addTest("BBlockCache", BlockCacheTestSuite());
|
||||||
suite->addTest("BStopWatch", BStopWatchTestSuite());
|
suite->addTest("BStopWatch", BStopWatchTestSuite());
|
||||||
suite->addTest("ByteOrder", ByteOrderTestSuite());
|
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <cppunit/TestFailure.h>
|
#include <cppunit/TestFailure.h>
|
||||||
#include <cppunit/TestResult.h>
|
#include <cppunit/TestResult.h>
|
||||||
#include <cppunit/TestSuite.h>
|
#include <cppunit/TestSuite.h>
|
||||||
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||||
|
|
||||||
#include <TestShell.h>
|
#include <TestShell.h>
|
||||||
#include <TestListener.h>
|
#include <TestListener.h>
|
||||||
@@ -63,24 +64,53 @@ BTestShell::AddSuite(BTestSuite *suite) {
|
|||||||
if (Verbosity() >= v3)
|
if (Verbosity() >= v3)
|
||||||
cout << "Adding suite '" << suite->getName() << "'" << endl;
|
cout << "Adding suite '" << suite->getName() << "'" << endl;
|
||||||
|
|
||||||
|
CppUnit::TestSuite *ts = new CppUnit::TestSuite(suite->getName());
|
||||||
// Add the suite
|
// Add the suite
|
||||||
fSuites[suite->getName()] = suite;
|
fSuites[suite->getName()] = ts;
|
||||||
|
|
||||||
// Add its tests
|
// Add its tests
|
||||||
const TestMap &map = suite->getTests();
|
const TestMap &map = suite->getTests();
|
||||||
for (TestMap::const_iterator i = map.begin();
|
for (TestMap::const_iterator i = map.begin();
|
||||||
i != map.end();
|
i != map.end();
|
||||||
i++) {
|
i++) {
|
||||||
AddTest(i->first, i->second);
|
ts->addTest(i->second);
|
||||||
if (Verbosity() >= v4 && i->second)
|
if (Verbosity() >= v4 && i->second)
|
||||||
cout << " " << i->first << endl;
|
cout << " " << i->first << endl;
|
||||||
}
|
}
|
||||||
|
AddSuite(ts);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
} else
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_EXPORT
|
||||||
|
status_t
|
||||||
|
BTestShell::AddSuite(CppUnit::TestSuite *suite) {
|
||||||
|
if (suite) {
|
||||||
|
if (Verbosity() >= v3)
|
||||||
|
cout << "Adding suite '" << suite->getName() << "'" << endl;
|
||||||
|
|
||||||
|
// Add the suite
|
||||||
|
fSuites[suite->getName()] = suite;
|
||||||
|
|
||||||
|
// Add its tests
|
||||||
|
const std::vector<CppUnit::Test*> &tests = suite->getTests();
|
||||||
|
for (std::vector<CppUnit::Test*>::const_iterator i = tests.begin();
|
||||||
|
i != tests.end();
|
||||||
|
i++) {
|
||||||
|
AddTest((*i)->getName(), *i);
|
||||||
|
if (Verbosity() >= v4 && *i)
|
||||||
|
cout << " " << (*i)->getName() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
} else
|
} else
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_EXPORT
|
_EXPORT
|
||||||
void
|
void
|
||||||
BTestShell::AddTest(const string &name, CppUnit::Test *test) {
|
BTestShell::AddTest(const string &name, CppUnit::Test *test) {
|
||||||
@@ -102,27 +132,43 @@ BTestShell::LoadSuitesFrom(BDirectory *libDir) {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
typedef BTestSuite* (*suiteFunc)(void);
|
typedef BTestSuite* (*suiteFunc)(void);
|
||||||
|
typedef const char* (*nameFunc)(void);
|
||||||
suiteFunc func;
|
suiteFunc func;
|
||||||
|
nameFunc nameF;
|
||||||
|
|
||||||
while (libDir->GetNextEntry(&addonEntry, true) == B_OK) {
|
while (libDir->GetNextEntry(&addonEntry, true) == B_OK) {
|
||||||
status_t err;
|
status_t err;
|
||||||
|
status_t addonStatus = B_ERROR;
|
||||||
err = addonEntry.GetPath(&addonPath);
|
err = addonEntry.GetPath(&addonPath);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
// cout << "Checking " << addonPath.Path() << "..." << endl;
|
cout << "Checking " << addonPath.Path() << "..." << endl;
|
||||||
addonImage = load_add_on(addonPath.Path());
|
addonImage = load_add_on(addonPath.Path());
|
||||||
err = (addonImage >= 0 ? B_OK : B_ERROR);
|
addonStatus = (addonImage >= 0 ? B_OK : B_ERROR);
|
||||||
}
|
}
|
||||||
if (err == B_OK) {
|
if (addonStatus == B_OK) {
|
||||||
// cout << "..." << endl;
|
|
||||||
err = get_image_symbol(addonImage, "getTestSuite",
|
err = get_image_symbol(addonImage, "getTestSuite",
|
||||||
B_SYMBOL_TYPE_TEXT, reinterpret_cast<void **>(&func));
|
B_SYMBOL_TYPE_TEXT, reinterpret_cast<void **>(&func));
|
||||||
} else {
|
} else {
|
||||||
// cout << " !!! err == " << err << endl;
|
// cout << " getTestSuite error == " << err << endl;
|
||||||
}
|
}
|
||||||
if (err == B_OK)
|
if (err == B_OK) {
|
||||||
err = AddSuite(func());
|
err = AddSuite(func());
|
||||||
if (err == B_OK)
|
if (err == B_OK)
|
||||||
count++;
|
count++;
|
||||||
|
}
|
||||||
|
if(addonStatus == B_OK) {
|
||||||
|
err = get_image_symbol(addonImage, "getTestSuiteName",
|
||||||
|
B_SYMBOL_TYPE_TEXT, reinterpret_cast<void **>(&nameF));
|
||||||
|
if(err == B_OK) {
|
||||||
|
const char* testSuiteName = nameF();
|
||||||
|
CppUnit::TestFactoryRegistry ®istry =
|
||||||
|
CppUnit::TestFactoryRegistry::getRegistry(testSuiteName);
|
||||||
|
AddSuite(static_cast<CppUnit::TestSuite*>(registry.makeTest()));
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
// cout << " getTestSuiteName error == " << err << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@@ -178,10 +224,10 @@ BTestShell::Run(int argc, char *argv[]) {
|
|||||||
if (fTests.find(*i) == fTests.end()) {
|
if (fTests.find(*i) == fTests.end()) {
|
||||||
suitesToRemove.insert(*i);
|
suitesToRemove.insert(*i);
|
||||||
}
|
}
|
||||||
const TestMap &tests = fSuites[*i]->getTests();
|
const std::vector<CppUnit::Test*> &tests = fSuites[*i]->getTests();
|
||||||
TestMap::const_iterator j;
|
std::vector<CppUnit::Test*>::const_iterator j;
|
||||||
for (j = tests.begin(); j != tests.end(); j++) {
|
for (j = tests.begin(); j != tests.end(); j++) {
|
||||||
fTestsToRun.insert( j->first );
|
fTestsToRun.insert( (*j)->getName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,7 +516,6 @@ BTestShell::LoadDynamicSuites() {
|
|||||||
endl << endl;
|
endl << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT
|
_EXPORT
|
||||||
|
|||||||
Reference in New Issue
Block a user