Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/values/bool_value.cc
Line
Count
Source
1
// Copyright 2023 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <string>
16
17
#include "google/protobuf/wrappers.pb.h"
18
#include "absl/base/nullability.h"
19
#include "absl/log/absl_check.h"
20
#include "absl/status/status.h"
21
#include "absl/strings/str_cat.h"
22
#include "common/value.h"
23
#include "internal/status_macros.h"
24
#include "internal/well_known_types.h"
25
#include "google/protobuf/arena.h"
26
#include "google/protobuf/descriptor.h"
27
#include "google/protobuf/io/zero_copy_stream.h"
28
#include "google/protobuf/message.h"
29
30
namespace cel {
31
32
namespace {
33
34
using ::cel::well_known_types::ValueReflection;
35
36
91
std::string BoolDebugString(bool value) { return value ? "true" : "false"; }
37
38
}  // namespace
39
40
91
std::string BoolValue::DebugString() const {
41
91
  return BoolDebugString(NativeValue());
42
91
}
43
44
absl::Status BoolValue::SerializeTo(
45
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
46
    google::protobuf::MessageFactory* absl_nonnull message_factory,
47
0
    google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const {
48
0
  ABSL_DCHECK(descriptor_pool != nullptr);
49
0
  ABSL_DCHECK(message_factory != nullptr);
50
0
  ABSL_DCHECK(output != nullptr);
51
52
0
  google::protobuf::BoolValue message;
53
0
  message.set_value(NativeValue());
54
0
  if (!message.SerializePartialToZeroCopyStream(output)) {
55
0
    return absl::UnknownError(
56
0
        absl::StrCat("failed to serialize message: ", message.GetTypeName()));
57
0
  }
58
59
0
  return absl::OkStatus();
60
0
}
61
62
absl::Status BoolValue::ConvertToJson(
63
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
64
    google::protobuf::MessageFactory* absl_nonnull message_factory,
65
0
    google::protobuf::Message* absl_nonnull json) const {
66
0
  ABSL_DCHECK(descriptor_pool != nullptr);
67
0
  ABSL_DCHECK(message_factory != nullptr);
68
0
  ABSL_DCHECK(json != nullptr);
69
0
  ABSL_DCHECK_EQ(json->GetDescriptor()->well_known_type(),
70
0
                 google::protobuf::Descriptor::WELLKNOWNTYPE_VALUE);
71
72
0
  ValueReflection value_reflection;
73
0
  CEL_RETURN_IF_ERROR(value_reflection.Initialize(json->GetDescriptor()));
74
0
  value_reflection.SetBoolValue(json, NativeValue());
75
76
0
  return absl::OkStatus();
77
0
}
78
79
absl::Status BoolValue::Equal(
80
    const Value& other,
81
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
82
    google::protobuf::MessageFactory* absl_nonnull message_factory,
83
1.13k
    google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const {
84
1.13k
  ABSL_DCHECK(descriptor_pool != nullptr);
85
1.13k
  ABSL_DCHECK(message_factory != nullptr);
86
1.13k
  ABSL_DCHECK(arena != nullptr);
87
1.13k
  ABSL_DCHECK(result != nullptr);
88
89
1.13k
  if (auto other_value = other.AsBool(); other_value.has_value()) {
90
301
    *result = BoolValue{NativeValue() == other_value->NativeValue()};
91
301
    return absl::OkStatus();
92
301
  }
93
831
  *result = FalseValue();
94
831
  return absl::OkStatus();
95
1.13k
}
96
97
}  // namespace cel