Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1019)

Side by Side Diff: net/base/listen_socket_unittest.h

Issue 6248021: Reapply r72562 with willchan's nits + locally tested shlib fixes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix path Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/gzip_filter_unittest.cc ('k') | net/base/listen_socket_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_BASE_LISTEN_SOCKET_UNITTEST_H_ 5 #ifndef NET_BASE_LISTEN_SOCKET_UNITTEST_H_
6 #define NET_BASE_LISTEN_SOCKET_UNITTEST_H_ 6 #define NET_BASE_LISTEN_SOCKET_UNITTEST_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 std::string data_; 61 std::string data_;
62 }; 62 };
63 63
64 64
65 // This had to be split out into a separate class because I couldn't 65 // This had to be split out into a separate class because I couldn't
66 // make a the testing::Test class refcounted. 66 // make a the testing::Test class refcounted.
67 class ListenSocketTester : 67 class ListenSocketTester :
68 public ListenSocket::ListenSocketDelegate, 68 public ListenSocket::ListenSocketDelegate,
69 public base::RefCountedThreadSafe<ListenSocketTester> { 69 public base::RefCountedThreadSafe<ListenSocketTester> {
70 70
71 protected: 71 public:
72 friend class base::RefCountedThreadSafe<ListenSocketTester>; 72 ListenSocketTester();
73 73
74 virtual ~ListenSocketTester() {} 74 void SetUp();
75 75 void TearDown();
76 virtual ListenSocket* DoListen();
77
78 public:
79 ListenSocketTester()
80 : thread_(NULL),
81 loop_(NULL),
82 server_(NULL),
83 connection_(NULL),
84 cv_(&lock_) {
85 }
86
87 virtual void SetUp();
88 virtual void TearDown();
89 76
90 void ReportAction(const ListenSocketTestAction& action); 77 void ReportAction(const ListenSocketTestAction& action);
91 void NextAction(); 78 void NextAction();
92 79
93 // read all pending data from the test socket 80 // read all pending data from the test socket
94 int ClearTestSocket(); 81 int ClearTestSocket();
95 // Release the connection and server sockets 82 // Release the connection and server sockets
96 void Shutdown(); 83 void Shutdown();
97 void Listen(); 84 void Listen();
98 void SendFromTester(); 85 void SendFromTester();
99 virtual void DidAccept(ListenSocket *server, ListenSocket *connection);
100 virtual void DidRead(ListenSocket *connection, const char* data, int len);
101 virtual void DidClose(ListenSocket *sock);
102 virtual bool Send(SOCKET sock, const std::string& str);
103 // verify the send/read from client to server 86 // verify the send/read from client to server
104 void TestClientSend(); 87 void TestClientSend();
105 // verify send/read of a longer string 88 // verify send/read of a longer string
106 void TestClientSendLong(); 89 void TestClientSendLong();
107 // verify a send/read from server to client 90 // verify a send/read from server to client
108 void TestServerSend(); 91 void TestServerSend();
109 92
93 virtual bool Send(SOCKET sock, const std::string& str);
94
95 // ListenSocket::ListenSocketDelegate:
96 virtual void DidAccept(ListenSocket *server, ListenSocket *connection);
97 virtual void DidRead(ListenSocket *connection, const char* data, int len);
98 virtual void DidClose(ListenSocket *sock);
99
110 scoped_ptr<base::Thread> thread_; 100 scoped_ptr<base::Thread> thread_;
111 MessageLoopForIO* loop_; 101 MessageLoopForIO* loop_;
112 ListenSocket* server_; 102 ListenSocket* server_;
113 ListenSocket* connection_; 103 ListenSocket* connection_;
114 ListenSocketTestAction last_action_; 104 ListenSocketTestAction last_action_;
115 105
116 SOCKET test_socket_; 106 SOCKET test_socket_;
117 static const int kTestPort; 107 static const int kTestPort;
118 108
119 base::Lock lock_; // protects |queue_| and wraps |cv_| 109 base::Lock lock_; // protects |queue_| and wraps |cv_|
120 base::ConditionVariable cv_; 110 base::ConditionVariable cv_;
121 std::deque<ListenSocketTestAction> queue_; 111 std::deque<ListenSocketTestAction> queue_;
112
113 protected:
114 friend class base::RefCountedThreadSafe<ListenSocketTester>;
115
116 virtual ~ListenSocketTester();
117
118 virtual ListenSocket* DoListen();
122 }; 119 };
123 120
124 #endif // NET_BASE_LISTEN_SOCKET_UNITTEST_H_ 121 #endif // NET_BASE_LISTEN_SOCKET_UNITTEST_H_
OLDNEW
« no previous file with comments | « net/base/gzip_filter_unittest.cc ('k') | net/base/listen_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698