-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathndef_parser_test.go
More file actions
79 lines (75 loc) · 2.14 KB
/
ndef_parser_test.go
File metadata and controls
79 lines (75 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2026 The Zaparoo Project Contributors.
// SPDX-License-Identifier: Apache-2.0
//
// 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 pn532
import (
"reflect"
"testing"
)
func TestExtractNDEFPayload(t *testing.T) {
t.Parallel()
tests := []struct {
name string
data []byte
want []byte
}{
{
name: "empty data",
data: []byte{},
want: nil,
},
{
name: "no NDEF TLV - only terminator",
data: []byte{0xFE},
want: nil,
},
{
name: "simple NDEF TLV with short form",
data: []byte{0x03, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05, 0xFE},
want: []byte{0x01, 0x02, 0x03, 0x04, 0x05},
},
{
name: "NDEF TLV after NULL padding",
data: []byte{0x00, 0x00, 0x03, 0x03, 0xAA, 0xBB, 0xCC, 0xFE},
want: []byte{0xAA, 0xBB, 0xCC},
},
{
name: "NDEF TLV after Lock Control TLV",
// Lock Control: 0x01, length 0x03, value (3 bytes)
// NDEF: 0x03, length 0x04, payload (4 bytes)
data: []byte{0x01, 0x03, 0xA0, 0x0C, 0x34, 0x03, 0x04, 0x11, 0x22, 0x33, 0x44, 0xFE},
want: []byte{0x11, 0x22, 0x33, 0x44},
},
{
name: "NDEF TLV with zero length",
data: []byte{0x03, 0x00, 0xFE},
want: []byte{},
},
{
name: "NDEF TLV after Memory Control TLV",
// Memory Control: 0x02, length 0x03, value (3 bytes)
// NDEF: 0x03, length 0x02, payload (2 bytes)
data: []byte{0x02, 0x03, 0xF0, 0xFF, 0xEE, 0x03, 0x02, 0xAA, 0xBB, 0xFE},
want: []byte{0xAA, 0xBB},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := extractNDEFPayload(tt.data); !reflect.DeepEqual(got, tt.want) {
t.Errorf("extractNDEFPayload() = %v, want %v", got, tt.want)
}
})
}
}