diff options
author | Jose <jose@zeroc.com> | 2013-07-17 00:09:35 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2013-07-17 00:09:35 +0200 |
commit | 3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86 (patch) | |
tree | 26fa5dbd2ff580933dc28b90af40ba9e3ca6fe7b /py | |
parent | Fixed ICE-5356 - Consider adding man pages for unix executables (diff) | |
download | ice-3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86.tar.bz2 ice-3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86.tar.xz ice-3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86.zip |
Fixed ICE-5375 - Consider to add ICE_TRANSLATOR preprocessor macro
Diffstat (limited to 'py')
-rwxr-xr-x | py/allTests.py | 1 | ||||
-rw-r--r-- | py/modules/IcePy/Slice.cpp | 2 | ||||
-rwxr-xr-x | py/test/Slice/macros/Client.py | 51 | ||||
-rw-r--r-- | py/test/Slice/macros/Test.ice | 57 | ||||
-rwxr-xr-x | py/test/Slice/macros/run.py | 28 |
5 files changed, 138 insertions, 1 deletions
diff --git a/py/allTests.py b/py/allTests.py index 5ce49abc82f..32fc14b7704 100755 --- a/py/allTests.py +++ b/py/allTests.py @@ -26,6 +26,7 @@ import TestUtil tests = [ ("Slice/keyword", ["once"]), ("Slice/structure", ["once"]), + ("Slice/macros", ["once"]), ("Ice/adapterDeactivation", ["core"]), ("Ice/binding", ["core"]), ("Ice/exceptions", ["core"]), diff --git a/py/modules/IcePy/Slice.cpp b/py/modules/IcePy/Slice.cpp index 1614fd6b27e..841dded5079 100644 --- a/py/modules/IcePy/Slice.cpp +++ b/py/modules/IcePy/Slice.cpp @@ -136,7 +136,7 @@ IcePy_loadSlice(PyObject* /*self*/, PyObject* args) { string file = *p; Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("icecpp", file, cppArgs); - FILE* cppHandle = icecpp->preprocess(keepComments); + FILE* cppHandle = icecpp->preprocess(keepComments, "-DICE_COMPILER=ICE_SLICE2PY"); if(cppHandle == 0) { diff --git a/py/test/Slice/macros/Client.py b/py/test/Slice/macros/Client.py new file mode 100755 index 00000000000..0913eb041ab --- /dev/null +++ b/py/test/Slice/macros/Client.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 RuntimeError("can't find toplevel directory!") + +import Ice + +Ice.loadSlice('Test.ice') +import Test, copy + +status = True + +def test(b): + if not b: + raise RuntimeError('test assertion failed') + +try: + sys.stdout.write("Testing Slice predefined macros... ") + sys.stdout.flush() + + d = Test.Default() + test(d.x == 10) + test(d.y == 10) + + nd = Test.NoDefault() + test(nd.x != 10) + test(nd.y != 10) + + c = Test.PythonOnly() + test(c.lang == "python") + test(c.version == Ice.intVersion()) + print("ok") +except: + traceback.print_exc() + status = False + +sys.exit(not status) diff --git a/py/test/Slice/macros/Test.ice b/py/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..c889ba75164 --- /dev/null +++ b/py/test/Slice/macros/Test.ice @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + + +// +// This macro sets the default value only when compile with slice2py +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2PY) +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compile with slice2py +// +#if defined(ICE_COMPILER) && (ICE_COMPILER != ICE_SLICE2PY) +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + + + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compile with slice2py. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2PY) +class PythonOnly +{ + string lang DEFAULT("python"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/py/test/Slice/macros/run.py b/py/test/Slice/macros/run.py new file mode 100755 index 00000000000..aed5c7927ed --- /dev/null +++ b/py/test/Slice/macros/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("Client.py", "--Ice.Default.Host=127.0.0.1", startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() |