~townsend/unity/fix-lp1301394-trusty

3616.3.1 by Brandon Schaefer
* Add EMConverter, take moslty from Nux/EMMetrics. We don't
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
/*
3
 * Copyright (C) 2014 Canonical Ltd
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 3 as
7
 * published by the Free Software Foundation.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
18
 */
19
20
#include <gmock/gmock.h>
21
using namespace testing;
22
23
#include "unity-shared/EMConverter.h"
24
25
namespace unity
26
{
27
28
int const PIXEL_SIZE = 24;
29
int const FONT_SIZE  = 13;
3616.3.3 by Brandon Schaefer
* Add some more tests.
30
double const DPI     = 96.0;
3616.3.1 by Brandon Schaefer
* Add EMConverter, take moslty from Nux/EMMetrics. We don't
31
32
class TestEMConverter : public Test
33
{
34
public:
35
  TestEMConverter()
36
    : em_converter(FONT_SIZE, DPI)
37
  {
38
  }
39
40
  EMConverter em_converter;
41
};
42
43
TEST_F(TestEMConverter, TestCtor)
44
{
45
  EXPECT_EQ(FONT_SIZE, em_converter.GetFontSize());
46
  EXPECT_EQ(DPI, em_converter.GetDPI());
47
}
48
49
TEST_F(TestEMConverter, TestSetFontSize)
50
{
51
  int const font_size = 15;
52
53
  em_converter.SetFontSize(font_size);
54
  EXPECT_EQ(font_size, em_converter.GetFontSize());
55
}
56
57
TEST_F(TestEMConverter, TestSetDPI)
58
{
3616.3.3 by Brandon Schaefer
* Add some more tests.
59
  int const dpi = 120.0;
3616.3.1 by Brandon Schaefer
* Add EMConverter, take moslty from Nux/EMMetrics. We don't
60
61
  em_converter.SetDPI(dpi);
62
  EXPECT_EQ(dpi, em_converter.GetDPI());
63
}
64
3627.1.1 by Brandon Schaefer
* Refactor the EMConverter API.
65
TEST_F(TestEMConverter, TestConvertPixel)
66
{
3566.6.3 by Brandon Schaefer
* Change ConvertPixels to CP
67
  EXPECT_EQ(PIXEL_SIZE, em_converter.CP(PIXEL_SIZE));
3627.1.1 by Brandon Schaefer
* Refactor the EMConverter API.
68
}
69
70
TEST_F(TestEMConverter, TestDPIScale)
71
{
72
  EXPECT_FLOAT_EQ(em_converter.DPIScale(), 1.0);
73
}
74
75
TEST_F(TestEMConverter, TestDPIScale2)
76
{
77
  float scale = 2.0f;
78
  em_converter.SetDPI(DPI * scale);
79
  EXPECT_FLOAT_EQ(em_converter.DPIScale(), 2.0);
80
}
3616.3.1 by Brandon Schaefer
* Add EMConverter, take moslty from Nux/EMMetrics. We don't
81
3632.2.1 by Brandon Schaefer
* Add a simple Pt to Px function to the EMConverter
82
TEST_F(TestEMConverter, TestPtToPx)
83
{
84
  int pt = 12;
85
  EXPECT_EQ(em_converter.PtToPx(pt), 16);
86
}
87
3616.3.1 by Brandon Schaefer
* Add EMConverter, take moslty from Nux/EMMetrics. We don't
88
} // namespace unity