You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2009 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. #include "rtc_base/win32_window.h"
  11. #include "rtc_base/gunit.h"
  12. #include "rtc_base/logging.h"
  13. static LRESULT kDummyResult = 0x1234ABCD;
  14. class TestWindow : public rtc::Win32Window {
  15. public:
  16. TestWindow() : destroyed_(false) { memset(&msg_, 0, sizeof(msg_)); }
  17. const MSG& msg() const { return msg_; }
  18. bool destroyed() const { return destroyed_; }
  19. bool OnMessage(UINT uMsg,
  20. WPARAM wParam,
  21. LPARAM lParam,
  22. LRESULT& result) override {
  23. msg_.message = uMsg;
  24. msg_.wParam = wParam;
  25. msg_.lParam = lParam;
  26. result = kDummyResult;
  27. return true;
  28. }
  29. void OnNcDestroy() override { destroyed_ = true; }
  30. private:
  31. MSG msg_;
  32. bool destroyed_;
  33. };
  34. TEST(Win32WindowTest, Basics) {
  35. TestWindow wnd;
  36. EXPECT_TRUE(wnd.handle() == nullptr);
  37. EXPECT_FALSE(wnd.destroyed());
  38. EXPECT_TRUE(wnd.Create(0, L"Test", 0, 0, 0, 0, 100, 100));
  39. EXPECT_TRUE(wnd.handle() != nullptr);
  40. EXPECT_EQ(kDummyResult, ::SendMessage(wnd.handle(), WM_USER, 1, 2));
  41. EXPECT_EQ(static_cast<UINT>(WM_USER), wnd.msg().message);
  42. EXPECT_EQ(1u, wnd.msg().wParam);
  43. EXPECT_EQ(2l, wnd.msg().lParam);
  44. wnd.Destroy();
  45. EXPECT_TRUE(wnd.handle() == nullptr);
  46. EXPECT_TRUE(wnd.destroyed());
  47. }
  48. TEST(Win32WindowTest, MultipleWindows) {
  49. TestWindow wnd1, wnd2;
  50. EXPECT_TRUE(wnd1.Create(0, L"Test", 0, 0, 0, 0, 100, 100));
  51. EXPECT_TRUE(wnd2.Create(0, L"Test", 0, 0, 0, 0, 100, 100));
  52. EXPECT_TRUE(wnd1.handle() != nullptr);
  53. EXPECT_TRUE(wnd2.handle() != nullptr);
  54. wnd1.Destroy();
  55. wnd2.Destroy();
  56. EXPECT_TRUE(wnd2.handle() == nullptr);
  57. EXPECT_TRUE(wnd1.handle() == nullptr);
  58. }