File: frame_test.go

package info (click to toggle)
golang-github-suapapa-go-eddystone 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 112 kB
  • sloc: makefile: 5
file content (82 lines) | stat: -rw-r--r-- 1,456 bytes parent folder | download
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
80
81
82
// Copyright (c) 2015-2020, go_eddystone authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package eddystone

import (
	"bytes"
	"testing"
)

func TestMakeUIDFrame(t *testing.T) {
	f, err := MakeUIDFrame("0102030405060708090a", "123456", -30)
	if err != nil {
		panic(err)
	}

	expect := []byte{
		0, // hdrUID
		intToByte(-30),
		0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
		0x00, 0x00, 0x00, 0x12, 0x34, 0x56,
		0, 0,
	}

	if !bytes.Equal([]byte(f), expect) {
		t.Errorf("expect: %v, got:%v", expect, []byte(f))
	}
}

func TestMakeURLFrame(t *testing.T) {
	urlGoogle := "http://google.com/"
	f, err := MakeURLFrame(urlGoogle, -20)
	if err != nil {
		panic(err)
	}

	expect := []byte{
		0x10, // hdrURL
		intToByte(-20),
		0x02, // URL Scheme Prefix: http://
		'g',  // 'g'
		'o',  // 'o'
		'o',  // 'o'
		'g',  // 'g'
		'l',  // 'l'
		'e',  // 'e'
		0x00, // Eddystone-URL HTTP URL encoding: .com/
	}

	if !bytes.Equal([]byte(f), expect) {
		t.Errorf("expect: %v, got:%v", expect, []byte(f))
	}
}

func TestMakeTLMFrame(t *testing.T) {
	f, err := MakeTLMFrame(50, 28, 100, 100)
	if err != nil {
		panic(err)
	}

	expect := []byte{
		0x20, // hdrTLM
		0x00,
		0x00,
		0x32,
		0x1C,
		0x00,
		0x00,
		0x00,
		0x00,
		0x64,
		0x00,
		0x00,
		0x00,
		0x64,
	}

	if !bytes.Equal([]byte(f), expect) {
		t.Errorf("expect: %v, got:%v", expect, []byte(f))
	}
}