Index: remoting/test/counter_stubs.h |
diff --git a/remoting/test/counter_stubs.h b/remoting/test/counter_stubs.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6a568ea1c0031ad519457ee80f58c73f53e30ee5 |
--- /dev/null |
+++ b/remoting/test/counter_stubs.h |
@@ -0,0 +1,154 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
joedow
2016/05/03 22:28:29
Missing guard macro in the header file.
Hzj_jie
2016/05/04 02:11:56
Done.
|
+#include <memory> |
+ |
+#include "base/atomicops.h" |
+#include "remoting/protocol/audio_stub.h" |
+#include "remoting/protocol/client_stub.h" |
+#include "remoting/protocol/host_stub.h" |
+#include "remoting/protocol/video_stub.h" |
+ |
+namespace base { |
+class Time; |
+ |
+#ifndef ARCH_CPU_64_BITS |
+class Lock; |
+#endif // ifndef ARCH_CPU_64_BITS |
+ |
+} // namespace ::base |
+ |
+namespace google { |
+namespace protobuf { |
+class MessageLite; |
+} // namespace protobuf |
+} // namespace ::google |
+ |
+namespace remoting { |
+ |
+namespace protocol { |
+class FakeConnectionToClient; |
+} // namespace protocol |
+ |
+namespace test { |
+ |
joedow
2016/05/03 22:28:29
This file should probably get broken down a bit mo
Hzj_jie
2016/05/04 02:11:56
Done.
|
+template <typename T> |
+class NoBarrierAtomic { |
+ public: |
+ T operator++() { |
+ return base::subtle::NoBarrier_AtomicIncrement(&i_, 1) - 1; |
+ } |
+ |
+ T operator++(int) { |
+ return base::subtle::NoBarrier_AtomicIncrement(&i_, 1); |
+ } |
+ |
+ T operator--() { |
+ return base::subtle::NoBarrier_AtomicIncrement(&i_, -1) - 1; |
+ } |
+ |
+ T operator--(int) { |
+ return base::subtle::NoBarrier_AtomicIncrement(&i_, -1); |
+ } |
+ |
+ T operator+=(T other) { |
+ return base::subtle::NoBarrier_AtomicIncrement(&i_, other); |
+ } |
+ |
+ T operator-=(T other) { |
+ return base::subtle::NoBarrier_AtomicIncrement(&i_, -other); |
+ } |
+ |
+ T operator*() const { |
+ return base::subtle::NoBarrier_Load(&i_); |
+ } |
+ |
+ private: |
+ volatile T i_; |
+}; |
+ |
+class NoBarrierAtomicInt32 : public NoBarrierAtomic<base::subtle::Atomic32> {}; |
+#ifdef ARCH_CPU_64_BITS |
+class NoBarrierAtomicInt64 : public NoBarrierAtomic<base::subtle::Atomic64> {}; |
+#else // ifdef ARCH_CPU_64_BITS |
+ |
+// A barriered, lock based implementation |
+class NoBarrierAtomicInt64 { |
+ public: |
+ int64_t operator++(); |
+ int64_t operator++(int); |
+ int64_t operator--(); |
+ int64_t operator--(int); |
+ int64_t operator+=(int64_t other); |
+ int64_t operator-=(int64_t other); |
+ int64_t operator*() const; |
+ |
+ private: |
+ volatile int64_t i_; |
+ mutable base::Lock lock_; // field is used in operator*() const |
+}; |
+#endif // ifdef ARCH_CPU_64_BITS |
+ |
+class MessageCounter { |
+ public: |
+ MessageCounter(); |
+ |
+ int message_count() const; |
+ int64_t message_size() const; |
+ int last_message_size() const; |
+ double DurationSeconds() const; |
+ double MessagesPerSecond() const; |
+ double SizePerSecond() const; |
+ double AverageMessageSize() const; |
+ |
+ void LogMessage(const ::google::protobuf::MessageLite& message); |
+ |
+ private: |
+ NoBarrierAtomicInt32 count_; |
+ NoBarrierAtomicInt64 size_; |
+ int last_size_; |
+ base::Time start_time_; |
+}; |
+ |
+class CounterClientStub : public protocol::ClientStub, public MessageCounter { |
+ public: |
+ void DeliverHostMessage(const protocol::ExtensionMessage& message) override; |
+ void InjectClipboardEvent(const protocol::ClipboardEvent& event) override {} |
+ void SetCapabilities(const protocol::Capabilities& capabilities) override {} |
+ void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override {} |
+ void SetPairingResponse(const protocol::PairingResponse& response) override {} |
+ void SetVideoLayout(const protocol::VideoLayout& video_layout) override {} |
+}; |
+ |
+class CounterHostStub : public protocol::HostStub, public MessageCounter { |
+ public: |
+ void ControlAudio(const protocol::AudioControl& audio_control) override {} |
+ void ControlVideo(const protocol::VideoControl& video_control) override {} |
+ void DeliverClientMessage( |
+ const protocol::ExtensionMessage& message) override; |
+ void NotifyClientResolution( |
+ const protocol::ClientResolution& resolution) override {} |
+ void RequestPairing( |
+ const protocol::PairingRequest& pairing_request) override {} |
+ void SetCapabilities(const protocol::Capabilities& capabilities) override {} |
+}; |
+ |
+class CounterAudioStub : public protocol::AudioStub, public MessageCounter { |
+ public: |
+ void ProcessAudioPacket(std::unique_ptr<AudioPacket> audio_packet, |
+ const base::Closure& done) override; |
+}; |
+ |
+class CounterVideoStub : public protocol::VideoStub, public MessageCounter { |
+ public: |
+ CounterVideoStub(protocol::FakeConnectionToClient* connection); |
+ void ProcessVideoPacket(std::unique_ptr<VideoPacket> video_packet, |
+ const base::Closure& done) override; |
+ |
+ private: |
+ protocol::FakeConnectionToClient* connection_ = nullptr; |
joedow
2016/05/03 22:28:29
DISALLOW_COPY_AND_ASSIGN(...)?
Hzj_jie
2016/05/04 02:11:56
I have disallowed copy and assign for MessageCount
|
+}; |
+ |
+} // namespace test |
+} // namespace remoting |