File: Test_ScrollBar.cpp

package info (click to toggle)
pymol 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 42,288 kB
  • sloc: cpp: 476,472; python: 76,538; ansic: 29,510; javascript: 6,792; sh: 47; makefile: 24
file content (105 lines) | stat: -rw-r--r-- 2,412 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <algorithm>
#include <iterator>

#include "CGO.h"
#include "ScrollBar.h"
#include "Test.h"

using namespace pymol::test;

namespace
{
ScrollBar getValuedScrollBar()
{
  ScrollBar sb{nullptr, true};
  sb.setLimits(11, 1); // m_MaxValue == 10
  return sb;
}
} // namespace

static
bool operator==(const BlockRect& lhs, const BlockRect& rhs)
{
  return lhs.top == rhs.top && lhs.left == rhs.left &&
         lhs.bottom == rhs.bottom && lhs.right == rhs.right;
}

TEST_CASE("ScrollBar Default", "[ScrollBar]")
{
  ScrollBar sb(nullptr, true);
  REQUIRE(sizeof(sb) == sizeof(ScrollBar));
}

TEST_CASE("ScrollBar getValue", "[ScrollBar]")
{
  ScrollBar sb(nullptr, true);
  REQUIRE(pymol::almost_equal(sb.getValue(), 0.0f));
}

TEST_CASE("ScrollBar setLimits & isMaxed", "[ScrollBar]")
{
  auto sb = getValuedScrollBar();
  REQUIRE(!sb.isMaxed());
  REQUIRE(pymol::almost_equal(sb.getValue(), 0.0f));
}

TEST_CASE("ScrollBar maxOut", "[ScrollBar]")
{
  auto sb = getValuedScrollBar();
  sb.maxOut();
  REQUIRE(sb.isMaxed());
  REQUIRE(pymol::almost_equal(sb.getValue(), 10.0f));
}

TEST_CASE("ScrollBar setValue (Clamped)", "[ScrollBar]")
{
  auto sb = getValuedScrollBar();
  sb.setValue(-2.0f);
  REQUIRE(pymol::almost_equal(sb.getValue(), 0.0f));
  sb.setValue(8.0f);
  REQUIRE(pymol::almost_equal(sb.getValue(), 8.0f));
  sb.setValue(12.0f);
  REQUIRE(pymol::almost_equal(sb.getValue(), 10.0f));
}

TEST_CASE("ScrollBar setValue (Unclamped)", "[ScrollBar]")
{
  auto sb = getValuedScrollBar();
  sb.setValueNoCheck(-2.0f);
  REQUIRE(pymol::almost_equal(sb.getValue(), -2.0f));
  sb.setValueNoCheck(8.0f);
  REQUIRE(pymol::almost_equal(sb.getValue(), 8.0f));
  sb.setValueNoCheck(12.0f);
  REQUIRE(pymol::almost_equal(sb.getValue(), 12.0f));
}

TEST_CASE("ScrollBar moveBy", "[ScrollBar]")
{
  auto sb = getValuedScrollBar();
  sb.moveBy(123.0f);
  REQUIRE(pymol::almost_equal(sb.getValue(), 10.0f));
}

TEST_CASE("ScrollBar setBox", "[ScrollBar]")
{
  auto sb = getValuedScrollBar();
  BlockRect br{5, 10, 15, 20};
  sb.setBox(5, 10, 15, 20);
  REQUIRE(br == sb.rect);
}

/**
 * TODO: Member functions to test
 *
 * int release(int, int, int, int) override;
 * int click(int, int, int, int) override;
 * int drag(int, int, int) override;
 * int draw(CGO*) override
 * int resphape(int, int) override
 *
 * void fill(CGO*);
 * void drawNoFill(CGO*);
 * int grabbed();
 * void drawHandle(float, CGO*);
 */