1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <cppunit/TestFixture.h>
24 #include <cppunit/extensions/HelperMacros.h>
27 #if !defined WIN32_LEAN_AND_MEAN
28 # define WIN32_LEAN_AND_MEAN
36 class createUuid
: public CppUnit::TestFixture
42 sal_uInt8 aNode
[TEST_UUID
][16];
44 for( i
= 0 ; i
< TEST_UUID
; i
++ )
46 rtl_createUuid( aNode
[i
], nullptr, false );
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 )
62 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes
);
68 sal_uInt8 aNode[TEST_UUID][16];
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 )
86 if ( bRes == sal_False )
89 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True );
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
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] = {
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);
133 if ( rtl_compareUuid( pNamedUUID
, pNamedUUID2
) > 0 )
134 { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2
, pNamedUUID
) < 0);
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: */