File: randr_output_manager_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (79 lines) | stat: -rw-r--r-- 2,738 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "ui/gfx/x/randr_output_manager.h"

#include <optional>
#include <vector>

#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"

namespace {

void* ContextOf(int i) {
  return reinterpret_cast<void*>(i);
}

}  // namespace

namespace x11 {

std::ostream& operator<<(std::ostream& os, const RandRMonitorConfig& layout) {
  if (layout.id().has_value()) {
    os << *layout.id() << ": ";
  } else {
    os << "(no screen id): ";
  }
  return os << layout.rect().ToString() << " @ " << layout.dpi().x() << "x"
            << layout.dpi().y();
}

std::ostream& operator<<(
    std::ostream& os,
    const RandRMonitorConfigWithContext& layout_with_context) {
  return os << "{config=" << layout_with_context.config
            << ", context=" << layout_with_context.context << "}";
}

bool operator==(const RandRMonitorConfigWithContext& a,
                const RandRMonitorConfigWithContext& b) {
  return a.config == b.config && a.context == b.context;
}

TEST(RandrOutputManagerTest, CalculateDisplayLayoutDiff) {
  std::vector<RandRMonitorConfigWithContext> current_displays = {
      {{123, gfx::Rect(0, 0, 1230, 1230), gfx::Vector2d(96, 96)}, ContextOf(1)},
      {{234, gfx::Rect(1230, 0, 2340, 2340), gfx::Vector2d(192, 192)},
       ContextOf(2)},
      {{345, gfx::Rect(0, 1230, 3450, 3450), gfx::Vector2d(96, 96)},
       ContextOf(3)}};
  x11::RandRMonitorLayout new_layout(
      {// Updated.
       {234, gfx::Rect(3450, 1230, 2340, 2000), gfx::Vector2d(100, 96)},
       // Unchanged.
       {345, gfx::Rect(0, 1230, 3450, 3450), gfx::Vector2d(96, 96)},
       // New.
       {{}, gfx::Rect(3450, 3450, 4560, 4560), gfx::Vector2d(192, 192)}});
  auto diff = CalculateDisplayLayoutDiff(current_displays, new_layout);

  x11::RandRMonitorLayout expected_new_displays;
  expected_new_displays.configs.push_back(RandRMonitorConfig(
      {}, gfx::Rect(3450, 3450, 4560, 4560), gfx::Vector2d(192, 192)));
  EXPECT_EQ(diff.new_displays, expected_new_displays);

  std::vector<RandRMonitorConfigWithContext> expected_updated_displays = {
      RandRMonitorConfigWithContext(
          RandRMonitorConfig(234, gfx::Rect(3450, 1230, 2340, 2000),
                             gfx::Vector2d(100, 96)),
          ContextOf(2))};
  EXPECT_EQ(diff.updated_displays, expected_updated_displays);

  std::vector<RandRMonitorConfigWithContext> expected_removed_displays = {
      RandRMonitorConfigWithContext(
          RandRMonitorConfig(123, gfx::Rect(0, 0, 1230, 1230),
                             gfx::Vector2d(96, 96)),
          ContextOf(1))};
  EXPECT_EQ(diff.removed_displays, expected_removed_displays);
}

}  // namespace x11