Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

61 líneas
1.5KB

  1. package mp3
  2. import (
  3. "bytes"
  4. "context"
  5. "errors"
  6. "os"
  7. "path/filepath"
  8. "testing"
  9. "github.com/jan/fm-rds-tx/internal/ingest"
  10. "github.com/jan/fm-rds-tx/internal/ingest/decoder"
  11. )
  12. func TestDecodeStream(t *testing.T) {
  13. tonePath := filepath.Join("testdata", "tone_44k_stereo.mp3")
  14. data, err := os.ReadFile(tonePath)
  15. if err != nil {
  16. t.Fatalf("read fixture: %v", err)
  17. }
  18. var chunks []ingest.PCMChunk
  19. d := New()
  20. err = d.DecodeStream(context.Background(), bytes.NewReader(data), decoder.StreamMeta{
  21. ContentType: "audio/mpeg",
  22. SourceID: "mp3-test",
  23. }, func(c ingest.PCMChunk) error {
  24. chunks = append(chunks, c)
  25. return nil
  26. })
  27. if err != nil {
  28. t.Fatalf("decode: %v", err)
  29. }
  30. if len(chunks) == 0 {
  31. t.Fatal("expected chunks")
  32. }
  33. if chunks[0].Channels != 2 {
  34. t.Fatalf("channels=%d want 2", chunks[0].Channels)
  35. }
  36. if chunks[0].SampleRateHz != 44100 {
  37. t.Fatalf("sampleRate=%d want 44100", chunks[0].SampleRateHz)
  38. }
  39. if len(chunks[0].Samples) == 0 {
  40. t.Fatal("expected samples in first chunk")
  41. }
  42. }
  43. func TestDecodeStreamNilReader(t *testing.T) {
  44. err := New().DecodeStream(context.Background(), nil, decoder.StreamMeta{}, func(ingest.PCMChunk) error { return nil })
  45. if !errors.Is(err, decoder.ErrUnsupported) {
  46. t.Fatalf("expected unsupported, got %v", err)
  47. }
  48. }
  49. func TestDecodeStreamNilEmit(t *testing.T) {
  50. err := New().DecodeStream(context.Background(), bytes.NewReader([]byte("not-mp3")), decoder.StreamMeta{}, nil)
  51. if !errors.Is(err, decoder.ErrUnsupported) {
  52. t.Fatalf("expected unsupported, got %v", err)
  53. }
  54. }