bump product version to 5.0.4.1
[LibreOffice.git] / sal / qa / rtl / uuid / rtl_Uuid.cxx
blobd20c38a67ad9c9725d41744b97fe6c22468f5f6f
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 WNT
32 #include <windows.h>
33 #elif defined UNX
34 #include <unistd.h>
35 #include <time.h>
36 #endif
38 using ::rtl::OUString;
39 using ::rtl::OUStringToOString;
40 using ::rtl::OString;
42 namespace rtl_Uuid
44 class createUuid : public CppUnit::TestFixture
46 public:
47 // initialise your test code values here.
48 void setUp() SAL_OVERRIDE
52 void tearDown() SAL_OVERRIDE
56 #define TEST_UUID 20
57 void createUuid_001()
59 sal_uInt8 aNode[TEST_UUID][16];
60 sal_Int32 i,i2;
61 for( i = 0 ; i < TEST_UUID ; i ++ )
63 rtl_createUuid( aNode[i], 0, sal_False );
65 bool bRes = true;
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 )
72 bRes = false;
73 break;
76 if ( !bRes )
77 break;
79 CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes);
82 void createUuid_002()
84 sal_uInt8 pNode[16];
85 sal_uInt8 aNode[TEST_UUID][16];
86 sal_Int32 i,i2;
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 )
99 bRes = sal_False;
100 break;
103 if ( bRes == sal_False )
104 break;
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
117 public:
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] = {
132 0x52,0xc9,0x30,0xa5,
133 0xd1,0x61,0x3b,0x16,
134 0x98,0xc5,0xf8,0xd1,
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);
156 //test compareUuid
157 if ( rtl_compareUuid( pNamedUUID , pNamedUUID2 ) > 0 )
158 { CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) < 0);
160 else
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: */