Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2014 Eyeo GmbH | 3 * Copyright (C) 2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <gtest/gtest.h> | 18 #include <gtest/gtest.h> |
19 | 19 |
20 #include "../src/shared/Registry.h" | 20 #include "../src/shared/Registry.h" |
21 #include "../src/shared/IE_Version.h" | 21 #include "../src/shared/IE_Version.h" |
22 | 22 |
23 using namespace AdblockPlus; | 23 using namespace AdblockPlus; |
24 | 24 |
25 //---------------------------------- | 25 //---------------------------------- |
26 // Registry_Key | 26 // Registry_Key |
27 //---------------------------------- | 27 //---------------------------------- |
28 | 28 TEST(RegistryTest, simple_0) |
29 class Registry_Test | |
30 : public ::testing::Test | |
31 { | 29 { |
32 }; | 30 ASSERT_NO_THROW({ auto r = RegistryKey(HKEY_CLASSES_ROOT, L"CLSID"); }); |
33 | |
34 TEST(Registry_Test, roots_0) | |
35 { | |
36 // Test succeeds if it does not throw | |
37 auto r = Registry_Key(Registry_Key::Predefined::HKCR); | |
38 r = Registry_Key(Registry_Key::Predefined::HKCC); | |
39 r = Registry_Key(Registry_Key::Predefined::HKCU); | |
40 r = Registry_Key(Registry_Key::Predefined::HKLM); | |
41 r = Registry_Key(Registry_Key::Predefined::HKU); | |
42 } | 31 } |
43 | 32 |
44 TEST(Registry_Test, roots_1) | 33 TEST(RegistryTest, constructor_illegal_argument_0) |
45 { | 34 { |
46 // Test succeeds if it does not throw | 35 ASSERT_ANY_THROW({ auto r1 = RegistryKey(HKEY_CLASSES_ROOT, L""); }); |
47 auto r = Registry_Key(Registry_Key::Predefined::HKCR, L""); | |
48 r = Registry_Key(Registry_Key::Predefined::HKCC, L""); | |
49 r = Registry_Key(Registry_Key::Predefined::HKCU, L""); | |
50 r = Registry_Key(Registry_Key::Predefined::HKLM, L""); | |
51 r = Registry_Key(Registry_Key::Predefined::HKU, L""); | |
52 } | 36 } |
53 | 37 |
54 TEST(Registry_Test, value_notfound_0) | 38 TEST(RegistryTest, value_notfound_0) |
55 { | 39 { |
56 auto r1 = Registry_Key(Registry_Key::Predefined::HKCR); | 40 auto r1 = RegistryKey(HKEY_CLASSES_ROOT, L"CLSID"); |
57 ASSERT_ANY_THROW({ r1.value_wstring(L"nonexistent"); }); | |
58 } | |
59 | |
60 TEST(Registry_Test, value_notfound_1) | |
61 { | |
62 auto r1 = Registry_Key(Registry_Key::Predefined::HKCR, L""); | |
63 ASSERT_ANY_THROW({ r1.value_wstring(L"nonexistent"); }); | |
64 } | |
65 | |
66 TEST(Registry_Test, value_notfound_2) | |
67 { | |
68 auto r1 = Registry_Key(Registry_Key::Predefined::HKCR, L"CLSID"); | |
69 ASSERT_ANY_THROW({ r1.value_wstring(L"nonexistent"); }); | 41 ASSERT_ANY_THROW({ r1.value_wstring(L"nonexistent"); }); |
70 } | 42 } |
71 | 43 |
72 //---------------------------------- | 44 //---------------------------------- |
73 // IE_Version | 45 // IE_Version |
sergei
2015/01/06 13:39:11
The tests below should be in IE_versionTest.cpp
Eric
2015/01/06 17:10:34
OK. I'll do it in a later change. We need to move
| |
74 //---------------------------------- | 46 //---------------------------------- |
75 | 47 /* |
76 class IE_Version_Test | 48 * Exact version tests enabled by default. |
77 : public ::testing::Test | 49 * If they are disabled, gtext will report 2 disabled tests. |
78 { | 50 */ |
79 }; | 51 #if !defined(DISABLE_EXACT_TESTS) |
52 #define exact(x) exact_##x | |
sergei
2015/01/06 13:39:11
What is the aim of it?
I would remove it.
Eric
2015/01/06 17:10:34
Ordinarily unit tests should always run independen
| |
53 #else | |
54 #define exact(x) DISABLED_exact_##x | |
55 #endif | |
56 /* | |
57 * Define a default version as the current version of IE in general release. | |
58 * Predefine on the command line to compile tests for non-standard development e nvironments. | |
59 */ | |
60 #ifndef INSTALLED_IE_VERSION | |
61 #define INSTALLED_IE_VERSION 11 | |
62 #endif | |
80 | 63 |
81 TEST(IE_Version_Test, sanity_string) | 64 TEST(IE_Version_Test, sanity_string) |
82 { | 65 { |
83 std::wstring version = AdblockPlus::IE::installed_version_string(); | 66 std::wstring version = AdblockPlus::IE::InstalledVersionString(); |
84 ASSERT_NE(version, L""); | 67 ASSERT_FALSE(version.length() == 0); // separate test for default value |
85 // Replace with local version prefix as appropriate | 68 ASSERT_TRUE(version.length() >= 2); |
86 if (false) | |
87 { | |
88 EXPECT_EQ(0, version.compare(0, 3, L"11.")); | |
89 } | |
90 } | 69 } |
91 | 70 |
92 TEST(IE_Version_Test, sanity_major) | 71 TEST(IE_Version_Test, sanity_major) |
93 { | 72 { |
94 int version = AdblockPlus::IE::installed_major_version(); | 73 int version = AdblockPlus::IE::InstalledMajorVersion(); |
95 ASSERT_NE(version, 0); | 74 ASSERT_NE(version, 0); // separate test for default value |
96 // Replace with local major version | 75 ASSERT_GE(version, 6); |
97 if (false) | 76 ASSERT_LE(version, 12); |
98 { | 77 EXPECT_NE(version, 12); // This check will point out when the test needs updat ing. |
99 EXPECT_EQ(version, 11); | |
100 } | |
101 } | 78 } |
79 | |
80 TEST(IE_Version_Test, exact(string)) | |
81 { | |
82 std::wstring version = AdblockPlus::IE::InstalledVersionString(); | |
83 std::wstring expected = std::to_wstring(INSTALLED_IE_VERSION) + L"."; | |
84 ASSERT_EQ(expected, version.substr(0, expected.length())); | |
85 } | |
86 | |
87 TEST(IE_Version_Test, exact(major)) | |
88 { | |
89 int version = AdblockPlus::IE::InstalledMajorVersion(); | |
90 ASSERT_EQ(version, INSTALLED_IE_VERSION); | |
91 } | |
LEFT | RIGHT |