ussd/debug/db_test.go

79 lines
1.5 KiB
Go
Raw Normal View History

2024-12-02 00:12:58 +01:00
package debug
import (
"testing"
2024-12-08 00:06:03 +01:00
"git.grassecon.net/urdt/ussd/common"
"git.defalsify.org/vise.git/db"
2024-12-02 00:12:58 +01:00
)
func TestDebugDbSubKeyInfo(t *testing.T) {
s := "foo"
2024-12-08 00:06:03 +01:00
b := []byte{0x20}
b = append(b, []byte(s)...)
b = append(b, []byte{0x00, 0x02}...)
2024-12-02 00:12:58 +01:00
r, err := ToKeyInfo(b, s)
if err != nil {
t.Fatal(err)
}
if r.SessionId != s {
t.Fatalf("expected %s, got %s", s, r.SessionId)
}
2024-12-08 00:06:03 +01:00
if r.Typ != 32 {
2024-12-02 00:12:58 +01:00
t.Fatalf("expected 64, got %d", r.Typ)
}
if r.SubTyp != 2 {
t.Fatalf("expected 2, got %d", r.SubTyp)
}
if DebugCap & 1 > 0 {
if r.Label != "tracking id" {
t.Fatalf("expected 'tracking id', got '%s'", r.Label)
}
}
}
func TestDebugDbKeyInfo(t *testing.T) {
s := "bar"
2024-12-08 00:06:03 +01:00
b := []byte{0x10}
b = append(b, []byte(s)...)
r, err := ToKeyInfo(b, s)
if err != nil {
t.Fatal(err)
}
if r.SessionId != s {
t.Fatalf("expected %s, got %s", s, r.SessionId)
}
if r.Typ != 16 {
t.Fatalf("expected 16, got %d", r.Typ)
}
if DebugCap & 1 > 0 {
if r.Label != "internal state" {
t.Fatalf("expected 'internal_state', got '%s'", r.Label)
}
}
}
func TestDebugDbKeyInfoRestore(t *testing.T) {
s := "bar"
b := []byte{db.DATATYPE_USERDATA}
b = append(b, []byte(s)...)
k := common.ToBytes(common.DATA_ACTIVE_SYM)
b = append(b, k...)
2024-12-02 00:12:58 +01:00
r, err := ToKeyInfo(b, s)
if err != nil {
t.Fatal(err)
}
if r.SessionId != s {
t.Fatalf("expected %s, got %s", s, r.SessionId)
}
if r.Typ != 32 {
2024-12-08 00:06:03 +01:00
t.Fatalf("expected 32, got %d", r.Typ)
2024-12-02 00:12:58 +01:00
}
if DebugCap & 1 > 0 {
2024-12-08 00:06:03 +01:00
if r.Label != "active sym" {
t.Fatalf("expected 'active sym', got '%s'", r.Label)
2024-12-02 00:12:58 +01:00
}
}
}