LCOV - code coverage report
Current view: top level - src/leveldb/util - status.cc (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 46.2 % 52 24
Test Date: 2026-02-04 04:43:42 Functions: 100.0 % 3 3
Branches: 48.0 % 25 12

             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                 :           1 : const char* Status::CopyState(const char* state) {
      14                 :           1 :   uint32_t size;
      15                 :           1 :   memcpy(&size, state, sizeof(size));
      16                 :           1 :   char* result = new char[size + 5];
      17                 :           1 :   memcpy(result, state, size + 5);
      18                 :           1 :   return result;
      19                 :             : }
      20                 :             : 
      21                 :     4659368 : Status::Status(Code code, const Slice& msg, const Slice& msg2) {
      22         [ -  + ]:     4659368 :   assert(code != kOk);
      23         [ +  + ]:     4659368 :   const uint32_t len1 = static_cast<uint32_t>(msg.size());
      24                 :     4659368 :   const uint32_t len2 = static_cast<uint32_t>(msg2.size());
      25         [ +  + ]:     4659368 :   const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
      26                 :     4659368 :   char* result = new char[size + 5];
      27         [ +  + ]:     4659368 :   memcpy(result, &size, sizeof(size));
      28                 :     4659368 :   result[4] = static_cast<char>(code);
      29         [ +  + ]:     4659368 :   memcpy(result + 5, msg.data(), len1);
      30         [ +  + ]:     4659368 :   if (len2) {
      31                 :         118 :     result[5 + len1] = ':';
      32                 :         118 :     result[6 + len1] = ' ';
      33                 :         118 :     memcpy(result + 7 + len1, msg2.data(), len2);
      34                 :             :   }
      35                 :     4659368 :   state_ = result;
      36                 :     4659368 : }
      37                 :             : 
      38                 :          62 : std::string Status::ToString() const {
      39         [ +  - ]:          62 :   if (state_ == nullptr) {
      40                 :          62 :     return "OK";
      41                 :             :   } else {
      42                 :           0 :     char tmp[30];
      43                 :           0 :     const char* type;
      44   [ #  #  #  #  :           0 :     switch (code()) {
                #  #  # ]
      45                 :             :       case kOk:
      46                 :             :         type = "OK";
      47                 :             :         break;
      48                 :           0 :       case kNotFound:
      49                 :           0 :         type = "NotFound: ";
      50                 :           0 :         break;
      51                 :           0 :       case kCorruption:
      52                 :           0 :         type = "Corruption: ";
      53                 :           0 :         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                 :             :     }
      69                 :           0 :     std::string result(type);
      70                 :           0 :     uint32_t length;
      71         [ #  # ]:           0 :     memcpy(&length, state_, sizeof(length));
      72         [ #  # ]:           0 :     result.append(state_ + 5, length);
      73                 :           0 :     return result;
      74                 :             :   }
      75                 :             : }
      76                 :             : 
      77                 :             : }  // namespace leveldb
        

Generated by: LCOV version 2.0-1