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 SingleMethodNameFound(std::wstring name, DISPID expected_id) | |
sergei
2014/11/03 14:41:36
I think we need some well known abbreviation like
Felix Dahlke
2014/11/03 16:05:18
I actually thought this is modified below and that
| |
30 { | |
31 CPluginUserSettings x; | |
32 wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())}; | |
33 DISPID ids[1]; | |
34 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); | |
35 ASSERT_EQ(S_OK, h); | |
36 DISPID id = ids[0]; | |
37 ASSERT_EQ(expected_id, id); | |
38 } | |
39 | |
40 void SingleMethodNameNotFound(std::wstring name) | |
sergei
2014/11/03 14:41:36
CRIM
| |
41 { | |
42 CPluginUserSettings x; | |
43 wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())}; | |
44 DISPID ids[1]; | |
45 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); | |
46 ASSERT_NE(S_OK, h); | |
47 // The old version returns a nonstandard error code. | |
48 if (h == DISP_E_MEMBERNOTFOUND) | |
49 { | |
50 return; | |
51 } | |
52 EXPECT_EQ(DISP_E_UNKNOWNNAME, h); | |
53 } | |
54 } | |
55 | |
56 TEST(CPluginUserSettingsGetIDsOfNames, AllDefinedMethodsMustBeFound) | |
57 { | |
58 CPluginUserSettings x; | |
59 SingleMethodNameFound(L"GetMessage", 0); | |
60 SingleMethodNameFound(L"GetLanguageCount", 1); | |
61 SingleMethodNameFound(L"GetLanguageByIndex", 2); | |
62 SingleMethodNameFound(L"GetLanguageTitleByIndex", 3); | |
63 SingleMethodNameFound(L"SetLanguage", 4); | |
64 SingleMethodNameFound(L"GetLanguage", 5); | |
65 SingleMethodNameFound(L"GetWhitelistDomains", 6); | |
66 SingleMethodNameFound(L"AddWhitelistDomain", 7); | |
67 SingleMethodNameFound(L"RemoveWhitelistDomain", 8); | |
68 SingleMethodNameFound(L"GetAppLocale", 9); | |
69 SingleMethodNameFound(L"GetDocumentationLink", 10); | |
70 SingleMethodNameFound(L"IsAcceptableAdsEnabled", 11); | |
71 SingleMethodNameFound(L"SetAcceptableAdsEnabled", 12); | |
72 } | |
73 | |
74 TEST(CPluginUserSettingsGetIDsOfNames, UndefinedMethodsMustNotBeFound) | |
75 { | |
76 SingleMethodNameNotFound(L""); | |
77 SingleMethodNameNotFound(L"clearly unknown"); | |
78 SingleMethodNameNotFound(L"GETMESSAGE"); | |
79 } | |
80 | |
81 //---------------------------------- | |
82 // Invoke | |
83 //---------------------------------- | |
84 | |
85 namespace | |
86 { | |
87 void InvokeInvalidDispatchId(DISPID id) | |
88 { | |
89 CPluginUserSettings x; | |
90 DISPPARAMS params; | |
91 params.rgvarg = nullptr; | |
92 params.rgdispidNamedArgs = nullptr; | |
93 params.cArgs = 0; | |
94 params.cNamedArgs = 0; | |
95 EXCEPINFO ex; | |
96 HRESULT h = x.Invoke(id, IID_NULL, 0, DISPATCH_METHOD, ¶ms, nullptr, &ex , nullptr); | |
97 ASSERT_NE(S_OK, h); | |
98 // The old version returns a nonstandard error code. | |
99 if (h == DISP_E_BADINDEX) | |
100 { | |
101 return; | |
102 } | |
103 EXPECT_EQ(DISP_E_MEMBERNOTFOUND, h); | |
104 } | |
105 } | |
106 | |
107 /** | |
108 * Verify that a negative Dispatch ID returns the proper error code. | |
109 */ | |
110 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldUnderflow) | |
111 { | |
112 InvokeInvalidDispatchId(-1); | |
113 } | |
114 | |
115 /** | |
116 * Verify that a positive Dispatch ID that's too large returns the proper error code. | |
117 */ | |
118 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldOverflow) | |
119 { | |
120 InvokeInvalidDispatchId(13); | |
121 } | |
OLD | NEW |