| // 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 log_test |
| |
| import ( |
| "testing" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| "golang.org/x/net/context" |
| ) |
| |
| func TestContext(t *testing.T) { |
| background := log.Background() |
| if background.Unwrap() != context.Background() { |
| t.Errorf("log.Background did not use context.Background") |
| } |
| todo := log.TODO() |
| if todo.Unwrap() != context.TODO() { |
| t.Errorf("log.TODO did not use context.TODO") |
| } |
| if background.Unwrap() == todo.Unwrap() { |
| t.Errorf("TODO and Background use the same context") |
| } |
| } |
| |
| func TestContextNotContext(t *testing.T) { |
| // the context package is very fussy about the types that actually implement context.Context |
| // all cancellation behaviour is broken if you implement your own version |
| // it would be very easy to accidentally pass a log.Context to something that expected a context.Context, so to make |
| // sure that never happens we enforce that it does not satisfy the interface, and expect log.Context.Unwrap to be |
| // explicitly called when needed. |
| var ctx interface{} = log.Background() |
| var ok bool |
| if _, ok = ctx.(context.Context); ok { |
| t.Error("log.Context should not implement context.Context") |
| } |
| } |