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

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

Issue 6267413888761856: Issue #1163 - add unit tests for CPluginUserSettings (Closed)
Patch Set: Created Aug. 6, 2014, 3:55 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 | « adblockplus.gyp ('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
(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)
30 {
31 CPluginUserSettings x;
32 wchar_t *names[1];
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];
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)
sergei 2014/08/14 11:37:26 `id` is not used.
Eric 2014/08/14 14:29:53 Oops. Forgot to replace the -1 below when I refact
90 {
91 CPluginUserSettings x;
92 DISPPARAMS params;
sergei 2014/08/14 11:37:26 DISPPARAMS params = {} looks better, but OK here.
Eric 2014/08/14 14:29:53 Neither this nor the EXCEPINFO below are involved
93 params.rgvarg = nullptr;
94 params.rgdispidNamedArgs = nullptr;
95 params.cArgs = 0;
96 params.cNamedArgs = 0;
97 EXCEPINFO ex;
sergei 2014/08/14 11:37:26 I would also initialize it.
98 HRESULT h = x.Invoke(-1, IID_NULL, 0, 0, &params, nullptr, &ex, nullptr);
sergei 2014/08/14 11:37:26 The first arg should be `id`.
sergei 2014/08/14 11:37:26 Why is the flag 0? As I see we expose only methods
Eric 2014/08/14 14:29:53 I changed this in the test, but the larger problem
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 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_underflow)
sergei 2014/08/14 11:37:26 I prefer more descriptive test names.
Eric 2014/08/14 14:29:53 I added comments. If the test fails, the first thi
110 {
111 invoke_invalid_dispatch_id(-1);
112 }
113
114 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_overflow)
115 {
116 invoke_invalid_dispatch_id(13);
117 }
OLDNEW
« no previous file with comments | « adblockplus.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld