Armando Montanez | 179aa8e | 2021-03-10 11:46:35 -0800 | [diff] [blame] | 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 <span> |
| 16 | |
| 17 | #include "gtest/gtest.h" |
| 18 | #include "pw_protobuf/encoder.h" |
| 19 | #include "pw_snapshot_protos/snapshot.pwpb.h" |
| 20 | |
| 21 | namespace pw::snapshot { |
| 22 | namespace { |
| 23 | |
Armando Montanez | 179aa8e | 2021-03-10 11:46:35 -0800 | [diff] [blame] | 24 | TEST(Status, CompileTest) { |
Armando Montanez | 32988e0 | 2021-05-21 11:56:09 -0700 | [diff] [blame] | 25 | constexpr size_t kMaxProtoSize = 256; |
| 26 | std::byte encode_buffer[kMaxProtoSize]; |
| 27 | std::byte submessage_buffer[kMaxProtoSize]; |
| 28 | |
| 29 | stream::MemoryWriter writer(encode_buffer); |
| 30 | Snapshot::StreamEncoder snapshot_encoder(writer, submessage_buffer); |
Armando Montanez | 179aa8e | 2021-03-10 11:46:35 -0800 | [diff] [blame] | 31 | { |
Armando Montanez | 32988e0 | 2021-05-21 11:56:09 -0700 | [diff] [blame] | 32 | Metadata::StreamEncoder metadata_encoder = |
Armando Montanez | 179aa8e | 2021-03-10 11:46:35 -0800 | [diff] [blame] | 33 | snapshot_encoder.GetMetadataEncoder(); |
Adrien Larbanet | d1ca56c | 2021-06-10 14:20:45 +0000 | [diff] [blame] | 34 | metadata_encoder |
| 35 | .WriteReason( |
| 36 | std::as_bytes(std::span("It just died, I didn't do anything"))) |
| 37 | .IgnoreError(); // TODO(pwbug/387): Handle Status properly |
| 38 | metadata_encoder.WriteFatal(true) |
| 39 | .IgnoreError(); // TODO(pwbug/387): Handle Status properly |
| 40 | metadata_encoder.WriteProjectName(std::as_bytes(std::span("smart-shoe"))) |
| 41 | .IgnoreError(); // TODO(pwbug/387): Handle Status properly |
| 42 | metadata_encoder.WriteDeviceName(std::as_bytes(std::span("smart-shoe-p1"))) |
| 43 | .IgnoreError(); // TODO(pwbug/387): Handle Status properly |
Armando Montanez | 179aa8e | 2021-03-10 11:46:35 -0800 | [diff] [blame] | 44 | } |
Armando Montanez | 32988e0 | 2021-05-21 11:56:09 -0700 | [diff] [blame] | 45 | ASSERT_TRUE(snapshot_encoder.status().ok()); |
Armando Montanez | 179aa8e | 2021-03-10 11:46:35 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | } // namespace |
| 49 | } // namespace pw::snapshot |