| 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 | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 37     ASSERT_EQ(expected_id, id); | 37     ASSERT_EQ(expected_id, id); | 
| 38   } | 38   } | 
| 39 | 39 | 
| 40   void SingleMethodNameNotFound(std::wstring name) | 40   void SingleMethodNameNotFound(std::wstring name) | 
| 41   { | 41   { | 
| 42     CPluginUserSettings x; | 42     CPluginUserSettings x; | 
| 43     wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())}; | 43     wchar_t* names[] = {const_cast<wchar_t*>(name.c_str())}; | 
| 44     DISPID ids[1]; | 44     DISPID ids[1]; | 
| 45     HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); | 45     HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); | 
| 46     ASSERT_NE(S_OK, h); | 46     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); | 47     EXPECT_EQ(DISP_E_UNKNOWNNAME, h); | 
| 53   } | 48   } | 
| 54 } | 49 } | 
| 55 | 50 | 
| 56 TEST(CPluginUserSettingsGetIDsOfNames, AllDefinedMethodsMustBeFound) | 51 TEST(CPluginUserSettingsGetIDsOfNames, AllDefinedMethodsMustBeFound) | 
| 57 { | 52 { | 
| 58   CPluginUserSettings x; | 53   CPluginUserSettings x; | 
| 59   SingleMethodNameFound(L"GetMessage", 0); | 54   SingleMethodNameFound(L"GetMessage", 0); | 
| 60   SingleMethodNameFound(L"GetLanguageCount", 1); | 55   SingleMethodNameFound(L"GetLanguageCount", 1); | 
| 61   SingleMethodNameFound(L"GetLanguageByIndex", 2); | 56   SingleMethodNameFound(L"GetLanguageByIndex", 2); | 
| 62   SingleMethodNameFound(L"GetLanguageTitleByIndex", 3); | 57   SingleMethodNameFound(L"GetLanguageTitleByIndex", 3); | 
| 63   SingleMethodNameFound(L"SetLanguage", 4); | 58   SingleMethodNameFound(L"SetLanguage", 4); | 
| 64   SingleMethodNameFound(L"GetLanguage", 5); | 59   SingleMethodNameFound(L"GetLanguage", 5); | 
| 65   SingleMethodNameFound(L"GetWhitelistDomains", 6); | 60   SingleMethodNameFound(L"GetWhitelistDomains", 6); | 
| 66   SingleMethodNameFound(L"AddWhitelistDomain", 7); | 61   SingleMethodNameFound(L"AddWhitelistDomain", 7); | 
| 67   SingleMethodNameFound(L"RemoveWhitelistDomain", 8); | 62   SingleMethodNameFound(L"RemoveWhitelistDomain", 8); | 
| 68   SingleMethodNameFound(L"GetAppLocale", 9); | 63   SingleMethodNameFound(L"GetAppLocale", 9); | 
| 69   SingleMethodNameFound(L"GetDocumentationLink", 10); | 64   SingleMethodNameFound(L"GetDocumentationLink", 10); | 
| 70   SingleMethodNameFound(L"IsAcceptableAdsEnabled", 11); | 65   SingleMethodNameFound(L"IsAcceptableAdsEnabled", 11); | 
| 71   SingleMethodNameFound(L"SetAcceptableAdsEnabled", 12); | 66   SingleMethodNameFound(L"SetAcceptableAdsEnabled", 12); | 
|  | 67   SingleMethodNameFound(L"IsUpdate", 13); | 
| 72 } | 68 } | 
| 73 | 69 | 
| 74 TEST(CPluginUserSettingsGetIDsOfNames, UndefinedMethodsMustNotBeFound) | 70 TEST(CPluginUserSettingsGetIDsOfNames, UndefinedMethodsMustNotBeFound) | 
| 75 { | 71 { | 
| 76   SingleMethodNameNotFound(L""); | 72   SingleMethodNameNotFound(L""); | 
| 77   SingleMethodNameNotFound(L"clearly unknown"); | 73   SingleMethodNameNotFound(L"clearly unknown"); | 
| 78   SingleMethodNameNotFound(L"GETMESSAGE"); | 74   SingleMethodNameNotFound(L"GETMESSAGE"); | 
| 79 } | 75 } | 
| 80 | 76 | 
| 81 //---------------------------------- | 77 //---------------------------------- | 
| 82 // Invoke | 78 // Invoke | 
| 83 //---------------------------------- | 79 //---------------------------------- | 
| 84 | 80 | 
| 85 namespace | 81 namespace | 
| 86 { | 82 { | 
| 87   void InvokeInvalidDispatchId(DISPID id) | 83   void InvokeInvalidDispatchId(DISPID id) | 
| 88   { | 84   { | 
| 89     CPluginUserSettings x; | 85     CPluginUserSettings x; | 
| 90     DISPPARAMS params; | 86     DISPPARAMS params; | 
| 91     params.rgvarg = nullptr; | 87     params.rgvarg = nullptr; | 
| 92     params.rgdispidNamedArgs = nullptr; | 88     params.rgdispidNamedArgs = nullptr; | 
| 93     params.cArgs = 0; | 89     params.cArgs = 0; | 
| 94     params.cNamedArgs = 0; | 90     params.cNamedArgs = 0; | 
| 95     EXCEPINFO ex; | 91     EXCEPINFO ex; | 
| 96     HRESULT h = x.Invoke(id, IID_NULL, 0, DISPATCH_METHOD, ¶ms, nullptr, &ex
     , nullptr); | 92     HRESULT h = x.Invoke(id, IID_NULL, 0, DISPATCH_METHOD, ¶ms, nullptr, &ex
     , nullptr); | 
| 97     ASSERT_NE(S_OK, h); | 93     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); | 94     EXPECT_EQ(DISP_E_MEMBERNOTFOUND, h); | 
| 104   } | 95   } | 
| 105 } | 96 } | 
| 106 | 97 | 
| 107 /** | 98 /** | 
| 108  * Verify that a negative Dispatch ID returns the proper error code. | 99  * Verify that a negative Dispatch ID returns the proper error code. | 
| 109  */ | 100  */ | 
| 110 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldUnderflow) | 101 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldUnderflow) | 
| 111 { | 102 { | 
| 112   InvokeInvalidDispatchId(-1); | 103   InvokeInvalidDispatchId(-1); | 
| 113 } | 104 } | 
| 114 | 105 | 
| 115 /** | 106 /** | 
| 116  * Verify that a positive Dispatch ID that's too large returns the proper error 
     code. | 107  * Verify that a positive Dispatch ID that's too large returns the proper error 
     code. | 
| 117  */ | 108  */ | 
| 118 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldOverflow) | 109 TEST(CPluginUserSettingsInvoke, InvalidDispatchIdShouldOverflow) | 
| 119 { | 110 { | 
| 120   InvokeInvalidDispatchId(13); | 111   InvokeInvalidDispatchId(14); | 
| 121 } | 112 } | 
| OLD | NEW | 
|---|