1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
34 #include <testshl/simpleheader.hxx>
36 #include <rtl/ustring.h>
37 #include <rtl/ustring.hxx>
46 /** print a UNI_CODE String. And also print some comments of the string.
48 inline void printUString( const ::rtl::OUString
& str
, const sal_Char
* msg
= "" )
50 t_print("#%s #printUString_u# ", msg
);
52 aString
= ::rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
53 t_print("%s\n", (char *)aString
.getStr( ) );
56 /************************************************************************
57 * For diagnostics( from sal/test/testuuid.cxx )
58 ************************************************************************/
60 void printUuid( sal_uInt8
*pNode
)
62 for( sal_Int32 i1
= 0 ; i1
< 4 ; i1
++ )
64 for( sal_Int32 i2
= 0 ; i2
< 4 ; i2
++ )
66 printf( "%02x" , pNode
[i1
*4 +i2
] );
78 class createUuid
: public CppUnit::TestFixture
81 // initialise your test code values here.
93 sal_uInt8 aNode
[TEST_UUID
][16];
95 for( i
= 0 ; i
< TEST_UUID
; i
++ )
97 rtl_createUuid( aNode
[i
], 0, sal_False
);
99 sal_Bool bRes
= sal_True
;
100 for( i
= 0 ; i
< TEST_UUID
; i
++ )
102 for( i2
= i
+1 ; i2
< TEST_UUID
; i2
++ )
104 if ( rtl_compareUuid( aNode
[i
] , aNode
[i2
] ) == 0 )
110 if ( bRes
== sal_False
)
113 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes
== sal_True
);
116 void createUuid_002()
119 sal_uInt8 aNode[TEST_UUID][16];
121 for( i = 0 ; i < TEST_UUID ; i ++ )
123 rtl_createUuid( aNode[i], pNode, sal_True );
125 sal_Bool bRes = sal_True;
126 for( i = 0 ; i < TEST_UUID ; i ++ )
128 //printUuid( aNode[i] );
129 for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
131 if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 )
137 if ( bRes == sal_False )
140 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True );
143 CPPUNIT_TEST_SUITE(createUuid
);
144 CPPUNIT_TEST(createUuid_001
);
145 //CPPUNIT_TEST(createUuid_002);
146 CPPUNIT_TEST_SUITE_END();
147 }; // class createUuid
149 namespace ThreadHelper
151 void thread_sleep(sal_Int32 _nSec
)
156 #if ( defined UNX ) || ( defined OS2 ) //Unix
162 class createNamedUuid
: public CppUnit::TestFixture
165 // initialise your test code values here.
174 void createNamedUuid_001()
176 sal_uInt8 NameSpace_DNS
[16] = RTL_UUID_NAMESPACE_DNS
;
177 sal_uInt8 NameSpace_URL
[16] = RTL_UUID_NAMESPACE_URL
;
178 sal_uInt8 pPriorCalculatedUUID
[16] = {
182 0x10,0x10,0x6d,0x4d };
184 sal_uInt8 pNamedUUID
[16], pNamedUUID2
[16];
186 // Same name does generate the same uuid
187 rtl_String
*pName
= 0;
188 rtl_string_newFromStr( &pName
, "this is a bla.blubs.DNS-Name" );
189 rtl_createNamedUuid( pNamedUUID
, NameSpace_DNS
, pName
);
190 rtl_createNamedUuid( pNamedUUID2
, NameSpace_DNS
, pName
);
191 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID
, pNamedUUID2
, 16 ) && rtl_compareUuid( pNamedUUID
, pNamedUUID2
) == 0 );
192 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID
, pPriorCalculatedUUID
, 16 ) );
194 // Different names does not generate the same uuid
195 rtl_string_newFromStr( &pName
, "this is a bla.blubs.DNS-Namf" );
196 rtl_createNamedUuid( pNamedUUID2
, NameSpace_DNS
, pName
);
197 CPPUNIT_ASSERT_MESSAGE("Different names does not generate the same uuid.", memcmp( pNamedUUID
, pNamedUUID2
, 16 ) );
199 // the same name with different namespace uuid produces different uuids
200 rtl_createNamedUuid( pNamedUUID
, NameSpace_URL
, pName
);
201 CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", memcmp( pNamedUUID
, pNamedUUID2
, 16 ) && rtl_compareUuid( pNamedUUID
, pNamedUUID2
) != 0);
204 if ( rtl_compareUuid( pNamedUUID
, pNamedUUID2
) > 0 )
205 { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2
, pNamedUUID
) < 0);
208 CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2
, pNamedUUID
) > 0);
210 rtl_string_release( pName
);
213 CPPUNIT_TEST_SUITE(createNamedUuid
);
214 CPPUNIT_TEST(createNamedUuid_001
);
215 CPPUNIT_TEST_SUITE_END();
216 }; // class createNamedUuid
218 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Uuid::createUuid
, "rtl_Uuid");
219 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_Uuid::createNamedUuid
, "rtl_Uuid");
220 } // namespace rtl_Uuid
222 // -----------------------------------------------------------------------------
224 // this macro creates an empty function, which will called by the RegisterAllFunctions()
225 // to let the user the possibility to also register some functions by hand.