diff options
author | Matthew Newhook <matthew@zeroc.com> | 2007-09-04 11:14:53 +0800 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2007-09-04 11:14:53 +0800 |
commit | a55b88dc20dacaf23c5fce8415daf28c63388ccf (patch) | |
tree | 713968abb7de9959600eb59461bd97384b0c4d74 | |
parent | bug 2442 - slice2java generating bad impl code (diff) | |
download | ice-a55b88dc20dacaf23c5fce8415daf28c63388ccf.tar.bz2 ice-a55b88dc20dacaf23c5fce8415daf28c63388ccf.tar.xz ice-a55b88dc20dacaf23c5fce8415daf28c63388ccf.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=2369
51 files changed, 1894 insertions, 57 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 61a61640a9b..50e002cf7f9 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -9,6 +9,10 @@ Changes since version 3.2.X (binary incompatible) of the communicator's logger from properties. This plugin must implement a LoggerPlugin. See manual for more details. +- Fixed a variety of bugs with slice2cpp where incorrect code + would be generated when C++ reserved words are used as Slice + identifiers. + - It is no longer possible to provide input files on the command line for icestormadmin nor icegridadmin. diff --git a/cpp/allTests.py b/cpp/allTests.py index ac3800b38b3..24f5b065f50 100755 --- a/cpp/allTests.py +++ b/cpp/allTests.py @@ -73,6 +73,7 @@ tests = [ \ "IceUtil/uuid", \ "IceUtil/timer", \ "Slice/errorDetection", \ + "Slice/keyword", \ "Ice/proxy", \ "Ice/operations", \ "Ice/exceptions", \ diff --git a/cpp/include/Slice/PythonUtil.h b/cpp/include/Slice/PythonUtil.h index d0caa2a2dcf..fdd1f98fc1c 100644 --- a/cpp/include/Slice/PythonUtil.h +++ b/cpp/include/Slice/PythonUtil.h @@ -46,11 +46,13 @@ SLICE_API std::string fixIdent(const std::string&); SLICE_API std::string getPackageMetadata(const Slice::ContainedPtr&); // -// Get the fully-qualified name of the given definition, including any package -// defined via metadata. If a suffix is provided, it is prepended to the -// definition's unqualified name. +// Get the fully-qualified name of the given definition, including any +// package defined via metadata. If a suffix is provided, it is +// prepended to the definition's unqualified name. If the nameSuffix +// is provided, it is appended to the containers name. // -SLICE_API std::string getAbsolute(const Slice::ContainedPtr&, const std::string& = std::string()); +SLICE_API std::string getAbsolute(const Slice::ContainedPtr&, const std::string& = std::string(), + const std::string& = std::string()); // // Emit a comment header. diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 5624801b8e5..03e1a85bc18 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -329,7 +329,7 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList& ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { - return "const " + fixKwd(cl->scoped()) + "Ptr&"; + return "const " + fixKwd(cl->scoped() + "Ptr&"); } StructPtr st = StructPtr::dynamicCast(type); @@ -337,7 +337,7 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList& { if(findMetaData(st->getMetaData(), false) == "class") { - return "const " + fixKwd(st->scoped()) + "Ptr&"; + return "const " + fixKwd(st->scoped() + "Ptr&"); } return "const " + fixKwd(st->scoped()) + "&"; } @@ -345,7 +345,7 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList& ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { - return "const " + fixKwd(proxy->_class()->scoped()) + "Prx&"; + return "const " + fixKwd(proxy->_class()->scoped() + "Prx&"); } EnumPtr en = EnumPtr::dynamicCast(type); @@ -445,7 +445,7 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { - return fixKwd(cl->scoped()) + "Ptr&"; + return fixKwd(cl->scoped() + "Ptr&"); } StructPtr st = StructPtr::dynamicCast(type); @@ -453,7 +453,7 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList { if(findMetaData(st->getMetaData(), false) == "class") { - return fixKwd(st->scoped()) + "Ptr&"; + return fixKwd(st->scoped() + "Ptr&"); } return fixKwd(st->scoped()) + "&"; } @@ -461,7 +461,7 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { - return fixKwd(proxy->_class()->scoped()) + "Prx&"; + return fixKwd(proxy->_class()->scoped() + "Prx&"); } SequencePtr seq = SequencePtr::dynamicCast(type); @@ -526,6 +526,12 @@ lookupKwd(const string& name) // // Keyword list. *Must* be kept in alphabetical order. // + // Note that this keyword list unnecessarily contains C++ keywords + // that are illegal slice identifiers -- namely identifiers that + // contain underscores (and_eq, for example), and slice keywords + // (class, int, etc.). They have not been removed so that the + // keyword list is kept complete. + // static const string keywordList[] = { "and", "and_eq", "asm", "auto", "bit_and", "bit_or", "bool", "break", "case", "catch", "char", diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 4ad55ef7432..8f27fb78708 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -216,7 +216,7 @@ lookupKwd(const string& name) // NOTE: Any changes made to this list must also be made in BasicStream.java. // static const string keywordList[] = - { + { "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "checkedCast", "class", "clone", "const", "continue", "default", "do", "double", "else", "enum", "equals", "extends", "false", "final", "finalize", diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index 0261e7aa516..fdc6449285d 100644 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -107,7 +107,7 @@ private: // // Return a Python symbol for the given parser element. // - string getSymbol(const ContainedPtr&); + string getSymbol(const ContainedPtr&, const string& = string()); // // Emit Python code to assign the given symbol in the current module. @@ -367,7 +367,7 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p) _out << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')"; if(!p->isLocal()) { - _out << nl << "_M_" << type << "Prx = IcePy.declareProxy('" << scoped << "')"; + _out << nl << "_M_" << getAbsolute(p, "_t_", "Prx") << " = IcePy.declareProxy('" << scoped << "')"; } _out.dec(); _classHistory.insert(scoped); // Avoid redundant declarations. @@ -381,6 +381,9 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) string type = getAbsolute(p, "_t_"); string abs = getAbsolute(p); string name = fixIdent(p->name()); + string prxAbs = getAbsolute(p, "", "Prx"); + string prxName = fixIdent(p->name() + "Prx"); + string prxType = getAbsolute(p, "_t_", "Prx"); ClassList bases = p->bases(); ClassDefPtr base; OperationList ops = p->operations(); @@ -590,8 +593,8 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // if(!p->isLocal()) { - _out << sp << nl << "_M_" << abs << "Prx = Ice.createTempClass()"; - _out << nl << "class " << name << "Prx("; + _out << sp << nl << "_M_" << prxAbs << " = Ice.createTempClass()"; + _out << nl << "class " << prxName << "("; if(bases.empty()) { _out << "Ice.ObjectPrx"; @@ -601,7 +604,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) ClassList::const_iterator q = bases.begin(); while(q != bases.end()) { - _out << getSymbol(*q) << "Prx"; + _out << getSymbol(*q, "Prx"); if(++q != bases.end()) { _out << ", "; @@ -671,19 +674,19 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << sp << nl << "def checkedCast(proxy, facetOrCtx=None, _ctx=None):"; _out.inc(); - _out << nl << "return _M_" << abs << "Prx.ice_checkedCast(proxy, '" << scoped << "', facetOrCtx, _ctx)"; + _out << nl << "return _M_" << prxAbs << ".ice_checkedCast(proxy, '" << scoped << "', facetOrCtx, _ctx)"; _out.dec(); _out << nl << "checkedCast = staticmethod(checkedCast)"; _out << sp << nl << "def uncheckedCast(proxy, facet=None):"; _out.inc(); - _out << nl << "return _M_" << abs << "Prx.ice_uncheckedCast(proxy, facet)"; + _out << nl << "return _M_" << prxAbs << ".ice_uncheckedCast(proxy, facet)"; _out.dec(); _out << nl << "uncheckedCast = staticmethod(uncheckedCast)"; _out.dec(); - _out << sp << nl << "_M_" << type << "Prx = IcePy.defineProxy('" << scoped << "', " << name << "Prx)"; + _out << sp << nl << "_M_" << prxType << " = IcePy.defineProxy('" << scoped << "', " << prxName << ")"; } if(_classHistory.count(scoped) == 0 && p->canBeCyclic()) @@ -882,7 +885,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) if(!p->isLocal()) { - registerName(name + "Prx"); + registerName(prxName); } _out.dec(); @@ -1455,12 +1458,12 @@ Slice::Python::CodeVisitor::visitConst(const ConstPtr& p) } string -Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p) +Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p, const string& nameSuffix) { // // An explicit reference to another type must always be prefixed with "_M_". // - return "_M_" + getAbsolute(p); + return "_M_" + getAbsolute(p, "", nameSuffix); } void @@ -1541,7 +1544,7 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p) ProxyPtr prx = ProxyPtr::dynamicCast(p); if(prx) { - _out << "_M_" << getAbsolute(prx->_class(), "_t_") << "Prx"; + _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx"); return; } @@ -1951,7 +1954,7 @@ Slice::Python::getPackageMetadata(const ContainedPtr& cont) } string -Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix) +Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix, const string& nameSuffix) { string scope = scopedToName(cont->scope()); @@ -1970,11 +1973,11 @@ Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix) if(suffix.empty()) { - return scope + fixIdent(cont->name()); + return scope + fixIdent(cont->name() + nameSuffix); } else { - return scope + suffix + fixIdent(cont->name()); + return scope + suffix + fixIdent(cont->name() + nameSuffix); } } diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp index bd995ce21aa..07bdebd46d6 100644 --- a/cpp/src/Slice/RubyUtil.cpp +++ b/cpp/src/Slice/RubyUtil.cpp @@ -1738,6 +1738,11 @@ Slice::Ruby::fixIdent(const string& ident, IdentStyle style) case IdentNormal: break; case IdentToUpper: + // Special case BEGIN & END for class/module names. + if(id == "BEGIN" || id == "END") + { + return id + "_"; + } if(id[0] >= 'a' && id[0] <= 'z') { id[0] += 'A' - 'a'; diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 986d5269f77..0d70727d44f 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -450,9 +450,7 @@ Slice::Gen::TypesVisitor::visitModuleStart(const ModulePtr& p) _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - string name = fixKwd(p->name()); - - H << sp << nl << "namespace " << name << nl << '{'; + H << sp << nl << "namespace " << fixKwd(p->name()) << nl << '{'; return true; } @@ -498,7 +496,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) { string typeName = inputTypeToString((*q)->type(), _useWstring, (*q)->getMetaData()); allTypes.push_back(typeName); - allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); + allParamDecls.push_back(typeName + " __ice_" + fixKwd((*q)->name())); } if(base) @@ -506,7 +504,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) DataMemberList baseDataMembers = base->allDataMembers(); for(q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) { - baseParams.push_back("__ice_" + (*q)->name()); + baseParams.push_back("__ice_" + fixKwd((*q)->name())); } } @@ -891,7 +889,8 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) } H << name << spar << types << epar << ';'; - C << sp << nl << p->scoped().substr(2) << "::" << fixKwd(p->name()) << spar << paramDecls << epar << " :"; + C << sp << nl << fixKwd(p->scoped()).substr(2) << "::" + << fixKwd(p->name()) << spar << paramDecls << epar << " :"; C.inc(); for(q = dataMembers.begin(); q != dataMembers.end(); ++q) @@ -1053,23 +1052,23 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) H << eb << ';'; if(findMetaData(p->getMetaData(), false) == "class") { - H << sp << nl << "typedef ::IceUtil::Handle< " << scoped << "> " << name << "Ptr;"; + H << sp << nl << "typedef ::IceUtil::Handle< " << scoped << "> " << p->name() + "Ptr;"; if(!p->isLocal() && _stream) { H << sp << nl << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " - << name << "Ptr&);"; - H << nl << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name + << p->name() << "Ptr&);"; + H << nl << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << p->name() << "Ptr&);"; C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() - << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "Ptr& __v)"; + << "(const ::Ice::OutputStreamPtr& __outS, const " << fixKwd(p->scoped() + "Ptr") << "& __v)"; C << sb; C << nl << "__v->ice_write(__outS);"; C << eb; C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name() - << "(const ::Ice::InputStreamPtr& __inS, " << scoped << "Ptr& __v)"; + << "(const ::Ice::InputStreamPtr& __inS, " << fixKwd(p->scoped() + "Ptr") << "& __v)"; C << sb; C << nl << "__v->ice_read(__inS);"; C << eb; @@ -1882,7 +1881,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) } H << fixKwd(name) << spar << args << "0" << epar << ';'; H << eb; - H << nl << deprecateSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << "const ::Ice::Context& __ctx" << epar; + H << nl << deprecateSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << "const ::Ice::Context& __ctx" + << epar; H << sb; H << nl; if(ret) @@ -1896,7 +1896,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) H.dec(); H << nl << "private:"; H.inc(); - H << sp << nl << _dllExport << retS << ' ' << fixKwd(name) << spar << params << "const ::Ice::Context*" << epar << ';'; + H << sp << nl << _dllExport << retS << ' ' << fixKwd(name) << spar << params << "const ::Ice::Context*" << epar + << ';'; H << nl; H.dec(); H << nl << "public:"; @@ -1952,19 +1953,22 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) string classScope = fixKwd(cl->scope()); string classScopedAMI = classScope + classNameAMI; - H << nl << _dllExport << "void " << name << "_async" << spar << ("const " + classScopedAMI + '_' + name + "Ptr&") + H << nl << _dllExport << "void " << name << "_async" << spar + << ("const " + classScopedAMI + '_' + p->name() + "Ptr&") << paramsAMI << epar << ';'; - H << nl << _dllExport << "void " << name << "_async" << spar << ("const " + classScopedAMI + '_' + name + "Ptr&") + H << nl << _dllExport << "void " << name << "_async" << spar + << ("const " + classScopedAMI + '_' + p->name() + "Ptr&") << paramsAMI << "const ::Ice::Context&" << epar << ';'; C << sp << nl << "void" << nl << "IceProxy" << scope << name << "_async" << spar - << ("const " + classScopedAMI + '_' + name + "Ptr& __cb") << paramsDeclAMI << epar; + << ("const " + classScopedAMI + '_' + p->name() + "Ptr& __cb") << paramsDeclAMI << epar; C << sb; C << nl << "__cb->__invoke" << spar << "this" << argsAMI << "0" << epar << ';'; C << eb; C << sp << nl << "void" << nl << "IceProxy" << scope << name << "_async" << spar - << ("const " + classScopedAMI + '_' + name + "Ptr& __cb") << paramsDeclAMI << "const ::Ice::Context& __ctx" + << ("const " + classScopedAMI + '_' + p->name() + "Ptr& __cb") + << paramsDeclAMI << "const ::Ice::Context& __ctx" << epar; C << sb; C << nl << "__cb->__invoke" << spar << "this" << argsAMI << "&__ctx" << epar << ';'; @@ -2809,9 +2813,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) if(!p->isLocal()) { - H << nl << "typedef " << name << "Prx ProxyType;"; + H << nl << "typedef " << p->name() << "Prx ProxyType;"; } - H << nl << "typedef " << name << "Ptr PointerType;"; + H << nl << "typedef " << p->name() << "Ptr PointerType;"; H << nl; vector<string> params; @@ -2969,11 +2973,11 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) C << sp; C << nl << "::Ice::ObjectPtr"; - C << nl << fixKwd(p->scoped()).substr(2) << "::ice_clone() const"; + C << nl << scoped.substr(2) << "::ice_clone() const"; C << sb; if(!p->isAbstract()) { - C << nl << fixKwd(p->scope()) << p->name() << "Ptr __p = new " << fixKwd(p->scoped()) << "(*this);"; + C << nl << fixKwd(p->scope()) << p->name() << "Ptr __p = new " << scoped << "(*this);"; C << nl << "return __p;"; } else @@ -3036,14 +3040,14 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) C << eb << ';'; C << sp; - C << nl << "bool" << nl << fixKwd(p->scoped()).substr(2) + C << nl << "bool" << nl << scoped.substr(2) << "::ice_isA(const ::std::string& _s, const ::Ice::Current&) const"; C << sb; C << nl << "return ::std::binary_search(" << flatName << ", " << flatName << " + " << ids.size() << ", _s);"; C << eb; C << sp; - C << nl << "::std::vector< ::std::string>" << nl << fixKwd(p->scoped()).substr(2) + C << nl << "::std::vector< ::std::string>" << nl << scoped.substr(2) << "::ice_ids(const ::Ice::Current&) const"; C << sb; C << nl << "return ::std::vector< ::std::string>(&" << flatName << "[0], &" << flatName @@ -3051,14 +3055,14 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) C << eb; C << sp; - C << nl << "const ::std::string&" << nl << fixKwd(p->scoped()).substr(2) + C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_id(const ::Ice::Current&) const"; C << sb; C << nl << "return " << flatName << '[' << scopedPos << "];"; C << eb; C << sp; - C << nl << "const ::std::string&" << nl << fixKwd(p->scoped()).substr(2) << "::ice_staticId()"; + C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_staticId()"; C << sb; C << nl << "return " << flatName << '[' << scopedPos << "];"; C << eb; @@ -3135,7 +3139,8 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) << ", current.operation);"; C << nl << "if(r.first == r.second)"; C << sb; - C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);"; + C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, " + << "current.facet, current.operation);"; C << eb; C << sp; C << nl << "switch(r.first - " << flatName << ')'; @@ -3151,7 +3156,8 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) C << eb; C << sp; C << nl << "assert(false);"; - C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);"; + C << nl << "throw ::Ice::OperationNotExistException(__FILE__, __LINE__, current.id, " + << "current.facet, current.operation);"; C << eb; @@ -4284,7 +4290,7 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) C << sp; C << nl << "void" << nl << scope.substr(2) << "ice_read" << name << "(const ::Ice::InputStreamPtr& __inS, " - << scoped << "Ptr& __v)"; + << scope << name << "Ptr& __v)"; C << sb; C << nl << "::Ice::ReadObjectCallbackPtr __cb = new ::Ice::ReadObjectCallbackI(" << scope << "__patch__" << name << "Ptr, &__v);"; diff --git a/cpp/test/Makefile b/cpp/test/Makefile index d7820b95c61..59dbc105836 100644 --- a/cpp/test/Makefile +++ b/cpp/test/Makefile @@ -12,6 +12,7 @@ top_srcdir = .. include $(top_srcdir)/config/Make.rules SUBDIRS = IceUtil \ + Slice \ Ice \ IceSSL \ IceStorm \ diff --git a/cpp/test/Makefile.mak b/cpp/test/Makefile.mak index e31c48fec56..1a9d6a70d3b 100644 --- a/cpp/test/Makefile.mak +++ b/cpp/test/Makefile.mak @@ -12,6 +12,7 @@ top_srcdir = .. !include $(top_srcdir)/config/Make.rules.mak SUBDIRS = IceUtil \ + Slice \ Ice \ IceSSL \ Glacier2 \ diff --git a/cpp/test/Slice/Makefile b/cpp/test/Slice/Makefile new file mode 100644 index 00000000000..864904542da --- /dev/null +++ b/cpp/test/Slice/Makefile @@ -0,0 +1,21 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ../.. + +include $(top_srcdir)/config/Make.rules + +SUBDIRS = keyword + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done diff --git a/cpp/test/Slice/Makefile.mak b/cpp/test/Slice/Makefile.mak new file mode 100644 index 00000000000..6b822657c05 --- /dev/null +++ b/cpp/test/Slice/Makefile.mak @@ -0,0 +1,19 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ..\.. + +!include $(top_srcdir)\config\Make.rules.mak + +SUBDIRS = keyword + +$(EVERYTHING):: + @for %i in ( $(SUBDIRS) ) do \ + @echo "making $@ in %i" && \ + cmd /c "cd %i && $(MAKE) -nologo -f Makefile.mak $@" || exit 1 diff --git a/cpp/test/Slice/keyword/.depend b/cpp/test/Slice/keyword/.depend new file mode 100644 index 00000000000..52576334989 --- /dev/null +++ b/cpp/test/Slice/keyword/.depend @@ -0,0 +1,4 @@ +Client$(OBJEXT): Client.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/StringConverter.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ImplicitContextF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/OutgoingAsync.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Process.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Direct.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../../include/Ice/ImplicitContext.h ../../../include/Ice/Locator.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/ProcessF.h ../../../include/Ice/Router.h ../../../include/Ice/DispatchInterceptor.h ../../../include/Ice/IconvStringConverter.h Key.h +Key$(OBJEXT): Key.cpp Key.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/StreamF.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/Outgoing.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/Ice/BasicStream.h ../../../include/Ice/InstanceF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/Ice/StringConverter.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/OutgoingAsync.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Direct.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/LocalException.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/Stream.h ../../../include/IceUtil/Iterator.h ../../../include/IceUtil/ScopedArray.h +Key.cpp: Key.ice +Key.ice: $(SLICE2CPP) $(SLICEPARSERLIB) diff --git a/cpp/test/Slice/keyword/Client.cpp b/cpp/test/Slice/keyword/Client.cpp new file mode 100644 index 00000000000..8d9bb8dd931 --- /dev/null +++ b/cpp/test/Slice/keyword/Client.cpp @@ -0,0 +1,175 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <Key.h> + +using namespace std; + +class breakI : public _cpp_and::_cpp_break +{ +public: + virtual void case_async(const ::_cpp_and::AMD_break_casePtr& cb, ::Ice::Int, const ::Ice::Current&) + { + cb->ice_response(0); + } +}; + +class charI: public _cpp_and::_cpp_char +{ +public: + virtual void _cpp_explicit(const ::Ice::Current& current) + { + assert(current.operation == "explicit"); + } +}; + +class complI: public _cpp_and::_cpp_compl +{ +public: + virtual void foo(const _cpp_and::charPrx&, Ice::Int&, const ::Ice::Current&) + { + } +}; + +class doI : public _cpp_and::_cpp_do +{ +public: + virtual void case_async(const ::_cpp_and::AMD_break_casePtr&, ::Ice::Int, const ::Ice::Current&) + { + } + virtual void _cpp_explicit(const ::Ice::Current&) + { + } + virtual void foo(const _cpp_and::charPrx&, Ice::Int&, const ::Ice::Current&) + { + } +}; + +class friendI : public _cpp_and::_cpp_friend +{ +public: + virtual _cpp_and::_cpp_auto + _cpp_goto(_cpp_and::_cpp_continue, const _cpp_and::_cpp_auto&, const _cpp_and::deletePtr&, + const _cpp_and::complPtr&, const _cpp_and::doPtr&, const _cpp_and::breakPrx&, + const _cpp_and::charPrx&, const _cpp_and::complPrx&, const _cpp_and::doPrx&, + ::Ice::Int, ::Ice::Int, ::Ice::Int, ::Ice::Int) + { + return _cpp_and::_cpp_auto(); + } +}; + +class fooI : public _cpp_and::AMI_compl_foo +{ +public: + + virtual void ice_response(Ice::Int) {} + virtual void ice_exception(const ::Ice::Exception&) {} +}; + +// +// This section of the test is present to ensure that the C++ types +// are named correctly. It is not expected to run. +// +void +testtypes() +{ + _cpp_and::_cpp_continue a = _cpp_and::_cpp_asm; + assert(a); + + _cpp_and::_cpp_auto b; + b._cpp_default = 0; + + _cpp_and::deletePtr c = new _cpp_and::_cpp_delete(); + c->_cpp_else = ""; + + _cpp_and::breakPrx d; + int d2; + d->_cpp_case(0, d2); + _cpp_and::breakPtr d1 = new breakI(); + + _cpp_and::charPrx e; + e->_cpp_explicit(); + _cpp_and::charPtr e1 = new charI(); + + _cpp_and::complPrx f; + f->foo_async(new fooI(), e); + _cpp_and::complPtr f1 = new complI(); + + _cpp_and::doPrx g; + g->_cpp_case(0, d2); + g->_cpp_explicit(); + _cpp_and::doPtr g1 = new doI(); + + _cpp_and::_cpp_extern h; + _cpp_and::_cpp_for i; + _cpp_and::_cpp_return j; + j._cpp_signed = 0; + _cpp_and::_cpp_sizeof k; + k._cpp_static = 0; + k._cpp_switch = 1; + k._cpp_signed = 2; + + _cpp_and::friendPtr l = new friendI(); + + const int m = _cpp_and::_cpp_template; + assert(m == _cpp_and::_cpp_template); +} + +int +run(const Ice::CommunicatorPtr& communicator) +{ + communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000:udp"); + Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); + adapter->add(new charI, communicator->stringToIdentity("test")); + adapter->activate(); + + cout << "Testing operation name... " << flush; + _cpp_and::charPrx p = _cpp_and::charPrx::uncheckedCast( + adapter->createProxy(communicator->stringToIdentity("test"))); + p->_cpp_explicit(); + cout << "ok!" << endl; + + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + Ice::CommunicatorPtr communicator; + + try + { + Ice::InitializationData initData; + initData.properties = Ice::createProperties(argc, argv); + communicator = Ice::initialize(argc, argv, initData); + status = run(communicator); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if(communicator) + { + try + { + communicator->destroy(); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/test/Slice/keyword/Key.ice b/cpp/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..790f5277746 --- /dev/null +++ b/cpp/test/Slice/keyword/Key.ice @@ -0,0 +1,81 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +module and +{ + +enum continue +{ + asm +}; + +struct auto +{ + int default; +}; + +["cpp:class"] struct delete +{ + string else; +}; + +interface break +{ + ["amd"] void case(int catch, out int try); +}; + +interface char +{ + void explicit(); +}; + +class compl +{ + ["ami"] void foo(char* export, out int volatile); +}; + +class do extends compl implements char, break +{ +}; + +sequence<auto> extern; + +dictionary<string,auto> for; + +exception return +{ + int signed; +}; + +exception sizeof extends return +{ + int static; int switch; +}; + +local interface friend +{ + auto goto(continue if, auto d, delete inline, compl private, do mutable, break* namespace, + char* new, compl* not, do* operator, int or, int protected, int public, int register) + throws return, sizeof; +}; + +const int template = 0; +const int this = 0; +const int throw = 0; +const int typedef = 0; +const int typeid = 0; +const int typename = 0; +const int union = 0; +const int unsigned = 0; +const int using = 0; +const int virtual = 0; +const int while = 0; +const int xor = 0; + +}; diff --git a/cpp/test/Slice/keyword/Makefile b/cpp/test/Slice/keyword/Makefile new file mode 100644 index 00000000000..c5f5f5e2813 --- /dev/null +++ b/cpp/test/Slice/keyword/Makefile @@ -0,0 +1,32 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +COBJS = Client.o \ + Key.o + +SRCS = $(COBJS:.o=.cpp) + +SLICE_SRCS = Key.ice + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include $(CPPFLAGS) +SLICE2CPPFLAGS := --stream $(SLICE2CPPFLAGS) + +$(CLIENT): $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(COBJS) $(LIBS) + +include .depend diff --git a/cpp/test/Slice/keyword/Makefile.mak b/cpp/test/Slice/keyword/Makefile.mak new file mode 100644 index 00000000000..b859b99f893 --- /dev/null +++ b/cpp/test/Slice/keyword/Makefile.mak @@ -0,0 +1,38 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ..\..\.. + +CLIENT = client.exe + +TARGETS = $(CLIENT) + +COBJS = Key.obj \ + Client.obj + +SRCS = $(COBJS:.obj=.cpp) + +!include $(top_srcdir)/config/Make.rules.mak + +CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN +SLICE2CPPFLAGS = --stream $(SLICE2CPPFLAGS) + +!if "$(CPP_COMPILER)" != "BCC2006" && "$(OPTIMIZE)" != "yes" +CPDBFLAGS = /pdb:$(CLIENT:.exe=.pdb) +!endif + +$(CLIENT): $(COBJS) + $(LINK) $(LD_EXEFLAGS) $(CPDBFLAGS) $(SETARGV) $(COBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +clean:: + del /q Key.cpp Key.h + +!include .depend diff --git a/cpp/test/Slice/keyword/run.py b/cpp/test/Slice/keyword/run.py new file mode 100755 index 00000000000..e033a8e4d1a --- /dev/null +++ b/cpp/test/Slice/keyword/run.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Slice", "keyword") +testdir = os.path.join(toplevel, "test", name) + +cwd = os.getcwd() +os.chdir(testdir) + +client = os.path.join(testdir, "client") + +print "starting client...", +clientPipe = os.popen(client + " 2>&1") +print "ok" + +TestUtil.printOutputFromPipe(clientPipe); + +clientStatus = TestUtil.closePipe(clientPipe) + +if clientStatus: + sys.exit(1) + +sys.exit(0) diff --git a/cs/allTests.py b/cs/allTests.py index 1e295120965..1eaeb0bdac5 100755 --- a/cs/allTests.py +++ b/cs/allTests.py @@ -58,6 +58,7 @@ def runTests(args, tests, num = 0): # List of all basic tests. # tests = [ \ + "Slice/keyword", \ "IceUtil/inputUtil", \ "Ice/proxy", \ "Ice/operations", \ diff --git a/cs/test/Makefile b/cs/test/Makefile index ac6ba7223fb..bedea4962bd 100644 --- a/cs/test/Makefile +++ b/cs/test/Makefile @@ -11,7 +11,7 @@ top_srcdir = .. include $(top_srcdir)/config/Make.rules.cs -SUBDIRS = IceUtil Ice Glacier2 IceGrid IceSSL +SUBDIRS = Slice IceUtil Ice Glacier2 IceGrid IceSSL $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cs/test/Makefile.mak b/cs/test/Makefile.mak index e9dc940b6d1..eb073fc0b50 100755 --- a/cs/test/Makefile.mak +++ b/cs/test/Makefile.mak @@ -11,7 +11,7 @@ top_srcdir = .. !include $(top_srcdir)\config\Make.rules.mak.cs -SUBDIRS = IceUtil Ice Glacier2 IceGrid IceSSL +SUBDIRS = Slice IceUtil Ice Glacier2 IceGrid IceSSL $(EVERYTHING):: @for %i in ( $(SUBDIRS) ) do \ diff --git a/cs/test/Slice/Makefile b/cs/test/Slice/Makefile new file mode 100644 index 00000000000..ce15547fb59 --- /dev/null +++ b/cs/test/Slice/Makefile @@ -0,0 +1,24 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ../.. + +include $(top_srcdir)/config/Make.rules.cs + +SUBDIRS = keyword + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done + +test:: + @python $(top_srcdir)/allTests.py diff --git a/cs/test/Slice/Makefile.mak b/cs/test/Slice/Makefile.mak new file mode 100755 index 00000000000..170fa25f659 --- /dev/null +++ b/cs/test/Slice/Makefile.mak @@ -0,0 +1,22 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ..\.. + +!include $(top_srcdir)\config\Make.rules.mak.cs + +SUBDIRS = keyword + +$(EVERYTHING):: + @for %i in ( $(SUBDIRS) ) do \ + @echo "making $@ in %i" && \ + cmd /c "cd %i && $(MAKE) -nologo -f Makefile.mak $@" || exit 1 + +test:: + @python $(top_srcdir)/allTests.py diff --git a/cs/test/Slice/keyword/.depend b/cs/test/Slice/keyword/.depend new file mode 100644 index 00000000000..e3120e32fb7 --- /dev/null +++ b/cs/test/Slice/keyword/.depend @@ -0,0 +1 @@ +Key.cs: ./Key.ice diff --git a/cs/test/Slice/keyword/Client.cs b/cs/test/Slice/keyword/Client.cs new file mode 100644 index 00000000000..5d1284fd981 --- /dev/null +++ b/cs/test/Slice/keyword/Client.cs @@ -0,0 +1,192 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using System; +using System.Diagnostics; + +public class Server +{ + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + public sealed class caseI : @abstract.caseDisp_ + { + public override void catch_async(@abstract.AMD_case_catch cb__, int @checked, Ice.Current current__) + { + int @continue = 0; + cb__.ice_response(@continue); + } + } + + public sealed class decimalI : @abstract.decimalDisp_ + { + public override void @default(Ice.Current current__) + { + } + } + + public sealed class delegateI : @abstract.@delegate + { + public override void foo(@abstract.casePrx @else, out int @event, Ice.Current current__) + { + @event = 0; + } + } + + public sealed class explicitI : @abstract.@explicit + { + public override void catch_async(@abstract.AMD_case_catch cb__, int @checked, Ice.Current current__) + { + int @continue = 0; + cb__.ice_response(@continue); + } + + public override void @default(Ice.Current current) + { + test(current.operation == "default"); + } + + public override void foo(@abstract.casePrx @else, out int @event, Ice.Current current__) + { + @event = 0; + } + } + + public sealed class implicitI : @abstract.@implicit + { + public @abstract.@as @in(@abstract.@break @internal, @abstract.@delegate @is, @abstract.@explicit @lock, + @abstract.casePrx @namespace, @abstract.decimalPrx @new, @abstract.delegatePrx @null, + @abstract.explicitPrx @operator, int @override, int @params, int @private) + { + return @abstract.@as.@base; + } + } + + static void + testtypes() + { + @abstract.@as a = @abstract.@as.@base; + test(a == @abstract.@as.@base); + @abstract.@break b = new @abstract.@break(); + b.@readonly = 0; + test(b.@readonly == 0); + @abstract.@case c = new caseI(); + test(c != null); + @abstract.@casePrx c1 = null; + test(c1 == null); + int c2 = 0; + if(c1 != null) + { + c1.@catch(0, out c2); + } + @abstract.@decimal d = new decimalI(); + test(d != null); + @abstract.@decimalPrx d1 = null; + if(d1 != null) + { + d1.@default(); + } + test(d1 == null); + @abstract.@delegate e = new delegateI(); + test(e != null); + @abstract.@delegatePrx e1 = null; + test(e1 == null); + @abstract.@explicit f = new explicitI(); + test(f != null); + @abstract.@explicitPrx f1 = null; + if(f1 != null) + { + f1.@catch(0, out c2); + f1.@default(); + } + test(f1 == null); + @abstract.@extern l = new @abstract.@extern(); + test(l != null); + @abstract.@finally g = new @abstract.@finally(); + test(g != null); + @abstract.@fixed h = new @abstract.@fixed(); + h.@for = 0; + test(h != null); + @abstract.@foreach i = new @abstract.@foreach(); + i.@for = 0; + i.@goto = 1; + i.@if = 2; + test(i != null); + @abstract.@implicit j = new implicitI(); + test(j != null); + int k = @abstract.@protected.value; + test(k == 0); + } + + private static int run(string[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new decimalI(), communicator.stringToIdentity("test")); + adapter.activate(); + + Console.Out.Write("testing operation name... "); + Console.Out.Flush(); + @abstract.@decimalPrx p = @abstract.@decimalPrxHelper.uncheckedCast( + adapter.createProxy(communicator.stringToIdentity("test"))); + p.@default(); + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing types... "); + Console.Out.Flush(); + testtypes(); + Console.Out.WriteLine("ok"); + + return 0; + } + + public static void Main(string[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + Debug.Listeners.Add(new ConsoleTraceListener()); + + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(ref args); + communicator = Ice.Util.initialize(ref args, initData); + status = run(args, communicator); + } + catch(Ice.LocalException ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + } + + if(status != 0) + { + System.Environment.Exit(status); + } + } +} diff --git a/cs/test/Slice/keyword/Key.ice b/cs/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..30f28f60698 --- /dev/null +++ b/cs/test/Slice/keyword/Key.ice @@ -0,0 +1,65 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +module abstract +{ + +enum as +{ + base +}; + +struct break +{ + int readonly; +}; + +interface case +{ + ["amd"] void catch(int checked, out int continue); +}; + +interface decimal +{ + void default(); +}; + +class delegate +{ + ["ami"] void foo(case* else, out int event); +}; + +class explicit extends delegate implements decimal, case +{ +}; +["clr:collection"] sequence<as> extern; +["clr:collection"] dictionary<string, as> finally; + +exception fixed +{ + int for; +}; + +exception foreach extends fixed +{ + int goto; + int if; +}; + +local interface implicit +{ + as in(break internal, delegate is, explicit lock, case* namespace, decimal* new, delegate* null, + explicit* operator, int override, int params, int private) + throws fixed, foreach; +}; + +const int protected = 0; +const int public = 0; + +}; diff --git a/cs/test/Slice/keyword/Makefile b/cs/test/Slice/keyword/Makefile new file mode 100644 index 00000000000..e6e20ff5aa6 --- /dev/null +++ b/cs/test/Slice/keyword/Makefile @@ -0,0 +1,31 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +TARGETS = client.exe + +C_SRCS = Client.cs + +SLICE_SRCS = $(SDIR)/Key.ice + +SDIR = . + +GDIR = generated + +include $(top_srcdir)/config/Make.rules.cs + +MCSFLAGS := $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS := $(SLICE2CSFLAGS) --stream + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +include .depend diff --git a/cs/test/Slice/keyword/Makefile.mak b/cs/test/Slice/keyword/Makefile.mak new file mode 100644 index 00000000000..2e25a69eb27 --- /dev/null +++ b/cs/test/Slice/keyword/Makefile.mak @@ -0,0 +1,31 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ..\..\.. + +TARGETS = client.exe + +C_SRCS = Key.cs Client.cs + +GEN_SRCS = $(GDIR)\Key.cs + +SDIR = . + +GDIR = generated + +!include $(top_srcdir)\config\Make.rules.mak.cs + +MCSFLAGS = $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS = $(SLICE2CSFLAGS) --stream + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)\icecs.dll $(C_SRCS) $(GEN_SRCS) + +!include .depend diff --git a/cs/test/Slice/keyword/run.py b/cs/test/Slice/keyword/run.py new file mode 100755 index 00000000000..c4e3ce152aa --- /dev/null +++ b/cs/test/Slice/keyword/run.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys, getopt + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Slice", "keyword") +testdir = os.path.join(toplevel, "test", name) +client = os.path.join(testdir, "client") + +print TestUtil.createMsg("client"), +clientPipe = os.popen(TestUtil.createCmd(client)) +print "ok" + +TestUtil.printOutputFromPipe(clientPipe) + +clientStatus = TestUtil.closePipe(clientPipe) +if clientStatus: + sys.exit(1) + +sys.exit(0) diff --git a/java/allTests.py b/java/allTests.py index 76eead1ea38..a243b1c6dd6 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -66,6 +66,7 @@ def runTests(args, tests, num = 0): # List of all basic tests. # tests = [ \ + "Slice/keyword", \ "IceUtil/inputUtil", \ "Ice/proxy", \ "Ice/operations", \ diff --git a/java/test/Slice/build.xml b/java/test/Slice/build.xml new file mode 100644 index 00000000000..7d02379843f --- /dev/null +++ b/java/test/Slice/build.xml @@ -0,0 +1,22 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2007 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. + + ********************************************************************** +--> + +<project name="test_Slice" default="all" basedir="."> + + <target name="all"> + <ant dir="keyword"/> + </target> + + <target name="clean"> + <ant dir="keyword" target="clean"/> + </target> + +</project> diff --git a/java/test/Slice/keyword/Client.java b/java/test/Slice/keyword/Client.java new file mode 100644 index 00000000000..6c47996d209 --- /dev/null +++ b/java/test/Slice/keyword/Client.java @@ -0,0 +1,198 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +public class Client +{ + static public class catchI extends _abstract._catchDisp + { + public + catchI() + { + } + + public void + checkedCast_async(_abstract.AMD_catch_checkedCast __cb, int _clone, Ice.Current __current) + { + int _continue = 0; + __cb.ice_response(_continue); + } + } + + static public class defaultI extends _abstract._defaultDisp + { + public + defaultI() + { + } + + public void + _do(Ice.Current __current) + { + assert __current.operation.equals("do"); + } + } + + static public class elseI extends _abstract._else + { + public + elseI() + { + } + + public void + foo(_abstract.defaultPrx _equals, Ice.IntHolder _final, Ice.Current __current) + { + } + } + + static public class newI implements _abstract._new + { + public + newI() + { + } + + public _abstract._assert + _notify(_abstract._break _notifyAll, _abstract._else _null, _abstract._finalize _package, + _abstract.elsePrx _private, _abstract.finalizePrx _protected, + _abstract.catchPrx _public, _abstract.defaultPrx _return, int _static, int _strictfp, int _super) + throws _abstract._hashCode, _abstract._import + { + return null; + } + } + + static public class finalizeI extends _abstract._finalize + { + public + finalizeI() + { + } + + public void + checkedCast_async(_abstract.AMD_catch_checkedCast __cb, int _clone, Ice.Current __current) + { + int _continue = 0; + __cb.ice_response(_continue); + } + + public void + _do(Ice.Current __current) + { + } + + public void + foo(_abstract.defaultPrx _equals, Ice.IntHolder _final, Ice.Current __current) + { + } + } + + // + // This section of the test is present to ensure that the C++ types + // are named correctly. It is not expected to run. + // + private static void + testtypes() + { + _abstract._assert v = _abstract._assert._boolean; + _abstract._break b = new _abstract._break(); + b._case = 0; + _abstract.catchPrx c = null; + c._checkedCast(0, new Ice.IntHolder()); + _abstract._catch c1 = new catchI(); + _abstract.defaultPrx d = null; + d._do(); + _abstract._default d1 = new defaultI(); + _abstract.elsePrx e; + _abstract._else e1 = new elseI(); + _abstract.finalizePrx f = null; + f._checkedCast(0, new Ice.IntHolder()); + f._do(); + _abstract._finalize f1 = new finalizeI(); + _abstract.forHolder g; + _abstract.gotoHolder h; + _abstract._hashCode i = new _abstract._hashCode(); + i._if = 0; + _abstract._import j = new _abstract._import(); + j._if = 0; + j._instanceof = 1; + j._native = 2; + _abstract._new k = new newI(); + assert _abstract._switch.value == 0; + } + + private static int + run(String[] args, Ice.Communicator communicator) + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new defaultI(), communicator.stringToIdentity("test")); + adapter.activate(); + + System.out.print("Testing operation name... "); + System.out.flush(); + _abstract.defaultPrx p = _abstract.defaultPrxHelper.uncheckedCast( + adapter.createProxy(communicator.stringToIdentity("test"))); + p._do(); + System.out.println("ok!"); + + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + // + // In this test, we need at least two threads in the + // client side thread pool for nested AMI. + // + Ice.StringSeqHolder argsH = new Ice.StringSeqHolder(args); + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.ThreadPool.Client.Size", "2"); + initData.properties.setProperty("Ice.ThreadPool.Client.SizeWarn", "0"); + + // + // We must set MessageSizeMax to an explicit values, + // because we run tests to check whether + // Ice.MemoryLimitException is raised as expected. + // + initData.properties.setProperty("Ice.MessageSizeMax", "100"); + + communicator = Ice.Util.initialize(argsH, initData); + status = run(argsH.value, communicator); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Slice/keyword/Key.ice b/java/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..3c6eec428cf --- /dev/null +++ b/java/test/Slice/keyword/Key.ice @@ -0,0 +1,76 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +module abstract +{ + +enum assert +{ + boolean +}; + +struct break +{ + int case; +}; + +interface catch +{ + ["amd"] void checkedCast(int clone, out int continue); +}; + +interface default +{ + void do(); +}; + +class else +{ + ["ami"] void foo(default* equals, out int final); +}; + +class finalize extends else implements default, catch +{ +}; +sequence<assert> for; +dictionary<string, assert> goto; + +exception hashCode +{ + int if; +}; + +exception import extends hashCode +{ + int instanceof; + int native; +}; + +local interface new +{ + assert notify( break notifyAll, else null, finalize package, else* private, finalize * protected, catch* public, + default* return, int static, int strictfp, int super) + throws hashCode, import; +}; + +const int switch = 0; +const int synchronized = 0; +const int this = 0; +const int throw = 0; +const int toString = 0; +const int try = 0; +const int uncheckedCast = 0; +const int volatile = 0; +const int wait = 0; +const int while = 0; +const int finally = 0; +const int getClass = 0; + +}; + diff --git a/java/test/Slice/keyword/build.xml b/java/test/Slice/keyword/build.xml new file mode 100644 index 00000000000..1996e96c69c --- /dev/null +++ b/java/test/Slice/keyword/build.xml @@ -0,0 +1,51 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2007 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. + + ********************************************************************** +--> + +<project name="test_Slice_keyword" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java2metadata}"/> + <fileset dir="." includes="Key.ice"/> + <includepath> + <pathelement path="${slice.dir}" /> + </includepath> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + source="${jdk.version}" classpath="${lib.dir}" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" source="${jdk.version}" + classpath="${lib.dir}" excludes="generated/**" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/test/Slice/keyword/run.py b/java/test/Slice/keyword/run.py new file mode 100755 index 00000000000..bebd5b4c61f --- /dev/null +++ b/java/test/Slice/keyword/run.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Slice", "keyword") +testdir = os.path.join(toplevel, "test", name) +os.environ["CLASSPATH"] = os.path.join(testdir, "classes") + TestUtil.sep + os.getenv("CLASSPATH", "") + +print "starting client...", +clientPipe = os.popen(TestUtil.javaCmd + " -ea Client 2>&1") +print "ok" + +TestUtil.printOutputFromPipe(clientPipe) + +clientStatus = TestUtil.closePipe(clientPipe) + +if clientStatus: + sys.exit(1) + +sys.exit(0) diff --git a/java/test/build.xml b/java/test/build.xml index 4fa578eee00..6cac9f9ad0f 100644 --- a/java/test/build.xml +++ b/java/test/build.xml @@ -12,6 +12,7 @@ <project name="test" default="all" basedir="."> <target name="all"> + <ant dir="Slice"/> <ant dir="IceUtil"/> <ant dir="Ice"/> <ant dir="Freeze"/> @@ -21,6 +22,7 @@ </target> <target name="clean"> + <ant dir="Slice" target="clean"/> <ant dir="IceUtil" target="clean"/> <ant dir="Ice" target="clean"/> <ant dir="Freeze" target="clean"/> diff --git a/php/config/TestUtil.py b/php/config/TestUtil.py index 7e3ed2db066..82f8cf9f067 100644 --- a/php/config/TestUtil.py +++ b/php/config/TestUtil.py @@ -331,6 +331,59 @@ else: # #php = "php -d extension_dir=\"" + os.path.abspath(os.path.join(toplevel, "lib")) + "\" -d extension=IcePHP.so" +def clientTest(name, clientName): + + # + # Write temporary INI file that contains the extension directives. + # This is a workaround for a limitation in PHP 5.1.x that prevents + # us from specifying the directives on PHP's command line. + # + # TODO: When we no longer support PHP 5.1.x, we can remove the extension + # directives. We still need to generate the temporary file to + # support ICE_HOME replacement. + # + tmpIniFile = "tmp.ini" + testdir = os.path.join(toplevel, "test", name) + client = php + " -c " + tmpIniFile + " -f " + clientName + #client = php + " -c . -f " + clientName + + cwd = os.getcwd() + os.chdir(testdir) + + # + # Replace all occurrences of ICE_HOME with the value of the environment variable. + # + iniLines = open("php.ini", "r").readlines() + for i in range(0,len(iniLines)): + iniLines[i] = iniLines[i].replace("ICE_HOME", ice_home) + + iniFile = open(tmpIniFile, "w") + iniFile.writelines(iniLines) + iniFile.write("extension_dir=" + extensionDir + "\n") + iniFile.write("extension=" + extensionFile + "\n") + iniFile.close() + + try: + print "starting " + clientName + "...", + clientCmd = client + " -- " + clientOptions + if debug: + print "(" + clientCmd + ")", + clientPipe = os.popen(clientCmd + " 2>&1") + print "ok" + + printOutputFromPipe(clientPipe) + + clientStatus = closePipe(clientPipe) + if clientStatus: + killServers() + finally: + os.remove(tmpIniFile) + + if clientStatus: + sys.exit(1) + + os.chdir(cwd) + def clientServerTestWithOptionsAndNames(name, additionalServerOptions, additionalClientOptions, \ serverName, clientName): diff --git a/php/test/Slice/keyword/Client.php b/php/test/Slice/keyword/Client.php new file mode 100644 index 00000000000..6e40ea30021 --- /dev/null +++ b/php/test/Slice/keyword/Client.php @@ -0,0 +1,74 @@ +<? +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +error_reporting(E_ALL | E_STRICT); + +if(!extension_loaded("ice")) +{ + echo "\nerror: Ice extension is not loaded.\n\n"; + exit(1); +} +Ice_loadProfileWithArgs($argv); + +function test($b) +{ + if(!$b) + { + $bt = debug_backtrace(); + die("\ntest failed in ".$bt[0]["file"]." line ".$bt[0]["line"]."\n"); + } +} + +class echoI extends and_echo +{ + function _else($a, &$b) + { + } +} + +class enddeclareI extends and_enddeclare +{ + function _else($a, &$b) + { + } + function _continue($a, $b) + { + } + function _do() + { + } +} + +function allTests() +{ + global $ICE; + + echo "testing type names... "; + flush(); + $a = and_array::_as; + $b = new and_break(); + $b->_case = 0; + $c = $ICE->stringToProxy("test:tcp -p 10000")->ice_uncheckedCast("::and::cfunction"); + $d = $ICE->stringToProxy("test:tcp -p 10000")->ice_uncheckedCast("::and::die"); + $e = $ICE->stringToProxy("test:tcp -p 10000")->ice_uncheckedCast("::and::echo"); + $e1 = new echoI(); + $f = $ICE->stringToProxy("test:tcp -p 10000")->ice_uncheckedCast("::and::enddeclare"); + $f1 = new enddeclareI(); + $g = new and_endif(); + $h = new and_endwhile(); + $i = constant("and_or"); + $j = constant("and_print"); + echo "ok\n"; +} + +allTests(); + +exit(); +?> diff --git a/php/test/Slice/keyword/Key.ice b/php/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..322e2659c64 --- /dev/null +++ b/php/test/Slice/keyword/Key.ice @@ -0,0 +1,50 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +module and +{ + enum array + { + as + }; + struct break + { + int case; + }; + interface cfunction + { + void continue(int declare, int default); + }; + interface die + { + void do(); + }; + class echo + { + void else(die* elseif, out int empty); + }; + class enddeclare extends echo implements die, cfunction + { + }; + sequence<array> endfor; + dictionary<string,array> endforeach; + + exception endif { int endswitch; }; + exception endwhile extends endif { int eval; int exit; }; + + local interface for + { + array foreach(break if, echo global, enddeclare require, cfunction* include, + die* return, echo* isset, enddeclare* list, int new, int static) + throws endif, endwhile; + }; + + const int or = 0; + const int print = 0; +}; diff --git a/php/test/Slice/keyword/php.ini b/php/test/Slice/keyword/php.ini new file mode 100644 index 00000000000..91dfdfddefd --- /dev/null +++ b/php/test/Slice/keyword/php.ini @@ -0,0 +1,2 @@ +ice.slice=Key.ice +display_startup_errors=1 diff --git a/php/test/Slice/keyword/run.py b/php/test/Slice/keyword/run.py new file mode 100755 index 00000000000..bd56ced8641 --- /dev/null +++ b/php/test/Slice/keyword/run.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Slice", "keyword") + +TestUtil.clientTest(name, "Client.php") + +sys.exit(0) diff --git a/py/CHANGES b/py/CHANGES index 782eb55bc0c..09cd39dabf8 100644 --- a/py/CHANGES +++ b/py/CHANGES @@ -1,6 +1,11 @@ Changes since version 3.2.X (binary incompatible) ------------------------------------------------- +- Fixed a code generation bug with slice2py where the proxy type + for a python reserved word would be incorrectly named. For example, + interface def would generate a proxy class named _defPrx, not the + correct class name defPrx. + - LocalObject is now mapped to the Python base 'object' type. The class Ice.LocalObject is now deprecated. diff --git a/py/allTests.py b/py/allTests.py index 01293b943eb..aa58236964e 100755 --- a/py/allTests.py +++ b/py/allTests.py @@ -46,6 +46,7 @@ def runTests(args, tests, num = 0): # List of all basic tests. # tests = [ \ + "Slice/keyword", \ "Ice/adapterDeactivation", \ "Ice/binding", \ "Ice/exceptions", \ diff --git a/py/config/Make.rules b/py/config/Make.rules index d557d6dea50..ede78459cdc 100644 --- a/py/config/Make.rules +++ b/py/config/Make.rules @@ -31,7 +31,7 @@ embedded_runpath_prefix ?= /opt/Ice-$(VERSION_MAJOR).$(VERSION_MINOR) # Otherwise the Ice extension is built with debug information. # -OPTIMIZE = yes +#OPTIMIZE = yes # # Define LP64 as yes if you want to build in 64 bit mode on a platform diff --git a/py/test/Slice/keyword/Client.py b/py/test/Slice/keyword/Client.py new file mode 100644 index 00000000000..960e7875c7f --- /dev/null +++ b/py/test/Slice/keyword/Client.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys, traceback + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "python", "Ice.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.insert(0, os.path.join(toplevel, "python")) +sys.path.insert(0, os.path.join(toplevel, "lib")) + +import Ice + +Ice.loadSlice('Key.ice') +import _and + +class delI(_and._del): + def _elif_async(self, _cb, _else, current=None): + pass + +class execI(_and._exec): + def _finally(self, current=None): + assert current.operation == "finally" + +class forI(_and._for): + def foo(self, _from, current=None): + pass + +class ifI(_and._if): + def _elif_async(self, _cb, _else, current=None): + pass + def _finally(self, current=None): + pass + def foo(self, _from, current=None): + pass + +class printI(_and._print): + def _raise(self, _else, _return, _try, _while, _yield, _lambda, _or, _global): + pass + +def testtypes(): + print("Testing generated type names... "), + a = _and._assert._break + b = _and._continue + b._def = 0 + c = _and.delPrx.uncheckedCast(None) + assert "_elif" in dir(_and.delPrx) + c1 = delI() + d = _and.execPrx.uncheckedCast(None) + assert "_finally" in dir(_and.execPrx) + d1 = execI() + e = _and.forPrx.uncheckedCast(None) + assert "foo_async" in dir(_and.forPrx) + e1 = forI() + f = _and.ifPrx.uncheckedCast(None) + assert "foo_async" in dir(_and.ifPrx) + assert "_finally" in dir(_and.ifPrx) + assert "_elif" in dir(_and.ifPrx) + f1 = ifI() + g = _and._is() + g._lamba = 0 + h = _and._not() + h._lamba = 0 + h._or = 1 + h._pass = 2 + i = printI() + j = _and._lambda; + print "ok!" + +def run(args, communicator): + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000:udp") + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(execI(), communicator.stringToIdentity("test")) + adapter.activate() + + print("Testing operation name... "), + p = _and.execPrx.uncheckedCast( + adapter.createProxy(communicator.stringToIdentity("test"))); + p._finally(); + print "ok!" + + testtypes() + + return True + +try: + initData = Ice.InitializationData() + initData.properties = Ice.createProperties(sys.argv) + # + # Its possible to have batch oneway requests dispatched after the + # adapter is deactivated due to thread scheduling so we supress + # this warning. + # + initData.properties.setProperty("Ice.Warn.Dispatch", "0"); + communicator = Ice.initialize(sys.argv, initData) + status = run(sys.argv, communicator) +except: + traceback.print_exc() + status = False + +if communicator: + try: + communicator.destroy() + except: + traceback.print_exc() + status = False + +sys.exit(not status) diff --git a/py/test/Slice/keyword/Key.ice b/py/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..4aa7731e373 --- /dev/null +++ b/py/test/Slice/keyword/Key.ice @@ -0,0 +1,62 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +module and +{ + enum assert + { + break + }; + + struct continue + { + int def; + }; + + interface del + { + ["amd"] void elif(int else, out int except); + }; + + interface exec + { + void finally(); + }; + + class for + { + ["ami"] void foo(exec* from, out int global); + }; + + class if extends for implements exec, del + { + }; + + sequence<assert> import; + dictionary<string,assert> in; + + exception is + { + int lambda; + }; + exception not extends is + { + int or; + int pass; + }; + + local interface print + { + assert raise(continue else, for return, if try, del* while, exec* yield, + for* lambda, if* or, int global) + throws is; + }; + + const int lambda = 0; +}; diff --git a/py/test/Slice/keyword/run.py b/py/test/Slice/keyword/run.py new file mode 100755 index 00000000000..25151547843 --- /dev/null +++ b/py/test/Slice/keyword/run.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +testdir = os.path.join(toplevel, "test", "Slice", "keyword") + +cwd = os.getcwd() +os.chdir(testdir) + +print "starting client...", +clientPipe = os.popen("python Client.py --Ice.Default.Host=127.0.0.1 2>&1") +print "ok" + +TestUtil.printOutputFromPipe(clientPipe); + +clientStatus = TestUtil.closePipe(clientPipe) + +if clientStatus: + sys.exit(1) + +sys.exit(0) diff --git a/rb/allTests.py b/rb/allTests.py index 75d0898f117..d5df19c037f 100755 --- a/rb/allTests.py +++ b/rb/allTests.py @@ -46,6 +46,7 @@ def runTests(args, tests, num = 0): # List of all basic tests. # tests = [ \ + "Slice/keyword", \ "Ice/binding", \ "Ice/checksum", \ "Ice/exceptions", \ diff --git a/rb/test/Slice/keyword/Client.rb b/rb/test/Slice/keyword/Client.rb new file mode 100644 index 00000000000..0924048579b --- /dev/null +++ b/rb/test/Slice/keyword/Client.rb @@ -0,0 +1,75 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +require 'Ice' +#Ice::loadSlice('Key.ice') +require 'Key' + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +class DisplayI < BEGIN_::Display + def _do(_dup, current=nil) + end +end + +def run(args, communicator) + print "testing type names... " + STDOUT.flush + a = BEGIN_::END_::Alias + b = BEGIN_::And.new + b._begin = 0; + c = BEGIN_::BreakPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + test(c.method(:_case)) + d = BEGIN_::DisplayPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + test(d.method(:_do)) + d1 = DisplayI.new + e = BEGIN_::ElsifPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + test(e.method(:_do)) + test(e.method(:_case)) + f = BEGIN_::Next.new + f.new = 0 + g = BEGIN_::Nil.new + g.new = 0 + g._not = 0 + g._or = 0 + # TODO: Test local interface + #h = BEGIN_::ExtendPrx::uncheckedCast(communicator.stringToProxy("test:tcp")) + i = BEGIN_::Redo + puts "ok" + + return true +end + +begin + initData = Ice::InitializationData.new + initData.properties = Ice.createProperties(ARGV) + communicator = Ice.initialize(ARGV, initData) + status = run(ARGV, communicator) +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +if communicator + begin + communicator.destroy() + rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false + end +end + +exit(status ? 0 : 1) diff --git a/rb/test/Slice/keyword/Key.ice b/rb/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..e794b43872f --- /dev/null +++ b/rb/test/Slice/keyword/Key.ice @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +module BEGIN +{ + enum END + { + alias + }; + + struct and + { + int begin; + }; + + interface break + { + void case(int clone, int def); + }; + + class display + { + void do(break* dup, out int else); + }; + + class elsif extends display implements break + { + }; + + sequence<END> rescue; + dictionary<string, END> ensure; + + exception next + { + int new; + }; + + exception nil extends next + { + int not; + int or; + }; + + local interface extend + { + END for(display freeze, elsif hash, break* if, display inspect, elsif method, int methods) + throws nil; + }; + + const int redo = 1; +}; diff --git a/rb/test/Slice/keyword/run.py b/rb/test/Slice/keyword/run.py new file mode 100755 index 00000000000..e9b149709c9 --- /dev/null +++ b/rb/test/Slice/keyword/run.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +testdir = os.path.join(toplevel, "test", "Slice", "keyword") + +cwd = os.getcwd() +os.chdir(testdir) + +print "starting client...", +clientPipe = os.popen("ruby Client.rb --Ice.Default.Host=127.0.0.1 2>&1") +print "ok" + +TestUtil.printOutputFromPipe(clientPipe); + +clientStatus = TestUtil.closePipe(clientPipe) + +if clientStatus: + sys.exit(1) + +sys.exit(0) |