LCOV - code coverage report
Current view: top level - sal/qa/rtl/uuid - rtl_Uuid.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 48 52 92.3 %
Date: 2015-06-13 12:38:46 Functions: 27 28 96.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <math.h>
      21             : #include <stdio.h>
      22             : #include <string.h>
      23             : 
      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>
      30             : 
      31             : #ifdef WNT
      32             : #include <windows.h>
      33             : #elif defined UNX
      34             : #include <unistd.h>
      35             : #include <time.h>
      36             : #endif
      37             : 
      38             : using ::rtl::OUString;
      39             : using ::rtl::OUStringToOString;
      40             : using ::rtl::OString;
      41             : 
      42             : namespace rtl_Uuid
      43             : {
      44           3 : class createUuid : public CppUnit::TestFixture
      45             : {
      46             : public:
      47             :     // initialise your test code values here.
      48           1 :     void setUp() SAL_OVERRIDE
      49             :     {
      50           1 :     }
      51             : 
      52           1 :     void tearDown() SAL_OVERRIDE
      53             :     {
      54           1 :     }
      55             : 
      56             : #define TEST_UUID 20
      57           1 :     void createUuid_001()
      58             :     {
      59             :     sal_uInt8 aNode[TEST_UUID][16];
      60             :     sal_Int32 i,i2;
      61          21 :     for( i = 0 ; i < TEST_UUID ; i ++ )
      62             :     {
      63          20 :         rtl_createUuid( aNode[i], 0, sal_False );
      64             :     }
      65           1 :     bool bRes = true;
      66          21 :     for( i = 0 ; i < TEST_UUID ; i ++ )
      67             :     {
      68         210 :         for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
      69             :         {
      70         190 :             if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0  )
      71             :             {
      72           0 :                 bRes = false;
      73           0 :                 break;
      74             :             }
      75             :         }
      76          20 :         if ( !bRes )
      77           0 :             break;
      78             :     }
      79           1 :     CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes);
      80           1 :     }
      81             :    /*
      82             :     void createUuid_002()
      83             :     {
      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 ++ )
      88             :     {
      89             :         rtl_createUuid( aNode[i], pNode, sal_True );
      90             :     }
      91             :     sal_Bool bRes = sal_True;
      92             :     for( i = 0 ; i < TEST_UUID ; i ++ )
      93             :     {
      94             :         //printUuid( aNode[i] );
      95             :         for( i2 = i+1 ; i2 < TEST_UUID ; i2 ++ )
      96             :         {
      97             :             if ( rtl_compareUuid( aNode[i] , aNode[i2] ) == 0  )
      98             :             {
      99             :                 bRes = sal_False;
     100             :                 break;
     101             :             }
     102             :         }
     103             :         if ( bRes == sal_False )
     104             :             break;
     105             :     }
     106             :     CPPUNIT_ASSERT_MESSAGE("createUuid: every uuid must be different.", bRes == sal_True );
     107             :     }*/
     108             : 
     109           2 :     CPPUNIT_TEST_SUITE(createUuid);
     110           1 :     CPPUNIT_TEST(createUuid_001);
     111             :     //CPPUNIT_TEST(createUuid_002);
     112           5 :     CPPUNIT_TEST_SUITE_END();
     113             : }; // class createUuid
     114             : 
     115           3 : class createNamedUuid : public CppUnit::TestFixture
     116             : {
     117             : public:
     118             :     // initialise your test code values here.
     119           1 :     void setUp() SAL_OVERRIDE
     120             :     {
     121           1 :     }
     122             : 
     123           1 :     void tearDown() SAL_OVERRIDE
     124             :     {
     125           1 :     }
     126             : 
     127           1 :     void createNamedUuid_001()
     128             :     {
     129           1 :         sal_uInt8 NameSpace_DNS[16] = RTL_UUID_NAMESPACE_DNS;
     130           1 :         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           1 :             0x10,0x10,0x6d,0x4d };
     136             : 
     137             :         sal_uInt8 pNamedUUID[16], pNamedUUID2[16];
     138             : 
     139             :         // Same name does generate the same uuid
     140           1 :         rtl_String *pName = 0;
     141           1 :         rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Name" );
     142           1 :         rtl_createNamedUuid( pNamedUUID , NameSpace_DNS , pName );
     143           1 :         rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
     144           1 :         CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) == 0 );
     145           1 :         CPPUNIT_ASSERT_MESSAGE( "Same name should generate the same uuid", ! memcmp( pNamedUUID  , pPriorCalculatedUUID , 16 ) );
     146             : 
     147             :         // Different names does not generate the same uuid
     148           1 :         rtl_string_newFromStr( &pName , "this is a bla.blubs.DNS-Namf" );
     149           1 :         rtl_createNamedUuid( pNamedUUID2 , NameSpace_DNS , pName );
     150           1 :         CPPUNIT_ASSERT_MESSAGE("Different names does not generate the same uuid.", memcmp( pNamedUUID , pNamedUUID2 , 16 ) );
     151             : 
     152             :         // the same name with different namespace uuid produces different uuids
     153           1 :         rtl_createNamedUuid( pNamedUUID , NameSpace_URL , pName );
     154           1 :         CPPUNIT_ASSERT_MESSAGE( " same name with different namespace uuid produces different uuids", memcmp( pNamedUUID , pNamedUUID2 , 16 ) && rtl_compareUuid( pNamedUUID , pNamedUUID2 ) != 0);
     155             : 
     156             :         //test compareUuid
     157           1 :         if ( rtl_compareUuid( pNamedUUID , pNamedUUID2 ) > 0 )
     158           0 :         {   CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) < 0);
     159             :         }
     160             :         else
     161           1 :             CPPUNIT_ASSERT_MESSAGE( " compare uuids", rtl_compareUuid( pNamedUUID2 , pNamedUUID ) > 0);
     162             : 
     163           1 :         rtl_string_release( pName );
     164           1 :     }
     165             : 
     166           2 :     CPPUNIT_TEST_SUITE(createNamedUuid);
     167           1 :     CPPUNIT_TEST(createNamedUuid_001);
     168           5 :     CPPUNIT_TEST_SUITE_END();
     169             : }; // class createNamedUuid
     170             : 
     171           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createUuid);
     172           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_Uuid::createNamedUuid);
     173             : } // namespace rtl_Uuid
     174             : 
     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           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11