187d2adbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 387d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 487d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 587d2adbcSAndrew Rist * distributed with this work for additional information 687d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 787d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 887d2adbcSAndrew Rist * "License"); you may not use this file except in compliance 987d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at 1087d2adbcSAndrew Rist * 1187d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1287d2adbcSAndrew Rist * 1387d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 1487d2adbcSAndrew Rist * software distributed under the License is distributed on an 1587d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1687d2adbcSAndrew Rist * KIND, either express or implied. See the License for the 1787d2adbcSAndrew Rist * specific language governing permissions and limitations 1887d2adbcSAndrew Rist * under the License. 1987d2adbcSAndrew Rist * 2087d2adbcSAndrew Rist *************************************************************/ 2187d2adbcSAndrew Rist 2287d2adbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sal.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <math.h> 28cdf0e10cSrcweir #include <stdio.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <rtl/uuid.h> 31cdf0e10cSrcweir #include <rtl/ustring.h> 32cdf0e10cSrcweir #include <rtl/ustring.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #ifdef UNX 35cdf0e10cSrcweir #include <unistd.h> 36cdf0e10cSrcweir #include <time.h> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir 39*eaff1a1bSDamjan Jovanovic #include "gtest/gtest.h" 40*eaff1a1bSDamjan Jovanovic 41cdf0e10cSrcweir using namespace rtl; 42cdf0e10cSrcweir 43cdf0e10cSrcweir /** print a UNI_CODE String. And also print some comments of the string. 44cdf0e10cSrcweir */ 45cdf0e10cSrcweir inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" ) 46cdf0e10cSrcweir { 47*eaff1a1bSDamjan Jovanovic printf("#%s #printUString_u# ", msg ); 48cdf0e10cSrcweir rtl::OString aString; 49cdf0e10cSrcweir aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); 50*eaff1a1bSDamjan Jovanovic printf("%s\n", (char *)aString.getStr( ) ); 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir /************************************************************************ 54cdf0e10cSrcweir * For diagnostics( from sal/test/testuuid.cxx ) 55cdf0e10cSrcweir ************************************************************************/ 56cdf0e10cSrcweir 57cdf0e10cSrcweir void printUuid( sal_uInt8 *pNode ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir for( sal_Int32 i1 = 0 ; i1 < 4 ; i1++ ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir for( sal_Int32 i2 = 0 ; i2 < 4 ; i2++ ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir printf( "%02x" , pNode[i1*4 +i2] ); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir if( i1 == 3 ) 66cdf0e10cSrcweir break; 67cdf0e10cSrcweir printf( "-" ); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir printf( "\n# " ); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir namespace rtl_Uuid 74cdf0e10cSrcweir { 75*eaff1a1bSDamjan Jovanovic class createUuid : public ::testing::Test 76cdf0e10cSrcweir { 77cdf0e10cSrcweir public: 78cdf0e10cSrcweir // initialise your test code values here. 79*eaff1a1bSDamjan Jovanovic void SetUp() 80cdf0e10cSrcweir { 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83*eaff1a1bSDamjan Jovanovic void TearDown() 84cdf0e10cSrcweir { 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87*eaff1a1bSDamjan Jovanovic }; // class createUuid 88*eaff1a1bSDamjan Jovanovic 89cdf0e10cSrcweir #define TEST_UUID 20 90*eaff1a1bSDamjan Jovanovic TEST_F(createUuid, createUuid_001) 91*eaff1a1bSDamjan Jovanovic { 92*eaff1a1bSDamjan Jovanovic sal_uInt8 aNode[TEST_UUID][16]; 93*eaff1a1bSDamjan Jovanovic sal_Int32 i,i2; 94*eaff1a1bSDamjan Jovanovic for( i = 0 ; i < TEST_UUID ; i ++ ) 95cdf0e10cSrcweir { 96*eaff1a1bSDamjan Jovanovic rtl_createUuid( aNode[i], 0, sal_False ); 97cdf0e10cSrcweir } 98*eaff1a1bSDamjan Jovanovic sal_Bool bRes = sal_True; 99*eaff1a1bSDamjan Jovanovic for( i = 0 ; i < TEST_UUID ; i ++ ) 100cdf0e10cSrcweir { 101*eaff1a1bSDamjan Jovanovic for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ ) 102*eaff1a1bSDamjan Jovanovic { 103*eaff1a1bSDamjan Jovanovic if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 ) 104*eaff1a1bSDamjan Jovanovic { 105*eaff1a1bSDamjan Jovanovic bRes = sal_False; 106*eaff1a1bSDamjan Jovanovic break; 107*eaff1a1bSDamjan Jovanovic } 108*eaff1a1bSDamjan Jovanovic } 109*eaff1a1bSDamjan Jovanovic if ( bRes == sal_False ) 110*eaff1a1bSDamjan Jovanovic break; 111*eaff1a1bSDamjan Jovanovic } 112*eaff1a1bSDamjan Jovanovic ASSERT_TRUE(bRes == sal_True) << "createUuid: every uuid must be different."; 113*eaff1a1bSDamjan Jovanovic } 114cdf0e10cSrcweir 115*eaff1a1bSDamjan Jovanovic /* 116*eaff1a1bSDamjan Jovanovic TEST_F(createUuid, createUuid_002) 117*eaff1a1bSDamjan Jovanovic { 118*eaff1a1bSDamjan Jovanovic sal_uInt8 pNode[16]; 119*eaff1a1bSDamjan Jovanovic sal_uInt8 aNode[TEST_UUID][16]; 120*eaff1a1bSDamjan Jovanovic sal_Int32 i,i2; 121*eaff1a1bSDamjan Jovanovic for( i = 0 ; i < TEST_UUID ; i ++ ) 122*eaff1a1bSDamjan Jovanovic { 123*eaff1a1bSDamjan Jovanovic rtl_createUuid( aNode[i], pNode, sal_True ); 124*eaff1a1bSDamjan Jovanovic } 125*eaff1a1bSDamjan Jovanovic sal_Bool bRes = sal_True; 126*eaff1a1bSDamjan Jovanovic for( i = 0 ; i < TEST_UUID ; i ++ ) 127*eaff1a1bSDamjan Jovanovic { 128*eaff1a1bSDamjan Jovanovic //printUuid( aNode[i] ); 129*eaff1a1bSDamjan Jovanovic for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ ) 130*eaff1a1bSDamjan Jovanovic { 131*eaff1a1bSDamjan Jovanovic if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 ) 132*eaff1a1bSDamjan Jovanovic { 133*eaff1a1bSDamjan Jovanovic bRes = sal_False; 134*eaff1a1bSDamjan Jovanovic break; 135*eaff1a1bSDamjan Jovanovic } 136*eaff1a1bSDamjan Jovanovic } 137*eaff1a1bSDamjan Jovanovic if ( bRes == sal_False ) 138*eaff1a1bSDamjan Jovanovic break; 139*eaff1a1bSDamjan Jovanovic } 140*eaff1a1bSDamjan Jovanovic ASSERT_TRUE(bRes == sal_True) << "createUuid: every uuid must be different."; 141*eaff1a1bSDamjan Jovanovic }*/ 142cdf0e10cSrcweir 143cdf0e10cSrcweir namespace ThreadHelper 144cdf0e10cSrcweir { 145cdf0e10cSrcweir void thread_sleep(sal_Int32 _nSec) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir #ifdef WNT //Windows 148cdf0e10cSrcweir Sleep(_nSec * 10 ); 149cdf0e10cSrcweir #endif 150cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 ) //Unix 151cdf0e10cSrcweir sleep( _nSec ); 152cdf0e10cSrcweir #endif 153cdf0e10cSrcweir } 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156*eaff1a1bSDamjan Jovanovic class createNamedUuid : public ::testing::Test 157cdf0e10cSrcweir { 158cdf0e10cSrcweir public: 159cdf0e10cSrcweir // initialise your test code values here. 160*eaff1a1bSDamjan Jovanovic void SetUp() 161cdf0e10cSrcweir { 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164*eaff1a1bSDamjan Jovanovic void TearDown() 165cdf0e10cSrcweir { 166cdf0e10cSrcweir } 167*eaff1a1bSDamjan Jovanovic }; // class createNamedUuid 168cdf0e10cSrcweir 169*eaff1a1bSDamjan Jovanovic TEST_F(createNamedUuid, createNamedUuid_001) 170*eaff1a1bSDamjan Jovanovic { 171*eaff1a1bSDamjan Jovanovic sal_uInt8 NameSpace_DNS[16] = RTL_UUID_NAMESPACE_DNS; 172*eaff1a1bSDamjan Jovanovic sal_uInt8 NameSpace_URL[16] = RTL_UUID_NAMESPACE_URL; 173*eaff1a1bSDamjan Jovanovic sal_uInt8 pPriorCalculatedUUID[16] = { 174*eaff1a1bSDamjan Jovanovic 0x52,0xc9,0x30,0xa5, 175*eaff1a1bSDamjan Jovanovic 0xd1,0x61,0x3b,0x16, 176*eaff1a1bSDamjan Jovanovic 0x98,0xc5,0xf8,0xd1, 177*eaff1a1bSDamjan Jovanovic 0x10,0x10,0x6d,0x4d }; 178*eaff1a1bSDamjan Jovanovic 179*eaff1a1bSDamjan Jovanovic sal_uInt8 pNamedUUID[16], pNamedUUID2[16]; 180*eaff1a1bSDamjan Jovanovic 181*eaff1a1bSDamjan Jovanovic // Same name does generate the same uuid 182*eaff1a1bSDamjan Jovanovic rtl_String *pName = 0; 183*eaff1a1bSDamjan Jovanovic rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Name" ); 184*eaff1a1bSDamjan Jovanovic rtl_createNamedUuid( pNamedUUID , NameSpace_DNS , pName ); 185*eaff1a1bSDamjan Jovanovic rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName ); 186*eaff1a1bSDamjan Jovanovic ASSERT_TRUE(! memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) == 0) 187*eaff1a1bSDamjan Jovanovic << "Same name should generate the same uuid"; 188*eaff1a1bSDamjan Jovanovic ASSERT_TRUE(! memcmp( pNamedUUID , pPriorCalculatedUUID , 16 )) << "Same name should generate the same uuid"; 189*eaff1a1bSDamjan Jovanovic 190*eaff1a1bSDamjan Jovanovic // Different names does not generate the same uuid 191*eaff1a1bSDamjan Jovanovic rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Namf" ); 192*eaff1a1bSDamjan Jovanovic rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName ); 193*eaff1a1bSDamjan Jovanovic ASSERT_TRUE(memcmp( pNamedUUID , pNamedUUID2 , 16 )) << "Different names does not generate the same uuid."; 194*eaff1a1bSDamjan Jovanovic 195*eaff1a1bSDamjan Jovanovic // the same name with different namespace uuid produces different uuids 196*eaff1a1bSDamjan Jovanovic rtl_createNamedUuid( pNamedUUID , NameSpace_URL , pName ); 197*eaff1a1bSDamjan Jovanovic ASSERT_TRUE(memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) != 0) 198*eaff1a1bSDamjan Jovanovic << " same name with different namespace uuid produces different uuids"; 199*eaff1a1bSDamjan Jovanovic 200*eaff1a1bSDamjan Jovanovic //test compareUuid 201*eaff1a1bSDamjan Jovanovic if ( rtl_compareUuid( pNamedUUID , pNamedUUID2 ) > 0 ) 202*eaff1a1bSDamjan Jovanovic { ASSERT_TRUE(rtl_compareUuid( pNamedUUID2 , pNamedUUID ) < 0) << " compare uuids"; 203cdf0e10cSrcweir } 204*eaff1a1bSDamjan Jovanovic else 205*eaff1a1bSDamjan Jovanovic ASSERT_TRUE(rtl_compareUuid( pNamedUUID2 , pNamedUUID ) > 0) << " compare uuids"; 206cdf0e10cSrcweir 207*eaff1a1bSDamjan Jovanovic rtl_string_release( pName ); 208*eaff1a1bSDamjan Jovanovic } 209cdf0e10cSrcweir 210cdf0e10cSrcweir } // namespace rtl_Uuid 211cdf0e10cSrcweir 212*eaff1a1bSDamjan Jovanovic int main(int argc, char **argv) 213*eaff1a1bSDamjan Jovanovic { 214*eaff1a1bSDamjan Jovanovic ::testing::InitGoogleTest(&argc, argv); 215*eaff1a1bSDamjan Jovanovic return RUN_ALL_TESTS(); 216*eaff1a1bSDamjan Jovanovic } 217