| ... | @@ -1,239 +0,0 @@ |
| 1 | const builtin = @import("builtin"); |
| 2 | const std = @import("std"); |
| 3 | const expect = std.testing.expect; |
| 4 | const expectEqual = std.testing.expectEqual; |
| 5 | const expectEqualStrings = std.testing.expectEqualStrings; |
| 6 | |
| 7 | const h = @cImport(@cInclude("macros.h")); |
| 8 | const latin1 = @cImport(@cInclude("macros_not_utf8.h")); |
| 9 | |
| 10 | test "casting to void with a macro" { |
| 11 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 12 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 13 | |
| 14 | h.IGNORE_ME_1(42); |
| 15 | h.IGNORE_ME_2(42); |
| 16 | h.IGNORE_ME_3(42); |
| 17 | h.IGNORE_ME_4(42); |
| 18 | h.IGNORE_ME_5(42); |
| 19 | h.IGNORE_ME_6(42); |
| 20 | h.IGNORE_ME_7(42); |
| 21 | h.IGNORE_ME_8(42); |
| 22 | h.IGNORE_ME_9(42); |
| 23 | h.IGNORE_ME_10(42); |
| 24 | } |
| 25 | |
| 26 | test "initializer list expression" { |
| 27 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 28 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 29 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 30 | |
| 31 | try expectEqual(h.Color{ |
| 32 | .r = 200, |
| 33 | .g = 200, |
| 34 | .b = 200, |
| 35 | .a = 255, |
| 36 | }, h.LIGHTGRAY); |
| 37 | } |
| 38 | |
| 39 | test "sizeof in macros" { |
| 40 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 41 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 42 | |
| 43 | try expect(@as(c_int, @sizeOf(u32)) == h.MY_SIZEOF(u32)); |
| 44 | try expect(@as(c_int, @sizeOf(u32)) == h.MY_SIZEOF2(u32)); |
| 45 | } |
| 46 | |
| 47 | test "reference to a struct type" { |
| 48 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 49 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 50 | |
| 51 | try expect(@sizeOf(h.struct_Foo) == h.SIZE_OF_FOO); |
| 52 | } |
| 53 | |
| 54 | test "cast negative integer to pointer" { |
| 55 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 56 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 57 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 58 | |
| 59 | try expectEqual(@as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))), h.MAP_FAILED); |
| 60 | } |
| 61 | |
| 62 | test "casting to union with a macro" { |
| 63 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 64 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 65 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 66 | |
| 67 | const l: c_long = 42; |
| 68 | const d: f64 = 2.0; |
| 69 | |
| 70 | var casted = h.UNION_CAST(l); |
| 71 | try expect(l == casted.l); |
| 72 | |
| 73 | casted = h.UNION_CAST(d); |
| 74 | try expect(d == casted.d); |
| 75 | } |
| 76 | |
| 77 | test "casting or calling a value with a paren-surrounded macro" { |
| 78 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 79 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 80 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 81 | |
| 82 | const l: c_long = 42; |
| 83 | const casted = h.CAST_OR_CALL_WITH_PARENS(c_int, l); |
| 84 | try expect(casted == @as(c_int, @intCast(l))); |
| 85 | |
| 86 | const Helper = struct { |
| 87 | fn foo(n: c_int) !void { |
| 88 | try expect(n == 42); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | try h.CAST_OR_CALL_WITH_PARENS(Helper.foo, 42); |
| 93 | } |
| 94 | |
| 95 | test "nested comma operator" { |
| 96 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 97 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 98 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 99 | |
| 100 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR); |
| 101 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR_LHS); |
| 102 | } |
| 103 | |
| 104 | test "cast functions" { |
| 105 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 106 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 107 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 108 | |
| 109 | const S = struct { |
| 110 | fn foo() void {} |
| 111 | }; |
| 112 | try expectEqual(true, h.CAST_TO_BOOL(S.foo)); |
| 113 | try expect(h.CAST_TO_UINTPTR(S.foo) != 0); |
| 114 | } |
| 115 | |
| 116 | test "large integer macro" { |
| 117 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 118 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 119 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 120 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 121 | |
| 122 | try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT); |
| 123 | } |
| 124 | |
| 125 | test "string literal macro with embedded tab character" { |
| 126 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 127 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 128 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 129 | |
| 130 | try expectEqualStrings("hello\t", h.EMBEDDED_TAB); |
| 131 | } |
| 132 | |
| 133 | test "string and char literals that are not UTF-8 encoded. Issue #12784" { |
| 134 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 135 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 136 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 137 | |
| 138 | try expectEqual(@as(u8, '\xA9'), latin1.UNPRINTABLE_CHAR); |
| 139 | try expectEqualStrings("\xA9\xA9\xA9", latin1.UNPRINTABLE_STRING); |
| 140 | } |
| 141 | |
| 142 | test "Macro that uses division operator. Issue #13162" { |
| 143 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 144 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 145 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 146 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 147 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; |
| 148 | |
| 149 | try expectEqual(@as(c_int, 42), h.DIVIDE_CONSTANT(@as(c_int, 42_000))); |
| 150 | try expectEqual(@as(c_uint, 42), h.DIVIDE_CONSTANT(@as(c_uint, 42_000))); |
| 151 | |
| 152 | try expectEqual( |
| 153 | @as(f64, 42.0), |
| 154 | h.DIVIDE_ARGS( |
| 155 | @as(f64, 42.0), |
| 156 | true, |
| 157 | ), |
| 158 | ); |
| 159 | |
| 160 | try expectEqual( |
| 161 | @as(c_int, 21), |
| 162 | h.DIVIDE_ARGS( |
| 163 | @as(i8, 42), |
| 164 | @as(i8, 2), |
| 165 | ), |
| 166 | ); |
| 167 | |
| 168 | try expectEqual( |
| 169 | @as(c_uint, 21), |
| 170 | h.DIVIDE_ARGS( |
| 171 | @as(u32, 42), |
| 172 | @as(u32, 2), |
| 173 | ), |
| 174 | ); |
| 175 | |
| 176 | try expectEqual( |
| 177 | @as(c_int, 21), |
| 178 | h.DIVIDE_ARGS( |
| 179 | @as(c_ushort, 42), |
| 180 | @as(c_ushort, 2), |
| 181 | ), |
| 182 | ); |
| 183 | } |
| 184 | |
| 185 | test "Macro that uses remainder operator. Issue #13346" { |
| 186 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 187 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 188 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 189 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 190 | |
| 191 | try expectEqual(@as(c_int, 2_010), h.REMAINDER_CONSTANT(@as(c_int, 42_010))); |
| 192 | try expectEqual(@as(c_uint, 2_030), h.REMAINDER_CONSTANT(@as(c_uint, 42_030))); |
| 193 | |
| 194 | try expectEqual( |
| 195 | @as(c_int, 7), |
| 196 | h.REMAINDER_ARGS( |
| 197 | @as(i8, 17), |
| 198 | @as(i8, 10), |
| 199 | ), |
| 200 | ); |
| 201 | |
| 202 | try expectEqual( |
| 203 | @as(c_int, 5), |
| 204 | h.REMAINDER_ARGS( |
| 205 | @as(c_ushort, 25), |
| 206 | @as(c_ushort, 20), |
| 207 | ), |
| 208 | ); |
| 209 | |
| 210 | try expectEqual( |
| 211 | @as(c_int, 1), |
| 212 | h.REMAINDER_ARGS( |
| 213 | @as(c_int, 5), |
| 214 | @as(c_int, -2), |
| 215 | ), |
| 216 | ); |
| 217 | } |
| 218 | |
| 219 | test "@typeInfo on @cImport result" { |
| 220 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 221 | |
| 222 | try expect(@typeInfo(h).@"struct".decls.len > 1); |
| 223 | } |
| 224 | |
| 225 | test "Macro that uses Long type concatenation casting" { |
| 226 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 227 | |
| 228 | try expect((@TypeOf(h.X)) == c_long); |
| 229 | try expectEqual(h.X, @as(c_long, 10)); |
| 230 | } |
| 231 | |
| 232 | test "Blank macros" { |
| 233 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 234 | |
| 235 | try expectEqual(h.BLANK_MACRO, ""); |
| 236 | try expectEqual(h.BLANK_CHILD_MACRO, ""); |
| 237 | try expect(@TypeOf(h.BLANK_MACRO_CAST) == h.def_type); |
| 238 | try expectEqual(h.BLANK_MACRO_CAST, @as(c_long, 0)); |
| 239 | } |