• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 <cstring>
16 
17 #include "pw_status/status.h"
18 #include "pw_string/string_builder.h"
19 #include "pw_unit_test/framework.h"
20 
21 namespace pw {
22 namespace {
23 
TEST(UnknownTypeToString,SmallObject)24 TEST(UnknownTypeToString, SmallObject) {
25   struct {
26     char a = 0xa1;
27   } object;
28 
29   StringBuffer<64> expected;
30   expected << "<1-byte object at 0x" << &object << '>';
31   ASSERT_EQ(OkStatus(), expected.status());
32 
33   StringBuffer<64> actual;
34   actual << object;
35   ASSERT_EQ(OkStatus(), actual.status());
36   EXPECT_STREQ(expected.c_str(), actual.c_str());
37 }
38 
TEST(UnknownTypeToString,NineByteObject)39 TEST(UnknownTypeToString, NineByteObject) {
40   struct {
41     char a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
42   } object;
43 
44   StringBuffer<64> expected;
45   expected << "<9-byte object at 0x" << &object << '>';
46   ASSERT_EQ(OkStatus(), expected.status());
47 
48   StringBuffer<64> actual;
49   actual << object;
50   ASSERT_EQ(OkStatus(), actual.status());
51   EXPECT_STREQ(expected.c_str(), actual.c_str());
52 }
53 
TEST(UnknownTypeToString,TenByteObject)54 TEST(UnknownTypeToString, TenByteObject) {
55   struct {
56     char a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
57   } object;
58 
59   StringBuffer<72> expected;
60   expected << "<10-byte object at 0x" << &object << '>';
61   ASSERT_EQ(OkStatus(), expected.status());
62 
63   StringBuffer<72> actual;
64   actual << object;
65   ASSERT_EQ(OkStatus(), actual.status());
66   EXPECT_STREQ(expected.c_str(), actual.c_str());
67 }
68 
69 }  // namespace
70 }  // namespace pw
71