2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
25 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
26 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/packer"
27 "github.com/google/go-cmp/cmp"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 var testLogger *log.Logger
40 testLogger = log.New(os.Stdout, "TEST: ", log.LstdFlags)
48 func (testctxt *ApTests) Name() string { return testctxt.name }
50 func (testctxt *ApTests) Desc() string { return testctxt.desc }
52 func (testctxt *ApTests) SetDesc(desc string) { testctxt.desc = desc }
54 func (testctxt *ApTests) String() string { return testctxt.name + string("-") + testctxt.desc }
56 func (testctxt *ApTests) testPrint(pattern string, args ...interface{}) {
57 testLogger.Printf("(%s): %s", testctxt.String(), fmt.Sprintf(pattern, args...))
60 func (testctxt *ApTests) testError(t *testing.T, pattern string, args ...interface{}) {
61 testLogger.Printf("(%s): %s", testctxt.String(), fmt.Sprintf(pattern, args...))
62 t.Errorf("(%s): %s", testctxt.String(), fmt.Sprintf(pattern, args...))
65 func (testctxt *ApTests) testValueEquality(t *testing.T, msg string, a interface{}, b interface{}) {
67 testLogger.Printf("(%s) %s Difference: %s", testctxt.String(), msg, cmp.Diff(a, b))
68 t.Errorf("(%s) %s Difference: %s", testctxt.String(), msg, cmp.Diff(a, b))
72 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
76 type E2ApTests struct {
78 packerif e2ap.E2APPackerIf
81 func (testCtxt *E2ApTests) toPackedData(t *testing.T, buffer string) *packer.PackedData {
82 msg, err := hex.DecodeString(buffer)
84 testCtxt.testError(t, "Hex DecodeString Failed: %s [%s]", err.Error(), buffer)
87 packedData := &packer.PackedData{}
92 func NewE2ApTests(name string, packerif e2ap.E2APPackerIf) *E2ApTests {
93 testCtxt := &E2ApTests{}
94 testCtxt.packerif = packerif
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
103 func RunTests(t *testing.T, e2aptestctxt *E2ApTests) {
104 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequest(t) })
105 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionResponse(t) })
106 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionFailure(t) })
107 t.Run(e2aptestctxt.Name(), func(t *testing.T) {
108 e2aptestctxt.E2ApTestMsgSubscriptionDeleteRequest(t)
110 t.Run(e2aptestctxt.Name(), func(t *testing.T) {
111 e2aptestctxt.E2ApTestMsgSubscriptionDeleteResponse(t)
113 t.Run(e2aptestctxt.Name(), func(t *testing.T) {
114 e2aptestctxt.E2ApTestMsgSubscriptionDeleteFailure(t)
116 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionRequestBuffers(t) })
117 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionResponseBuffers(t) })
118 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionFailureBuffers(t) })
119 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteRequestBuffers(t) })
120 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteResponseBuffers(t) })
121 t.Run(e2aptestctxt.Name(), func(t *testing.T) { e2aptestctxt.E2ApTestMsgSubscriptionDeleteFailureBuffers(t) })