1 // 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 "pw_protobuf/encoder.h"
16 #include "pw_snapshot_protos/snapshot.pwpb.h"
17 #include "pw_span/span.h"
18 #include "pw_unit_test/framework.h"
19
20 namespace pw::snapshot {
21 namespace {
22
TEST(Status,CompileTest)23 TEST(Status, CompileTest) {
24 constexpr size_t kMaxProtoSize = 256;
25 std::byte encode_buffer[kMaxProtoSize];
26 std::byte submessage_buffer[kMaxProtoSize];
27
28 stream::MemoryWriter writer(encode_buffer);
29 pwpb::Snapshot::StreamEncoder snapshot_encoder(writer, submessage_buffer);
30 {
31 pwpb::Metadata::StreamEncoder metadata_encoder =
32 snapshot_encoder.GetMetadataEncoder();
33 ASSERT_EQ(OkStatus(),
34 metadata_encoder.WriteReason(
35 as_bytes(span("It just died, I didn't do anything"))));
36 ASSERT_EQ(OkStatus(), metadata_encoder.WriteFatal(true));
37 ASSERT_EQ(OkStatus(),
38 metadata_encoder.WriteProjectName(as_bytes(span("smart-shoe"))));
39 ASSERT_EQ(
40 OkStatus(),
41 metadata_encoder.WriteDeviceName(as_bytes(span("smart-shoe-p1"))));
42 }
43 ASSERT_TRUE(snapshot_encoder.status().ok());
44 }
45
46 } // namespace
47 } // namespace pw::snapshot
48