[Tests][Interop] Add test fields of _Bool type

This commit is contained in:
Sergey Bogolepov
2020-07-08 19:35:15 +07:00
committed by Sergey Bogolepov
parent 10484fbb29
commit 6c45bb416b
4 changed files with 29 additions and 14 deletions
+19 -13
View File
@@ -11,7 +11,7 @@ fun assertEquals(value1: Any?, value2: Any?) {
throw AssertionError("Expected $value1, got $value2")
}
fun check(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) {
fun check(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E, x8: Boolean) {
assertEquals(x1, s.x1)
assertEquals(x1, getX1(s.ptr))
@@ -32,9 +32,12 @@ fun check(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E
assertEquals(x7, s.x7)
assertEquals(x7, getX7(s.ptr))
assertEquals(x8, s.x8)
assertEquals(x8, getX8(s.ptr))
}
fun assign(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) {
fun assign(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E, x8: Boolean) {
s.x1 = x1
s.x2 = x2
s.x3 = x3
@@ -42,9 +45,11 @@ fun assign(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7:
s.x5 = x5
s.x6 = x6
s.x7 = x7
s.x8 = x8
}
fun assignReversed(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) {
fun assignReversed(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E, x8: Boolean) {
s.x8 = x8
s.x7 = x7
s.x6 = x6
s.x5 = x5
@@ -54,20 +59,20 @@ fun assignReversed(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Lo
s.x1 = x1
}
fun test(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E) {
assign(s, x1, x2, x3, x4, x5, x6, x7)
check(s, x1, x2, x3, x4, x5, x6, x7)
fun test(s: S, x1: Long, x2: B2, x3: UShort, x4: UInt, x5: Int, x6: Long, x7: E, x8: Boolean) {
assign(s, x1, x2, x3, x4, x5, x6, x7, x8)
check(s, x1, x2, x3, x4, x5, x6, x7, x8)
assignReversed(s, x1, x2, x3, x4, x5, x6, x7)
check(s, x1, x2, x3, x4, x5, x6, x7)
assignReversed(s, x1, x2, x3, x4, x5, x6, x7, x8)
check(s, x1, x2, x3, x4, x5, x6, x7, x8)
// Also check with some insignificant bits modified:
assign(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE, x7)
check(s, x1, x2, x3, x4, x5, x6, x7)
assign(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE, x7, x8)
check(s, x1, x2, x3, x4, x5, x6, x7, x8)
assignReversed(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE, x7)
check(s, x1, x2, x3, x4, x5, x6, x7)
assignReversed(s, x1 + 2, x2, (x3 + 8u).toUShort(), x4 - 16u, x5 + 32, x6 + Long.MIN_VALUE, x7, x8)
check(s, x1, x2, x3, x4, x5, x6, x7, x8)
}
fun main(args: Array<String>) {
@@ -80,6 +85,7 @@ fun main(args: Array<String>) {
for (x5 in intArrayOf(-16, -2, -1, 0, 5, 15))
for (x6 in longArrayOf(Long.MIN_VALUE/2, -1L shl 36, -325L, 0, 1L shl 48, Long.MAX_VALUE/2))
for (x7 in E.values())
test(s, x1, x2, x3.toUShort(), x4, x5, x6, x7)
for (x8 in arrayOf(false, true))
test(s, x1, x2, x3.toUShort(), x4, x5, x6, x7, x8)
}
}
@@ -15,6 +15,7 @@ struct __attribute__((packed)) S {
int x5 : 5;
long long x6 : 63;
enum E x7: 2;
_Bool x8 : 1;
};
static long long getX1(struct S* s) { return s->x1; }
@@ -24,3 +25,4 @@ static unsigned int getX4(struct S* s) { return s->x4; }
static int getX5(struct S* s) { return s->x5; }
static long long getX6(struct S* s) { return s->x6; }
static enum E getX7(struct S* s) { return s->x7; }
static _Bool getX8(struct S* s) { return s->x8; }
@@ -19,6 +19,7 @@ struct Complex {
enum E e;
enum NonStrict nonStrict;
int arr[2];
_Bool b;
};
struct __attribute__((packed)) Packed {
@@ -33,7 +34,8 @@ struct Complex produceComplex() {
.next = 0,
.e = R,
.nonStrict = K,
.arr = {-51, -19}
.arr = {-51, -19},
.b = 1
};
return complex;
};
@@ -34,6 +34,10 @@ fun main() {
assertEquals(arr[0], 51)
assertEquals(arr[1], 19)
assertEquals(true, b)
b = false
assertEquals(false, b)
// Check that subtyping via Nothing-returning functions does not break compiler.
assertFailsWith<NotImplementedError> {
ui = TODO()
@@ -41,6 +45,7 @@ fun main() {
next = TODO()
e = TODO()
nonStrict = TODO()
b = TODO()
}
}
memScoped {