3
pwd | grep "koffice/plugins/chartshape/tests/odf$" > /dev/null
4
# If grep returns 1 (instead of 0), the string wasn't found in pwd's output
6
echo "Error: This script must be run from koffice/plugins/chartshape/tests/odf"
10
echo "Usage: $0 test-document.[odt|ods|odp] test-name"
14
# The document to create the test case from, e.g. "/path/to/test-doc.odt"
16
# Extract document name
17
doc_name=`echo $doc | sed "s/.*\///"`
18
# The name of the test case, e.g. "mytest"
20
uppercase_name=`echo $name | tr [:lower:] [:upper:] | tr - _`
23
echo "A test case with the name \"$name\" already exists. Aborting."
27
echo $name | grep -v [\ \;\,\\\/] > /dev/null
29
echo "The test name must not contain spaces or any other special characters. Aborting"
33
# 1) Create new test folder from template/
34
cp -r template/ "$name"
36
# 2) TODO: Replace template's placeholders
37
sed -i "" "s/@@NAME@@/$name/g" "$name/CMakeLists.txt"
38
sed -i "" "s/@@UPPERCASE_NAME@@/$uppercase_name/g" "$name/TestLoading.h"
40
echo "========= Info ========="
41
echo "Don't forget to fill in @@COPYRIGHT@@ in TestLoading.h and TestLoading.cpp."
43
# 3) Keep a copy or original document
49
echo "add_subdirectory( $name )" >> CMakeLists.txt
52
echo "========= Added test case to ./CMakeLists.txt ========="
55
echo "========= Extracting $doc_name ========="
57
unzip "$doc" -d "$doc_path/orig"
59
# Remove object replacements, we don't need them and the directory name
60
# "ObjectReplacements" gets in the way of looking for objects with the pattern Object*
61
rm -rf "$doc_path/orig/ObjectReplacements"
63
# 5) Find chart document
64
# If Chart* or Object* is expended to a valid directory name, this means there is only
65
# one embedded object, which we will assume is the chart.
66
chart_doc_path=`echo "$doc_path/orig/"Chart*`
68
if [ ! -d "$chart_doc_path" ]; then
69
chart_doc_path=`echo "$doc_path/orig/"Object*`
72
if [ -d "$chart_doc_path" ]; then
73
mv "$chart_doc_path/content.xml" "$doc_path/content.xml"
74
mv "$chart_doc_path/styles.xml" "$doc_path/styles.xml"
75
if [ -e "$chart_doc_path/meta.xml" ]; then
76
mv "$chart_doc_path/meta.xml" "$doc_path/meta.xml"
78
if [ -e "$doc_path/orig/meta.xml" ]; then
79
mv "$doc_path/orig/meta.xml" "$doc_path/meta.xml"
80
echo "Warning: No meta.xml found in chart document. Instead the embedding document's meta.xml was used. This should work, but might lead to problems in the loading process."
82
echo "Warning: No meta.xml found. Workarounds for ODF bugs in other office suites don't work if the document's creator is unknown."
87
echo "========= Process not yet completed ========="
88
echo "There is more than one embedded object in this document. Look in $doc_path/orig and find the chart document's directory, e.g. \"Object 3\". Then copy the meta.xml, styles.xml and content.xml from there to $doc_path/. After that you can safely remove $doc_path/orig/ and you're done."
93
rm -rf "$doc_path/orig"
96
echo "========= Successfully created test case \"$name\"! ========="