summaryrefslogtreecommitdiff
path: root/cpp/test/Slice/headers/run.py
blob: 12ba0d1d805fb7f9d57db40b7da4d5ebdb59a79e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2015 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, re

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

def clean():
    for f in ["iceslices",
              "linktoslices",
              os.path.join("slices", "linktodir2"),
              os.path.join("slices", "linktodir1"),
              os.path.join("slices", "dir1", "linktoa3.ice")]:
        if os.path.exists(f):
            os.unlink(f)
    os.system("rm -rf project1 tmp")

clean()
os.symlink("slices", "linktoslices")
os.symlink("dir1", os.path.join("slices", "linktodir1"))
os.symlink("a3.ice", os.path.join("slices", "dir1", "linktoa3.ice"))
os.symlink("dir2", os.path.join("slices", "linktodir2"))

slice2cpp = TestUtil.getSliceTranslator()

basedir = os.path.dirname(os.path.abspath(__file__))
slicedir = TestUtil.getSliceDir()
os.symlink(slicedir, "iceslices")

def runTest(cmd):
    os.system(cmd)
    f = open("b.h")
    if not re.search('#include <dir1\/a1\.h>\n'
                     '#include <linktodir1\/a2\.h>\n'
                     '#include <linktodir1\/linktoa3\.h>\n'
                     '#include <Ice\/Identity\.h>\n', f.read(), re.S):
        print("failed!")
        sys.exit(1)
    os.unlink("b.h")
    os.unlink("b.cpp")

sys.stdout.write("compiling slice files and checking headers... ")
sys.stdout.flush()
runTest("%s -Iiceslices -Islices slices/dir2/b.ice" % (slice2cpp))
runTest("%s -Iiceslices -I../headers/slices slices/dir2/b.ice" % (slice2cpp))
runTest("%s -Iiceslices -Ilinktoslices slices/dir2/b.ice" % (slice2cpp))
runTest("%s -Iiceslices -Ilinktoslices/../linktoslices slices/dir2/b.ice" % (slice2cpp))
runTest("%s -I%s -Islices linktoslices/dir2/b.ice" % (slice2cpp, slicedir))
runTest("%s -I%s -Ilinktoslices linktoslices/linktodir2/b.ice" % (slice2cpp, slicedir))

# Also ensure it works with case insensitive file system
if os.path.exists("SLICES"):
    runTest("%s -IICESLICES -ISLICES SLICES/DIR2/B.ice" % (slice2cpp))
    runTest("%s -IICESLICES -ILINKTOSLICES LINKTOSLICES/LINKTODIR2/B.ice" % (slice2cpp))

#
# Slice files are symlinks, include dir is a regular directory
#
os.system("mkdir -p project1/git/services.settings.slices")
os.system("mkdir -p project1/src/services/settings")
os.system("cd project1/src/services/settings &&  ln -s ../../../git/services.settings.slices slices")

f = open("project1/git/services.settings.slices/A.ice", "w")
f.write("// dumy file")
f.close()
f = open("project1/git/services.settings.slices/B.ice", "w")
f.write("#include <services/settings/slices/A.ice>")
f.close()

os.system("cd project1 && %s -Isrc src/services/settings/slices/B.ice" % slice2cpp)
f = open("project1/B.h")

if not re.search(re.escape('#include <services/settings/slices/A.h>'), f.read()):
    print("failed!")
    sys.exit(1)

clean()

#
# Slice file is regular file, include dir is a symlink to a second symlink
#
os.system("mkdir -p tmp/Ice-x.y.z/share")
os.system("cd tmp/Ice-x.y.z/share && ln -s %s" % slicedir)


os.system("mkdir -p project1/share")
os.system("cd project1/share && ln -s %s/tmp/Ice-x.y.z/share/slice" % basedir)
f = open("project1/A.ice", "w")
f.write("#include <Ice/Identity.ice>")
f.close()
os.system("cd project1 && %s -Ishare/slice A.ice" % slice2cpp)
f = open("project1/A.h")
if not re.search(re.escape('#include <Ice/Identity.h>'), f.read()):
    print("failed!")
    sys.exit(1)

clean()

#
# Typical Ice install with symlink Ice-x.y -> Ice-x.y.z
#
os.system("mkdir -p tmp/Ice-x.y.z/slice/Ice")
os.system("cd tmp && ln -s Ice-x.y.z Ice-x.y")
f = open("tmp/Ice-x.y.z/slice/Ice/Identity.ice", "w")
f.write("// dumy file")

os.system("mkdir -p project1")
f = open("project1/A.ice", "w")
f.write("#include <Ice/Identity.ice>")
f.close()
os.system("cd project1 && %s -I%s/tmp/Ice-x.y/slice A.ice" % (slice2cpp, basedir))
f = open("project1/A.h")
if not re.search(re.escape('#include <Ice/Identity.h>'), f.read()):
    print("failed!")
    sys.exit(1)

clean()    

#
# symlink directory with extra / at end
#
#
os.system("mkdir -p tmp/Ice-x.y.z/slice/Ice")
os.system("mkdir -p tmp/Ice")
os.system("cd tmp/Ice && ln -s ../Ice-x.y.z/slice/ .")
f = open("tmp/Ice-x.y.z/slice/Ice/Identity.ice", "w")
f.write("// dumy file")

os.system("mkdir -p project1")
f = open("project1/A.ice", "w")
f.write("#include <Ice/Identity.ice>")
f.close()
os.system("cd project1 && %s -I%s/tmp/Ice/slice A.ice" % (slice2cpp, basedir))
f = open("project1/A.h")
if not re.search(re.escape('#include <Ice/Identity.h>'), f.read()):
    print("failed!")
    sys.exit(1)
clean()

print("ok")