blob: 778ce4a8dddde2a05803d8c16af8296b1813950c [file] [log] [blame]
Bob Badoura99ac622021-10-25 16:21:00 -07001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package compliance
16
17import (
Bob Badoura99ac622021-10-25 16:21:00 -070018 "testing"
19)
20
Bob Badour103eb0f2022-01-10 13:50:57 -080021func TestConditionSetHas(t *testing.T) {
22 impliesShare := ImpliesShared
Bob Badoura99ac622021-10-25 16:21:00 -070023
Bob Badour103eb0f2022-01-10 13:50:57 -080024 t.Logf("testing with imliesShare=%04x", impliesShare)
25
26 if impliesShare.HasAny(NoticeCondition) {
27 t.Errorf("impliesShare.HasAny(\"notice\"=%04x) got true, want false", NoticeCondition)
Bob Badoura99ac622021-10-25 16:21:00 -070028 }
29
Bob Badour103eb0f2022-01-10 13:50:57 -080030 if !impliesShare.HasAny(RestrictedCondition) {
31 t.Errorf("impliesShare.HasAny(\"restricted\"=%04x) got false, want true", RestrictedCondition)
Bob Badoura99ac622021-10-25 16:21:00 -070032 }
33
Bob Badour103eb0f2022-01-10 13:50:57 -080034 if !impliesShare.HasAny(ReciprocalCondition) {
35 t.Errorf("impliesShare.HasAny(\"reciprocal\"=%04x) got false, want true", ReciprocalCondition)
Bob Badoura99ac622021-10-25 16:21:00 -070036 }
37
Bob Badour103eb0f2022-01-10 13:50:57 -080038 if impliesShare.HasAny(LicenseCondition(0x0000)) {
39 t.Errorf("impliesShare.HasAny(nil=%04x) got true, want false", LicenseCondition(0x0000))
Bob Badoura99ac622021-10-25 16:21:00 -070040 }
41}
42
Bob Badour103eb0f2022-01-10 13:50:57 -080043func TestConditionName(t *testing.T) {
44 for expected, condition := range RecognizedConditionNames {
45 actual := condition.Name()
46 if expected != actual {
47 t.Errorf("unexpected name for condition %04x: got %s, want %s", condition, actual, expected)
48 }
Bob Badoura99ac622021-10-25 16:21:00 -070049 }
Bob Badour103eb0f2022-01-10 13:50:57 -080050}
51
52func TestConditionName_InvalidCondition(t *testing.T) {
53 panicked := false
54 var lc LicenseCondition
55 func() {
56 defer func() {
57 if err := recover(); err != nil {
58 panicked = true
Bob Badoura99ac622021-10-25 16:21:00 -070059 }
Bob Badour103eb0f2022-01-10 13:50:57 -080060 }()
61 name := lc.Name()
62 t.Errorf("invalid condition unexpected name: got %s, wanted panic", name)
63 }()
64 if !panicked {
65 t.Errorf("no expected panic for %04x.Name(): got no panic, wanted panic", lc)
Bob Badoura99ac622021-10-25 16:21:00 -070066 }
67}