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>
38 using ::rtl::OUString
;
39 using ::rtl::OUStringToOString
;
44 class createUuid
: public CppUnit::TestFixture
47 // initialise your test code values here.
48 void setUp() SAL_OVERRIDE
52 void tearDown() SAL_OVERRIDE
59 sal_uInt8 aNode
[TEST_UUID
][16];
61 for( i
= 0 ; i
< TEST_UUID
; i
++ )
63 rtl_createUuid( aNode
[i
], 0, sal_False
);
66 for( i
= 0 ; i
< TEST_UUID
; i
++ )
68 for( i2
= i
+1 ; i2
< TEST_UUID
; i2
++ )
70 if ( rtl_compareUuid( aNode
[i
] , aNode
[i2
] ) == 0 )
79 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes
);
85 sal_uInt8 aNode[TEST_UUID][16];
87 for( i = 0 ; i < TEST_UUID ; i ++ )
89 rtl_createUuid( aNode[i], pNode, sal_True );
91 sal_Bool bRes = sal_True;
92 for( i = 0 ; i < TEST_UUID ; i ++ )
94 //printUuid( aNode[i] );
95 for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
97 if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0 )
103 if ( bRes == sal_False )
106 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True );
109 CPPUNIT_TEST_SUITE(createUuid
);
110 CPPUNIT_TEST(createUuid_001
);
111 //CPPUNIT_TEST(createUuid_002);
112 CPPUNIT_TEST_SUITE_END();
113 }; // class createUuid
115 class createNamedUuid
: public CppUnit::TestFixture
118 // initialise your test code values here.
119 void setUp() SAL_OVERRIDE
123 void tearDown() SAL_OVERRIDE
127 void createNamedUuid_001()
129 sal_uInt8 NameSpace_DNS
[16] = RTL_UUID_NAMESPACE_DNS
;
130 sal_uInt8 NameSpace_URL
[16] = RTL_UUID_NAMESPACE_URL
;
131 sal_uInt8 pPriorCalculatedUUID
[16] = {
135 0x10,0x10,0x6d,0x4d };
137 sal_uInt8 pNamedUUID
[16], pNamedUUID2
[16];
139 // Same name does generate the same uuid
140 rtl_String
*pName
= 0;
141 rtl_string_newFromStr( &pName
, "this is a bla.blubs.DNS-Name" );
142 rtl_createNamedUuid( pNamedUUID
, NameSpace_DNS
, pName
);
143 rtl_createNamedUuid( pNamedUUID2
, NameSpace_DNS
, pName
);
144 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID
, pNamedUUID2
, 16 ) && rtl_compareUuid( pNamedUUID
, pNamedUUID2
) == 0 );
145 CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID
, pPriorCalculatedUUID
, 16 ) );
147 // Different names does not generate the same uuid
148 rtl_string_newFromStr( &pName
, "this is a bla.blubs.DNS-Namf" );
149 rtl_createNamedUuid( pNamedUUID2
, NameSpace_DNS
, pName
);
150 CPPUNIT_ASSERT_MESSAGE("Different names does not generate the same uuid.", memcmp( pNamedUUID
, pNamedUUID2
, 16 ) );
152 // the same name with different namespace uuid produces different uuids
153 rtl_createNamedUuid( pNamedUUID
, NameSpace_URL
, pName
);
154 CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", memcmp( pNamedUUID
, pNamedUUID2
, 16 ) && rtl_compareUuid( pNamedUUID
, pNamedUUID2
) != 0);
157 if ( rtl_compareUuid( pNamedUUID
, pNamedUUID2
) > 0 )
158 { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2
, pNamedUUID
) < 0);
161 CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2
, pNamedUUID
) > 0);
163 rtl_string_release( pName
);
166 CPPUNIT_TEST_SUITE(createNamedUuid
);
167 CPPUNIT_TEST(createNamedUuid_001
);
168 CPPUNIT_TEST_SUITE_END();
169 }; // class createNamedUuid
171 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createUuid
);
172 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createNamedUuid
);
173 } // namespace rtl_Uuid
175 // this macro creates an empty function, which will called by the RegisterAllFunctions()
176 // to let the user the possibility to also register some functions by hand.
177 CPPUNIT_PLUGIN_IMPLEMENT();
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */