1 /*******************************************************************************
3 * Copyright (c) 2019 AT&T Intellectual Property.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
28 func TestParseRicId(t *testing.T) {
29 var testCases = []struct {
37 ricId: "bbbccc-abcd02/18",
38 pLMNId: []byte{0xbb, 0xbc, 0xcc},
39 eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
40 eNBIdBitqty: ShortMacro_eNB_ID,
43 ricId: "bbbccc-abcd0e/20",
44 pLMNId: []byte{0xbb, 0xbc, 0xcc},
45 eNBId: []byte{0xab, 0xcd, 0xe},
46 eNBIdBitqty: Macro_eNB_ID,
49 ricId: "bbbccc-abcd07/21",
50 pLMNId: []byte{0xbb, 0xbc, 0xcc},
51 eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
52 eNBIdBitqty: LongMacro_eNB_ID,
55 ricId: "bbbccc-abcdef08/28",
56 pLMNId: []byte{0xbb, 0xbc, 0xcc},
57 eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
58 eNBIdBitqty: Home_eNB_ID,
62 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
67 failure: fmt.Errorf("unable to extract the value of RIC_ID: unexpected EOF"),
71 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
75 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
79 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
82 ricId: "bbbcccdd-abcdef08/28", // pLMNId too long
83 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
86 ricId: "bbbccc-abcdef0809/28", // eNBId too long
87 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
91 ricId: "bbbc-abcdef08/28", // pLMNId too short
92 failure: fmt.Errorf("invalid value for RIC_ID, len(pLMNId:[187 188]) != 3"),
95 ricId: "bbbccc-abcd/28", // eNBId too short
96 failure: fmt.Errorf("invalid value for RIC_ID, len(eNBId:[171 205]) != 3 or 4"),
99 ricId: "bbbccc-abcdef08/239", // bit quantity too long - no error, will return 23 (which is invalid)
100 failure: fmt.Errorf("invalid value for RIC_ID, eNBIdBitqty: 23"),
104 for _, tc := range testCases {
105 t.Run(tc.ricId, func(t *testing.T) {
107 err := parseRicID(tc.ricId)
109 if tc.failure == nil {
110 t.Errorf("want: success, got: parse failed. Error: %v\n", err)
112 if strings.Compare(err.Error(), tc.failure.Error()) != 0 {
113 t.Errorf("want: %s, got: %s\n", err, tc.failure)
117 if bytes.Compare(tc.pLMNId, pLMNId) != 0 {
118 t.Errorf("want: pLMNId = %v, got: pLMNId = %v", tc.pLMNId, pLMNId)
121 if bytes.Compare(tc.eNBId, eNBId) != 0 {
122 t.Errorf("want: eNBId = %v, got: eNBId = %v", tc.eNBId, eNBId)
125 if tc.eNBIdBitqty != eNBIdBitqty {
126 t.Errorf("want: eNBIdBitqty = %d, got: eNBIdBitqty = %d", tc.eNBIdBitqty, eNBIdBitqty)