streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

playlist_test.go (1215B)


      1 package cair
      2 
      3 import (
      4 	"testing"
      5 	"time"
      6 )
      7 
      8 func TestParse(t *testing.T) {
      9 	_, err := playlistFromFile("testdata/playlist.xml")
     10 	if err != nil {
     11 		t.Fatalf("parse playlist %s: %v", "testdata/playlist.xml", err)
     12 	}
     13 }
     14 
     15 func TestTimecode(t *testing.T) {
     16 	tests := []struct {
     17 		name string
     18 		in   string
     19 		want time.Duration
     20 	}{
     21 		{"zero", "00:00:00.000", 0},
     22 		{"1min15sec", "00:01:15.000", time.Minute + 15*time.Second},
     23 		{
     24 			"longest",
     25 			"12:34:56.789",
     26 			12*time.Hour + 34*time.Minute + 56*time.Second + 789*time.Millisecond,
     27 		},
     28 	}
     29 	for _, tt := range tests {
     30 		t.Run(tt.name, func(t *testing.T) {
     31 			got, err := parseDuration(tt.in)
     32 			if err != nil {
     33 				t.Errorf("parse duration: %v", err)
     34 			}
     35 			if got != tt.want {
     36 				t.Errorf("got %v; want %v", got, tt.want)
     37 			}
     38 		})
     39 	}
     40 }
     41 
     42 func TestBadTimecode(t *testing.T) {
     43 	tests := []struct {
     44 		name string
     45 		in   string
     46 	}{
     47 		{"empty", ""},
     48 		{"garbage", "世界 Hello"},
     49 		{"decimal", "00:12:009999"},
     50 		{"colon", "00:1122.9999"},
     51 		{"letters", "00:ab:00.000"},
     52 	}
     53 
     54 	for _, tt := range tests {
     55 		t.Run(tt.name, func(t *testing.T) {
     56 			_, err := parseDuration(tt.in)
     57 			if err == nil {
     58 				t.Errorf("parsing %q succeeded", tt.in)
     59 			}
     60 			t.Log(err)
     61 		})
     62 	}
     63 }