summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2013-09-30 15:23:35 +0300
committerTor Lillqvist <tml@collabora.com>2013-09-30 17:40:53 +0300
commitc1015fdd51909495cefdc0258c3899cd73d4d2df (patch)
tree901f0fb94a93dbd614c18d3320bcfa414672e441 /sfx2
parent32e0f451d69b68d69a4aa91c271b81ea6264d3c1 (diff)
Add hack to optionally get stable ODF output from the same input
To be used in regression testing and similar scenarios, where the output ODF is *not* intended to be further manipulated in LibreOffice. An environment variable LIBO_ONEWAY_STABLE_ODF_EXPORT is used to toggle this behaviour. I am not 100% sure whether the generated ODF with the hack toggled on is even fully correct, but correctness is not the purpose of the hack anyway. Two classes of issues handled: 1) Automatic style names and 2) use of randomness. For class 1), when the hack toggle is in effect, we generate the names at first as strings based on all the properties of the style, and sort them based on those, and then rename them (for brevity in the output) to the "normal" form of a short prefix plus a number (like "P12"). Sure, it would have been better to just figure out *why* the automatic style naming currently is not stable in the first place, but outputs the styles in different order (with some styles being assigned different numbers) in separate invokations of LibreOffice), but I was unable to understand that. Possibly this code could be used in all cases, except that it does break some unit test (can't recall which right now). I don't know whether that is simply because the unit test assumes too much knowledge of the internal workings of the automatic style name generation, or whether the generated ODF is actually invalid. For 2), I found a handful of places where randomness was used to generated various kinds of identifiers in ODF output. I changed those to just use large (64-bit) non-overlapping integers instead. I assume there *is* a point in the original code in each case that explains why randomness is needed, so the hack definitely needs to be optional and used only for the above mentioned scenarios. Change-Id: I17b657197e38bcf24abdfe61ad4a277f4339eeae
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/Metadatable.cxx29
1 files changed, 22 insertions, 7 deletions
diff --git a/sfx2/source/doc/Metadatable.cxx b/sfx2/source/doc/Metadatable.cxx
index d7528f63de40..ae4a72368658 100644
--- a/sfx2/source/doc/Metadatable.cxx
+++ b/sfx2/source/doc/Metadatable.cxx
@@ -394,19 +394,34 @@ template< typename T >
/*static*/ OUString create_id(const
::boost::unordered_map< OUString, T, OUStringHash > & i_rXmlIdMap)
{
- static rtlRandomPool s_Pool( rtl_random_createPool() );
+ static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != NULL);
const OUString prefix(s_prefix);
typename ::boost::unordered_map< OUString, T, OUStringHash >
::const_iterator iter;
OUString id;
- do
+
+ if (bHack)
+ {
+ static sal_Int64 nIdCounter = SAL_CONST_INT64(4000000000);
+ do
+ {
+ id = prefix + OUString::number(nIdCounter++);
+ iter = i_rXmlIdMap.find(id);
+ }
+ while (iter != i_rXmlIdMap.end());
+ }
+ else
{
- sal_Int32 n;
- rtl_random_getBytes(s_Pool, & n, sizeof(n));
- id = prefix + OUString::number(abs(n));
- iter = i_rXmlIdMap.find(id);
+ static rtlRandomPool s_Pool( rtl_random_createPool() );
+ do
+ {
+ sal_Int32 n;
+ rtl_random_getBytes(s_Pool, & n, sizeof(n));
+ id = prefix + OUString::number(abs(n));
+ iter = i_rXmlIdMap.find(id);
+ }
+ while (iter != i_rXmlIdMap.end());
}
- while (iter != i_rXmlIdMap.end());
return id;
}