|
| 1 | +--------------------------------------------------------------------------------------------------- |
| 2 | +-- User story: https://github.com/smartdevicelink/sdl_requirements/issues/26 |
| 3 | +-- Use case: https://github.com/smartdevicelink/sdl_requirements/blob/master/detailed_docs/embedded_navi/Subscribe_to_Destination_and_Waypoints.md |
| 4 | +-- Item: Use Case 1: Main Flow |
| 5 | +-- |
| 6 | +-- Requirement summary: |
| 7 | +-- [SubscribeWayPoints] As a mobile app I want to be able to subscribe on notifications about |
| 8 | +-- any changes to the destination or waypoints. |
| 9 | +-- |
| 10 | +-- Description: |
| 11 | +-- In case: |
| 12 | +-- 1) mobile application sent valid and allowed by Policies SubscribeWayPoints_request to SDL |
| 13 | +-- |
| 14 | +-- SDL must: |
| 15 | +-- 1) transfer SubscribeWayPoints_request_ to HMI |
| 16 | +-- 2) respond with <resultCode> received from HMI to mobile app |
| 17 | + |
| 18 | +--------------------------------------------------------------------------------------------------- |
| 19 | +--[[ Required Shared libraries ]] |
| 20 | +local runner = require('user_modules/script_runner') |
| 21 | +local common = require('test_scripts/API/Navigation/commonNavigation') |
| 22 | +local events = require("events") |
| 23 | + |
| 24 | +--[[ Local Variables ]] |
| 25 | +local isSubscribed = false |
| 26 | +local resultCodes = { |
| 27 | + success = common.getSuccessResultCodes("SubscribeWayPoints"), |
| 28 | + failure = common.getFailureResultCodes("SubscribeWayPoints"), |
| 29 | + unexpected = common.getUnexpectedResultCodes("SubscribeWayPoints"), |
| 30 | + unmapped = common.getUnmappedResultCodes("SubscribeWayPoints") |
| 31 | +} |
| 32 | + |
| 33 | +--[[ Local Functions ]] |
| 34 | +local function unsubscribeWayPoints(self) |
| 35 | + local event = events.Event() |
| 36 | + event.matches = function(e1, e2) return e1 == e2 end |
| 37 | + local ret = EXPECT_EVENT(event, "Precondition event") |
| 38 | + if isSubscribed then |
| 39 | + local cid = self.mobileSession1:SendRPC("UnsubscribeWayPoints", {}) |
| 40 | + EXPECT_HMICALL("Navigation.UnsubscribeWayPoints") |
| 41 | + :Do(function(_,data) |
| 42 | + self.hmiConnection:SendResponse(data.id, data.method, "SUCCESS", {}) |
| 43 | + end) |
| 44 | + self.mobileSession1:ExpectResponse(cid, { success = true, resultCode = "SUCCESS" }) |
| 45 | + :Do(function(_, data) |
| 46 | + if data.payload.success then isSubscribed = false end |
| 47 | + RAISE_EVENT(event, event, "Precondition event") |
| 48 | + end) |
| 49 | + else |
| 50 | + local function raise_event() |
| 51 | + RAISE_EVENT(event, event, "Precondition event") |
| 52 | + end |
| 53 | + RUN_AFTER(raise_event, 100) |
| 54 | + end |
| 55 | + return ret |
| 56 | +end |
| 57 | + |
| 58 | +local function subscribeWayPointsSuccess(pResultCodeMap, self) |
| 59 | + unsubscribeWayPoints(self) |
| 60 | + :Do(function() |
| 61 | + local cid = self.mobileSession1:SendRPC("SubscribeWayPoints", {}) |
| 62 | + EXPECT_HMICALL("Navigation.SubscribeWayPoints") |
| 63 | + :Do(function(_,data) |
| 64 | + self.hmiConnection:SendResponse(data.id, data.method, pResultCodeMap.hmi, {}) |
| 65 | + end) |
| 66 | + self.mobileSession1:ExpectResponse(cid, { success = true, resultCode = pResultCodeMap.mobile }) |
| 67 | + :Do(function(_, data) |
| 68 | + if data.payload.success then isSubscribed = true end |
| 69 | + end) |
| 70 | + end) |
| 71 | +end |
| 72 | + |
| 73 | +local function subscribeWayPointsUnsuccess(pResultCodeMap, self) |
| 74 | + unsubscribeWayPoints(self) |
| 75 | + :Do(function() |
| 76 | + local cid = self.mobileSession1:SendRPC("SubscribeWayPoints", {}) |
| 77 | + EXPECT_HMICALL("Navigation.SubscribeWayPoints") |
| 78 | + :Do(function(_,data) |
| 79 | + self.hmiConnection:SendError(data.id, data.method, pResultCodeMap.hmi, "Error error") |
| 80 | + end) |
| 81 | + |
| 82 | + self.mobileSession1:ExpectResponse(cid, { success = false, resultCode = pResultCodeMap.mobile }) |
| 83 | + :ValidIf(function(_,data) |
| 84 | + if not data.payload.info then |
| 85 | + return false, "SDL doesn't resend info parameter to mobile App" |
| 86 | + end |
| 87 | + return true |
| 88 | + end) |
| 89 | + :Do(function(_, data) |
| 90 | + if data.payload.success then isSubscribed = true end |
| 91 | + end) |
| 92 | + end) |
| 93 | +end |
| 94 | + |
| 95 | +local function subscribeWayPointsUnexpected(pResultCodeMap, self) |
| 96 | + unsubscribeWayPoints(self) |
| 97 | + :Do(function() |
| 98 | + local cid = self.mobileSession1:SendRPC("SubscribeWayPoints", {}) |
| 99 | + |
| 100 | + EXPECT_HMICALL("Navigation.SubscribeWayPoints") |
| 101 | + :Do(function(_,data) |
| 102 | + if pResultCodeMap.success then |
| 103 | + self.hmiConnection:SendResponse(data.id, data.method, pResultCodeMap.hmi, {}) |
| 104 | + else |
| 105 | + self.hmiConnection:SendError(data.id, data.method, pResultCodeMap.hmi, "Error error") |
| 106 | + end |
| 107 | + end) |
| 108 | + |
| 109 | + self.mobileSession1:ExpectResponse(cid, { success = pResultCodeMap.success, resultCode = pResultCodeMap.mobile }) |
| 110 | + :Do(function(_, data) |
| 111 | + if data.payload.success then isSubscribed = true end |
| 112 | + end) |
| 113 | + end) |
| 114 | +end |
| 115 | + |
| 116 | +--[[ Scenario ]] |
| 117 | +runner.Title("Preconditions") |
| 118 | +runner.Step("Clean environment", common.preconditions) |
| 119 | +runner.Step("Start SDL, HMI, connect Mobile, start Session", common.start) |
| 120 | +runner.Step("RAI, PTU", common.registerAppWithPTU) |
| 121 | +runner.Step("Activate App", common.activateApp) |
| 122 | + |
| 123 | +runner.Title("Test") |
| 124 | +runner.Step("Result Codes", common.printResultCodes, { resultCodes }) |
| 125 | + |
| 126 | +runner.Title("Successful codes") |
| 127 | +for _, item in pairs(resultCodes.success) do |
| 128 | + runner.Step("SubscribeWayPoints with " .. item.hmi .. " resultCode", subscribeWayPointsSuccess, { item }) |
| 129 | +end |
| 130 | + |
| 131 | +runner.Title("Erroneous codes") |
| 132 | +for _, item in pairs(resultCodes.failure) do |
| 133 | + runner.Step("SubscribeWayPoints with " .. item.hmi .. " resultCode", subscribeWayPointsUnsuccess, { item }) |
| 134 | +end |
| 135 | + |
| 136 | +runner.Title("Unexpected codes") |
| 137 | +for _, item in pairs(resultCodes.unexpected) do |
| 138 | + runner.Step("SubscribeWayPoints with " .. item.hmi .. " resultCode", subscribeWayPointsUnexpected, { item }) |
| 139 | +end |
| 140 | + |
| 141 | +runner.Title("Postconditions") |
| 142 | +runner.Step("Stop SDL", common.postconditions) |
0 commit comments