From 6af5989872635b44607657fc1c4ff80b4df20798 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 31 Mar 2016 23:33:44 +0200 Subject: add test cases for switch commands diff --git a/Makefile b/Makefile index d424e5d..2bb8872 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,10 @@ format: @echo "formating: $(EXECUTEABLE)" @$(GOCMD) fmt $(EXECUTEABLE) +test: + @echo "testing: $(EXECUTEABLE)" + @$(GOCMD) test $(EXECUTEABLE) + build: getlibs @echo "installing: $(EXECUTEABLE)" @$(GOCMD) install $(EXECUTEABLE) diff --git a/src/rhctl/audio_switch_command_test.go b/src/rhctl/audio_switch_command_test.go new file mode 100644 index 0000000..2702565 --- /dev/null +++ b/src/rhctl/audio_switch_command_test.go @@ -0,0 +1,157 @@ +// +// rhctl +// +// Copyright (C) 2009-2016 Christian Pointner +// +// This file is part of rhctl. +// +// rhctl is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// rhctl is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with rhctl. If not, see . +// + +package main + +import ( + "testing" +) + +func TestSwitchCommandStatus(t *testing.T) { + var result string + + result = SwitchCmdStatusAudio.Generate(SwitchUnitID(2)) + if result != "*2SL" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdStatusGPI.Generate(SwitchUnitID(0)) + if result != "*0SPA" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdStatusOC.Generate(SwitchUnitID(1)) + if result != "*1SO" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdStatusRelay.Generate(SwitchUnitID(3)) + if result != "*3SR" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdStatusSilence.Generate(SwitchUnitID(1)) + if result != "*1SS" { + t.Fatalf("wrong output: got '%s'", result) + } +} + +func TestSwitchCommandAudio(t *testing.T) { + var result string + + result = SwitchCmdAudioSelectInput.Generate(SwitchUnitID(0), SwitchInputNum(8), SwitchOutputNum(1)) + if result != "*0081" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioSelectInputAll.Generate(SwitchUnitID(0), SwitchInputNum(3)) + if result != "*003A" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioAddInputTo1.Generate(SwitchUnitID(3), SwitchInputNum(4)) + if result != "*3043" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioAddInputTo2.Generate(SwitchUnitID(0), SwitchInputNum(0)) + if result != "*0004" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioRemoveInputFrom1.Generate(SwitchUnitID(2), SwitchInputNum(7)) + if result != "*2075" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioRemoveInputFrom2.Generate(SwitchUnitID(1), SwitchInputNum(2)) + if result != "*1026" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioMuteInput.Generate(SwitchUnitID(1), SwitchInputNum(2), SwitchOutputNum(2)) + if result != "*102M2" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioMuteInputAll.Generate(SwitchUnitID(1), SwitchInputNum(2)) + if result != "*102MA" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioMuteOutput.Generate(SwitchUnitID(0), SwitchOutputNum(1)) + if result != "*0M1" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioMuteOutputAll.Generate(SwitchUnitID(3)) + if result != "*3MA" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioFadeUpInput.Generate(SwitchUnitID(0), SwitchInputNum(3)) + if result != "*0FU03" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdAudioFadeDownInput.Generate(SwitchUnitID(1), SwitchInputNum(7)) + if result != "*1FD07" { + t.Fatalf("wrong output: got '%s'", result) + } +} + +func TestSwitchCommandOC(t *testing.T) { + var result string + + result = SwitchCmdOCUnlatch.Generate(SwitchUnitID(2), SwitchOCNum(3)) + if result != "*2OO3F" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdOCLatch.Generate(SwitchUnitID(3), SwitchOCNum(2)) + if result != "*3OO2L" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdOCPulse.Generate(SwitchUnitID(0), SwitchOCNum(7)) + if result != "*0OO7P" { + t.Fatalf("wrong output: got '%s'", result) + } +} + +func TestSwitchCommandRelay(t *testing.T) { + var result string + + result = SwitchCmdRelayUnlatch.Generate(SwitchUnitID(3), SwitchRelayNum(3)) + if result != "*3OR3F" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdRelayLatch.Generate(SwitchUnitID(1), SwitchRelayNum(6)) + if result != "*1OR6L" { + t.Fatalf("wrong output: got '%s'", result) + } + + result = SwitchCmdRelayPulse.Generate(SwitchUnitID(1), SwitchRelayNum(4)) + if result != "*1OR4P" { + t.Fatalf("wrong output: got '%s'", result) + } +} -- cgit v0.10.2