Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | |
3 * Copyright (C) 2014 Eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus 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 Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 #include <gtest/gtest.h> | |
19 | |
20 #include <OAIdl.h> | |
21 #include "../../src/plugin/PluginUserSettings.h" | |
22 | |
23 //---------------------------------- | |
24 // GetIDsOfNames | |
25 //---------------------------------- | |
26 | |
27 namespace | |
28 { | |
29 void single_method_name_found(std::wstring name, DISPID expected_id) | |
Felix Dahlke
2014/09/30 13:50:59
Camel case here and below please, coding style and
| |
30 { | |
31 CPluginUserSettings x; | |
32 wchar_t *names[1]; | |
Eric
2014/10/07 16:58:10
It used to be that this wouldn't compile in Visual
| |
33 names[0] = const_cast<wchar_t *>(name.c_str()); | |
34 DISPID ids[1]; | |
35 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); | |
36 ASSERT_EQ(S_OK, h); | |
37 DISPID id=ids[0]; | |
Felix Dahlke
2014/09/30 13:50:59
Spaces around the = please.
| |
38 ASSERT_EQ(expected_id, id); | |
39 } | |
40 | |
41 void single_method_name_notfound(std::wstring name) | |
42 { | |
43 CPluginUserSettings x; | |
44 wchar_t *names[1]; | |
45 names[0] = const_cast<wchar_t *>(name.c_str()); | |
46 DISPID ids[1]; | |
47 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); | |
48 ASSERT_NE(S_OK, h); | |
49 // The old version returns a nonstandard error code. | |
50 if (h == DISP_E_MEMBERNOTFOUND) | |
51 { | |
52 return; | |
53 } | |
54 EXPECT_EQ(DISP_E_UNKNOWNNAME, h); | |
55 } | |
56 } | |
57 | |
58 TEST(CPluginUserSettings_GetIDsOfNames_Test, all_defined_found) | |
59 { | |
60 CPluginUserSettings x; | |
61 single_method_name_found(L"GetMessage", 0); | |
62 single_method_name_found(L"GetLanguageCount", 1); | |
63 single_method_name_found(L"GetLanguageByIndex", 2); | |
64 single_method_name_found(L"GetLanguageTitleByIndex", 3); | |
65 single_method_name_found(L"SetLanguage", 4); | |
66 single_method_name_found(L"GetLanguage", 5); | |
67 single_method_name_found(L"GetWhitelistDomains", 6); | |
68 single_method_name_found(L"AddWhitelistDomain", 7); | |
69 single_method_name_found(L"RemoveWhitelistDomain", 8); | |
70 single_method_name_found(L"GetAppLocale", 9); | |
71 single_method_name_found(L"GetDocumentationLink", 10); | |
72 single_method_name_found(L"IsAcceptableAdsEnabled", 11); | |
73 single_method_name_found(L"SetAcceptableAdsEnabled", 12); | |
74 } | |
75 | |
76 TEST(CPluginUserSettings_GetIDsOfNames_Test, undefined_not_found) | |
77 { | |
78 single_method_name_notfound(L""); | |
79 single_method_name_notfound(L"clearly unknown"); | |
80 single_method_name_notfound(L"GETMESSAGE"); | |
81 } | |
82 | |
83 //---------------------------------- | |
84 // Invoke | |
85 //---------------------------------- | |
86 | |
87 namespace | |
88 { | |
89 void invoke_invalid_dispatch_id(DISPID id) | |
90 { | |
91 CPluginUserSettings x; | |
92 DISPPARAMS params; | |
93 params.rgvarg = nullptr; | |
94 params.rgdispidNamedArgs = nullptr; | |
95 params.cArgs = 0; | |
96 params.cNamedArgs = 0; | |
97 EXCEPINFO ex; | |
98 HRESULT h = x.Invoke(id, IID_NULL, 0, DISPATCH_METHOD, ¶ms, nullptr, &ex , nullptr); | |
99 ASSERT_NE(S_OK, h); | |
100 // The old version returns a nonstandard error code. | |
101 if (h == DISP_E_BADINDEX) | |
102 { | |
103 return; | |
104 } | |
105 EXPECT_EQ(DISP_E_MEMBERNOTFOUND, h); | |
106 } | |
107 } | |
108 | |
109 /** | |
110 * Verify that a negative Dispatch ID returns the proper error code. | |
111 */ | |
112 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_underflow) | |
113 { | |
114 invoke_invalid_dispatch_id(-1); | |
115 } | |
116 | |
117 /** | |
118 * Verify that a positive Dispatch ID that's too large returns the proper error code. | |
119 */ | |
120 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_overflow) | |
121 { | |
122 invoke_invalid_dispatch_id(13); | |
123 } | |
OLD | NEW |