Bump version to 24.04.3.4
[LibreOffice.git] / sal / qa / rtl / uuid / rtl_Uuid.cxx
blobe7b524db89fb77c339a9bbb1a6251bdf63ac235d
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 <string.h>
22 #include <rtl/uuid.h>
23 #include <cppunit/TestFixture.h>
24 #include <cppunit/extensions/HelperMacros.h>
26 #ifdef _WIN32
27 #if !defined WIN32_LEAN_AND_MEAN
28 # define WIN32_LEAN_AND_MEAN
29 #endif
30 #include <windows.h>
31 #endif
34 namespace rtl_Uuid
36 class createUuid : public CppUnit::TestFixture
38 public:
39 #define TEST_UUID 20
40 void createUuid_001()
42 sal_uInt8 aNode[TEST_UUID][16];
43 sal_Int32 i,i2;
44 for( i = 0 ; i < TEST_UUID ; i ++ )
46 rtl_createUuid( aNode[i], nullptr, false );
48 bool bRes = true;
49 for( i = 0 ; i < TEST_UUID ; i ++ )
51 for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
53 if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 )
55 bRes = false;
56 break;
59 if ( !bRes )
60 break;
62 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes);
65 void createUuid_002()
67 sal_uInt8 pNode[16];
68 sal_uInt8 aNode[TEST_UUID][16];
69 sal_Int32 i,i2;
70 for( i = 0 ; i < TEST_UUID ; i ++ )
72 rtl_createUuid( aNode[i], pNode, sal_True );
74 sal_Bool bRes = sal_True;
75 for( i = 0 ; i < TEST_UUID ; i ++ )
77 //printUuid( aNode[i] );
78 for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
80 if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 )
82 bRes = sal_False;
83 break;
86 if ( bRes == sal_False )
87 break;
89 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True );
90 }*/
92 CPPUNIT_TEST_SUITE(createUuid);
93 CPPUNIT_TEST(createUuid_001);
94 //CPPUNIT_TEST(createUuid_002);
95 CPPUNIT_TEST_SUITE_END();
96 }; // class createUuid
98 class createNamedUuid : public CppUnit::TestFixture
100 public:
101 void createNamedUuid_001()
103 sal_uInt8 NameSpace_DNS[16] = RTL_UUID_NAMESPACE_DNS;
104 sal_uInt8 NameSpace_URL[16] = RTL_UUID_NAMESPACE_URL;
105 sal_uInt8 pPriorCalculatedUUID[16] = {
106 0x52,0xc9,0x30,0xa5,
107 0xd1,0x61,0x3b,0x16,
108 0x98,0xc5,0xf8,0xd1,
109 0x10,0x10,0x6d,0x4d };
111 sal_uInt8 pNamedUUID[16], pNamedUUID2[16];
113 // Same name does generate the same uuid
114 rtl_String *pName = nullptr;
115 rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Name" );
116 rtl_createNamedUuid( pNamedUUID , NameSpace_DNS , pName );
117 rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
118 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pNamedUUID2 , 16 ));
119 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Same name should generate the same uuid", sal_Int32(0), rtl_compareUuid( pNamedUUID , pNamedUUID2 ) );
120 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pPriorCalculatedUUID , 16 ) );
122 // Different names does not generate the same uuid
123 rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Namf" );
124 rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
125 CPPUNIT_ASSERT_MESSAGE("Different names does not generate the same uuid.", memcmp( pNamedUUID , pNamedUUID2 , 16 ) );
127 // the same name with different namespace uuid produces different uuids
128 rtl_createNamedUuid( pNamedUUID , NameSpace_URL , pName );
129 CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", memcmp( pNamedUUID , pNamedUUID2 , 16 ));
130 CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", rtl_compareUuid( pNamedUUID , pNamedUUID2 ) != 0);
132 //test compareUuid
133 if ( rtl_compareUuid( pNamedUUID , pNamedUUID2 ) > 0 )
134 { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) < 0);
136 else
137 CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) > 0);
139 rtl_string_release( pName );
142 CPPUNIT_TEST_SUITE(createNamedUuid);
143 CPPUNIT_TEST(createNamedUuid_001);
144 CPPUNIT_TEST_SUITE_END();
145 }; // class createNamedUuid
147 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createUuid);
148 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createNamedUuid);
149 } // namespace rtl_Uuid
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */