Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
740 olof 1
import logging as log
2
log.basicConfig(level=log.DEBUG,
3
                format='%(asctime)s %(levelname)s %(message)s',
4
                filename=__name__ + '.log',
5
                filemode='w')
6
import unittest
7
import sys
8
import os
9
 
10
os.chdir(os.getcwd()[0:-6]) # ouch that hurts!
11
STDOUT_REDIRECT_FILE = 'tests/' + __name__ + '2.log'
12
 
13
if os.path.exists(STDOUT_REDIRECT_FILE):
14
    os.remove(STDOUT_REDIRECT_FILE)
15
 
16
#--------------------------------------------------------------------------
17
 
18
from Main import CanDaemon
19
canDaemon = CanDaemon()
20
 
21
class MainCmdTests(unittest.TestCase):
22
 
23
    def setUp(self):
24
        """Call before every test case."""
25
        sys.stdout = open(STDOUT_REDIRECT_FILE, 'a')
26
 
27
    def tearDown(self):
28
        """Call after every test case."""
29
        sys.stdout = sys.__stdout__
30
 
743 olof 31
    def testA_CmdBasic(self):
740 olof 32
        log.debug('testCmdBasic')
741 olof 33
        canDaemon.parseCommand('hello')
34
 
743 olof 35
    def testB_CmdHelp(self):
741 olof 36
        log.debug('testCmdBasic')
37
        canDaemon.parseCommand('help')
38
        canDaemon.parseCommand('help log')
39
        canDaemon.parseCommand('help filter')
40
        canDaemon.parseCommand('help state')
41
        canDaemon.parseCommand('help addif')
42
        canDaemon.parseCommand('help addbridge')
43
        canDaemon.parseCommand('help tcpd')
44
        canDaemon.parseCommand('help tlsd')
45
        canDaemon.parseCommand('help canctld')
46
        canDaemon.parseCommand('help sim')
740 olof 47
 
743 olof 48
    def testC_ImportFilter(self):
740 olof 49
        log.debug('testImportFilter')
741 olof 50
        canDaemon.parseCommand('filter add DefaultFilter')
51
 
743 olof 52
    def testD_RemoveFilter(self):
741 olof 53
        log.debug('testRemoveFilter')
54
        canDaemon.parseCommand('filter rem DefaultFilter')
740 olof 55
 
743 olof 56
    def testE_ImportSpace(self):
740 olof 57
        log.debug('testImportSpace')
741 olof 58
        canDaemon.parseCommand('state add DefaultStateSpace')
59
 
743 olof 60
    def testF_RemoveSpace(self):
741 olof 61
        log.debug('testRemoveSpace')
62
        canDaemon.parseCommand('state rem DefaultStateSpace')
63
 
743 olof 64
    def testG_AddCanStimIf(self):
741 olof 65
        log.debug('testAddCanStimIf')
66
        canDaemon.parseCommand('addif stim0 stim')
67
 
743 olof 68
    def testH_RemCanStimIf(self):
741 olof 69
        log.debug('testRemCanStimIf')
70
        canDaemon.parseCommand('remif stim0')
71
 
743 olof 72
    def testI_AddUDPIf(self):
741 olof 73
        log.debug('testAddUDPIf')
74
        canDaemon.parseCommand('addif udp0 udp host=192.168.10.2 port=1000')
75
 
743 olof 76
    def testJ_RemUDPIf(self):
741 olof 77
        log.debug('testRemUDPIf')
78
        canDaemon.parseCommand('remif udp0')
740 olof 79
 
747 olof 80
    def testK_AddTCPIf(self):
81
        log.debug('testAddTCPIf')
741 olof 82
        canDaemon.parseCommand('addif telnet0 host=192.168.10.2 port=1000')
83
 
747 olof 84
    def testL_RemTCPIf(self):
85
        log.debug('testRemTCPIf')
741 olof 86
        canDaemon.parseCommand('remif telnet0')
87
 
743 olof 88
    def testM_AddTcpTlsIf(self):
741 olof 89
        log.debug('testAddTcpTlsIf')
90
        canDaemon.parseCommand('addif tcptls0 tcptls host=192.168.10.2 port=1000 key=mykey.pub')
91
 
743 olof 92
    def testN_RemTcpTlsIf(self):
741 olof 93
        log.debug('testRemTcpTlsIf')
94
        canDaemon.parseCommand('remif tcptls0')
95
 
96