aboutsummaryrefslogtreecommitdiffstats
path: root/test/afb-test/tests/gps_BasicAPITest.lua
blob: 965f5057209d83dfc405b00d1f5ef14c153094b8 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
--[[
   Copyright (C) 2018 "IoT.bzh"
   Author Frédéric Marec <frederic.marec@iot.bzh>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


   NOTE: strict mode: every global variables should be prefixed by '_'
--]]

local testPrefix ="gps_BasicAPITest_"

_AFT.setBeforeEach(function()
    os.execute("gpsfake -r -q ".._AFT.bindingRootDir.."/var/test.nmea &")
end)


_AFT.setAfterEach(function()
    os.execute("pkill -f -9 gpsfake")
    os.execute("pkill -9 gpsd")
end)


-- This tests the 'subscribe' verb of the gps API
_AFT.testVerbStatusSuccess(testPrefix.."subscribe","gps","subscribe", {value = "location" },
    nil,
    function()
        _AFT.callVerb("gps","unsubscribe", {value = "location" })
    end)

-- This tests the 'unsubscribe' verb of the gps API
_AFT.testVerbStatusSuccess(testPrefix.."unsubscribe","gps","unsubscribe",{value = "location" },
    function()
        _AFT.callVerb("gps","subscribe",{value = "location" })
    end,
    nil)

-- This tests the 'record' verb of the gps API
_AFT.testVerbStatusSuccess(testPrefix.."record","gps","record",{state= "on"},nil,
    function()
       _AFT.callVerb("gps","record",{state = "off"})
    end)

-- This tests the 'replay' verb of the gps API
    _AFT.describe(testPrefix.."replay", function()
    local api = "gps"

    _AFT.assertVerbStatusSuccess(api, "record", {state= "on"})
    _AFT.assertVerbStatusSuccess(api, "record", {state= "off"})
    _AFT.assertVerbStatusSuccess(api, "record", {state= "on"})
    _AFT.assertVerbStatusSuccess(api, "record", {state= "off"})

   end)

-- This tests the 'double off' verb of the gps API
_AFT.describe(testPrefix.."double off", function()
    local api = "gps"

    _AFT.assertVerbStatusSuccess(api, "record", {state= "on"})
    _AFT.assertVerbStatusSuccess(api, "record", {state= "off"})
    _AFT.assertVerbStatusError(api, "record", {state= "off"})

   end)

-- This tests the 'double subscribe' verb of the gps API
_AFT.describe(testPrefix.."double subscribe",
    function()
        local api = "gps"

        _AFT.assertVerbStatusSuccess(api, "subscribe",{value = "location"})
        _AFT.assertVerbStatusSuccess(api, "subscribe",{value = "location"})

    end)

-- This tests the 'unsubscribe' verb of the gps API
_AFT.testVerbStatusError(testPrefix.."unsubscribe","gps","sucribe",{value = "location" },
    function()
        _AFT.callVerb("gps","subscribe",{value = "location" })
    end, nil)

   -- This tests the 'location' verb of the gps API when we are not actually subscribed to a device
_AFT.testVerbStatusError(testPrefix.."location_with_wrong_argument","gps","location",{state= "on"}, nil, nil)

-- This tests the 'subscribe' verb of the gps API with wrong argument
_AFT.testVerbStatusError(testPrefix.."subscribe_with_wrong_argument","gps","subscribe", {value = "error" }, nil, nil)

-- This tests the 'unsubscribe' verb of the gps API with wrong argument
_AFT.testVerbStatusError(testPrefix.."unsubscribe_with_wrong_argument","gps","unsubscribe",{value = "error" }, nil, nil)

-- This tests the 'subscribe' verb of the gps API with wrong argument
_AFT.testVerbStatusError(testPrefix.."subscribe_with_wrong_argument","gps","subscribe", {}, nil, nil)

-- This tests the 'unsubscribe' verb of the gps API with wrong argument
_AFT.testVerbStatusError(testPrefix.."unsubscribe_with_wrong_argument","gps","unsubscribe",{}, nil, nil)

_AFT.exitAtEnd()