|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Project CHIP Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#pragma once |
| 17 | + |
| 18 | +/// This header includes pigweed stringbuilder adaptations for various chip types. |
| 19 | +/// You can see https://pigweed.dev/pw_string/guide.html as a reference. |
| 20 | +/// |
| 21 | +/// In particular, pigweed code generally looks like: |
| 22 | +/// |
| 23 | +/// pw::StringBuffer<42> sb; |
| 24 | +/// sb << "Here is a value: "; |
| 25 | +/// sb << value; |
| 26 | +/// |
| 27 | +/// Where specific formatters exist for "value". In particular these are used when |
| 28 | +/// reporting unit test assertions such as ASSERT_EQ/EXPECT_EQ so if you write code |
| 29 | +/// like: |
| 30 | +/// |
| 31 | +/// ASSERT_EQ(SomeCall(), CHIP_NO_ERROR); |
| 32 | +/// |
| 33 | +/// On failure without adapters, the objects are reported as "24-byte object at 0x....." |
| 34 | +/// which is not as helpful as a full CHIP_ERROR formatted output. |
| 35 | +/// |
| 36 | +/// Example output WITHOUT the adapters |
| 37 | +/// Expected: .... == CHIP_ERROR(0, "src/setup_payload/tests/TestAdditionalDataPayload.cpp", 234) |
| 38 | +/// Actual: <24-byte object at 0x7ffe39510b80> == <24-byte object at 0x7ffe39510ba0> |
| 39 | +/// |
| 40 | +/// Example output WITH the adapters: |
| 41 | +/// Expected: .... == CHIP_ERROR(0, "src/setup_payload/tests/TestAdditionalDataPayload.cpp", 234) |
| 42 | +/// Actual: CHIP_ERROR:<src/lib/core/TLVReader.cpp:889: Error 0x00000022> == CHIP_NO_ERROR |
| 43 | + |
| 44 | +#include <pw_string/string_builder.h> |
| 45 | + |
| 46 | +#include <lib/core/CHIPError.h> |
| 47 | + |
| 48 | +namespace pw { |
| 49 | + |
| 50 | +template <> |
| 51 | +StatusWithSize ToString<CHIP_ERROR>(const CHIP_ERROR & err, pw::span<char> buffer); |
| 52 | + |
| 53 | +} // namespace pw |
0 commit comments