-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathStdLibFunctionTests.cs
More file actions
90 lines (80 loc) · 2.78 KB
/
Copy pathStdLibFunctionTests.cs
File metadata and controls
90 lines (80 loc) · 2.78 KB
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
87
88
89
90
// SPDX-FileCopyrightText: 2025 Cesium contributors <https://github.com/ForNeVeR/Cesium>
//
// SPDX-License-Identifier: MIT
using System.Text;
namespace Cesium.Runtime.Tests;
public class StdLibFunctionTests
{
[Theory]
[InlineData("1010", 2, 10)]
[InlineData("12", 8, 10)]
[InlineData("A", 16, 10)]
[InlineData("junk", 36, 926192)]
[InlineData(" -40", 10, -40)]
[InlineData("012", 0, 10)]
[InlineData("0xA", 0, 10)]
[InlineData("junk", 0, 0)]
[InlineData("111.", 10, 111)]
public unsafe void StrToL(string input, int @base, long expectedResult)
{
var stringBytes = Encoding.UTF8.GetBytes(input);
fixed (byte* str = stringBytes)
{
var actual = StdLibFunctions.StrToL(str, null, @base);
Assert.Equal(expectedResult, actual);
}
byte* strEnd;
fixed (byte* str = stringBytes)
{
var actual = StdLibFunctions.StrToL(str, &strEnd, @base);
Assert.Equal(expectedResult, actual);
}
}
[Fact]
public unsafe void StrToLOutOfRange()
{
var stringBytes = Encoding.UTF8.GetBytes("10 200000000000000000000000000000");
fixed (byte* str = stringBytes)
{
byte* str_end;
StdLibFunctions.StrToL(str, &str_end, 10);
var actual = StdLibFunctions.StrToL(str_end, &str_end, 10);
var errorCode = *StdLibFunctions.GetErrNo();
Assert.Equal(34, errorCode);
Assert.Equal(long.MaxValue, actual);
}
stringBytes = Encoding.UTF8.GetBytes(" -200000000000000000000000000000");
fixed (byte* str = stringBytes)
{
var actual = StdLibFunctions.StrToL(str, null, 10);
var errorCode = *StdLibFunctions.GetErrNo();
Assert.Equal(34, errorCode);
Assert.Equal(long.MinValue, actual);
}
}
[Theory]
[InlineData("111.11", 111.11, 0)]
[InlineData("-2.22", -2.22, 0)]
[InlineData(" -2.22", -2.22, 0)]
[InlineData("NaN", double.NaN, 0)]
[InlineData("nan(2)", double.NaN, 0)]
[InlineData("inF", double.PositiveInfinity, 0)]
[InlineData("0X1.BC70A3D70A3D7P+6", 111.11, 0)]
[InlineData("junk", 0, (int)(byte)'j')]
public unsafe void StrToD(string input, double expectedResult, int expectedLastByte)
{
var stringBytes = Encoding.UTF8.GetBytes(input);
fixed (byte* str = stringBytes)
{
var actual = StdLibFunctions.StrToD(str, null);
Assert.Equal(expectedResult, actual);
}
byte* strEnd;
fixed (byte* str = stringBytes)
{
var actual = StdLibFunctions.StrToD(str, &strEnd);
Assert.Equal(expectedResult, actual);
Assert.Equal(expectedLastByte, *strEnd);
}
}
}