forked from degauden/Elements
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaddCppClass_test
More file actions
executable file
·353 lines (293 loc) · 11.2 KB
/
Copy pathaddCppClass_test
File metadata and controls
executable file
·353 lines (293 loc) · 11.2 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/sh
# Call common script
. createCommonStructure_test
class_name="ClassTest"
elt_dep_name="Alexandria"
external_dep_name="Boost"
# Create a unique directory
tmploc=${TEMPORARY_LOCATION}
cd "${tmploc}" || exit
cd "${MODULE_NAME_PATH}" || exit
# Create a class
AddCppClass $class_name -ed $elt_dep_name -extd $external_dep_name
# if error stop and clean up
if [ $? -ne 0 ]; then
echo "Error: <AddCppClass $class_name -ed $elt_dep_name -extd $external_dep_name> command failed!" 1>&2
clean_and_exit 1
fi
# Make sure the class files are created
if [ ! -e "${MODULE_NAME}/${class_name}.h" ]; then
echo "Error: <${MODULE_NAME}/${class_name}.h> file not found!" 1>&2
clean_and_exit 1
fi
if [ ! -e "src/lib/${class_name}.cpp" ]; then
echo "Error: <src/lib/${class_name}.cpp> file not found!" 1>&2
clean_and_exit 1
fi
if [ ! -e "tests/src/${class_name}_test.cpp" ]; then
echo "Error: <tests/src/${class_name}_test.cpp> file not found!" 1>&2
clean_and_exit 1
fi
# test if the include statement contains a double slash
result=$(grep -e "^\s*#\s*include\s*\(<[^>/]*/\{2,\}.*>\|\"[^\"/]*/\{2,\}.*\"\)\s*" tests/src/${class_name}_test.cpp)
if [ $? -eq 0 ] ;then
echo "The tests/src/${class_name}_test.cpp contains an include statement with double //" 1>&2
clean_and_exit 1
fi
# Make sure the elements_depends_on_subdirs macro is there and ElementsKernel
result=$( grep "elements_depends_on_subdirs" "${MODULE_NAME_PATH}"/CMakeLists.txt |
grep -v "#" | grep "ElementsKernel" )
if [ $? -ne 0 ] ;then
echo "Error: <elements_depends_on_subdirs> macro with <ElementsKernel> module not found!" 1>&2
clean_and_exit 1
fi
# Make sure the elements_depends_on_subdirs macro is there and dependency
result=$( grep "elements_depends_on_subdirs" "${MODULE_NAME_PATH}"/CMakeLists.txt |
grep -v "#" | grep $elt_dep_name )
if [ $? -ne 0 ] ;then
echo "Error: <elements_depends_on_subdirs> macro with <$elt_dep_name> dependency not found!" 1>&2
clean_and_exit 1
fi
# Make sure the find_package macro is there
result=$( grep "find_package" "${MODULE_NAME_PATH}"/CMakeLists.txt |
grep -v "#" | grep $external_dep_name )
if [ $? -ne 0 ] ;then
echo "Error: find_package macro not found!" 1>&2
clean_and_exit 1
fi
# Make sure the elements_add_library macro is there
result=$( grep "elements_add_library" "${MODULE_NAME_PATH}"/CMakeLists.txt | grep -v "#" |
grep "$module_name" )
if [ $? -ne 0 ] ;then
echo "Error: <elements_add_library> macro with <$module_name> module not found!" 1>&2
clean_and_exit 1
fi
# Make sure the LINK_LIBRARIES is there and Elements dependency
result=$( grep "LINK_LIBRARIES" "${MODULE_NAME_PATH}"/CMakeLists.txt | grep -v "#" |
grep $elt_dep_name)
if [ $? -ne 0 ] ;then
echo "Error: LINK_LIBRARIES macro with <$elt_dep_name> Elements dependency not found!" 1>&2
clean_and_exit 1
fi
# Make sure the LINK_LIBRARIES is there and external dependency
result=$( grep "LINK_LIBRARIES" "${MODULE_NAME_PATH}"/CMakeLists.txt | grep -v "#" |
grep $external_dep_name)
if [ $? -ne 0 ] ;then
echo "Error: LINK_LIBRARIES macro with <$external_dep_name> external dependency not found!" 1>&2
clean_and_exit 1
fi
# Make sure the INCLUDE_DIRS is there and Elements dependency
result=$( grep "INCLUDE_DIRS" "${MODULE_NAME_PATH}"/CMakeLists.txt | grep -v "#" |
grep $elt_dep_name)
if [ $? -ne 0 ] ;then
echo "Error: INCLUDE_DIRS macro with <$elt_dep_name> Elements dependency not found!" 1>&2
clean_and_exit 1
fi
# Make sure the INCLUDE_DIRS is there and external dependency
result=$( grep "INCLUDE_DIRS" "${MODULE_NAME_PATH}"/CMakeLists.txt | grep -v "#" |
grep $external_dep_name)
if [ $? -ne 0 ] ;then
echo "Error: INCLUDE_DIRS macro with <$external_dep_name> external dependency not found!" 1>&2
clean_and_exit 1
fi
# Create a class into a subdir and make sure the elements_add_unit_test macro
# is correct and files are at the right place
# Create a class with subdir
subdir="subdir"
AddCppClass $subdir/$class_name
result=$( grep "elements_add_unit_test" "${MODULE_NAME_PATH}"/CMakeLists.txt | grep -v "#" |
grep $class_name | grep $subdir)
if [ $? -ne 0 ] ;then
echo "Error: in elements_add_unit_test macro, no <$subdir> not found!" 1>&2
clean_and_exit 1
fi
# Make sure the class files are created
if [ ! -e "${MODULE_NAME}/${subdir}/${class_name}.h" ]; then
echo "Error: <${MODULE_NAME}/${class_name}.h> file not found!" 1>&2
clean_and_exit 1
fi
if [ ! -e "src/lib/${subdir}/${class_name}.cpp" ]; then
echo "Error: <src/lib/${subdir}/${class_name}.cpp> file not found!" 1>&2
clean_and_exit 1
fi
if [ ! -e "tests/src/${subdir}/${class_name}_test.cpp" ]; then
echo "Error: <tests/src/${subdir}/${class_name}_test.cpp> file not found!" 1>&2
clean_and_exit 1
fi
# test if the include statement contains a double slash
result=$(grep -e "^\s*#\s*include\s*\(<[^>/]*/\{2,\}.*>\|\"[^\"/]*/\{2,\}.*\"\)\s*" tests/src/${subdir}/${class_name}_test.cpp)
if [ $? -eq 0 ]; then
echo "The tests/src/${subdir}/${class_name}_test.cpp contains an include statement with double //" 1>&2
clean_and_exit 1
fi
# Test if the include in class.cpp is correct
result=$( grep "#include" src/lib/${subdir}/${class_name}.cpp | grep "${MODULE_NAME}/${subdir}/${class_name}.h" )
if [ $? -ne 0 ]; then
echo "The ${MODULE_NAME}/${subdir}/${class_name}.h contains an wrong include statement" 1>&2
clean_and_exit 1
fi
# Test if the include is correct in the class_name_test.cpp
result=$( grep "#include" tests/src/${subdir}/${class_name}_test.cpp | grep -v boost| grep "${MODULE_NAME}/${subdir}/${class_name}.h" )
if [ $? -ne 0 ] ;then
echo "The tests/src/${subdir}/${class_name}_test.cpp contains a wrong include statement" 1>&2
clean_and_exit 1
fi
#
# Test the visibility option : simple
#
class_name_vis="ClassVisibilityTestSimple"
file_h="${MODULE_NAME}/${class_name_vis}.h"
AddCppClass ${class_name_vis} -V simple
# Check the ELEMENTS_API pattern
result=$( grep ELEMENTS_API "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains pattern : < ELEMENTS_API >" 1>&2
clean_and_exit 1
fi
# Check the include
result=$( grep "#include \"ElementsKernel/Export.h\"" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the include : < \"ElementsKernel/Export.h\" >" 1>&2
clean_and_exit 1
fi
#
# Test the visibility option : native
#
class_name_vis="ClassVisibilityTestNative"
file_h="${MODULE_NAME}/${class_name_vis}.h"
AddCppClass ${class_name_vis} -V native
# Check the EXPORT pattern
exp_str="class ${MODULE_NAME_UPPER}_EXPORT"
result=$( grep "${exp_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${exp_str} >" 1>&2
clean_and_exit 1
fi
# Check the include
pattern_str="#include \"${MODULE_NAME}_export.h\""
result=$( grep "${pattern_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
#
# Test the template option
#
class_name_temp="ClassTemplateTest"
class_name_temp_upper="$(echo $class_name_temp | tr 'a-z' 'A-Z')"
file_h="${MODULE_NAME}/${class_name_temp}.h"
file_tpp="${MODULE_NAME}/_impl/${class_name_temp}.tpp"
file_cpp="src/lib/${class_name_temp}.cpp"
AddCppClass ${class_name_temp} -t
# Make sure the .tpp files is created
if [ ! -e "${file_tpp}" ]; then
echo "Error: <${file_tpp}> file not found!" 1>&2
clean_and_exit 1
fi
# Make sure the .cpp files is created
if [ ! -e "${file_cpp}" ]; then
echo "Error: <${file_cpp}> file not found!" 1>&2
clean_and_exit 1
fi
# Make sure the .h files is created
if [ ! -e "${file_h}" ]; then
echo "Error: <${file_h}> file not found!" 1>&2
clean_and_exit 1
fi
# Check the template statement
pattern_str="template<typename T>"
result=$( grep "${pattern_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
# Check several patterns in the *.h file
pattern_str="#include \"${MODULE_NAME}/_impl/${class_name_temp}.tpp\""
result=$( grep "${pattern_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
pattern_str="#define _${MODULE_NAME_UPPER}_${MODULE_NAME_UPPER}_${class_name_temp_upper}_IMPL"
result=$( grep "${pattern_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
pattern_str="#undef _${MODULE_NAME_UPPER}_${MODULE_NAME_UPPER}_${class_name_temp_upper}_IMPL"
result=$( grep "${pattern_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
# Make sure the tpp files is created
if [ ! -e "${file_tpp}" ]; then
echo "Error: <${file_tpp}> file not found!" 1>&2
clean_and_exit 1
fi
# Check several patterns in the *.tpp file
pattern_str="#ifndef _${MODULE_NAME_UPPER}_${MODULE_NAME_UPPER}_${class_name_temp_upper}_IMPL"
result=$( grep "${pattern_str}" "${file_tpp}" )
if [ $? -ne 0 ] ;then
echo "The ${file_tpp} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
pattern_str="// template<typename T>"
result=$( grep "${pattern_str}" "${file_tpp}" )
if [ $? -ne 0 ] ;then
echo "The ${file_tpp} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
# Check pattern in the .cpp file
pattern_str="// template ${class_name_temp}<double>;"
result=$( grep "${pattern_str}" "${file_cpp}" )
if [ $? -ne 0 ] ;then
echo "The ${file_cpp} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
#
# Test the template option with a sub-directory
#
class_name_temp_subdir="ClassTemplateSubdirTest"
subdir="subdir"
file_h="${MODULE_NAME}/${subdir}/${class_name_temp_subdir}.h"
file_tpp="${MODULE_NAME}/${subdir}/_impl/${class_name_temp_subdir}.tpp"
file_cpp="src/lib/${subdir}/${class_name_temp_subdir}.cpp"
AddCppClass ${subdir}/${class_name_temp_subdir} -t
# Make sure the .tpp file is created
if [ ! -e "${file_tpp}" ]; then
echo "Error: <${file_tpp}> file not found!" 1>&2
clean_and_exit 1
fi
# Make sure the .cpp file is created
if [ ! -e "${file_cpp}" ]; then
echo "Error: <${file_cpp}> file not found!" 1>&2
clean_and_exit 1
fi
# Make sure the .h file is created
if [ ! -e "${file_h}" ]; then
echo "Error: <${file_h}> file not found!" 1>&2
clean_and_exit 1
fi
# Check include pattern in tpp file
pattern_str="#include \"${file_tpp}\""
result=$( grep "${pattern_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
# Check filename in header of .h file
pattern_str=" * @file ${file_h}"
result=$( grep "${pattern_str}" "${file_h}" )
if [ $? -ne 0 ] ;then
echo "The ${file_h} does not contains the following pattern : < ${pattern_str} >" 1>&2
clean_and_exit 1
fi
#
# Test the template option and -V option
#
class_name_temp_v="ClassTemplateVTest"
file_h="${MODULE_NAME}/${class_name_temp_v}.h"
file_tpp="${MODULE_NAME}/_impl/${class_name_temp_v}.tpp"
file_cpp="src/lib/${class_name_temp_v}.cpp"
clean_and_exit 0