/src/mozilla-central/gfx/tests/gtest/TestGfxPrefs.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "gtest/gtest.h" |
8 | | |
9 | | #include "gfxPrefs.h" |
10 | | #ifdef GFX_DECL_PREF |
11 | | #error "This is not supposed to be defined outside of gfxPrefs.h" |
12 | | #endif |
13 | | |
14 | | // If the default values for any of these preferences change, |
15 | | // just modify the test to match. We are only testing against |
16 | | // a particular value to make sure we receive the correct |
17 | | // result through this API. |
18 | | |
19 | 0 | TEST(GfxPrefs, Singleton) { |
20 | 0 | gfxPrefs::GetSingleton(); |
21 | 0 | ASSERT_TRUE(gfxPrefs::SingletonExists()); |
22 | 0 | } |
23 | | |
24 | 0 | TEST(GfxPrefs, LiveValues) { |
25 | 0 | gfxPrefs::GetSingleton(); |
26 | 0 | ASSERT_TRUE(gfxPrefs::SingletonExists()); |
27 | 0 |
|
28 | 0 | // Live boolean, default false |
29 | 0 | ASSERT_FALSE(gfxPrefs::LayersDumpTexture()); |
30 | 0 |
|
31 | 0 | // Live int32_t, default 23456 |
32 | 0 | ASSERT_TRUE(gfxPrefs::LayerScopePort() == 23456); |
33 | 0 |
|
34 | 0 | // Live uint32_t, default 2 |
35 | 0 | ASSERT_TRUE(gfxPrefs::MSAALevel() == 2); |
36 | 0 | } |
37 | | |
38 | 0 | TEST(GfxPrefs, OnceValues) { |
39 | 0 | gfxPrefs::GetSingleton(); |
40 | 0 | ASSERT_TRUE(gfxPrefs::SingletonExists()); |
41 | 0 |
|
42 | 0 | // Once boolean, default true |
43 | 0 | ASSERT_TRUE(gfxPrefs::WorkAroundDriverBugs()); |
44 | 0 |
|
45 | 0 | // Once boolean, default false |
46 | 0 | ASSERT_FALSE(gfxPrefs::LayersDump()); |
47 | 0 |
|
48 | 0 | // Once int32_t, default 95 |
49 | 0 | ASSERT_TRUE(gfxPrefs::CanvasSkiaGLCacheSize() == 96); |
50 | 0 |
|
51 | 0 | // Once uint32_t, default 5 |
52 | 0 | ASSERT_TRUE(gfxPrefs::APZMaxVelocityQueueSize() == 5); |
53 | 0 |
|
54 | 0 | // Once float, default -1 (should be OK with ==) |
55 | 0 | ASSERT_TRUE(gfxPrefs::APZMaxVelocity() == -1.0f); |
56 | 0 | } |
57 | | |
58 | 0 | TEST(GfxPrefs, Set) { |
59 | 0 | gfxPrefs::GetSingleton(); |
60 | 0 | ASSERT_TRUE(gfxPrefs::SingletonExists()); |
61 | 0 |
|
62 | 0 | // Once boolean, default false |
63 | 0 | ASSERT_FALSE(gfxPrefs::LayersDump()); |
64 | 0 | gfxPrefs::SetLayersDump(true); |
65 | 0 | ASSERT_TRUE(gfxPrefs::LayersDump()); |
66 | 0 | gfxPrefs::SetLayersDump(false); |
67 | 0 | ASSERT_FALSE(gfxPrefs::LayersDump()); |
68 | 0 |
|
69 | 0 | // Live boolean, default false |
70 | 0 | ASSERT_FALSE(gfxPrefs::LayersDumpTexture()); |
71 | 0 | gfxPrefs::SetLayersDumpTexture(true); |
72 | 0 | ASSERT_TRUE(gfxPrefs::LayersDumpTexture()); |
73 | 0 | gfxPrefs::SetLayersDumpTexture(false); |
74 | 0 | ASSERT_FALSE(gfxPrefs::LayersDumpTexture()); |
75 | 0 |
|
76 | 0 | // Once float, default -1 |
77 | 0 | ASSERT_TRUE(gfxPrefs::APZMaxVelocity() == -1.0f); |
78 | 0 | gfxPrefs::SetAPZMaxVelocity(1.75f); |
79 | 0 | ASSERT_TRUE(gfxPrefs::APZMaxVelocity() == 1.75f); |
80 | 0 | gfxPrefs::SetAPZMaxVelocity(-1.0f); |
81 | 0 | ASSERT_TRUE(gfxPrefs::APZMaxVelocity() == -1.0f); |
82 | 0 | } |
83 | | |
84 | | // Randomly test the function we use in nsExceptionHandler.cpp here: |
85 | | extern bool SimpleNoCLibDtoA(double aValue, char* aBuffer, int aBufferLength); |
86 | | TEST(GfxPrefs, StringUtility) |
87 | 0 | { |
88 | 0 | char testBuffer[64]; |
89 | 0 | double testVal[] = {13.4, |
90 | 0 | 3324243.42, |
91 | 0 | 0.332424342, |
92 | 0 | 864.0, |
93 | 0 | 86400 * 100000000.0 * 10000000000.0 * 10000000000.0 * 100.0, |
94 | 0 | 86400.0 * 366.0 * 100.0 + 14243.44332}; |
95 | 0 | for (size_t i=0; i<mozilla::ArrayLength(testVal); i++) { |
96 | 0 | ASSERT_TRUE(SimpleNoCLibDtoA(testVal[i], testBuffer, sizeof(testBuffer))); |
97 | 0 | ASSERT_TRUE(fabs(1.0 - atof(testBuffer)/testVal[i]) < 0.0001); |
98 | 0 | } |
99 | 0 |
|
100 | 0 | // We do not like negative numbers (random limitation) |
101 | 0 | ASSERT_FALSE(SimpleNoCLibDtoA(-864.0, testBuffer, sizeof(testBuffer))); |
102 | 0 |
|
103 | 0 | // It won't fit into 32: |
104 | 0 | ASSERT_FALSE(SimpleNoCLibDtoA(testVal[4], testBuffer, sizeof(testBuffer)/2)); |
105 | 0 | } |