Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa216b96 authored by Myles Watson's avatar Myles Watson
Browse files

PDL: Update generated enum logging

Remove unused stream logging.  Add hex values to enum logs.

Bug: 322230000
Test: mma -j32
Test: bluetooth_test_gd_unit --gtest_filter=*on_hci_timeout*
Flag: EXEMPT, logging-only change
Change-Id: I0b6f940af4a4243734c3bd94061bed88e25fa0c2
parent 2d8674ee
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -307,7 +307,7 @@ TEST(AddressWithTypeTest, StringStream) {


  std::stringstream oss;
  std::stringstream oss;
  oss << address_with_type;
  oss << address_with_type;
  ASSERT_STREQ("66:55:44:33:22:11[PUBLIC_DEVICE_ADDRESS]", oss.str().c_str());
  ASSERT_STREQ("66:55:44:33:22:11[PUBLIC_DEVICE_ADDRESS(0x00)]", oss.str().c_str());
}
}


}  // namespace hci
}  // namespace hci
+7 −7
Original line number Original line Diff line number Diff line
@@ -44,18 +44,18 @@ void EnumGen::GenDefinitionPybind11(std::ostream& stream) {
void EnumGen::GenLogging(std::ostream& stream) {
void EnumGen::GenLogging(std::ostream& stream) {
  // Print out the switch statement that converts all the constants to strings.
  // Print out the switch statement that converts all the constants to strings.
  stream << "inline std::string " << e_.name_ << "Text(const " << e_.name_ << "& param) {";
  stream << "inline std::string " << e_.name_ << "Text(const " << e_.name_ << "& param) {";
  stream << "std::stringstream builder;";
  stream << "switch (param) {";
  stream << "switch (param) {";
  for (const auto& pair : e_.constants_) {
  for (const auto& pair : e_.constants_) {
    stream << "case " << e_.name_ << "::" << pair.second << ":";
    stream << "case " << e_.name_ << "::" << pair.second << ":";
    stream << "  return \"" << pair.second << "\";";
    stream << "  builder << \"" << pair.second << "\"; break;";
  }
  }
  stream << "default:";
  stream << "default:";
  stream << "  return std::string(\"Unknown " << e_.name_ << ": \") + std::to_string(static_cast<int>(param));";
  stream << "  builder << \"Unknown " << e_.name_ << "\";";
  stream << "}";
  stream << "}";
  stream << "builder << \"(\" << std::hex << \"0x\" << std::setfill('0')";
  stream << "<< std::setw(" << (e_.size_ > 0 ? e_.size_ : 0) << "/4)";
  stream << "<< static_cast<uint64_t>(param) << \")\";";
  stream << "return builder.str();";
  stream << "}\n\n";
  stream << "}\n\n";

  // Print out the stream operator so that the constant can be written to streams.
  stream << "inline std::ostream& operator<<(std::ostream& os, const " << e_.name_ << "& param) {";
  stream << "  return os << " << e_.name_ << "Text(param);";
  stream << "}\n";
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -82,6 +82,7 @@ bool generate_cpp_headers_one_file(


#include <cstdint>
#include <cstdint>
#include <functional>
#include <functional>
#include <iomanip>
#include <optional>
#include <optional>
#include <sstream>
#include <sstream>
#include <string>
#include <string>
+9 −2
Original line number Original line Diff line number Diff line
@@ -1936,6 +1936,13 @@ TEST(GeneratedPacketTest, testToStringOutput) {
      view.ToString());
      view.ToString());
}
}


TEST(GeneratedPacketTest, testEnumText) {
  EXPECT_EQ("FIVE(0x5)", FourBitsText(FourBits::FIVE));
  EXPECT_EQ("THREE(0x3)", TwoBitsText(TwoBits::THREE));
  EXPECT_EQ("FOUR_BYTE(0x04)", StructTypeText(StructType::FOUR_BYTE));
  EXPECT_EQ("TWO_THREE(0x0302)", ForArraysText(ForArrays::TWO_THREE));
}

TEST(GeneratedPacketTest, testToStringOneFixedTypesStruct) {
TEST(GeneratedPacketTest, testToStringOneFixedTypesStruct) {
  StructWithFixedTypes swf;
  StructWithFixedTypes swf;
  swf.four_bits_ = FourBits::FIVE;
  swf.four_bits_ = FourBits::FIVE;
@@ -1960,8 +1967,8 @@ TEST(GeneratedPacketTest, testToStringOneFixedTypesStruct) {
  ASSERT_TRUE(view.IsValid());
  ASSERT_TRUE(view.IsValid());


  ASSERT_EQ(
  ASSERT_EQ(
      "OneFixedTypesStruct { one = StructWithFixedTypes { four_bits = FIVE, id = 0xd, array = ARRAY[0x1, 0x2, 0x3], "
      "OneFixedTypesStruct { one = StructWithFixedTypes { four_bits = FIVE(0x5), id = 0xd, "
      "example_checksum = CHECKSUM, six_bytes = SixBytes } }",
      "array = ARRAY[0x1, 0x2, 0x3], example_checksum = CHECKSUM, six_bytes = SixBytes } }",
      view.ToString());
      view.ToString());
}
}