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 .
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>
32 #if !defined WIN32_LEAN_AND_MEAN
33 # define WIN32_LEAN_AND_MEAN
44 class createUuid
: public CppUnit::TestFixture
50 sal_uInt8 aNode
[TEST_UUID
][16];
52 for( i
= 0 ; i
< TEST_UUID
; i
++ )
54 rtl_createUuid( aNode
[i
], nullptr, false );
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 )
70 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes
);
76 sal_uInt8 aNode[TEST_UUID][16];
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 )
94 if ( bRes == sal_False )
97 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True );
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
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] = {
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);
139 if ( rtl_compareUuid( pNamedUUID
, pNamedUUID2
) > 0 )
140 { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2
, pNamedUUID
) < 0);
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: */