1 /* 2 * Copyright 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef TEST_SCENARIO_COLUMN_PRINTER_H_ 11 #define TEST_SCENARIO_COLUMN_PRINTER_H_ 12 #include <functional> 13 #include <memory> 14 #include <string> 15 #include <vector> 16 17 #include "rtc_base/strings/string_builder.h" 18 #include "test/logging/log_writer.h" 19 20 namespace webrtc { 21 namespace test { 22 class ColumnPrinter { 23 public: 24 ColumnPrinter(const ColumnPrinter&); 25 ~ColumnPrinter(); 26 static ColumnPrinter Fixed(const char* headers, std::string fields); 27 static ColumnPrinter Lambda( 28 const char* headers, 29 std::function<void(rtc::SimpleStringBuilder&)> printer, 30 size_t max_length = 256); 31 32 protected: 33 friend class StatesPrinter; 34 const char* headers_; 35 std::function<void(rtc::SimpleStringBuilder&)> printer_; 36 size_t max_length_; 37 38 private: 39 ColumnPrinter(const char* headers, 40 std::function<void(rtc::SimpleStringBuilder&)> printer, 41 size_t max_length); 42 }; 43 44 class StatesPrinter { 45 public: 46 StatesPrinter(std::unique_ptr<RtcEventLogOutput> writer, 47 std::vector<ColumnPrinter> printers); 48 49 ~StatesPrinter(); 50 51 StatesPrinter(const StatesPrinter&) = delete; 52 StatesPrinter& operator=(const StatesPrinter&) = delete; 53 54 void PrintHeaders(); 55 void PrintRow(); 56 57 private: 58 const std::unique_ptr<RtcEventLogOutput> writer_; 59 const std::vector<ColumnPrinter> printers_; 60 size_t buffer_size_ = 0; 61 std::vector<char> buffer_; 62 }; 63 } // namespace test 64 } // namespace webrtc 65 66 #endif // TEST_SCENARIO_COLUMN_PRINTER_H_ 67