platform.cpp (4931B)
1 #include "helper.hpp" 2 3 #include <platform.hpp> 4 5 #include <utility> 6 7 static const char *M = "[platform]"; 8 9 TEST_CASE("default platform", M) { 10 const Platform pl; 11 REQUIRE(pl.value() == Platform::Generic); 12 REQUIRE(pl.test()); 13 } 14 15 TEST_CASE("platform from string", M) { 16 SECTION("unknown") 17 REQUIRE(Platform("hello") == Platform::Unknown); 18 19 SECTION("generic") 20 REQUIRE(Platform("all") == Platform::Generic); 21 22 SECTION("windows") { 23 REQUIRE(Platform("windows") == Platform::Windows_Any); 24 REQUIRE(Platform("win32") == Platform::Windows_x86); 25 REQUIRE(Platform("win64") == Platform::Windows_x64); 26 REQUIRE(Platform("win64", false) == Platform::Windows_x64_arm64ec); 27 REQUIRE(Platform("windows-arm64ec") == Platform::Windows_arm64ec); 28 } 29 30 SECTION("macOS") { 31 REQUIRE(Platform("darwin") == Platform::Darwin_Any); 32 REQUIRE(Platform("darwin32") == Platform::Darwin_i386); 33 REQUIRE(Platform("darwin64") == Platform::Darwin_x86_64); 34 REQUIRE(Platform("darwin-arm64") == Platform::Darwin_arm64); 35 } 36 37 SECTION("linux") { 38 REQUIRE(Platform("linux") == Platform::Linux_Any); 39 REQUIRE(Platform("linux32") == Platform::Linux_i686); 40 REQUIRE(Platform("linux64") == Platform::Linux_x86_64); 41 REQUIRE(Platform("linux-armv7l") == Platform::Linux_armv7l); 42 REQUIRE(Platform("linux-aarch64") == Platform::Linux_aarch64); 43 } 44 } 45 46 TEST_CASE("test platform", M) { 47 const std::pair<Platform, bool> tests[] { 48 {Platform::Unknown, false}, 49 {Platform::Generic, true }, 50 51 #ifdef __APPLE__ 52 {Platform::Linux_Any, false}, 53 {Platform::Linux_x86_64, false}, 54 {Platform::Linux_i686, false}, 55 {Platform::Linux_armv7l, false}, 56 {Platform::Linux_aarch64, false}, 57 {Platform::Windows_Any, false}, 58 {Platform::Windows_x64, false}, 59 {Platform::Windows_x86, false}, 60 {Platform::Windows_arm64ec, false}, 61 62 {Platform::Darwin_Any, true }, 63 # ifdef __x86_64__ 64 {Platform::Darwin_i386, false}, 65 {Platform::Darwin_x86_64, true }, 66 {Platform::Darwin_arm64, false}, 67 # elif __i386__ 68 {Platform::Darwin_i386, true }, 69 {Platform::Darwin_x86_64, false}, 70 {Platform::Darwin_arm64, false}, 71 # elif __arm64__ 72 {Platform::Darwin_i386, false}, 73 {Platform::Darwin_x86_64, false}, 74 {Platform::Darwin_arm64, true }, 75 # else 76 # error Untested architecture 77 # endif 78 79 #elif __linux__ 80 {Platform::Darwin_Any, false}, 81 {Platform::Darwin_i386, false}, 82 {Platform::Darwin_x86_64, false}, 83 {Platform::Darwin_arm64, false}, 84 {Platform::Windows_Any, false}, 85 {Platform::Windows_x86, false}, 86 {Platform::Windows_x64, false}, 87 {Platform::Windows_arm64ec, false}, 88 89 {Platform::Linux_Any, true }, 90 # ifdef __x86_64__ 91 {Platform::Linux_i686, false}, 92 {Platform::Linux_x86_64, true }, 93 {Platform::Linux_armv7l, false}, 94 {Platform::Linux_aarch64, false}, 95 # elif __i686__ 96 {Platform::Linux_i686, true }, 97 {Platform::Linux_x86_64, false}, 98 {Platform::Linux_armv7l, false}, 99 {Platform::Linux_aarch64, false}, 100 # elif __ARM_ARCH_7A__ 101 {Platform::Linux_i686, false}, 102 {Platform::Linux_x86_64, false}, 103 {Platform::Linux_armv7l, true }, 104 {Platform::Linux_aarch64, false}, 105 # elif __aarch64__ 106 {Platform::Linux_i686, false}, 107 {Platform::Linux_x86_64, false}, 108 {Platform::Linux_armv7l, false}, 109 {Platform::Linux_aarch64, true }, 110 # else 111 # error Untested architecture 112 # endif 113 114 #elif _WIN32 115 {Platform::Darwin_Any, false}, 116 {Platform::Darwin_i386, false}, 117 {Platform::Darwin_x86_64, false}, 118 {Platform::Darwin_arm64, false}, 119 {Platform::Linux_Any, false}, 120 {Platform::Linux_x86_64, false}, 121 {Platform::Linux_i686, false}, 122 {Platform::Linux_armv7l, false}, 123 {Platform::Linux_aarch64, false}, 124 125 {Platform::Windows_Any, true }, 126 # ifdef _M_ARM64EC 127 {Platform::Windows_x86, false}, 128 {Platform::Windows_x64, false}, 129 {Platform::Windows_arm64ec, true }, 130 # elif _M_X64 131 {Platform::Windows_x86, false}, 132 {Platform::Windows_x64, true }, 133 {Platform::Windows_arm64ec, false}, 134 # else 135 {Platform::Windows_x86, true }, 136 {Platform::Windows_x64, false}, 137 {Platform::Windows_arm64ec, false}, 138 # endif 139 140 #else 141 # error Untested platform 142 #endif 143 }; 144 145 for(const auto &[platform, expected] : tests) { 146 INFO("Testing platform: " << platform); 147 REQUIRE(platform.test() == expected); 148 } 149 } 150 151 TEST_CASE("current platform", M) { 152 REQUIRE((Platform::Current & Platform::Unknown) == 0); 153 REQUIRE((Platform::Current & Platform::Unknown) == Platform::Unknown); 154 155 REQUIRE((Platform::Current & Platform::Generic) != 0); 156 REQUIRE((Platform::Current & Platform::Generic) != Platform::Generic); 157 }