aboutsummaryrefslogtreecommitdiffstats
path: root/test/afb-test/tests
diff options
context:
space:
mode:
authorFrederic Marec <frederic.marec@iot.bzh>2018-08-30 16:46:48 +0200
committerFrederic Marec <frederic.marec@iot.bzh>2018-09-26 17:57:33 +0200
commit6e4f5c92c6162116b79dea2533d07a8723964232 (patch)
treed9b9ce85626806a56733aa898c2199838a48e556 /test/afb-test/tests
parentf3d87deb907cb189b1a0cdb4af0b3d9df55a06fa (diff)
Add tests for gps binding
ADD test.nmea in fixtures ADD README.md to launch test Change-Id: I10e12e94f8dfac54c6bb10c269c48c21a5971f8a Signed-off-by: Frederic Marec <frederic.marec@iot.bzh>
Diffstat (limited to 'test/afb-test/tests')
-rw-r--r--test/afb-test/tests/CMakeLists.txt31
-rw-r--r--test/afb-test/tests/gps_BasicAPITest.lua106
2 files changed, 137 insertions, 0 deletions
diff --git a/test/afb-test/tests/CMakeLists.txt b/test/afb-test/tests/CMakeLists.txt
new file mode 100644
index 0000000..426adac
--- /dev/null
+++ b/test/afb-test/tests/CMakeLists.txt
@@ -0,0 +1,31 @@
+###########################################################################
+# Copyright 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.
+###########################################################################
+
+
+##################################################
+# GPS Lua Scripts
+##################################################
+PROJECT_TARGET_ADD(test-files)
+
+ file(GLOB LUA_FILES "*.lua")
+ add_input_files("${LUA_FILES}")
+
+ SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
+ LABELS "TEST-DATA"
+ OUTPUT_NAME ${TARGET_NAME}
+ ) \ No newline at end of file
diff --git a/test/afb-test/tests/gps_BasicAPITest.lua b/test/afb-test/tests/gps_BasicAPITest.lua
new file mode 100644
index 0000000..965f505
--- /dev/null
+++ b/test/afb-test/tests/gps_BasicAPITest.lua
@@ -0,0 +1,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()