blob: d188d1cec8bac3f3fbd8b4e2dcd36bd749b12fa8 [file] [log] [blame]
Armando Montanez179aa8e2021-03-10 11:46:35 -08001// Copyright 2021 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// 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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#include <span>
16
17#include "gtest/gtest.h"
18#include "pw_protobuf/encoder.h"
19#include "pw_snapshot_protos/snapshot.pwpb.h"
20
21namespace pw::snapshot {
22namespace {
23
24constexpr size_t kMaxProtoSize = 256;
25constexpr size_t kMaxNestedProtoDepth = 4;
26
27std::byte encode_buffer[kMaxProtoSize];
28
29TEST(Status, CompileTest) {
30 pw::protobuf::NestedEncoder<kMaxNestedProtoDepth> proto_encoder(
31 encode_buffer);
32 pw::snapshot::Snapshot::Encoder snapshot_encoder(&proto_encoder);
33 {
34 pw::snapshot::Metadata::Encoder metadata_encoder =
35 snapshot_encoder.GetMetadataEncoder();
36 metadata_encoder.WriteReason(
37 std::as_bytes(std::span("It just died, I didn't do anything")));
38 metadata_encoder.WriteFatal(true);
39 metadata_encoder.WriteProjectName(std::as_bytes(std::span("smart-shoe")));
40 metadata_encoder.WriteDeviceName(std::as_bytes(std::span("smart-shoe-p1")));
41 }
42 ASSERT_TRUE(proto_encoder.Encode().ok());
43}
44
45} // namespace
46} // namespace pw::snapshot