summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qaudio.py
blob: a1572ca1fb95f9d2a0bf411c913326dffa5c7c3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from test.helpers.syscmd import SysCommand
import unittest
#class name
class Qaudio(unittest.TestCase):
    # Initialize the variables

    def __init__(self, testname, testfunc, dtmfFile):
        # Doing this we will initialize the class and later on perform a particular method inside this class
        super(Qaudio, self).__init__(testfunc)
        self._testMethodDoc = testname
        self._dtmfFile=dtmfFile
        self.__sum=0
        self.__refSum = 25 # 1+3+5+7+9

    def execute(self):
        str_cmd = "aplay test/files/dtmf-13579.wav 2> /dev/null & arecord -r 8000 -d 1 recorded.wav 2> /dev/null" #.format(self.__dtmfFile)
        audio_loop = SysCommand("command-name", str_cmd)
        if audio_loop.execute() == 0:# BUG: Returns -1 but work
            lines = audio_loop.getOutput().splitlines()
            str_cmd = "multimon -t wav -a DTMF recorded.wav -q 2> /dev/null"
            dtmf_decoder = SysCommand("command-name", str_cmd)
            if dtmf_decoder.execute() == 0: # BUG: Returns -1 but work
                self.__raw_out = dtmf_decoder.getOutput()
                if self.__raw_out == "":
                    return -1
                lines = dtmf_decoder.getOutput().splitlines()
                for i in range(0, 5):
                    aux=[int(s) for s in lines[i].split() if s.isdigit()]
                    self.__sum=self.__sum+aux[0]
                self.failUnless(self.__sum == self.__refSum), "failed: incorrect dtmf code" + str(self.__sum)
            else:
                self.fail("failed: fail reading recorded file")
                return -1
        else:
            self.fail("failed: fail playing/recording file")
            return -1
        return 0