| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package msg |
| |
| import ( |
| "testing" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/assert" |
| "android.googlesource.com/platform/tools/gpu/framework/binary/any" |
| ) |
| |
| func TestArgHash(t *testing.T) { |
| ctx := assert.Context(t) |
| |
| args1 := Arg{ |
| Key: "Atom", |
| Value: BoxOrPanic(1023), |
| } |
| args2 := Arg{ |
| Key: "Atom", |
| Value: BoxOrPanic(1023), |
| } |
| args3 := Arg{ |
| Key: "Atom", |
| Value: BoxOrPanic(1024), |
| } |
| args4 := Arg{ |
| Key: "AtomGroup", |
| Value: BoxOrPanic(1023), |
| } |
| args5 := Arg{ |
| Key: "Atom", |
| Value: BoxOrPanic("1023"), |
| } |
| |
| // Force to import any package in order to initialize boxer. |
| _ = any.Namespace |
| for _, test := range []struct { |
| name string |
| lhs Arg |
| rhs Arg |
| expected bool |
| }{ |
| { |
| name: "Compare similar args", |
| lhs: args1, |
| rhs: args2, |
| expected: true, |
| }, { |
| name: "Compare args with different values", |
| lhs: args1, |
| rhs: args3, |
| expected: false, |
| }, { |
| name: "Compare args with different keys", |
| lhs: args3, |
| rhs: args4, |
| expected: false, |
| }, { |
| name: "Compare args with different types of values", |
| lhs: args1, |
| rhs: args5, |
| expected: false, |
| }, |
| } { |
| lhsHash, lhsErr := test.lhs.Hash() |
| assert.With(ctx).That(lhsErr).IsNil() |
| assert.With(ctx).That(lhsHash.IsValid()).Equals(true) |
| rhsHash, rhsErr := test.rhs.Hash() |
| assert.With(ctx).That(rhsErr).IsNil() |
| assert.With(ctx).That(rhsHash.IsValid()).Equals(true) |
| assert.With(ctx).That(lhsHash == rhsHash).Equals(test.expected) |
| } |
| } |