• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/constructor_magic.h"
18 #include "rtc_base/strings/string_builder.h"
19 #include "test/logging/log_writer.h"
20 
21 namespace webrtc {
22 namespace test {
23 class ColumnPrinter {
24  public:
25   ColumnPrinter(const ColumnPrinter&);
26   ~ColumnPrinter();
27   static ColumnPrinter Fixed(const char* headers, std::string fields);
28   static ColumnPrinter Lambda(
29       const char* headers,
30       std::function<void(rtc::SimpleStringBuilder&)> printer,
31       size_t max_length = 256);
32 
33  protected:
34   friend class StatesPrinter;
35   const char* headers_;
36   std::function<void(rtc::SimpleStringBuilder&)> printer_;
37   size_t max_length_;
38 
39  private:
40   ColumnPrinter(const char* headers,
41                 std::function<void(rtc::SimpleStringBuilder&)> printer,
42                 size_t max_length);
43 };
44 
45 class StatesPrinter {
46  public:
47   StatesPrinter(std::unique_ptr<RtcEventLogOutput> writer,
48                 std::vector<ColumnPrinter> printers);
49   RTC_DISALLOW_COPY_AND_ASSIGN(StatesPrinter);
50   ~StatesPrinter();
51   void PrintHeaders();
52   void PrintRow();
53 
54  private:
55   const std::unique_ptr<RtcEventLogOutput> writer_;
56   const std::vector<ColumnPrinter> printers_;
57   size_t buffer_size_ = 0;
58   std::vector<char> buffer_;
59 };
60 }  // namespace test
61 }  // namespace webrtc
62 
63 #endif  // TEST_SCENARIO_COLUMN_PRINTER_H_
64