LCOV - code coverage report
Current view: top level - src/leveldb/util - status.cc (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 33 61 54.1 %
Date: 2022-04-21 14:51:19 Functions: 2 3 66.7 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 13 20 65.0 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
#       2                 :            : // Use of this source code is governed by a BSD-style license that can be
#       3                 :            : // found in the LICENSE file. See the AUTHORS file for names of contributors.
#       4                 :            : 
#       5                 :            : #include "leveldb/status.h"
#       6                 :            : 
#       7                 :            : #include <stdio.h>
#       8                 :            : 
#       9                 :            : #include "port/port.h"
#      10                 :            : 
#      11                 :            : namespace leveldb {
#      12                 :            : 
#      13                 :          0 : const char* Status::CopyState(const char* state) {
#      14                 :          0 :   uint32_t size;
#      15                 :          0 :   memcpy(&size, state, sizeof(size));
#      16                 :          0 :   char* result = new char[size + 5];
#      17                 :          0 :   memcpy(result, state, size + 5);
#      18                 :          0 :   return result;
#      19                 :          0 : }
#      20                 :            : 
#      21                 :    9918566 : Status::Status(Code code, const Slice& msg, const Slice& msg2) {
#      22                 :    9918566 :   assert(code != kOk);
#      23                 :          0 :   const uint32_t len1 = static_cast<uint32_t>(msg.size());
#      24                 :    9918566 :   const uint32_t len2 = static_cast<uint32_t>(msg2.size());
#      25         [ +  + ]:    9918566 :   const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
#      26                 :    9918566 :   char* result = new char[size + 5];
#      27                 :    9918566 :   memcpy(result, &size, sizeof(size));
#      28                 :    9918566 :   result[4] = static_cast<char>(code);
#      29                 :    9918566 :   memcpy(result + 5, msg.data(), len1);
#      30         [ +  + ]:    9918566 :   if (len2) {
#      31                 :       1548 :     result[5 + len1] = ':';
#      32                 :       1548 :     result[6 + len1] = ' ';
#      33                 :       1548 :     memcpy(result + 7 + len1, msg2.data(), len2);
#      34                 :       1548 :   }
#      35                 :    9918566 :   state_ = result;
#      36                 :    9918566 : }
#      37                 :            : 
#      38                 :        971 : std::string Status::ToString() const {
#      39         [ +  + ]:        971 :   if (state_ == nullptr) {
#      40                 :        969 :     return "OK";
#      41                 :        969 :   } else {
#      42                 :          2 :     char tmp[30];
#      43                 :          2 :     const char* type;
#      44                 :          2 :     switch (code()) {
#      45         [ -  + ]:          0 :       case kOk:
#      46                 :          0 :         type = "OK";
#      47                 :          0 :         break;
#      48         [ -  + ]:          0 :       case kNotFound:
#      49                 :          0 :         type = "NotFound: ";
#      50                 :          0 :         break;
#      51         [ +  - ]:          2 :       case kCorruption:
#      52                 :          2 :         type = "Corruption: ";
#      53                 :          2 :         break;
#      54         [ -  + ]:          0 :       case kNotSupported:
#      55                 :          0 :         type = "Not implemented: ";
#      56                 :          0 :         break;
#      57         [ -  + ]:          0 :       case kInvalidArgument:
#      58                 :          0 :         type = "Invalid argument: ";
#      59                 :          0 :         break;
#      60         [ -  + ]:          0 :       case kIOError:
#      61                 :          0 :         type = "IO error: ";
#      62                 :          0 :         break;
#      63         [ -  + ]:          0 :       default:
#      64                 :          0 :         snprintf(tmp, sizeof(tmp),
#      65                 :          0 :                  "Unknown code(%d): ", static_cast<int>(code()));
#      66                 :          0 :         type = tmp;
#      67                 :          0 :         break;
#      68                 :          2 :     }
#      69                 :          2 :     std::string result(type);
#      70                 :          2 :     uint32_t length;
#      71                 :          2 :     memcpy(&length, state_, sizeof(length));
#      72                 :          2 :     result.append(state_ + 5, length);
#      73                 :          2 :     return result;
#      74                 :          2 :   }
#      75                 :        971 : }
#      76                 :            : 
#      77                 :            : }  // namespace leveldb

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a