summaryrefslogtreecommitdiff
path: root/test/base/PlatformInfoTest.c
blob: 474460226ef88b7c6a3bb2145518a770f463a485 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;
}