| // Copyright 2020 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package zx_test |
| |
| import ( |
| "syscall/zx" |
| "testing" |
| ) |
| |
| func TestRightsSubtract(t *testing.T) { |
| var minuend zx.Rights = 0b0011 |
| var subrahend zx.Rights = 0b0101 |
| var expectedDifference zx.Rights = 0b0010 |
| if res := minuend.Subtract(subrahend); res != expectedDifference { |
| t.Fatalf("unexpected rights subtraction result %d - %d = %d not %d", |
| minuend, subrahend, res, expectedDifference) |
| } |
| } |
| |
| func TestSupersetSubset(t *testing.T) { |
| type testCase struct { |
| leftOperand zx.Rights |
| rightOperand zx.Rights |
| isStrictSubset bool |
| isSubset bool |
| isStrictSuperset bool |
| isSuperset bool |
| } |
| testCases := []testCase{ |
| { |
| leftOperand: 0b0, |
| rightOperand: 0b0, |
| isStrictSubset: false, |
| isSubset: true, |
| isStrictSuperset: false, |
| isSuperset: true, |
| }, |
| { |
| leftOperand: 0b1, |
| rightOperand: 0b1, |
| isStrictSubset: false, |
| isSubset: true, |
| isStrictSuperset: false, |
| isSuperset: true, |
| }, |
| { |
| leftOperand: 0b11, |
| rightOperand: 0b01, |
| isStrictSubset: false, |
| isSubset: false, |
| isStrictSuperset: true, |
| isSuperset: true, |
| }, |
| { |
| leftOperand: 0b01, |
| rightOperand: 0b11, |
| isStrictSubset: true, |
| isSubset: true, |
| isStrictSuperset: false, |
| isSuperset: false, |
| }, |
| { |
| leftOperand: 0b10, |
| rightOperand: 0b01, |
| isStrictSubset: false, |
| isSubset: false, |
| isStrictSuperset: false, |
| isSuperset: false, |
| }, |
| } |
| for _, testCase := range testCases { |
| if res := testCase.leftOperand.StrictSubsetOf(testCase.rightOperand); res != testCase.isStrictSubset { |
| t.Errorf("(%d).StrictSubsetOf(%d) was %v, wanted %v", testCase.leftOperand, testCase.rightOperand, res, testCase.isStrictSubset) |
| } |
| if res := testCase.leftOperand.SubsetOf(testCase.rightOperand); res != testCase.isSubset { |
| t.Errorf("(%d).SubsetOf(%d) was %v, wanted %v", testCase.leftOperand, testCase.rightOperand, res, testCase.isSubset) |
| } |
| if res := testCase.leftOperand.StrictSupersetOf(testCase.rightOperand); res != testCase.isStrictSuperset { |
| t.Errorf("(%d).StrictSupersetOf(%d) was %v, wanted %v", testCase.leftOperand, testCase.rightOperand, res, testCase.isStrictSuperset) |
| } |
| if res := testCase.leftOperand.SupersetOf(testCase.rightOperand); res != testCase.isSuperset { |
| t.Errorf("(%d).SupersetOf(%d) was %v, wanted %v", testCase.leftOperand, testCase.rightOperand, res, testCase.isSuperset) |
| } |
| } |
| } |