| 1 | const builtin = @import("builtin"); |
| 2 | const std = @import("std"); |
| 3 | |
| 4 | const c = std.c; |
| 5 | const testing = std.testing; |
| 6 | |
| 7 | test "wcsdup" { |
| 8 | const org: [*:0]const c.wchar_t = &[_:0]c.wchar_t{ 'H', 'e', 'l', 'l', 'o' }; |
| 9 | const cpy_opt = c.wcsdup(org); |
| 10 | const cpy = cpy_opt orelse return error.OutOfMemory; |
| 11 | defer c.free(cpy); |
| 12 | |
| 13 | try testing.expectEqual(@as(usize, 5), std.mem.len(@as([*:0]const c.wchar_t, cpy))); |
| 14 | |
| 15 | try testing.expectEqual(@as(c.wchar_t, 'H'), cpy[0]); |
| 16 | try testing.expectEqual(@as(c.wchar_t, 'e'), cpy[1]); |
| 17 | try testing.expectEqual(@as(c.wchar_t, 'l'), cpy[2]); |
| 18 | try testing.expectEqual(@as(c.wchar_t, 'l'), cpy[3]); |
| 19 | try testing.expectEqual(@as(c.wchar_t, 'o'), cpy[4]); |
| 20 | try testing.expectEqual(@as(c.wchar_t, 0), cpy[5]); |
| 21 | |
| 22 | try testing.expect(@intFromPtr(cpy) != @intFromPtr(org)); |
| 23 | |
| 24 | cpy[0] = 'B'; |
| 25 | try testing.expectEqual(@as(c.wchar_t, 'H'), org[0]); |
| 26 | try testing.expectEqual(@as(c.wchar_t, 'B'), cpy[0]); |
| 27 | } |
| 28 | |
| 29 | test "wcsdup empty string" { |
| 30 | const org: [*:0]const c.wchar_t = &[_:0]c.wchar_t{}; |
| 31 | const cpy = c.wcsdup(org) orelse return error.OutOfMemory; |
| 32 | defer c.free(cpy); |
| 33 | try testing.expectEqual(@as(c.wchar_t, 0), cpy[0]); |
| 34 | } |