diff options
author | Mark Spruiell <mes@zeroc.com> | 2017-10-03 15:15:31 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2017-10-03 15:15:31 -0700 |
commit | 3c1ed6f3c56943fa7938042f72dc20dc79f6ae2a (patch) | |
tree | 5af66030548c3250946ee68f786e60fa5bfee9c7 | |
parent | Adding inheritance test (diff) | |
download | ice-3c1ed6f3c56943fa7938042f72dc20dc79f6ae2a.tar.bz2 ice-3c1ed6f3c56943fa7938042f72dc20dc79f6ae2a.tar.xz ice-3c1ed6f3c56943fa7938042f72dc20dc79f6ae2a.zip |
Adding more tests; checksum support
61 files changed, 2659 insertions, 207 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 568bc075cf7..89a9874aac2 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -724,6 +724,18 @@ Slice::Preprocessor::printMakefileDependencies(ostream& out, Language lang, cons } break; } + case MATLAB: + { + // + // Change .o[bj] suffix to .m suffix. + // + string::size_type pos; + if((pos = result.find(suffix)) != string::npos) + { + result.replace(pos, suffix.size() - 1, ".m"); + } + break; + } default: { assert(false); diff --git a/cpp/src/Slice/Preprocessor.h b/cpp/src/Slice/Preprocessor.h index 70ef5c2dc5b..cc6b5a48596 100644 --- a/cpp/src/Slice/Preprocessor.h +++ b/cpp/src/Slice/Preprocessor.h @@ -32,7 +32,7 @@ public: FILE* preprocess(bool, const std::vector<std::string>&); bool close(); - enum Language { CPlusPlus, Java, CSharp, Python, Ruby, PHP, JavaScript, JavaScriptJSON, ObjC, SliceXML }; + enum Language { CPlusPlus, Java, CSharp, Python, Ruby, PHP, JavaScript, JavaScriptJSON, ObjC, SliceXML, MATLAB }; bool printMakefileDependencies(std::ostream&, Language, const std::vector<std::string>&, const std::string& = "", const std::string& = "cpp", const std::string& = ""); diff --git a/cpp/src/slice2matlab/Main.cpp b/cpp/src/slice2matlab/Main.cpp index dc9a25136cf..70ed6d28960 100644 --- a/cpp/src/slice2matlab/Main.cpp +++ b/cpp/src/slice2matlab/Main.cpp @@ -25,6 +25,7 @@ #include <Slice/Util.h> #include <cstring> #include <climits> +#include <iterator> #include <sys/types.h> #include <sys/stat.h> @@ -191,6 +192,76 @@ scopedToName(const string& scoped) return fixIdent(str); } +void +printHeader(IceUtilInternal::Output& out) +{ + static const char* header = + "%{\n" + "**********************************************************************\n" + "\n" + "Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.\n" + "\n" + "This copy of Ice is licensed to you under the terms described in the\n" + "ICE_LICENSE file included in this distribution.\n" + "\n" + "**********************************************************************\n" + "%}\n" + ; + + out << header; + out << "%\n"; + out << "% Ice version " << ICE_STRING_VERSION << "\n"; + out << "%\n"; +} + +void +openClass(const string& abs, const string& dir, IceUtilInternal::Output& out) +{ + vector<string> v = splitAbsoluteName(abs); + assert(v.size() > 1); + + string path; + if(!dir.empty()) + { + path = dir + "/"; + } + + // + // Create a package directory corresponding to each component. + // + for(vector<string>::size_type i = 0; i < v.size() - 1; i++) + { + path += "+" + lookupKwd(v[i]); + if(!IceUtilInternal::directoryExists(path)) + { + if(IceUtilInternal::mkdir(path, 0777) != 0) + { + ostringstream os; + os << "cannot create directory `" << path << "': " << strerror(errno); + throw FileException(__FILE__, __LINE__, os.str()); + } + FileTracker::instance()->addDirectory(path); + } + path += "/"; + } + + // + // There are two options: + // + // 1) Create a subdirectory named "@ClassName" containing a file "ClassName.m". + // 2) Create a file named "ClassName.m". + // + // The class directory is useful if you want to add additional supporting files for the class. We only + // generate a single file for a class so we use option 2. + // + const string cls = lookupKwd(v[v.size() - 1]); + path += cls + ".m"; + + out.open(path); + printHeader(out); + FileTracker::instance()->addFile(path); +} + map<string, string> _filePackagePrefix; string @@ -234,28 +305,6 @@ getAbsolute(const ContainedPtr& cont, const string& pfx = std::string(), const s return pkg + scopedToName(cont->scope() + pfx + cont->name() + suffix); } -void -printHeader(IceUtilInternal::Output& out) -{ - static const char* header = - "%{\n" - "**********************************************************************\n" - "\n" - "Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.\n" - "\n" - "This copy of Ice is licensed to you under the terms described in the\n" - "ICE_LICENSE file included in this distribution.\n" - "\n" - "**********************************************************************\n" - "%}\n" - ; - - out << header; - out << "%\n"; - out << "% Ice version " << ICE_STRING_VERSION << "\n"; - out << "%\n"; -} - string typeToString(const TypePtr& type) { @@ -507,6 +556,13 @@ defaultValue(const DataMemberPtr& m) } } + EnumPtr en = EnumPtr::dynamicCast(m->type()); + if(en) + { + const EnumeratorList enumerators = en->enumerators(); + return getAbsolute(*enumerators.begin()); + } + return "[]"; } } @@ -596,6 +652,62 @@ convertValueType(IceUtilInternal::Output& out, const string& dest, const string& } } +void +writeChecksums(const string& name, const string& dir, const ChecksumMap& m) +{ + // + // Attempt to open the source file for the checksums. + // + IceUtilInternal::Output out; + openClass(name, dir, out); + + // + // Get the name. + // + string func; + string::size_type pos = name.rfind('.'); + if(pos == string::npos) + { + func = name; + } + else + { + func = name.substr(pos + 1); + } + + // + // Emit the function. + // + out << nl << "function r = " << func << "()"; + out.inc(); + out << nl << "persistent ice_checksums;"; + out << nl << "if isempty(ice_checksums)"; + out.inc(); + out << nl << "ice_checksums = containers.Map('KeyType', 'char', 'ValueType', 'char');"; + + for(ChecksumMap::const_iterator p = m.begin(); p != m.end(); ++p) + { + out << nl << "ice_checksums('" << p->first << "') = '"; + ostringstream str; + str.flags(ios_base::hex); + str.fill('0'); + for(vector<unsigned char>::const_iterator q = p->second.begin(); q != p->second.end(); ++q) + { + str << static_cast<int>(*q); + } + out << str.str() << "';"; + } + + out.dec(); + out << nl << "end"; + out << nl << "r = ice_checksums;"; + out.dec(); + out << nl << "end"; + out << nl; + + out.close(); +} + } // @@ -617,8 +729,6 @@ public: private: - void openClass(const string&, IceUtilInternal::Output&); - struct MemberInfo { string fixedName; @@ -695,7 +805,7 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) } IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); out << nl << "classdef "; if(p->isLocal() && !allOps.empty()) @@ -1080,7 +1190,7 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) ostringstream ostr; ostr << "IceCompactId.TypeId_" << p->compactId(); - openClass(ostr.str(), out); + openClass(ostr.str(), _dir, out); out << nl << "classdef TypeId_" << p->compactId(); out.inc(); @@ -1118,7 +1228,7 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) } IceUtilInternal::Output out; - openClass(prxAbs, out); + openClass(prxAbs, _dir, out); out << nl << "classdef " << prxName << " < "; if(!prxBases.empty()) @@ -1637,7 +1747,7 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); out << nl << "classdef (Abstract) " << name; if(bases.empty()) @@ -1733,7 +1843,7 @@ CodeVisitor::visitExceptionStart(const ExceptionPtr& p) const bool preserved = p->hasMetaData("preserve-slice"); IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); ExceptionPtr base = p->base(); @@ -1997,7 +2107,7 @@ CodeVisitor::visitStructStart(const StructPtr& p) const string abs = getAbsolute(p); IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); const DataMemberList members = p->dataMembers(); const DataMemberList classMembers = p->classDataMembers(); @@ -2203,7 +2313,7 @@ CodeVisitor::visitSequence(const SequencePtr& p) const bool convert = needsConversion(content); IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); out << nl << "classdef " << name; out.inc(); @@ -2460,7 +2570,7 @@ CodeVisitor::visitDictionary(const DictionaryPtr& p) const string self = name == "obj" ? "this" : "obj"; IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); out << nl << "classdef " << name; out.inc(); @@ -2695,7 +2805,7 @@ CodeVisitor::visitEnum(const EnumPtr& p) const string abs = getAbsolute(p); IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); out << nl << "classdef " << name << " < int32"; @@ -2797,7 +2907,7 @@ CodeVisitor::visitConst(const ConstPtr& p) const string abs = getAbsolute(p); IceUtilInternal::Output out; - openClass(abs, out); + openClass(abs, _dir, out); out << nl << "classdef " << name; @@ -2816,54 +2926,6 @@ CodeVisitor::visitConst(const ConstPtr& p) out.close(); } -void -CodeVisitor::openClass(const string& abs, IceUtilInternal::Output& out) -{ - vector<string> v = splitAbsoluteName(abs); - assert(v.size() > 1); - - string path; - if(!_dir.empty()) - { - path = _dir + "/"; - } - - // - // Create a package directory corresponding to each component. - // - for(vector<string>::size_type i = 0; i < v.size() - 1; i++) - { - path += "+" + lookupKwd(v[i]); - if(!IceUtilInternal::directoryExists(path)) - { - if(IceUtilInternal::mkdir(path, 0777) != 0) - { - ostringstream os; - os << "cannot create directory `" << path << "': " << strerror(errno); - throw FileException(__FILE__, __LINE__, os.str()); - } - FileTracker::instance()->addDirectory(path); - } - path += "/"; - } - - // - // There are two options: - // - // 1) Create a subdirectory named "@ClassName" containing a file "ClassName.m". - // 2) Create a file named "ClassName.m". - // - // The class directory is useful if you want to add additional supporting files for the class. We only - // generate a single file for a class so we use option 2. - // - const string cls = lookupKwd(v[v.size() - 1]); - path += "/" + cls + ".m"; - - out.open(path); - printHeader(out); - FileTracker::instance()->addFile(path); -} - string CodeVisitor::getOperationMode(Slice::Operation::Mode mode) { @@ -3730,65 +3792,6 @@ CodeVisitor::convertStruct(IceUtilInternal::Output& out, const StructPtr& p, con } } -static void -generate(const UnitPtr& un, const string& dir, bool all, bool checksum, const vector<string>& includePaths) -{ - CodeVisitor codeVisitor(dir); - un->visit(&codeVisitor, false); - -#if 0 - if(checksum) - { - ChecksumMap checksums = createChecksums(un); - if(!checksums.empty()) - { - out << sp; - if(ns) - { - out << "namespace"; // Global namespace. - out << sb; - out << "new Ice\\SliceChecksumInit(array("; - for(ChecksumMap::const_iterator p = checksums.begin(); p != checksums.end();) - { - out << nl << "\"" << p->first << "\" => \""; - ostringstream str; - str.flags(ios_base::hex); - str.fill('0'); - for(vector<unsigned char>::const_iterator q = p->second.begin(); q != p->second.end(); ++q) - { - str << static_cast<int>(*q); - } - out << str.str() << "\""; - if(++p != checksums.end()) - { - out << ","; - } - } - out << "));"; - out << eb; - } - else - { - for(ChecksumMap::const_iterator p = checksums.begin(); p != checksums.end(); ++p) - { - out << nl << "$Ice_sliceChecksums[\"" << p->first << "\"] = \""; - ostringstream str; - str.flags(ios_base::hex); - str.fill('0'); - for(vector<unsigned char>::const_iterator q = p->second.begin(); q != p->second.end(); ++q) - { - str << static_cast<int>(*q); - } - out << str.str() << "\";"; - } - } - } - } - - out << nl; // Trailing newline. -#endif -} - namespace { @@ -3843,7 +3846,9 @@ usage(const string& n) "--depend-file FILE Write dependencies to FILE instead of standard output.\n" "--validate Validate command line options.\n" "--all Generate code for Slice definitions in included files.\n" - "--checksum Generate checksums for Slice definitions.\n" + "--checksum FUNC Generate checksums for Slice definitions into function FUNC.\n" + "--meta META Define global metadata directive META.\n" + "--list-generated Emit list of generated files in XML format.\n" ; } @@ -3862,9 +3867,11 @@ compile(const vector<string>& argv) opts.addOpt("", "depend"); opts.addOpt("", "depend-xml"); opts.addOpt("", "depend-file", IceUtilInternal::Options::NeedArg, ""); + opts.addOpt("", "list-generated"); opts.addOpt("d", "debug"); opts.addOpt("", "all"); - opts.addOpt("", "checksum"); + opts.addOpt("", "checksum", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "meta", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); @@ -3928,7 +3935,13 @@ compile(const vector<string>& argv) bool all = opts.isSet("all"); - bool checksum = opts.isSet("checksum"); + string checksumFunc = opts.optArg("checksum"); + + bool listGenerated = opts.isSet("list-generated"); + + StringList globalMetadata; + vector<string> v = opts.argVec("meta"); + copy(v.begin(), v.end(), back_inserter(globalMetadata)); if(args.empty()) { @@ -3957,6 +3970,8 @@ compile(const vector<string>& argv) int status = EXIT_SUCCESS; + ChecksumMap checksums; + IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); @@ -3980,7 +3995,7 @@ compile(const vector<string>& argv) if(depend || dependxml) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false, "-D__SLICE2PHP__"); + FILE* cppHandle = icecpp->preprocess(false, "-D__SLICE2MATLAB__"); if(cppHandle == 0) { @@ -3997,7 +4012,7 @@ compile(const vector<string>& argv) } if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::PHP : Preprocessor::SliceXML, - includePaths, "-D__SLICE2PHP__")) + includePaths, "-D__SLICE2MATLAB__")) { return EXIT_FAILURE; } @@ -4009,8 +4024,10 @@ compile(const vector<string>& argv) } else { + FileTracker::instance()->setSource(*i); + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false, "-D__SLICE2PHP__"); + FILE* cppHandle = icecpp->preprocess(false, "-D__SLICE2MATLAB__"); if(cppHandle == 0) { @@ -4034,7 +4051,7 @@ compile(const vector<string>& argv) } else { - UnitPtr u = Unit::createUnit(false, all, false, false); + UnitPtr u = Unit::createUnit(false, all, false, false, globalMetadata); int parseStatus = u->parse(*i, cppHandle, debug); if(!icecpp->close()) @@ -4058,7 +4075,17 @@ compile(const vector<string>& argv) try { - generate(u, output, all, checksum, includePaths); + CodeVisitor codeVisitor(output); + u->visit(&codeVisitor, all); + + if(!checksumFunc.empty()) + { + // + // Calculate checksums for the Slice definitions in the unit. + // + ChecksumMap m = createChecksums(u); + copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); + } } catch(const Slice::FileException& ex) { @@ -4068,13 +4095,9 @@ compile(const vector<string>& argv) FileTracker::instance()->cleanup(); u->destroy(); consoleErr << argv[0] << ": error: " << ex.reason() << endl; - return EXIT_FAILURE; - } - catch(const string& err) - { - FileTracker::instance()->cleanup(); - consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; + FileTracker::instance()->error(); + break; } } @@ -4103,6 +4126,28 @@ compile(const vector<string>& argv) writeDependencies(os.str(), dependFile); } + if(status == EXIT_SUCCESS && !checksumFunc.empty() && !dependxml) + { + try + { + writeChecksums(checksumFunc, output, checksums); + } + catch(const Slice::FileException& ex) + { + // + // If a file could not be created, then cleanup any created files. + // + FileTracker::instance()->cleanup(); + consoleErr << argv[0] << ": error: " << ex.reason() << endl; + return EXIT_FAILURE; + } + } + + if(listGenerated) + { + FileTracker::instance()->dumpxml(); + } + return status; } diff --git a/matlab/lib/+Ice/Communicator.m b/matlab/lib/+Ice/Communicator.m index 0b81eba4026..c79c70cb7a0 100644 --- a/matlab/lib/+Ice/Communicator.m +++ b/matlab/lib/+Ice/Communicator.m @@ -78,9 +78,12 @@ classdef Communicator < IceInternal.WrapperObject r = obj.callWithResult_('identityToString', id); end function r = getProperties(obj) - impl = libpointer('voidPtr'); - obj.call_('getProperties', impl); - r = Ice.Properties(impl); + if isempty(obj.properties_) + impl = libpointer('voidPtr'); + obj.call_('getProperties', impl); + obj.properties_ = Ice.Properties(impl); + end + r = obj.properties_; end function r = getLogger(obj) if isempty(obj.logger) @@ -164,5 +167,6 @@ classdef Communicator < IceInternal.WrapperObject classResolver encoding logger + properties_ end end diff --git a/matlab/lib/+Ice/Connection.m b/matlab/lib/+Ice/Connection.m index efdd01700fa..7d747d9a2fa 100755 --- a/matlab/lib/+Ice/Connection.m +++ b/matlab/lib/+Ice/Connection.m @@ -21,6 +21,19 @@ classdef Connection < IceInternal.WrapperObject obj = obj@IceInternal.WrapperObject(impl);
obj.communicator = communicator;
end
+ function r = eq(obj, other)
+ %
+ % Override == operator.
+ %
+ if isempty(other) || ~isa(other, 'Ice.Connection')
+ r = false;
+ else
+ %
+ % Call into C++ to compare the two objects.
+ %
+ r = obj.callWithResult_('equals', other.impl_);
+ end
+ end
function close(obj, mode)
obj.call_('close', mode);
end
diff --git a/matlab/lib/+Ice/ObjectPrx.m b/matlab/lib/+Ice/ObjectPrx.m index 668558cde56..fa41016b7e5 100644 --- a/matlab/lib/+Ice/ObjectPrx.m +++ b/matlab/lib/+Ice/ObjectPrx.m @@ -48,9 +48,7 @@ classdef ObjectPrx < IceInternal.WrapperObject % obj.instantiate_(); other.instantiate_(); - v = libpointer('uint8Ptr', 0); - obj.call_('equals', other.impl_, v); - r = v.Value == 1; + r = obj.callWithResult_('equals', other.impl_); end end diff --git a/matlab/msbuild/ice.proj b/matlab/msbuild/ice.proj index 171456105a0..7342931efa7 100644 --- a/matlab/msbuild/ice.proj +++ b/matlab/msbuild/ice.proj @@ -32,6 +32,7 @@ <Slice Include="$(sliceDir)\Ice\LocalException.ice" /> <Slice Include="$(sliceDir)\Ice\Locator.ice" /> <Slice Include="$(sliceDir)\Ice\Router.ice" /> + <Slice Include="$(sliceDir)\Ice\SliceChecksumDict.ice" /> <Slice Include="$(sliceDir)\Ice\ValueFactory.ice" /> <Slice Include="$(sliceDir)\Ice\Version.ice" /> </ItemGroup> @@ -49,7 +50,10 @@ <Target Name="Build" DependsOnTargets="CppPrereqs"> <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(MSBuildThisFileDirectory)..\lib\generated %(Slice.FullPath)"/> + <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\acm\generated $(testDir)\Ice\acm\Test.ice"/> <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\ami\generated $(testDir)\Ice\ami\Test.ice"/> + <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\checksum\generated --checksum test.Ice.checksum.Test.SliceChecksums $(testDir)\Ice\checksum\Test.ice $(testDir)\Ice\checksum\Types.ice"/> + <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\defaultValue\generated $(testDir)\Ice\defaultValue\Test.ice"/> <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\exceptions\generated $(testDir)\Ice\exceptions\Test.ice"/> <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\enums\generated $(testDir)\Ice\enums\Test.ice"/> <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\facets\generated $(testDir)\Ice\facets\Test.ice"/> @@ -63,6 +67,7 @@ <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\proxy\generated $(testDir)\Ice\proxy\Test.ice"/> <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\slicing\exceptions\generated $(testDir)\Ice\slicing\exceptions\ClientPrivate.ice"/> <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\slicing\objects\generated $(testDir)\Ice\slicing\objects\ClientPrivate.ice"/> + <Exec Command="$(slice2matlabexe) -I$(sliceDir) --output-dir $(testDir)\Ice\timeout\generated $(testDir)\Ice\timeout\Test.ice"/> <Exec Command="mex -v -outdir $(srcDir) -output icematlab $(MexCompilerFlags) -I$(topSrcDir)\cpp\include -I$(topSrcDir)\cpp\include\generated\cpp11\$(Platform)\$(Configuration) -DICE_CPP11_MAPPING -DICE_BUILDING_SRC -L$(topSrcDir)\cpp\lib\$(Platform)\$(Configuration) -lmex -lmx $(srcDir)\*.cpp"/> <Exec Command="copy /Y $(topSrcDir)\cpp\bin\$(Platform)\$(Configuration)\bzip2$(DebugExt).dll $(srcDir)"/> <Exec Command="copy /Y "$(topSrcDir)\cpp\bin\$(Platform)\$(Configuration)\ice37++11$(DebugExt).dll" $(srcDir)"/> diff --git a/matlab/src/IceMatlab/Connection.cpp b/matlab/src/IceMatlab/Connection.cpp index 5e4053b033f..4e06def390c 100644 --- a/matlab/src/IceMatlab/Connection.cpp +++ b/matlab/src/IceMatlab/Connection.cpp @@ -15,7 +15,8 @@ #include "Future.h" #include "Util.h" -#define SELF (*(reinterpret_cast<shared_ptr<Ice::Connection>*>(self))) +#define DEREF(x) (*(reinterpret_cast<shared_ptr<Ice::Connection>*>(x))) +#define SELF DEREF(self) using namespace std; using namespace IceMatlab; @@ -61,7 +62,7 @@ static const char* infoFields[] = }; mxArray* -createInfo(shared_ptr<Ice::ConnectionInfo> info) +createInfo(const shared_ptr<Ice::ConnectionInfo>& info) { // // Create and return a struct array containing the fields that describe the EndpointInfo object. @@ -142,6 +143,21 @@ Ice_Connection__release(void* self) } EXPORTED_FUNCTION mxArray* +Ice_Connection_equals(void* self, void* other) +{ + assert(other); // Wrapper only calls this function for non-nil arguments. + try + { + return createResultValue(createBool(SELF == DEREF(other))); + } + catch(const std::exception& ex) + { + return createResultException(convertException(ex)); + } + return 0; +} + +EXPORTED_FUNCTION mxArray* Ice_Connection_close(void* self, mxArray* m) { try diff --git a/matlab/src/IceMatlab/Endpoint.cpp b/matlab/src/IceMatlab/Endpoint.cpp index 78688469262..bb9dfca9862 100644 --- a/matlab/src/IceMatlab/Endpoint.cpp +++ b/matlab/src/IceMatlab/Endpoint.cpp @@ -21,7 +21,7 @@ using namespace std; using namespace IceMatlab; void* -IceMatlab::createEndpoint(shared_ptr<Ice::Endpoint> p) +IceMatlab::createEndpoint(const shared_ptr<Ice::Endpoint>& p) { return new shared_ptr<Ice::Endpoint>(p); } @@ -73,7 +73,7 @@ static const char* infoFields[] = }; mxArray* -createInfo(shared_ptr<Ice::EndpointInfo> info) +createInfo(const shared_ptr<Ice::EndpointInfo>& info) { // // Create and return a struct array containing the fields that describe the EndpointInfo object. diff --git a/matlab/src/IceMatlab/Endpoint.h b/matlab/src/IceMatlab/Endpoint.h index f3c6a4b41ed..42878c38e56 100644 --- a/matlab/src/IceMatlab/Endpoint.h +++ b/matlab/src/IceMatlab/Endpoint.h @@ -12,7 +12,7 @@ namespace IceMatlab { -void* createEndpoint(std::shared_ptr<Ice::Endpoint>); +void* createEndpoint(const std::shared_ptr<Ice::Endpoint>&); std::shared_ptr<Ice::Endpoint> getEndpoint(void*); } diff --git a/matlab/src/IceMatlab/ObjectPrx.cpp b/matlab/src/IceMatlab/ObjectPrx.cpp index 11242b88ca2..8ce5a98f9b8 100644 --- a/matlab/src/IceMatlab/ObjectPrx.cpp +++ b/matlab/src/IceMatlab/ObjectPrx.cpp @@ -234,16 +234,16 @@ Ice_ObjectPrx__release(void* self) } EXPORTED_FUNCTION mxArray* -Ice_ObjectPrx_equals(void* self, void* other, unsigned char* r) +Ice_ObjectPrx_equals(void* self, void* other) { assert(other); // Wrapper only calls this function for non-nil arguments. try { - *r = Ice::targetEqualTo(SELF, DEREF(other)) ? 1 : 0; + return createResultValue(createBool(Ice::targetEqualTo(SELF, DEREF(other)))); } catch(const std::exception& ex) { - return convertException(ex); + return createResultException(convertException(ex)); } return 0; } diff --git a/matlab/src/IceMatlab/icematlab.h b/matlab/src/IceMatlab/icematlab.h index d7d65e18f6f..facdc81364e 100644 --- a/matlab/src/IceMatlab/icematlab.h +++ b/matlab/src/IceMatlab/icematlab.h @@ -51,7 +51,7 @@ EXPORTED_FUNCTION mxArray* Ice_Communicator_flushBatchRequests(void*, mxArray*); EXPORTED_FUNCTION mxArray* Ice_Communicator_flushBatchRequestsAsync(void*, mxArray*, void**); EXPORTED_FUNCTION mxArray* Ice_ObjectPrx__release(void*); -EXPORTED_FUNCTION mxArray* Ice_ObjectPrx_equals(void*, void*, unsigned char*); +EXPORTED_FUNCTION mxArray* Ice_ObjectPrx_equals(void*, void*); EXPORTED_FUNCTION mxArray* Ice_ObjectPrx_read(void*, mxArray*, mxArray*, int, int, void**); EXPORTED_FUNCTION mxArray* Ice_ObjectPrx_write(void*, void*, mxArray*); EXPORTED_FUNCTION mxArray* Ice_ObjectPrx_ice_invoke(void*, const char*, int, mxArray*, unsigned int, mxArray*); @@ -148,6 +148,7 @@ EXPORTED_FUNCTION mxArray* Ice_Properties_load(void*, const char*); EXPORTED_FUNCTION mxArray* Ice_Properties_clone(void*, void**); EXPORTED_FUNCTION mxArray* Ice_Connection__release(void*); +EXPORTED_FUNCTION mxArray* Ice_Connection_equals(void*, void*); EXPORTED_FUNCTION mxArray* Ice_Connection_close(void*, mxArray*); EXPORTED_FUNCTION mxArray* Ice_Connection_closeAsync(void*, mxArray*, void**); EXPORTED_FUNCTION mxArray* Ice_Connection_createProxy(void*, mxArray*, void**); 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 diff --git a/matlab/test/Ice/ami/Client.m b/matlab/test/Ice/ami/Client.m index 10d1c635a21..2d1475a67d4 100644 --- a/matlab/test/Ice/ami/Client.m +++ b/matlab/test/Ice/ami/Client.m @@ -32,7 +32,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/ami/runTest.m b/matlab/test/Ice/ami/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/ami/runTest.m +++ b/matlab/test/Ice/ami/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/checksum/AllTests.m b/matlab/test/Ice/checksum/AllTests.m new file mode 100644 index 00000000000..16eaf366f6e --- /dev/null +++ b/matlab/test/Ice/checksum/AllTests.m @@ -0,0 +1,70 @@ +%{ +********************************************************************** + +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 r = allTests(app) + import test.Ice.checksum.Test.*; + + communicator = app.communicator(); + + ref = ['test:', app.getTestEndpoint(0, '')]; + base = communicator.stringToProxy(ref); + assert(~isempty(base)); + + checksum = ChecksumPrx.checkedCast(base); + assert(~isempty(checksum)); + + % + % Verify that no checksums are present for local types. + % + fprintf('testing checksums... '); + map = SliceChecksums(); + keys = map.keys(); + for i = 1:length(keys) + key = keys{i}; + assert(isempty(strfind(key, 'Local'))); + end + + % + % Get server's Slice checksums. + % + d = checksum.getSliceChecksums(); + + % + % Compare the checksums. For a type FooN whose name ends in an integer N, + % we assume that the server's type does not change for N = 1, and does + % change for N > 1. + % + skeys = d.keys(); + for i = 1:length(skeys) + n = 0; + key = skeys{i}; + pos = regexp(key, '\d+'); + if ~isempty(pos) + n = str2num(key(pos:end)); + end + + assert(map.isKey(key)); + value = map(key); + + if n <= 1 + assert(strcmp(value, d(key))); + else + assert(~strcmp(value, d(key))); + end + end + fprintf('ok\n'); + + r = checksum; + end + end +end diff --git a/matlab/test/Ice/checksum/Application.m b/matlab/test/Ice/checksum/Application.m new file mode 100644 index 00000000000..4735c1cd057 --- /dev/null +++ b/matlab/test/Ice/checksum/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/checksum/Client.m b/matlab/test/Ice/checksum/Client.m new file mode 100644 index 00000000000..55bcb87448b --- /dev/null +++ b/matlab/test/Ice/checksum/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) + checksum = AllTests.allTests(obj); + checksum.shutdown(); + 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.checksum'); + 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/checksum/Test.ice b/matlab/test/Ice/checksum/Test.ice new file mode 100644 index 00000000000..0b8f9722063 --- /dev/null +++ b/matlab/test/Ice/checksum/Test.ice @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// 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 + +#include <Ice/SliceChecksumDict.ice> + +[["matlab:package:test.Ice.checksum"]] +module Test +{ + +interface Checksum +{ + idempotent Ice::SliceChecksumDict getSliceChecksums(); + + void shutdown(); +} + +} diff --git a/matlab/test/Ice/checksum/Types.ice b/matlab/test/Ice/checksum/Types.ice new file mode 100644 index 00000000000..485330caf42 --- /dev/null +++ b/matlab/test/Ice/checksum/Types.ice @@ -0,0 +1,615 @@ +// ********************************************************************** +// +// 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.checksum"]] +module Test +{ + +// +// TEST: Same +// +const int IntConst1 = 100; + +// +// TEST: Value changed +// +const int IntConst2 = 100; + +// +// TEST: Type changed +// +const int IntConst3 = 100; + +// +// TEST: Same +// +enum Enum1 { Enum11, Enum12, Enum13 } + +// +// TEST: Add enumerator +// +enum Enum2 { Enum21, Enum22, Enum23 } + +// +// TEST: Remove enumerator +// +enum Enum3 { Enum31, Enum32, Enum33 } + +// +// TEST: Change to a different type +// +enum Enum4 { Enum41, Enum42, Enum43 } + +// +// TEST: Enum with explicit values. +// +enum EnumExplicit0 { EnumExplicit01 = 1, EnumExplicit02 = 2, EnumExplicit03 = 3 } + +// +// TEST: Enum with same explicit values, different order. +// +enum EnumExplicit1 { EnumExplicit11 = 1, EnumExplicit12 = 2, EnumExplicit13 = 3 } + +// +// TEST: Enum with different explicit values. +// +enum EnumExplicit2 { EnumExplicit21 = 1, EnumExplicit22 = 2, EnumExplicit23 = 3} + +// +// TEST: Enum with explicit values, removed enumerator. +// +enum EnumExplicit3 { EnumExplicit31 = 1, EnumExplicit32 = 2, EnumExplicit33 = 3} + +// +// TEST: Same +// +sequence<int> Sequence1; + +// +// TEST: Change sequence type +// +sequence<int> Sequence2; + +// +// TEST: Change to a different type +// +sequence<int> Sequence3; + +// +// TEST: Same +// +dictionary<string, int> Dictionary1; + +// +// TEST: Change key type +// +dictionary<string, int> Dictionary2; + +// +// TEST: Change value type +// +dictionary<string, int> Dictionary3; + +// +// TEST: Change to a different type +// +dictionary<string, int> Dictionary4; + +// +// TEST: Same +// +struct Struct1 +{ + string str; + bool b; +} + +// +// TEST: Add member +// +struct Struct2 +{ + string str; + bool b; +} + +// +// TEST: Change member type +// +struct Struct3 +{ + string str; + bool b; +} + +// +// TEST: Remove member +// +struct Struct4 +{ + string str; + bool b; +} + +// +// TEST: Change to a different type +// +struct Struct5 +{ + string str; + bool b; +} + +// +// TEST: Same +// +interface Interface1 +{ +} + +// +// TEST: Change interface to class +// +interface Interface2 +{ +} + +// +// TEST: Add base interface +// +interface Interface3 +{ +} + +// +// TEST: Add operation +// +interface Interface4 +{ +} + +// +// TEST: Same +// +class EmptyClass1 +{ +} + +// +// TEST: Add data member +// +class EmptyClass2 +{ +} + +// +// TEST: Add operation +// +class EmptyClass3 +{ +} + +// +// TEST: Add base class +// +class EmptyClass4 +{ +} + +// +// TEST: Add interface +// +class EmptyClass5 +{ +} + +// +// TEST: Same +// +class SimpleClass1 +{ + string str; + float f; +} + +// +// TEST: Add operation +// +class SimpleClass2 +{ + string str; + float f; +} + +// +// TEST: Rename member +// +class SimpleClass3 +{ + string str; + float f; +} + +// +// TEST: Add member +// +class SimpleClass4 +{ + string str; + float f; +} + +// +// TEST: Remove member +// +class SimpleClass5 +{ + string str; + float f; +} + +// +// TEST: Reorder members +// +class SimpleClass6 +{ + string str; + float f; +} + +// +// TEST: Change member type +// +class SimpleClass7 +{ + string str; + float f; +} + +// +// TEST: Same +// +exception Exception1 +{ + string str; + bool b; +} + +// +// TEST: Add member +// +exception Exception2 +{ + string str; + bool b; +} + +// +// TEST: Change member type +// +exception Exception3 +{ + string str; + bool b; +} + +// +// TEST: Remove member +// +exception Exception4 +{ + string str; + bool b; +} + +// +// TEST: Add base exception +// +exception Exception5 +{ +} + +// +// TEST: Change to a different type +// +exception Exception6 +{ + string str; + bool b; +} + +// +// TEST: Exception with optional members. +// +exception OptionalEx0 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Exception with optional members, different order, same tags. +// +exception OptionalEx1 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Exception with different optional members. +// +exception OptionalEx2 +{ + string firstName; + string secondName; + optional(1) string emailAddress; +} + +// +// TEST: Exception with different optional members. +// +exception OptionalEx3 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Exception with optional members using different tags. +// +exception OptionalEx4 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Same +// +interface BaseInterface1 +{ + void baseOp1(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Change return type +// +interface BaseInterface2 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Add parameter +// +interface BaseInterface3 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Add exception +// +interface BaseInterface4 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Change out parameter to in parameter +// +interface BaseInterface5 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Remove parameter +// +interface BaseInterface6 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Remove exception +// +interface BaseInterface7 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Remove operation +// +interface BaseInterface8 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Add base interface +// +interface BaseInterface9 +{ + void baseOp(); + void baseOp2(int i, out string s) throws Exception1; +} + +// +// TEST: Class with compact id +// +class Compact1(1) +{ + int id; +} + +// +// TEST: Derived from class with compact id +// +class Derived1 extends Compact1 +{ +} + +// +// TEST: Same class names but different compact id +// +class Compact2(2) +{ + int id; +} + +// +// TEST: Class with optional members. +// +class Optional0 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Class with optional members, different order, same tags. +// +class Optional1 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Class with different optional members. +// +class Optional2 +{ + string firstName; + string secondName; + optional(1) string emailAddress; +} + +// +// TEST: Class with different optional members. +// +class Optional3 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Class with optional members using different tags. +// +class Optional4 +{ + string firstName; + optional(1) string secondName; + optional(2) string emailAddress; +} + +// +// TEST: Interface with optional parameters. +// +interface OptionalParameters0 +{ + void op1(string firstName, optional(1) string secondName, + optional(2) string emailAddress); +} + +// +// TEST: Interface with optional parameters, different order. +// +interface OptionalParameters1 +{ + void op1(string firstName, optional(1) string secondName, + optional(2) string emailAddress); +} + +// +// TEST: Interface with optional parameters, different tags. +// +interface OptionalParameters2 +{ + void op1(string firstName, optional(1) string emailAddress, + optional(2) string secondName); +} + +// +// TEST: Interface with different optional parameters. +// +interface OptionalParameters3 +{ + void op1(string firstName, optional(1) string emailAddress, + string secondName); +} + +// +// TEST: Interface with optional return type. +// +interface OptionalReturn0 +{ + optional(1) int op(); +} + +// +// TEST: Interface that changes optional return type. +// +interface OptionalReturn2 +{ + optional(1) int op(); +} + +// +// TEST: Local +// +local enum LocalEnum { LocalEnum1, LocalEnum2, LocalEnum3 } + +// +// TEST: Local +// +local sequence<string> LocalSequence; + +// +// TEST: Local +// +local dictionary<string, string> LocalDictionary; + +// +// TEST: Local +// +local struct LocalStruct +{ + string str; +} + +// +// TEST: Local +// +local class LocalClass +{ +} + +} diff --git a/matlab/test/Ice/checksum/generated/.gitignore b/matlab/test/Ice/checksum/generated/.gitignore new file mode 100644 index 00000000000..39af5887579 --- /dev/null +++ b/matlab/test/Ice/checksum/generated/.gitignore @@ -0,0 +1 @@ +# Dummy file, so that git retains this otherwise empty directory. diff --git a/matlab/test/Ice/checksum/runTest.m b/matlab/test/Ice/checksum/runTest.m new file mode 100644 index 00000000000..66a1e8dda5e --- /dev/null +++ b/matlab/test/Ice/checksum/runTest.m @@ -0,0 +1,4 @@ +function runTest(varargin) + status = Client.start(varargin); + exit(status); +end diff --git a/matlab/test/Ice/defaultValue/AllTests.m b/matlab/test/Ice/defaultValue/AllTests.m new file mode 100644 index 00000000000..499604924fd --- /dev/null +++ b/matlab/test/Ice/defaultValue/AllTests.m @@ -0,0 +1,181 @@ +%{ +********************************************************************** + +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.defaultValue.Test.*; + + communicator = app.communicator(); + + fprintf('testing default values... '); + + v = Struct1(); + assert(~v.boolFalse); + assert(v.boolTrue); + assert(v.b == 254); + assert(v.s == 16000); + assert(v.i == 3); + assert(v.l == 4); + assert(v.f == single(5.1)); + assert(v.d == 6.2); + assert(strcmp(v.str, sprintf('foo \\ "bar\n \r\n\t\v\f\a\b? \a \a'))); + assert(v.c1 == Color.red); + assert(v.c2 == Color.green); + assert(v.c3 == Color.blue); + assert(v.nc1 == test.Ice.defaultValue.Test.Nested.Color.red); + assert(v.nc2 == test.Ice.defaultValue.Test.Nested.Color.green); + assert(v.nc3 == test.Ice.defaultValue.Test.Nested.Color.blue); + assert(strcmp(v.noDefault, '')); + assert(v.zeroI == 0); + assert(v.zeroL == 0); + assert(v.zeroF == 0); + assert(v.zeroDotF == 0); + assert(v.zeroD == 0); + assert(v.zeroDotD == 0); + + v = Struct2(); + assert(v.boolTrue == ConstBool.value); + assert(v.b == ConstByte.value); + assert(v.s == ConstShort.value); + assert(v.i == ConstInt.value); + assert(v.l == ConstLong.value); + assert(v.f == ConstFloat.value); + assert(v.d == ConstDouble.value); + assert(strcmp(v.str, ConstString.value)); + assert(v.c1 == ConstColor1.value); + assert(v.c2 == ConstColor2.value); + assert(v.c3 == ConstColor3.value); + assert(v.nc1 == ConstNestedColor1.value); + assert(v.nc2 == ConstNestedColor2.value); + assert(v.nc3 == ConstNestedColor3.value); + + v = Base(); + assert(~v.boolFalse); + assert(v.boolTrue); + assert(v.b == 1); + assert(v.s == 2); + assert(v.i == 3); + assert(v.l == 4); + assert(v.f == single(5.1)); + assert(v.d == 6.2); + assert(strcmp(v.str, sprintf('foo \\ "bar\n \r\n\t\v\f\a\b? \a \a'))); + assert(strcmp(v.noDefault, '')); + assert(v.zeroI == 0); + assert(v.zeroL == 0); + assert(v.zeroF == 0); + assert(v.zeroDotF == 0); + assert(v.zeroD == 0); + assert(v.zeroDotD == 0); + + v = Derived(); + assert(~v.boolFalse); + assert(v.boolTrue); + assert(v.b == 1); + assert(v.s == 2); + assert(v.i == 3); + assert(v.l == 4); + assert(v.f == single(5.1)); + assert(v.d == 6.2); + assert(strcmp(v.str, sprintf('foo \\ "bar\n \r\n\t\v\f\a\b? \a \a'))); + assert(v.c1 == Color.red); + assert(v.c2 == Color.green); + assert(v.c3 == Color.blue); + assert(v.nc1 == test.Ice.defaultValue.Test.Nested.Color.red); + assert(v.nc2 == test.Ice.defaultValue.Test.Nested.Color.green); + assert(v.nc3 == test.Ice.defaultValue.Test.Nested.Color.blue); + assert(strcmp(v.noDefault, '')); + assert(v.zeroI == 0); + assert(v.zeroL == 0); + assert(v.zeroF == 0); + assert(v.zeroDotF == 0); + assert(v.zeroD == 0); + assert(v.zeroDotD == 0); + + v = BaseEx(); + assert(~v.boolFalse); + assert(v.boolTrue); + assert(v.b == 1); + assert(v.s == 2); + assert(v.i == 3); + assert(v.l == 4); + assert(v.f == single(5.1)); + assert(v.d == 6.2); + assert(strcmp(v.str, sprintf('foo \\ "bar\n \r\n\t\v\f\a\b? \a \a'))); + assert(strcmp(v.noDefault, '')); + assert(v.zeroI == 0); + assert(v.zeroL == 0); + assert(v.zeroF == 0); + assert(v.zeroDotF == 0); + assert(v.zeroD == 0); + assert(v.zeroDotD == 0); + + v = DerivedEx(); + assert(~v.boolFalse); + assert(v.boolTrue); + assert(v.b == 1); + assert(v.s == 2); + assert(v.i == 3); + assert(v.l == 4); + assert(v.f == single(5.1)); + assert(v.d == 6.2); + assert(strcmp(v.str, sprintf('foo \\ "bar\n \r\n\t\v\f\a\b? \a \a'))); + assert(strcmp(v.noDefault, '')); + assert(v.c1 == Color.red); + assert(v.c2 == Color.green); + assert(v.c3 == Color.blue); + assert(v.nc1 == test.Ice.defaultValue.Test.Nested.Color.red); + assert(v.nc2 == test.Ice.defaultValue.Test.Nested.Color.green); + assert(v.nc3 == test.Ice.defaultValue.Test.Nested.Color.blue); + assert(v.zeroI == 0); + assert(v.zeroL == 0); + assert(v.zeroF == 0); + assert(v.zeroDotF == 0); + assert(v.zeroD == 0); + assert(v.zeroDotD == 0); + + fprintf('ok\n'); + + fprintf('testing default constructor... '); + + v = test.Ice.defaultValue.Test.StructNoDefaults(); + assert(v.bo == false); + assert(v.b == 0); + assert(v.s == 0); + assert(v.i == 0); + assert(v.l == 0); + assert(v.f == 0.0); + assert(v.d == 0.0); + assert(strcmp(v.str, '')); + assert(v.c1 == test.Ice.defaultValue.Test.Color.red); + assert(isempty(v.bs)); + assert(isempty(v.is)); + assert(~isempty(v.st)); + assert(isempty(v.dict)); + + e = test.Ice.defaultValue.Test.ExceptionNoDefaults(); + assert(strcmp(e.str, '')); + assert(e.c1 == test.Ice.defaultValue.Test.Color.red); + assert(isempty(e.bs)); + assert(~isempty(e.st)); + assert(isempty(e.dict)); + + cl = test.Ice.defaultValue.Test.ClassNoDefaults(); + assert(strcmp(cl.str, '')); + assert(cl.c1 == test.Ice.defaultValue.Test.Color.red); + assert(isempty(cl.bs)); + assert(~isempty(cl.st)); + assert(isempty(cl.dict)); + + fprintf('ok\n'); + end + end +end diff --git a/matlab/test/Ice/defaultValue/Application.m b/matlab/test/Ice/defaultValue/Application.m new file mode 100644 index 00000000000..4735c1cd057 --- /dev/null +++ b/matlab/test/Ice/defaultValue/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/defaultValue/Client.m b/matlab/test/Ice/defaultValue/Client.m new file mode 100644 index 00000000000..98e0a2e29cc --- /dev/null +++ b/matlab/test/Ice/defaultValue/Client.m @@ -0,0 +1,29 @@ +%{ +********************************************************************** + +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(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/defaultValue/Test.ice b/matlab/test/Ice/defaultValue/Test.ice new file mode 100644 index 00000000000..3b474aeeb23 --- /dev/null +++ b/matlab/test/Ice/defaultValue/Test.ice @@ -0,0 +1,211 @@ +// ********************************************************************** +// +// 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.defaultValue"]] + +[["suppress-warning:deprecated"]] // For enumerator references + +module Test +{ + +enum Color { red, green, blue } + +module Nested +{ + +enum Color { red, green, blue } + +} + +struct Struct1 +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 254; + short s = 16000; + int i = 3; + long l = 4; + float f = 5.1; + double d = 6.2; + string str = "foo \\ \"bar\n \r\n\t\v\f\a\b\? \007 \x07"; + Color c1 = ::Test::Color::red; + Color c2 = Test::green; + Color c3 = blue; + Nested::Color nc1 = Test::Nested::Color::red; + Nested::Color nc2 = Nested::green; + Nested::Color nc3 = blue; + string noDefault; + int zeroI = 0; + long zeroL = 0; + float zeroF = 0; + float zeroDotF = 0.0; + double zeroD = 0; + double zeroDotD = 0; +} + +const bool ConstBool = true; +const byte ConstByte = 254; +const short ConstShort = 16000; +const int ConstInt = 3; +const long ConstLong = 4; +const float ConstFloat = 5.1; +const double ConstDouble = 6.2; +const string ConstString = "foo \\ \"bar\n \r\n\t\v\f\a\b\? \007 \x07"; +const Color ConstColor1 = ::Test::Color::red; +const Color ConstColor2 = Test::green; +const Color ConstColor3 = blue; +const Nested::Color ConstNestedColor1 = Test::Nested::Color::red; +const Nested::Color ConstNestedColor2 = Test::Nested::green; +const Nested::Color ConstNestedColor3 = blue; +const int ConstZeroI = 0; +const long ConstZeroL = 0; +const float ConstZeroF = 0; +const float ConstZeroDotF = 0.0; +const double ConstZeroD = 0; +const double ConstZeroDotD = 0; + +struct Struct2 +{ + bool boolTrue = ConstBool; + byte b = ConstByte; + short s = ConstShort; + int i = ConstInt; + long l = ConstLong; + float f = ConstFloat; + double d = ConstDouble; + string str = ConstString; + Color c1 = ConstColor1; + Color c2 = ConstColor2; + Color c3 = ConstColor3; + Nested::Color nc1 = ConstNestedColor1; + Nested::Color nc2 = ConstNestedColor2; + Nested::Color nc3 = ConstNestedColor3; + int zeroI = ConstZeroI; + long zeroL = ConstZeroL; + float zeroF = ConstZeroF; + float zeroDotF = ConstZeroDotF; + double zeroD = ConstZeroD; + double zeroDotD = ConstZeroDotD; +} + +class Base +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.1; + double d = 6.2; + string str = "foo \\ \"bar\n \r\n\t\v\f\a\b\? \007 \x07"; + string noDefault; + int zeroI = 0; + long zeroL = 0; + float zeroF = 0; + float zeroDotF = 0.0; + double zeroD = 0; + double zeroDotD = 0; +} + +class Derived extends Base +{ + Color c1 = ::Test::Color::red; + Color c2 = Test::green; + Color c3 = blue; + Nested::Color nc1 = ::Test::Nested::Color::red; + Nested::Color nc2 = Nested::green; + Nested::Color nc3 = blue; +} + +exception BaseEx +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.1; + double d = 6.2; + string str = "foo \\ \"bar\n \r\n\t\v\f\a\b\? \007 \x07"; + string noDefault; + int zeroI = 0; + long zeroL = 0; + float zeroF = 0; + float zeroDotF = 0.0; + double zeroD = 0; + double zeroDotD = 0; +} + +exception DerivedEx extends BaseEx +{ + Color c1 = ConstColor1; + Color c2 = ConstColor2; + Color c3 = ConstColor3; + Nested::Color nc1 = ConstNestedColor1; + Nested::Color nc2 = ConstNestedColor2; + Nested::Color nc3 = ConstNestedColor3; +} + +sequence<byte> ByteSeq; +sequence<int> IntSeq; +dictionary<int, string> IntStringDict; + +struct InnerStruct +{ + int a; +} + +struct StructNoDefaults +{ + bool bo; + byte b; + short s; + int i; + long l; + float f; + double d; + string str; + Color c1; + ByteSeq bs; + IntSeq is; + InnerStruct st; + IntStringDict dict; +} + +exception ExceptionNoDefaultsBase +{ + string str; + Color c1; + ByteSeq bs; +} + +exception ExceptionNoDefaults extends ExceptionNoDefaultsBase +{ + InnerStruct st; + IntStringDict dict; +} + +class ClassNoDefaultsBase +{ + string str; + Color c1; + ByteSeq bs; +} + +class ClassNoDefaults extends ClassNoDefaultsBase +{ + InnerStruct st; + IntStringDict dict; +} + +} diff --git a/matlab/test/Ice/defaultValue/generated/.gitignore b/matlab/test/Ice/defaultValue/generated/.gitignore new file mode 100644 index 00000000000..39af5887579 --- /dev/null +++ b/matlab/test/Ice/defaultValue/generated/.gitignore @@ -0,0 +1 @@ +# Dummy file, so that git retains this otherwise empty directory. diff --git a/matlab/test/Ice/defaultValue/runTest.m b/matlab/test/Ice/defaultValue/runTest.m new file mode 100644 index 00000000000..66a1e8dda5e --- /dev/null +++ b/matlab/test/Ice/defaultValue/runTest.m @@ -0,0 +1,4 @@ +function runTest(varargin) + status = Client.start(varargin); + exit(status); +end diff --git a/matlab/test/Ice/enums/Client.m b/matlab/test/Ice/enums/Client.m index 697bf720a22..2bb55598b28 100644 --- a/matlab/test/Ice/enums/Client.m +++ b/matlab/test/Ice/enums/Client.m @@ -25,7 +25,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/enums/runTest.m b/matlab/test/Ice/enums/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/enums/runTest.m +++ b/matlab/test/Ice/enums/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/exceptions/Client.m b/matlab/test/Ice/exceptions/Client.m index f5ca5baf8ed..fac92f81d4a 100644 --- a/matlab/test/Ice/exceptions/Client.m +++ b/matlab/test/Ice/exceptions/Client.m @@ -27,7 +27,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/exceptions/runTest.m b/matlab/test/Ice/exceptions/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/exceptions/runTest.m +++ b/matlab/test/Ice/exceptions/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/facets/Client.m b/matlab/test/Ice/facets/Client.m index 7cc32e939bf..7282d7cf92e 100644 --- a/matlab/test/Ice/facets/Client.m +++ b/matlab/test/Ice/facets/Client.m @@ -25,7 +25,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/facets/runTest.m b/matlab/test/Ice/facets/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/facets/runTest.m +++ b/matlab/test/Ice/facets/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/info/Client.m b/matlab/test/Ice/info/Client.m index a46732415fe..fd6d9189671 100644 --- a/matlab/test/Ice/info/Client.m +++ b/matlab/test/Ice/info/Client.m @@ -24,7 +24,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/info/runTest.m b/matlab/test/Ice/info/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/info/runTest.m +++ b/matlab/test/Ice/info/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/inheritance/Client.m b/matlab/test/Ice/inheritance/Client.m index 00b8798d2b8..7e2fa5ab6d1 100644 --- a/matlab/test/Ice/inheritance/Client.m +++ b/matlab/test/Ice/inheritance/Client.m @@ -25,7 +25,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/inheritance/runTest.m b/matlab/test/Ice/inheritance/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/inheritance/runTest.m +++ b/matlab/test/Ice/inheritance/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/objects/Client.m b/matlab/test/Ice/objects/Client.m index 124911de4f9..7fb48de6576 100644 --- a/matlab/test/Ice/objects/Client.m +++ b/matlab/test/Ice/objects/Client.m @@ -55,7 +55,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/objects/runTest.m b/matlab/test/Ice/objects/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/objects/runTest.m +++ b/matlab/test/Ice/objects/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/operations/Client.m b/matlab/test/Ice/operations/Client.m index 4d898e22ef2..81493fa543f 100644 --- a/matlab/test/Ice/operations/Client.m +++ b/matlab/test/Ice/operations/Client.m @@ -41,7 +41,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/operations/runTest.m b/matlab/test/Ice/operations/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/operations/runTest.m +++ b/matlab/test/Ice/operations/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/optional/Client.m b/matlab/test/Ice/optional/Client.m index 23d3a9957b4..5357b276707 100644 --- a/matlab/test/Ice/optional/Client.m +++ b/matlab/test/Ice/optional/Client.m @@ -25,7 +25,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/optional/runTest.m b/matlab/test/Ice/optional/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/optional/runTest.m +++ b/matlab/test/Ice/optional/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/proxy/Client.m b/matlab/test/Ice/proxy/Client.m index d6fde0f2068..3a44ad592df 100644 --- a/matlab/test/Ice/proxy/Client.m +++ b/matlab/test/Ice/proxy/Client.m @@ -25,7 +25,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/proxy/runTest.m b/matlab/test/Ice/proxy/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/proxy/runTest.m +++ b/matlab/test/Ice/proxy/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/slicing/exceptions/Client.m b/matlab/test/Ice/slicing/exceptions/Client.m index 7937df88aa1..ddc1dbd0601 100644 --- a/matlab/test/Ice/slicing/exceptions/Client.m +++ b/matlab/test/Ice/slicing/exceptions/Client.m @@ -25,7 +25,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/slicing/exceptions/runTest.m b/matlab/test/Ice/slicing/exceptions/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/slicing/exceptions/runTest.m +++ b/matlab/test/Ice/slicing/exceptions/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/slicing/objects/Client.m b/matlab/test/Ice/slicing/objects/Client.m index 19549675263..8b93685d66a 100644 --- a/matlab/test/Ice/slicing/objects/Client.m +++ b/matlab/test/Ice/slicing/objects/Client.m @@ -25,7 +25,7 @@ classdef Client < Application end end methods(Static) - function start(args) + function status = start(args) addpath('generated'); if ~libisloaded('icematlab') loadlibrary('icematlab') diff --git a/matlab/test/Ice/slicing/objects/runTest.m b/matlab/test/Ice/slicing/objects/runTest.m index ca3eaa751c8..66a1e8dda5e 100644 --- a/matlab/test/Ice/slicing/objects/runTest.m +++ b/matlab/test/Ice/slicing/objects/runTest.m @@ -1,4 +1,4 @@ function runTest(varargin) - Client.start(varargin); - quit + status = Client.start(varargin); + exit(status); end diff --git a/matlab/test/Ice/timeout/AllTests.m b/matlab/test/Ice/timeout/AllTests.m new file mode 100644 index 00000000000..5e01cfe9547 --- /dev/null +++ b/matlab/test/Ice/timeout/AllTests.m @@ -0,0 +1,340 @@ +%{ +********************************************************************** + +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 r = connect(prx) + nRetry = 10; + while nRetry > 0 + nRetry = nRetry - 1; + try + prx.ice_getConnection(); + break; + catch ex + if isa(ex, 'Ice.ConnectTimeoutException') + % Can sporadically occur with slow machines + else + rethrow(ex); + end + end + end + r = prx.ice_getConnection(); % Establish connection + end + function r = allTests(app) + import test.Ice.timeout.Test.*; + + communicator = app.communicator(); + + sref = ['timeout:', app.getTestEndpoint(0, '')]; + obj = communicator.stringToProxy(sref); + assert(~isempty(obj)); + + mult = 1; + if ~strcmp(communicator.getProperties().getPropertyWithDefault('Ice.Default.Protocol', 'tcp'), 'tcp') + mult = 4; + end + + timeout = TimeoutPrx.checkedCast(obj); + assert(~isempty(timeout)); + + fprintf('testing connect timeout... '); + + % + % Expect ConnectTimeoutException. + % + to = timeout.ice_timeout(100 * mult); + timeout.holdAdapter(500 * mult); + try + to.op(); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.ConnectTimeoutException')); + end + + % + % Expect success. + % + timeout.op(); % Ensure adapter is active. + to = timeout.ice_timeout(1000 * mult); + timeout.holdAdapter(500 * mult); + try + to.op(); + catch ex + if isa(ex, 'Ice.ConnectTimeoutException') + assert(false); + else + rethrow(ex); + end + end + + fprintf('ok\n'); + + % The sequence needs to be large enough to fill the write/recv buffers + bufSize = 2000000; + seq = zeros(1, bufSize, 'uint8'); + + fprintf('testing connection timeout... '); + + % + % Expect TimeoutException. + % + to = timeout.ice_timeout(250); + AllTests.connect(to); + timeout.holdAdapter(750 * mult); + try + to.sendData(seq); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.TimeoutException')); + end + + % + % Expect success. + % + timeout.op(); % Ensure adapter is active. + to = timeout.ice_timeout(1000 * mult); + timeout.holdAdapter(500 * mult); + try + to.sendData(zeros(1, 1000000, 'uint8')); + catch ex + if isa(ex, 'Ice.TimeoutException') + assert(false); + else + rethrow(ex); + end + end + + fprintf('ok\n'); + + fprintf('testing invocation timeout... '); + + connection = obj.ice_getConnection(); + to = timeout.ice_invocationTimeout(100); + assert(connection == to.ice_getConnection()); + try + to.sleep(750 * mult); + assert(false); + catch ex + assert(isa(ex, 'Ice.InvocationTimeoutException')); + end + obj.ice_ping(); + to = TimeoutPrx.checkedCast(obj.ice_invocationTimeout(500 * mult)); + assert(connection == to.ice_getConnection()); + try + to.sleep(100 * mult); + catch ex + if isa(ex, 'Ice.InvocationTimeoutException') + assert(false); + else + rethrow(ex); + end + end + assert(connection == to.ice_getConnection()); + + % + % Expect InvocationTimeoutException. + % + to = timeout.ice_invocationTimeout(100); + f = to.sleepAsync(750 * mult); + try + f.fetchOutputs(); + catch ex + assert(isa(ex, 'Ice.TimeoutException')); + end + obj.ice_ping(); + + % + % Expect success. + % + to = timeout.ice_invocationTimeout(500 * mult); + f = to.sleepAsync(100 * mult); + f.fetchOutputs(); + + % + % Backward compatible connection timeouts + % + to = timeout.ice_invocationTimeout(-2).ice_timeout(250); + con = AllTests.connect(to); + try + to.sleep(750); + assert(false); + catch ex + if isa(ex, 'Ice.TimeoutException') + assert(~isempty(con)); + try + con.getInfo(); + assert(false); + catch ex + if isa(ex, 'Ice.TimeoutException') + % Connection got closed as well. + else + rethrow(ex); + end + end + end + end + obj.ice_ping(); + + try + con = AllTests.connect(to); + to.sleepAsync(750).fetchOutputs(); + assert(false); + catch ex + assert(isa(ex, 'Ice.TimeoutException')); + assert(~isempty(con)); + try + con.getInfo(); + assert(false); + catch ex + if isa(ex, 'Ice.TimeoutException') + % Connection got closed as well. + else + rethrow(ex); + end + end + end + obj.ice_ping(); + + fprintf('ok\n'); + + fprintf('testing close timeout... '); + + to = TimeoutPrx.uncheckedCast(obj.ice_timeout(250 * mult)); + connection = AllTests.connect(to); + timeout.holdAdapter(600); + connection.close(Ice.ConnectionClose.GracefullyWithWait); + try + connection.getInfo(); % getInfo() doesn't throw in the closing state. + catch ex + assert(false); + end + + pause(.650 * mult); + + try + connection.getInfo(); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.ConnectionManuallyClosedException')); + assert(ex.graceful); + end + timeout.op(); % Ensure adapter is active. + + fprintf('ok\n'); + + fprintf('testing timeout overrides... '); + + % + % Test Ice.Override.Timeout. This property overrides all + % endpoint timeouts. + % + initData = app.createInitializationData(); + initData.properties_ = communicator.getProperties().clone(); + initData.properties_.setProperty('Ice.Override.ConnectTimeout', '250'); + initData.properties_.setProperty('Ice.Override.Timeout', '100'); + comm = app.initialize(initData); + to = TimeoutPrx.uncheckedCast(comm.stringToProxy(sref)); + AllTests.connect(to); + timeout.holdAdapter(500 * mult); + try + to.sendData(seq); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.TimeoutException')); + end + % + % Calling ice_timeout() should have no effect. + % + timeout.op(); % Ensure adapter is active. + to = TimeoutPrx.uncheckedCast(to.ice_timeout(1000 * mult)); + AllTests.connect(to); + timeout.holdAdapter(500 * mult); + try + to.sendData(seq); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.TimeoutException')); + end + comm.destroy(); + + % + % Test Ice.Override.ConnectTimeout. + % + initData = app.createInitializationData(); + initData.properties_ = communicator.getProperties().clone(); + if mult == 1 + initData.properties_.setProperty('Ice.Override.ConnectTimeout', '250'); + else + initData.properties_.setProperty('Ice.Override.ConnectTimeout', '2500'); + end + + comm = app.initialize(initData); + to = TimeoutPrx.uncheckedCast(comm.stringToProxy(sref)); + timeout.holdAdapter(750 * mult); + try + to.op(); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.ConnectTimeoutException')); + end + % + % Calling ice_timeout() should have no effect on the connect timeout. + % + timeout.op(); % Ensure adapter is active. + timeout.holdAdapter(750 * mult); + to = to.ice_timeout(1000 * mult); + try + to.op(); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.ConnectTimeoutException')); + end + % + % Verify that timeout set via ice_timeout() is still used for requests. + % + timeout.op(); % Ensure adapter is active. + to = to.ice_timeout(250); + AllTests.connect(to); + timeout.holdAdapter(750 * mult); + try + to.sendData(seq); + assert(false); + catch ex + % Expected. + assert(isa(ex, 'Ice.TimeoutException')); + end + comm.destroy(); + % + % Test Ice.Override.CloseTimeout. + % + initData = app.createInitializationData(); + initData.properties_ = communicator.getProperties().clone(); + initData.properties_.setProperty('Ice.Override.CloseTimeout', '100'); + comm = app.initialize(initData); + comm.stringToProxy(sref).ice_getConnection(); + timeout.holdAdapter(800); + tic(); + comm.destroy(); + assert(toc() < .7); + + fprintf('ok\n'); + + r = timeout; + end + end +end diff --git a/matlab/test/Ice/timeout/Application.m b/matlab/test/Ice/timeout/Application.m new file mode 100644 index 00000000000..4735c1cd057 --- /dev/null +++ b/matlab/test/Ice/timeout/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/timeout/Client.m b/matlab/test/Ice/timeout/Client.m new file mode 100644 index 00000000000..fcdcdef26b8 --- /dev/null +++ b/matlab/test/Ice/timeout/Client.m @@ -0,0 +1,54 @@ +%{ +********************************************************************** + +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) + timeout = AllTests.allTests(obj); + timeout.shutdown(); + 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.timeout'); + + % + % For this test, we want to disable retries. + % + initData.properties_.setProperty('Ice.RetryIntervals', '-1'); + + % + % This test kills connections, so we don't want warnings. + % + initData.properties_.setProperty('Ice.Warn.Connections', '0'); + + % + % Limit the send buffer size, this test relies on the socket + % send() blocking after sending a given amount of data. + % + initData.properties_.setProperty('Ice.TCP.SndSize', '50000'); + + 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/timeout/Test.ice b/matlab/test/Ice/timeout/Test.ice new file mode 100644 index 00000000000..cbe4d4a7258 --- /dev/null +++ b/matlab/test/Ice/timeout/Test.ice @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// 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.timeout"]] +module Test +{ + +sequence<byte> ByteSeq; + +interface Timeout +{ + void op(); + void sendData(ByteSeq seq); + void sleep(int to); + + void holdAdapter(int to); + + void shutdown(); +} + +} diff --git a/matlab/test/Ice/timeout/generated/.gitignore b/matlab/test/Ice/timeout/generated/.gitignore new file mode 100644 index 00000000000..39af5887579 --- /dev/null +++ b/matlab/test/Ice/timeout/generated/.gitignore @@ -0,0 +1 @@ +# Dummy file, so that git retains this otherwise empty directory. diff --git a/matlab/test/Ice/timeout/runTest.m b/matlab/test/Ice/timeout/runTest.m new file mode 100644 index 00000000000..66a1e8dda5e --- /dev/null +++ b/matlab/test/Ice/timeout/runTest.m @@ -0,0 +1,4 @@ +function runTest(varargin) + status = Client.start(varargin); + exit(status); +end |