Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

82 Zeilen
1.8KB

  1. package app
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. cfgpkg "github.com/jan/fm-rds-tx/internal/config"
  7. "github.com/jan/fm-rds-tx/internal/platform"
  8. )
  9. func TestEngineContinuousRun(t *testing.T) {
  10. cfg := cfgpkg.Default()
  11. driver := platform.NewSimulatedDriver(nil)
  12. eng := NewEngine(cfg, driver)
  13. eng.SetChunkDuration(10 * time.Millisecond)
  14. ctx := context.Background()
  15. if err := eng.Start(ctx); err != nil {
  16. t.Fatalf("start: %v", err)
  17. }
  18. // Let it run for 200ms
  19. time.Sleep(200 * time.Millisecond)
  20. stats := eng.Stats()
  21. if stats.State != "running" {
  22. t.Fatalf("expected running, got %s", stats.State)
  23. }
  24. if stats.ChunksProduced < 5 {
  25. t.Fatalf("expected at least 5 chunks, got %d", stats.ChunksProduced)
  26. }
  27. if stats.TotalSamples == 0 {
  28. t.Fatal("expected non-zero samples")
  29. }
  30. if err := eng.Stop(ctx); err != nil {
  31. t.Fatalf("stop: %v", err)
  32. }
  33. stats = eng.Stats()
  34. if stats.State != "idle" {
  35. t.Fatalf("expected idle after stop, got %s", stats.State)
  36. }
  37. }
  38. func TestEngineDoubleStartFails(t *testing.T) {
  39. cfg := cfgpkg.Default()
  40. driver := platform.NewSimulatedDriver(nil)
  41. eng := NewEngine(cfg, driver)
  42. ctx := context.Background()
  43. if err := eng.Start(ctx); err != nil {
  44. t.Fatalf("first start: %v", err)
  45. }
  46. defer eng.Stop(ctx)
  47. if err := eng.Start(ctx); err == nil {
  48. t.Fatal("expected error on double start")
  49. }
  50. }
  51. func TestEngineDriverStats(t *testing.T) {
  52. cfg := cfgpkg.Default()
  53. driver := platform.NewSimulatedDriver(nil)
  54. eng := NewEngine(cfg, driver)
  55. eng.SetChunkDuration(10 * time.Millisecond)
  56. ctx := context.Background()
  57. _ = eng.Start(ctx)
  58. time.Sleep(100 * time.Millisecond)
  59. _ = eng.Stop(ctx)
  60. driverStats := driver.Stats()
  61. if driverStats.SamplesWritten == 0 {
  62. t.Fatal("expected driver to have written samples")
  63. }
  64. if driverStats.FramesWritten == 0 {
  65. t.Fatal("expected driver to have written frames")
  66. }
  67. }