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