Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/utility - UUIDGenerator.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 7 8 87.5 %
Date: 2012-04-09 Functions: 3 3 100.0 %
Branches: 3 6 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2010 Savarese Software Research Corporation
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at
       7                 :            :  *
       8                 :            :  *     https://www.savarese.com/software/ApacheLicense-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <ssrc/wispers/utility/UUIDGenerator.h>
      18                 :            : #include <ssrc/wispers/utility/endian.h>
      19                 :            : 
      20                 :            : #include <algorithm>
      21                 :            : #include <cstring>
      22                 :            : 
      23                 :            : __BEGIN_NS_SSRC_WSPR_UTILITY
      24                 :            : 
      25                 :            : namespace {
      26                 :          1 :   const bool IsLittleEndian = is_little_endian();
      27                 :            : }
      28                 :            : 
      29                 :        100 : uuid_key_type uuid_to_uuid_key(const boost::uuids::uuid & uuid) {
      30                 :            :   uuid_key_type key;
      31                 :            : 
      32                 :            :   // We could also do this at compile-time via an ifdef.
      33         [ +  - ]:        100 :   if(IsLittleEndian) {
      34                 :            :     std::reverse_copy(uuid.begin(), uuid.end(),
      35                 :        100 :                       reinterpret_cast<boost::uuids::uuid::iterator>(&key));
      36                 :        100 :     std::swap(key.high_bits, key.low_bits);
      37                 :            :   } else {
      38                 :          0 :     std::memcpy(&key, uuid.data, sizeof(uuid.data));
      39                 :            :   }
      40                 :            : 
      41                 :        100 :   return key;
      42                 :            : }
      43                 :            : 
      44   [ +  -  +  - ]:          3 : __END_NS_SSRC_WSPR_UTILITY