• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2024 The Android Open Source Project
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 requirementsdata_test
16
17import (
18	"testing"
19
20	"google3/third_party/android/mediapc_requirements/requirements"
21	pb "cts/test/mediapc/requirements/requirements_go_proto"
22
23	_ "embed"
24)
25
26// MPC Requirements data from requirements.txtpb
27//
28//go:embed requirements.binbp
29var reqBinary []byte
30
31func TestUniqueRequirementIDs(t *testing.T) {
32	reqList := mustUnmarshalRequirementList(t)
33
34	// Requirement ids must be unique
35	ids := make(map[string]bool)
36	for _, req := range reqList.GetRequirements() {
37		id := req.GetId()
38		if ids[id] {
39			t.Errorf("requirement [%s] is a duplicate", id)
40		}
41		ids[id] = true
42	}
43}
44
45func TestUniqueRequirementNames(t *testing.T) {
46	reqList := mustUnmarshalRequirementList(t)
47
48	// Requirement names must be unique
49	nameToID := make(map[string]string) // name to id
50	for _, req := range reqList.GetRequirements() {
51		if req.HasName() {
52			name := req.GetName()
53			if nameToID[name] != "" {
54				t.Errorf("the name %q of requirement [%s] is a duplicate of requirement [%s]'s name", req.GetId(), name, nameToID[name])
55			}
56			nameToID[name] = req.GetId()
57		}
58	}
59
60}
61
62func mustUnmarshalRequirementList(t *testing.T) *pb.RequirementList {
63	t.Helper()
64	reqList, err := requirements.UnmarshalRequirementList(reqBinary)
65	if err != nil {
66		t.Fatalf("failed to unmarshal reqBinary: %v", err)
67	}
68	return reqList
69}
70