Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2KB

  1. package dryrun
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. cfgpkg "github.com/jan/fm-rds-tx/internal/config"
  7. )
  8. func TestGenerate(t *testing.T) {
  9. cfg := cfgpkg.Default()
  10. frame := Generate(cfg)
  11. if frame.Mode != "dry-run" {
  12. t.Fatalf("unexpected mode: %s", frame.Mode)
  13. }
  14. if len(frame.PreviewSamples) != 16 {
  15. t.Fatalf("unexpected preview length: %d", len(frame.PreviewSamples))
  16. }
  17. if frame.Source != "tones" {
  18. t.Fatalf("unexpected source: %s", frame.Source)
  19. }
  20. if frame.PreEmphasisUS != 50 {
  21. t.Fatalf("unexpected preEmphasisUS: %.0f", frame.PreEmphasisUS)
  22. }
  23. if !frame.FMModulation {
  24. t.Fatal("expected fmModulationEnabled=true")
  25. }
  26. }
  27. func TestGenerateUsesInputPathAsSource(t *testing.T) {
  28. cfg := cfgpkg.Default()
  29. cfg.Audio.InputPath = "demo.wav"
  30. frame := Generate(cfg)
  31. if frame.Source != "demo.wav" {
  32. t.Fatalf("unexpected source: %s", frame.Source)
  33. }
  34. }
  35. func TestWriteJSONFile(t *testing.T) {
  36. dir := t.TempDir()
  37. out := filepath.Join(dir, "frame.json")
  38. if err := WriteJSON(out, Generate(cfgpkg.Default())); err != nil {
  39. t.Fatalf("WriteJSON failed: %v", err)
  40. }
  41. if _, err := os.Stat(out); err != nil {
  42. t.Fatalf("expected output file: %v", err)
  43. }
  44. }