forked from aseprite/laf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rect_tests.cpp
65 lines (54 loc) · 1.8 KB
/
rect_tests.cpp
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
// LAF Gfx Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2013 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gtest/gtest.h>
#include "gfx/border.h"
#include "gfx/rect.h"
#include "gfx/rect_io.h"
#include "gfx/size.h"
using namespace std;
using namespace gfx;
TEST(Rect, Ctor)
{
EXPECT_EQ(Rect(0, 0, 0, 0), Rect());
EXPECT_EQ(10, Rect(10, 20, 30, 40).x);
EXPECT_EQ(20, Rect(10, 20, 30, 40).y);
EXPECT_EQ(30, Rect(10, 20, 30, 40).w);
EXPECT_EQ(40, Rect(10, 20, 30, 40).h);
}
TEST(Rect, Inflate)
{
EXPECT_EQ(Rect(10, 20, 31, 42), Rect(10, 20, 30, 40).inflate(1, 2));
EXPECT_EQ(Rect(10, 20, 31, 42), Rect(10, 20, 30, 40).inflate(Size(1, 2)));
}
TEST(Rect, Enlarge)
{
EXPECT_EQ(Rect(9, 19, 32, 42), Rect(10, 20, 30, 40).enlarge(1));
EXPECT_EQ(Rect(9, 18, 34, 46), Rect(10, 20, 30, 40).enlarge(Border(1, 2, 3, 4)));
EXPECT_EQ(Rect(9, 18, 34, 46), Rect(10, 20, 30, 40) + Border(1, 2, 3, 4));
}
TEST(Rect, Shrink)
{
EXPECT_EQ(Rect(11, 21, 28, 38), Rect(10, 20, 30, 40).shrink(1));
EXPECT_EQ(Rect(11, 22, 26, 34), Rect(10, 20, 30, 40).shrink(Border(1, 2, 3, 4)));
EXPECT_EQ(Rect(11, 22, 26, 34), Rect(10, 20, 30, 40) - Border(1, 2, 3, 4));
}
TEST(Rect, FitIn)
{
EXPECT_EQ(Rect(10, 10, 8, 8), Rect(0, 0, 4, 4).fitIn(Rect(10, 10, 8, 8)));
EXPECT_EQ(Rect(10, 10, 4, 4), Rect(0, 0, 8, 8).fitIn(Rect(10, 10, 4, 4)));
EXPECT_EQ(Rect(10, 10, 8, 4), Rect(0, 0, 16, 8).fitIn(Rect(10, 10, 8, 4)));
EXPECT_EQ(Rect(10, 12, 8, 4), Rect(0, 0, 16, 8).fitIn(Rect(10, 10, 8, 8)));
EXPECT_EQ(Rect(13, 10, 2, 4), Rect(0, 0, 8, 16).fitIn(Rect(10, 10, 8, 4)));
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}