1 // Copyright 2019 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef CRASHPAD_UTIL_STREAM_TEST_OUTPUT_STREAM_H_
16 #define CRASHPAD_UTIL_STREAM_TEST_OUTPUT_STREAM_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include <vector>
22 
23 #include "base/macros.h"
24 #include "util/stream/output_stream_interface.h"
25 
26 namespace crashpad {
27 namespace test {
28 
29 //! \brief The help class for \a OutputStreamInterface related tests.
30 class TestOutputStream : public OutputStreamInterface {
31  public:
32   TestOutputStream();
33   ~TestOutputStream() override;
34 
35   // OutputStreamInterface:
36   bool Write(const uint8_t* data, size_t size) override;
37   bool Flush() override;
38 
39   //! \return the data that has been received by the last call of Write().
last_written_data()40   const std::vector<uint8_t>& last_written_data() const {
41     return last_written_data_;
42   }
43 
44   //! \return all data that has been received.
all_data()45   const std::vector<uint8_t>& all_data() const { return all_data_; }
46 
47   //! \return the number of times Write() has been called.
write_count()48   size_t write_count() const { return write_count_; }
49 
50   //! \return the number of times Flush() has been called.
flush_count()51   size_t flush_count() const { return flush_count_; }
52 
53  private:
54   std::vector<uint8_t> last_written_data_;
55   std::vector<uint8_t> all_data_;
56   size_t write_count_;
57   size_t flush_count_;
58   bool flush_needed_;
59 
60   DISALLOW_COPY_AND_ASSIGN(TestOutputStream);
61 };
62 
63 }  // namespace test
64 }  // namespace crashpad
65 
66 #endif  // CRASHPAD_UTIL_STREAM_TEST_OUTPUT_STREAM_H_
67