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

Unified Diff: webrtc/test/channel_transport/udp_socket_manager_unittest.cc

Issue 2336123002: Revert of Moved webrtc/test/channel_transport/ into webrtc/voice_engine/test/ (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/test/channel_transport/udp_socket_manager_unittest.cc
diff --git a/webrtc/test/channel_transport/udp_socket_manager_unittest.cc b/webrtc/test/channel_transport/udp_socket_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b49021bffe82e946e6c2eca54b86f345db949199
--- /dev/null
+++ b/webrtc/test/channel_transport/udp_socket_manager_unittest.cc
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+// Tests for the UdpSocketManager interface.
+// Note: This tests UdpSocketManager together with UdpSocketWrapper,
+// due to the way the code is full of static-casts to the platform dependent
+// subtypes.
+// It also uses the static UdpSocketManager object.
+// The most important property of these tests is that they do not leak memory.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/system_wrappers/include/trace.h"
+#include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h"
+#include "webrtc/test/channel_transport/udp_socket_wrapper.h"
+
+namespace webrtc {
+namespace test {
+
+TEST(UdpSocketManager, CreateCallsInitAndDoesNotLeakMemory) {
+ int32_t id = 42;
+ uint8_t threads = 1;
+ UdpSocketManager* mgr = UdpSocketManager::Create(id, threads);
+ // Create is supposed to have called init on the object.
+ EXPECT_FALSE(mgr->Init(id, threads))
+ << "Init should return false since Create is supposed to call it.";
+ UdpSocketManager::Return();
+}
+
+// Creates a socket and adds it to the socket manager, and then removes it
+// before destroying the socket manager.
+TEST(UdpSocketManager, AddAndRemoveSocketDoesNotLeakMemory) {
+ int32_t id = 42;
+ uint8_t threads = 1;
+ UdpSocketManager* mgr = UdpSocketManager::Create(id, threads);
+ UdpSocketWrapper* socket =
+ UdpSocketWrapper::CreateSocket(id,
+ mgr,
+ NULL, // CallbackObj
+ NULL, // IncomingSocketCallback
+ false, // ipV6Enable
+ false); // disableGQOS
+ // The constructor will do AddSocket on the manager.
+ // RemoveSocket indirectly calls Delete.
+ EXPECT_EQ(true, mgr->RemoveSocket(socket));
+ UdpSocketManager::Return();
+}
+
+// Creates a socket and add it to the socket manager, but does not remove it
+// before destroying the socket manager.
+// On Posix, this destroys the socket.
+// On Winsock2 Windows, it enters an infinite wait for all the sockets
+// to go away.
+TEST(UdpSocketManager, UnremovedSocketsGetCollectedAtManagerDeletion) {
+#if defined(_WIN32)
+ // It's hard to test an infinite wait, so we don't.
+#else
+ int32_t id = 42;
+ uint8_t threads = 1;
+ UdpSocketManager* mgr = UdpSocketManager::Create(id, threads);
+ UdpSocketWrapper* unused_socket = UdpSocketWrapper::CreateSocket(
+ id,
+ mgr,
+ NULL, // CallbackObj
+ NULL, // IncomingSocketCallback
+ false, // ipV6Enable
+ false); // disableGQOS
+ // The constructor will do AddSocket on the manager.
+ // Call a member funtion to work around "set but not used" compliation
+ // error on ChromeOS ARM.
+ unused_socket->SetEventToNull();
+ unused_socket = NULL;
+ UdpSocketManager::Return();
+#endif
+}
+
+} // namespace test
+} // namespace webrtc
« no previous file with comments | « webrtc/test/channel_transport/udp_socket_manager_posix.cc ('k') | webrtc/test/channel_transport/udp_socket_manager_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698