/* ----------------------------------------------------------------------------- Copyright 2022 Kevin P. Barry 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. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] testcase "Pointer passing" { success } concrete CallHelper { @type call (String) -> (String) @type call2 (String) -> (String) } define CallHelper { call (data) { Request request <- Request.create(data) Response response <- Response.create("") // This is just meant to test code generated for passing Pointer as a // function arg or return. return Response.getData(callWithPointers(request.asRequest(),response.asResponse())) } call2 (data) { Request request <- Request.create(data) Response response <- Response.create("") \ Service.send2(request.asMessage(),response.asResponse()) return response.formatted() } @type callWithPointers (Pointer,Pointer) -> (Pointer) callWithPointers (request,response) { \ Service.send(request,response) return response } } unittest test { \ CallHelper.call("DATA") `Testing.checkEquals` "DATA has been processed as Request" \ CallHelper.call2("DATA") `Testing.checkEquals` "REQUEST has been processed as Message" } testcase "Pointer storage" { success } concrete Helper { @type new () -> (Helper) @value call () -> () } define Helper { @category Request request <- Request.create("request") @category Pointer requestPointer <- request.asRequest() @value Response response @value Pointer responsePointer new () { Response response <- Response.create("response") return #self{ response, response.asResponse() } } call () { \ Request.getData(requestPointer) `Testing.checkEquals` "request" \ Response.getData(responsePointer) `Testing.checkEquals` "response" Pointer localRequest <- requestPointer Pointer localResponse <- responsePointer \ Request.getData(localRequest) `Testing.checkEquals` "request" \ Response.getData(localResponse) `Testing.checkEquals` "response" localRequest <- request.asRequest() localResponse <- response.asResponse() \ Request.getData(localRequest) `Testing.checkEquals` "request" \ Response.getData(localResponse) `Testing.checkEquals` "response" requestPointer <- localRequest responsePointer <- localResponse \ Request.getData(requestPointer) `Testing.checkEquals` "request" \ Response.getData(responsePointer) `Testing.checkEquals` "response" } } unittest test { \ Helper.new().call() }