summaryrefslogtreecommitdiff
path: root/matlab/test/Ice/acm
diff options
context:
space:
mode:
Diffstat (limited to 'matlab/test/Ice/acm')
-rw-r--r--matlab/test/Ice/acm/AllTests.m99
-rw-r--r--matlab/test/Ice/acm/Application.m143
-rw-r--r--matlab/test/Ice/acm/Client.m37
-rw-r--r--matlab/test/Ice/acm/Test.ice39
-rw-r--r--matlab/test/Ice/acm/generated/.gitignore1
-rw-r--r--matlab/test/Ice/acm/runTest.m4
6 files changed, 323 insertions, 0 deletions
diff --git a/matlab/test/Ice/acm/AllTests.m b/matlab/test/Ice/acm/AllTests.m
new file mode 100644
index 00000000000..44085259f7f
--- /dev/null
+++ b/matlab/test/Ice/acm/AllTests.m
@@ -0,0 +1,99 @@
+%{
+**********************************************************************
+
+Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
+
+This copy of Ice is licensed to you under the terms described in the
+ICE_LICENSE file included in this distribution.
+
+**********************************************************************
+%}
+
+classdef AllTests
+ methods(Static)
+ function allTests(app)
+ import test.Ice.acm.Test.*;
+
+ communicator = app.communicator();
+
+ ref = 'communicator:default -p 12010';
+ com = RemoteCommunicatorPrx.uncheckedCast(communicator.stringToProxy(ref));
+
+ AllTests.testSetACM(communicator, com);
+ AllTests.testHeartbeatManual(communicator, com);
+
+ com.shutdown();
+ end
+ function testSetACM(communicator, com)
+ import test.Ice.acm.Test.*;
+
+ fprintf('testing setACM/getACM... ');
+
+ adapter = com.createObjectAdapter(-1, -1, -1);
+
+ initData = Ice.InitializationData();
+ initData.properties_ = communicator.getProperties().clone();
+ initData.properties_.setProperty('Ice.ACM.Timeout', '1');
+ initData.properties_.setProperty('Ice.ACM.Client.Timeout', '15');
+ initData.properties_.setProperty('Ice.ACM.Client.Close', '4');
+ initData.properties_.setProperty('Ice.ACM.Client.Heartbeat', '2');
+ testCommunicator = Ice.initialize(initData);
+ proxy = TestIntfPrx.uncheckedCast(testCommunicator.stringToProxy(adapter.getTestIntf().ice_toString()));
+ proxy.ice_getConnection();
+
+ acm = proxy.ice_getCachedConnection().getACM();
+ assert(acm.timeout == 15);
+ assert(acm.close == Ice.ACMClose.CloseOnIdleForceful);
+ assert(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatOnIdle);
+
+ proxy.ice_getCachedConnection().setACM(Ice.Unset, Ice.Unset, Ice.Unset);
+ acm = proxy.ice_getCachedConnection().getACM();
+ assert(acm.timeout == 15);
+ assert(acm.close == Ice.ACMClose.CloseOnIdleForceful);
+ assert(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatOnIdle);
+
+ proxy.ice_getCachedConnection().setACM(1, Ice.ACMClose.CloseOnInvocationAndIdle, ...
+ Ice.ACMHeartbeat.HeartbeatAlways);
+ acm = proxy.ice_getCachedConnection().getACM();
+ assert(acm.timeout == 1);
+ assert(acm.close == Ice.ACMClose.CloseOnInvocationAndIdle);
+ assert(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatAlways);
+
+ proxy.startHeartbeatCount();
+ proxy.waitForHeartbeatCount(2);
+
+ adapter.deactivate();
+ testCommunicator.destroy();
+ fprintf('ok\n');
+ end
+ function testHeartbeatManual(communicator, com)
+ import test.Ice.acm.Test.*;
+
+ fprintf('testing manual heartbeats... ');
+
+ adapter = com.createObjectAdapter(10, -1, 0);
+
+ initData = Ice.InitializationData();
+ initData.properties_ = communicator.getProperties().clone();
+ initData.properties_.setProperty('Ice.ACM.Timeout', '10');
+ initData.properties_.setProperty('Ice.ACM.Client.Timeout', '10');
+ initData.properties_.setProperty('Ice.ACM.Client.Close', '0');
+ initData.properties_.setProperty('Ice.ACM.Client.Heartbeat', '0');
+ testCommunicator = Ice.initialize(initData);
+ proxy = TestIntfPrx.uncheckedCast(testCommunicator.stringToProxy(adapter.getTestIntf().ice_toString()));
+ con = proxy.ice_getConnection();
+
+ proxy.startHeartbeatCount();
+ con.heartbeat();
+ con.heartbeat();
+ con.heartbeat();
+ con.heartbeat();
+ con.heartbeat();
+ proxy.waitForHeartbeatCount(5);
+
+ adapter.deactivate();
+ testCommunicator.destroy();
+ fprintf('ok\n');
+ end
+ end
+end
diff --git a/matlab/test/Ice/acm/Application.m b/matlab/test/Ice/acm/Application.m
new file mode 100644
index 00000000000..4735c1cd057
--- /dev/null
+++ b/matlab/test/Ice/acm/Application.m
@@ -0,0 +1,143 @@
+%{
+**********************************************************************
+
+Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
+
+This copy of Ice is licensed to you under the terms described in the
+ICE_LICENSE file included in this distribution.
+
+**********************************************************************
+%}
+
+classdef (Abstract) Application < handle
+ methods(Sealed)
+ %
+ % main() initializes the Communicator, calls run(), and destroys
+ % the Communicator upon return from run(). It thereby handles
+ % all exceptions properly, i.e., error messages are printed
+ % if exceptions propagate to main(), and the Communicator is
+ % always destroyed, regardless of exceptions.
+ %
+ function r = main(obj, appName, varargin)
+ if ~isempty(obj.communicator_)
+ printf('%s: only one instance of the Application class can be used', appName);
+ r = 1;
+ return;
+ end
+
+ obj.testName_ = appName;
+
+ args = {};
+ initializationData = [];
+
+ if length(varargin) >= 1
+ args = varargin{1};
+ end
+ if length(varargin) >= 2
+ initializationData = varargin{2};
+ end
+
+ %
+ % We parse the properties here to extract Ice.ProgramName.
+ %
+ if isempty(initializationData)
+ [initializationData, args] = obj.getInitData(args);
+ end
+
+ if ~isempty(initializationData)
+ initData = initializationData.clone();
+ else
+ initData = Ice.InitializationData();
+ end
+
+ [initData.properties_, args] = Ice.createProperties(args, initData.properties_);
+
+ status = 0;
+
+ try
+ [communicator, args] = Ice.initialize(args, initData);
+ obj.communicator_ = communicator;
+
+ status = obj.run(args);
+ catch ex
+ fprintf('%s: caught %s', obj.testName_, ex.identifier);
+ disp(getReport(ex, 'extended'));
+ status = 1;
+ end
+ obj.communicator_.destroy();
+ obj.communicator_ = [];
+
+ r = status;
+ end
+ function r = initialize(obj, varargin)
+ assert(length(varargin) <= 1);
+ if length(varargin) == 0
+ r = Ice.initialize();
+ else
+ r = Ice.initialize(varargin{1});
+ end
+ end
+ function r = appName(obj)
+ r = obj.testName_;
+ end
+ function r = communicator(obj)
+ r = obj.communicator_;
+ end
+ function r = createInitializationData(obj)
+ initData = Ice.InitializationData();
+ r = initData;
+ end
+ function r = getTestEndpoint(obj, num, prot)
+ r = Application.getTestEndpointWithProperties(obj.communicator_.getProperties(), num, prot);
+ end
+ function r = getTestHost(obj)
+ r = Application.getTestHostWithProperties(obj.communicator_.getProperties());
+ end
+ function r = getTestProtocol(obj)
+ r = Application.getTestProtocolWithProperties(obj.communicator_.getProperties());
+ end
+ function r = getTestPort(obj, num)
+ r = Application.getTestPortWithProperties(obj.communicator_.getProperties(), num);
+ end
+ end
+ methods(Static)
+ function r = getTestEndpointWithProperties(props, num, prot)
+ protocol = prot;
+ if length(protocol) == 0
+ protocol = props.getPropertyWithDefault('Ice.Default.Protocol', 'default');
+ end
+
+ basePort = props.getPropertyAsIntWithDefault('Test.BasePort', 12010);
+
+ r = sprintf('%s -p %d', protocol, basePort + num);
+ end
+ function r = getTestHostWithProperties(props)
+ r = props.getPropertyWithDefault('Ice.Default.Host', '127.0.0.1');
+ end
+ function r = getTestProtocolWithProperties(props)
+ r = props.getPropertyWithDefault('Ice.Default.Protocol', 'tcp');
+ end
+ function r = getTestPortWithProperties(props, num)
+ r = props.getPropertyAsIntWithDefault('Test.BasePort', 12010) + num;
+ end
+ end
+ methods(Abstract)
+ r = run(obj, args)
+ end
+ methods(Access=protected)
+ %
+ % Hook to override the initialization data. This hook is
+ % necessary because some properties must be set prior to
+ % communicator initialization.
+ %
+ function [initData, remArgs] = getInitData(obj, args)
+ initData = obj.createInitializationData();
+ [initData.properties_, remArgs] = Ice.createProperties(args);
+ remArgs = initData.properties_.parseCommandLineOptions('Test', remArgs);
+ end
+ end
+ properties(Access=private)
+ testName_
+ communicator_
+ end
+end
diff --git a/matlab/test/Ice/acm/Client.m b/matlab/test/Ice/acm/Client.m
new file mode 100644
index 00000000000..7cde23db42b
--- /dev/null
+++ b/matlab/test/Ice/acm/Client.m
@@ -0,0 +1,37 @@
+%{
+**********************************************************************
+
+Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
+
+This copy of Ice is licensed to you under the terms described in the
+ICE_LICENSE file included in this distribution.
+
+**********************************************************************
+%}
+
+classdef Client < Application
+ methods
+ function r = run(obj, args)
+ AllTests.allTests(obj);
+ r = 0;
+ end
+ end
+ methods(Access=protected)
+ function [r, remArgs] = getInitData(obj, args)
+ [initData, remArgs] = getInitData@Application(obj, args);
+ initData.properties_.setProperty('Ice.Package.Test', 'test.Ice.acm');
+ initData.properties_.setProperty('Ice.Warn.Connections', '0');
+ r = initData;
+ end
+ end
+ methods(Static)
+ function status = start(args)
+ addpath('generated');
+ if ~libisloaded('icematlab')
+ loadlibrary('icematlab')
+ end
+ c = Client();
+ status = c.main('Client', args);
+ end
+ end
+end
diff --git a/matlab/test/Ice/acm/Test.ice b/matlab/test/Ice/acm/Test.ice
new file mode 100644
index 00000000000..71fd1163244
--- /dev/null
+++ b/matlab/test/Ice/acm/Test.ice
@@ -0,0 +1,39 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#pragma once
+
+[["matlab:package:test.Ice.acm"]]
+module Test
+{
+
+interface TestIntf
+{
+ void sleep(int seconds);
+ void sleepAndHold(int seconds);
+ void interruptSleep();
+ void startHeartbeatCount();
+ void waitForHeartbeatCount(int count);
+}
+
+interface RemoteObjectAdapter
+{
+ TestIntf* getTestIntf();
+ void activate();
+ void hold();
+ void deactivate();
+}
+
+interface RemoteCommunicator
+{
+ RemoteObjectAdapter* createObjectAdapter(int acmTimeout, int close, int heartbeat);
+ void shutdown();
+}
+
+}
diff --git a/matlab/test/Ice/acm/generated/.gitignore b/matlab/test/Ice/acm/generated/.gitignore
new file mode 100644
index 00000000000..39af5887579
--- /dev/null
+++ b/matlab/test/Ice/acm/generated/.gitignore
@@ -0,0 +1 @@
+# Dummy file, so that git retains this otherwise empty directory.
diff --git a/matlab/test/Ice/acm/runTest.m b/matlab/test/Ice/acm/runTest.m
new file mode 100644
index 00000000000..66a1e8dda5e
--- /dev/null
+++ b/matlab/test/Ice/acm/runTest.m
@@ -0,0 +1,4 @@
+function runTest(varargin)
+ status = Client.start(varargin);
+ exit(status);
+end