Bump version to 6.4-15
[LibreOffice.git] / sal / qa / rtl / uuid / rtl_Uuid.cxx
blobb77e84afe2ffd58595b1ae4ce2fd733e54cca22b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <math.h>
21 #include <stdio.h>
22 #include <string.h>
24 #include <rtl/uuid.h>
25 #include <rtl/ustring.h>
26 #include <rtl/ustring.hxx>
27 #include <cppunit/TestFixture.h>
28 #include <cppunit/extensions/HelperMacros.h>
29 #include <cppunit/plugin/TestPlugIn.h>
31 #ifdef _WIN32
32 #if !defined WIN32_LEAN_AND_MEAN
33 # define WIN32_LEAN_AND_MEAN
34 #endif
35 #include <windows.h>
36 #elif defined UNX
37 #include <unistd.h>
38 #include <time.h>
39 #endif
42 namespace rtl_Uuid
44 class createUuid : public CppUnit::TestFixture
46 public:
47 #define TEST_UUID 20
48 void createUuid_001()
50 sal_uInt8 aNode[TEST_UUID][16];
51 sal_Int32 i,i2;
52 for( i = 0 ; i < TEST_UUID ; i ++ )
54 rtl_createUuid( aNode[i], nullptr, false );
56 bool bRes = true;
57 for( i = 0 ; i < TEST_UUID ; i ++ )
59 for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
61 if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 )
63 bRes = false;
64 break;
67 if ( !bRes )
68 break;
70 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes);
73 void createUuid_002()
75 sal_uInt8 pNode[16];
76 sal_uInt8 aNode[TEST_UUID][16];
77 sal_Int32 i,i2;
78 for( i = 0 ; i < TEST_UUID ; i ++ )
80 rtl_createUuid( aNode[i], pNode, sal_True );
82 sal_Bool bRes = sal_True;
83 for( i = 0 ; i < TEST_UUID ; i ++ )
85 //printUuid( aNode[i] );
86 for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
88 if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 )
90 bRes = sal_False;
91 break;
94 if ( bRes == sal_False )
95 break;
97 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True );
98 }*/
100 CPPUNIT_TEST_SUITE(createUuid);
101 CPPUNIT_TEST(createUuid_001);
102 //CPPUNIT_TEST(createUuid_002);
103 CPPUNIT_TEST_SUITE_END();
104 }; // class createUuid
106 class createNamedUuid : public CppUnit::TestFixture
108 public:
109 void createNamedUuid_001()
111 sal_uInt8 NameSpace_DNS[16] = RTL_UUID_NAMESPACE_DNS;
112 sal_uInt8 NameSpace_URL[16] = RTL_UUID_NAMESPACE_URL;
113 sal_uInt8 pPriorCalculatedUUID[16] = {
114 0x52,0xc9,0x30,0xa5,
115 0xd1,0x61,0x3b,0x16,
116 0x98,0xc5,0xf8,0xd1,
117 0x10,0x10,0x6d,0x4d };
119 sal_uInt8 pNamedUUID[16], pNamedUUID2[16];
121 // Same name does generate the same uuid
122 rtl_String *pName = nullptr;
123 rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Name" );
124 rtl_createNamedUuid( pNamedUUID , NameSpace_DNS , pName );
125 rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
126 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) == 0 );
127 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pPriorCalculatedUUID , 16 ) );
129 // Different names does not generate the same uuid
130 rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Namf" );
131 rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
132 CPPUNIT_ASSERT_MESSAGE("Different names does not generate the same uuid.", memcmp( pNamedUUID , pNamedUUID2 , 16 ) );
134 // the same name with different namespace uuid produces different uuids
135 rtl_createNamedUuid( pNamedUUID , NameSpace_URL , pName );
136 CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) != 0);
138 //test compareUuid
139 if ( rtl_compareUuid( pNamedUUID , pNamedUUID2 ) > 0 )
140 { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) < 0);
142 else
143 CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) > 0);
145 rtl_string_release( pName );
148 CPPUNIT_TEST_SUITE(createNamedUuid);
149 CPPUNIT_TEST(createNamedUuid_001);
150 CPPUNIT_TEST_SUITE_END();
151 }; // class createNamedUuid
153 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createUuid);
154 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createNamedUuid);
155 } // namespace rtl_Uuid
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */