| OLD | NEW |
| 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> | |
| 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 single_method_name_found(std::wstring name, DISPID expected_id) | 28 void single_method_name_found(std::wstring name, DISPID expected_id) |
| 30 { | 29 { |
| 31 CPluginUserSettings x; | 30 CPluginUserSettings x; |
| 32 wchar_t *names[1]; | 31 wchar_t *names[1]; |
| 33 names[0] = const_cast<wchar_t *>(name.c_str()); | 32 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]; |
| 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 single_method_name_notfound(std::wstring name) |
| 42 { | 41 { |
| 43 CPluginUserSettings x; | 42 CPluginUserSettings x; |
| 44 wchar_t *names[1]; | 43 wchar_t *names[1]; |
| 45 names[0] = const_cast<wchar_t *>(name.c_str()); | 44 names[0] = const_cast<wchar_t *>(name.c_str()); |
| 46 DISPID ids[1]; | 45 DISPID ids[1]; |
| 47 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); | 46 HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); |
| 48 ASSERT_NE(S_OK, h); | 47 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); | 48 EXPECT_EQ(DISP_E_UNKNOWNNAME, h); |
| 55 } | 49 } |
| 56 } | 50 } |
| 57 | 51 |
| 58 TEST(CPluginUserSettings_GetIDsOfNames_Test, all_defined_found) | 52 TEST(CPluginUserSettings_GetIDsOfNames_Test, all_defined_found) |
| 59 { | 53 { |
| 60 CPluginUserSettings x; | 54 CPluginUserSettings x; |
| 61 single_method_name_found(L"GetMessage", 0); | 55 single_method_name_found(L"GetMessage", 0); |
| 62 single_method_name_found(L"GetLanguageCount", 1); | 56 single_method_name_found(L"GetLanguageCount", 1); |
| 63 single_method_name_found(L"GetLanguageByIndex", 2); | 57 single_method_name_found(L"GetLanguageByIndex", 2); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 90 { | 84 { |
| 91 CPluginUserSettings x; | 85 CPluginUserSettings x; |
| 92 DISPPARAMS params; | 86 DISPPARAMS params; |
| 93 params.rgvarg = nullptr; | 87 params.rgvarg = nullptr; |
| 94 params.rgdispidNamedArgs = nullptr; | 88 params.rgdispidNamedArgs = nullptr; |
| 95 params.cArgs = 0; | 89 params.cArgs = 0; |
| 96 params.cNamedArgs = 0; | 90 params.cNamedArgs = 0; |
| 97 EXCEPINFO ex; | 91 EXCEPINFO ex; |
| 98 HRESULT h = x.Invoke(-1, IID_NULL, 0, 0, ¶ms, nullptr, &ex, nullptr); | 92 HRESULT h = x.Invoke(-1, IID_NULL, 0, 0, ¶ms, nullptr, &ex, nullptr); |
| 99 ASSERT_NE(S_OK, h); | 93 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); | 94 EXPECT_EQ(DISP_E_MEMBERNOTFOUND, h); |
| 106 } | 95 } |
| 107 } | 96 } |
| 108 | 97 |
| 109 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_underflow) | 98 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_underflow) |
| 110 { | 99 { |
| 111 invoke_invalid_dispatch_id(-1); | 100 invoke_invalid_dispatch_id(-1); |
| 112 } | 101 } |
| 113 | 102 |
| 114 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_overflow) | 103 TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_overflow) |
| 115 { | 104 { |
| 116 invoke_invalid_dispatch_id(13); | 105 invoke_invalid_dispatch_id(13); |
| 117 } | 106 } |
| OLD | NEW |