From d53fa8a169832563c62262078b8d2ffe5cab8473 Mon Sep 17 00:00:00 2001 From: pepper Date: Sat, 10 Jan 2015 21:32:32 -0800 Subject: first --- test/base/PlatformInfoTest.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/base/PlatformInfoTest.c (limited to 'test/base/PlatformInfoTest.c') diff --git a/test/base/PlatformInfoTest.c b/test/base/PlatformInfoTest.c new file mode 100644 index 0000000..4744602 --- /dev/null +++ b/test/base/PlatformInfoTest.c @@ -0,0 +1,86 @@ +#include "unit/TestRunner.h" +#include "base/PlatformInfo.h" + +static int _testGetPlatformType(void) +{ + PlatformInfo platform = newPlatformInfo(); +#if LINUX + assertIntEquals(PLATFORM_LINUX, platform->type); +#elif MACOSX + assertIntEquals(PLATFORM_MACOSX, platform->type); +#elif WINDOWS + assertIntEquals(PLATFORM_WINDOWS, platform->type); +#else + assertIntEquals(PLATFORM_UNSUPPORTED, platform->type); +#endif + freePlatformInfo(platform); + return 0; +} + +static int _testGetPlatformName(void) +{ + PlatformInfo platform = newPlatformInfo(); +#if LINUX + assertCharStringContains("Linux", platform->name); +#elif MACOSX + assertCharStringContains("Mac OS X", platform->name); +#elif WINDOWS + assertCharStringContains("Windows", platform->name); +#else + assertCharStringEquals("Unsupported platform", platform->name); +#endif + freePlatformInfo(platform); + return 0; +} + +static int _testGetShortPlatformName(void) +{ + PlatformInfo platform = newPlatformInfo(); +#if LINUX + + if (platformInfoIsHost64Bit() && platformInfoIsRuntime64Bit()) { + assertCharStringEquals("Linux-x86_64", platform->shortName); + } else { + assertCharStringEquals("Linux-i686", platform->shortName); + } + +#elif MACOSX + assertCharStringEquals("Mac OS X", platform->shortName); +#elif WINDOWS + + if (platformInfoIsHost64Bit() && platformInfoIsRuntime64Bit()) { + assertCharStringEquals("Windows 64-bit", platform->shortName); + } else { + assertCharStringEquals("Windows 32-bit", platform->shortName); + } + +#else + assertCharStringEquals("Unsupported", platform->shortName); +#endif + freePlatformInfo(platform); + return 0; +} + +static int _testIsHostLittleEndian(void) +{ +#if HOST_BIG_ENDIAN + assertFalse(isHostLittleEndian()); +#elif HOST_LITTLE_ENDIAN + assert(isHostLittleEndian()); +#endif + return 0; +} + +TestSuite addPlatformInfoTests(void); +TestSuite addPlatformInfoTests(void) +{ + TestSuite testSuite = newTestSuite("PlatformInfo", NULL, NULL); + + addTest(testSuite, "GetPlatformType", _testGetPlatformType); + addTest(testSuite, "GetPlatformName", _testGetPlatformName); + addTest(testSuite, "GetShortPlatformName", _testGetShortPlatformName); + + addTest(testSuite, "IsHostLittleEndian", _testIsHostLittleEndian); + + return testSuite; +} -- cgit v1.2.3-70-g09d2