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

Delta Between Two Patch Sets: test/plugin/UserSettingsTest.cpp

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

Powered by Google App Engine
This is Rietveld