Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/plugin/UserSettingsTest.cpp

Issue 5979857238360064: Issues #1163, #1173 - refactor CPluginUserSettings (Closed)
Patch Set: rebase + add one final space character Created Feb. 23, 2015, 1:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/PluginUserSettings.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
18 #include <gtest/gtest.h> 17 #include <gtest/gtest.h>
19 18
20 #include <OAIdl.h> 19 #include <OAIdl.h>
21 #include "../../src/plugin/PluginUserSettings.h" 20 #include "../../src/plugin/PluginUserSettings.h"
22 21
23 //---------------------------------- 22 //----------------------------------
24 // GetIDsOfNames 23 // GetIDsOfNames
25 //---------------------------------- 24 //----------------------------------
26 25
27 namespace 26 namespace
28 { 27 {
29 void SingleMethodNameFound(std::wstring name, DISPID expected_id) 28 void SingleMethodNameFound(std::wstring name, DISPID expected_id)
30 { 29 {
31 CPluginUserSettings x; 30 CPluginUserSettings x;
32 wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())}; 31 wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())};
33 DISPID ids[1]; 32 DISPID ids[1];
34 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); 33 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids);
35 ASSERT_EQ(S_OK, h); 34 ASSERT_EQ(S_OK, h);
36 DISPID id = ids[0]; 35 DISPID id = ids[0];
37 ASSERT_EQ(expected_id, id); 36 ASSERT_EQ(expected_id, id);
38 } 37 }
39 38
40 void SingleMethodNameNotFound(std::wstring name) 39 void SingleMethodNameNotFound(std::wstring name)
41 { 40 {
42 CPluginUserSettings x; 41 CPluginUserSettings x;
43 wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())}; 42 wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())};
44 DISPID ids[1]; 43 DISPID ids[1];
45 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); 44 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids);
46 ASSERT_NE(S_OK, h); 45 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); 46 EXPECT_EQ(DISP_E_UNKNOWNNAME, h);
53 } 47 }
54 } 48 }
55 49
56 TEST(CPluginUserSettingsGetIDsOfNames, AllDefinedMethodsMustBeFound) 50 TEST(CPluginUserSettingsGetIDsOfNames, AllDefinedMethodsMustBeFound)
57 { 51 {
58 CPluginUserSettings x; 52 CPluginUserSettings x;
59 SingleMethodNameFound(L"GetMessage", 0); 53 SingleMethodNameFound(L"GetMessage", 0);
60 SingleMethodNameFound(L"GetLanguageCount", 1); 54 SingleMethodNameFound(L"GetLanguageCount", 1);
61 SingleMethodNameFound(L"GetLanguageByIndex", 2); 55 SingleMethodNameFound(L"GetLanguageByIndex", 2);
62 SingleMethodNameFound(L"GetLanguageTitleByIndex", 3); 56 SingleMethodNameFound(L"GetLanguageTitleByIndex", 3);
63 SingleMethodNameFound(L"SetLanguage", 4); 57 SingleMethodNameFound(L"SetLanguage", 4);
64 SingleMethodNameFound(L"GetLanguage", 5); 58 SingleMethodNameFound(L"GetLanguage", 5);
65 SingleMethodNameFound(L"GetWhitelistDomains", 6); 59 SingleMethodNameFound(L"GetWhitelistDomains", 6);
66 SingleMethodNameFound(L"AddWhitelistDomain", 7); 60 SingleMethodNameFound(L"AddWhitelistDomain", 7);
67 SingleMethodNameFound(L"RemoveWhitelistDomain", 8); 61 SingleMethodNameFound(L"RemoveWhitelistDomain", 8);
68 SingleMethodNameFound(L"GetAppLocale", 9); 62 SingleMethodNameFound(L"GetAppLocale", 9);
69 SingleMethodNameFound(L"GetDocumentationLink", 10); 63 SingleMethodNameFound(L"GetDocumentationLink", 10);
70 SingleMethodNameFound(L"IsAcceptableAdsEnabled", 11); 64 SingleMethodNameFound(L"IsAcceptableAdsEnabled", 11);
71 SingleMethodNameFound(L"SetAcceptableAdsEnabled", 12); 65 SingleMethodNameFound(L"SetAcceptableAdsEnabled", 12);
66 SingleMethodNameFound(L"IsUpdate", 13);
72 } 67 }
73 68
74 TEST(CPluginUserSettingsGetIDsOfNames, UndefinedMethodsMustNotBeFound) 69 TEST(CPluginUserSettingsGetIDsOfNames, UndefinedMethodsMustNotBeFound)
75 { 70 {
76 SingleMethodNameNotFound(L""); 71 SingleMethodNameNotFound(L"");
77 SingleMethodNameNotFound(L"clearly unknown"); 72 SingleMethodNameNotFound(L"clearly unknown");
78 SingleMethodNameNotFound(L"GETMESSAGE"); 73 SingleMethodNameNotFound(L"GETMESSAGE");
79 } 74 }
80 75
81 //---------------------------------- 76 //----------------------------------
82 // Invoke 77 // Invoke
83 //---------------------------------- 78 //----------------------------------
84 79
85 namespace 80 namespace
86 { 81 {
87 void InvokeInvalidDispatchId(DISPID id) 82 void InvokeInvalidDispatchId(DISPID id)
88 { 83 {
89 CPluginUserSettings x; 84 CPluginUserSettings x;
90 DISPPARAMS params; 85 DISPPARAMS params;
91 params.rgvarg = nullptr; 86 params.rgvarg = nullptr;
92 params.rgdispidNamedArgs = nullptr; 87 params.rgdispidNamedArgs = nullptr;
93 params.cArgs = 0; 88 params.cArgs = 0;
94 params.cNamedArgs = 0; 89 params.cNamedArgs = 0;
95 EXCEPINFO ex; 90 EXCEPINFO ex;
96 HRESULT h = x.Invoke(id, IID_NULL, 0, DISPATCH_METHOD, &params, nullptr, &ex , nullptr); 91 HRESULT h = x.Invoke(id, IID_NULL, 0, DISPATCH_METHOD, &params, nullptr, &ex , nullptr);
97 ASSERT_NE(S_OK, h); 92 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); 93 EXPECT_EQ(DISP_E_MEMBERNOTFOUND, h);
104 } 94 }
105 } 95 }
106 96
107 /** 97 /**
108 * Verify that a negative Dispatch ID returns the proper error code. 98 * Verify that a negative Dispatch ID returns the proper error code.
109 */ 99 */
110 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldUnderflow) 100 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldUnderflow)
111 { 101 {
112 InvokeInvalidDispatchId(-1); 102 InvokeInvalidDispatchId(-1);
113 } 103 }
114 104
115 /** 105 /**
116 * Verify that a positive Dispatch ID that's too large returns the proper error code. 106 * Verify that a positive Dispatch ID that's too large returns the proper error code.
117 */ 107 */
118 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldOverflow) 108 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldOverflow)
119 { 109 {
120 InvokeInvalidDispatchId(14); 110 InvokeInvalidDispatchId(14);
121 } 111 }
OLDNEW
« no previous file with comments | « src/plugin/PluginUserSettings.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld