Index: test/plugin/UserSettingsTest.cpp |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/test/plugin/UserSettingsTest.cpp |
@@ -0,0 +1,117 @@ |
+/* |
+ * This file is part of Adblock Plus <http://adblockplus.org/>, |
+ * Copyright (C) 2014 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+#include <gtest/gtest.h> |
+ |
+#include <OAIdl.h> |
+#include "../../src/plugin/PluginUserSettings.h" |
+ |
+//---------------------------------- |
+// GetIDsOfNames |
+//---------------------------------- |
+ |
+namespace |
+{ |
+ void single_method_name_found(std::wstring name, DISPID expected_id) |
+ { |
+ CPluginUserSettings x; |
+ wchar_t *names[1]; |
+ names[0] = const_cast<wchar_t *>(name.c_str()); |
+ DISPID ids[1]; |
+ HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); |
+ ASSERT_EQ(S_OK, h); |
+ DISPID id=ids[0]; |
+ ASSERT_EQ(expected_id, id); |
+ } |
+ |
+ void single_method_name_notfound(std::wstring name) |
+ { |
+ CPluginUserSettings x; |
+ wchar_t *names[1]; |
+ names[0] = const_cast<wchar_t *>(name.c_str()); |
+ DISPID ids[1]; |
+ HRESULT h = x.GetIDsOfNames(IID_NULL, names, 1, 0, ids); |
+ ASSERT_NE(S_OK, h); |
+ // The old version returns a nonstandard error code. |
+ if (h == DISP_E_MEMBERNOTFOUND) |
+ { |
+ return; |
+ } |
+ EXPECT_EQ(DISP_E_UNKNOWNNAME, h); |
+ } |
+} |
+ |
+TEST(CPluginUserSettings_GetIDsOfNames_Test, all_defined_found) |
+{ |
+ CPluginUserSettings x; |
+ single_method_name_found(L"GetMessage", 0); |
+ single_method_name_found(L"GetLanguageCount", 1); |
+ single_method_name_found(L"GetLanguageByIndex", 2); |
+ single_method_name_found(L"GetLanguageTitleByIndex", 3); |
+ single_method_name_found(L"SetLanguage", 4); |
+ single_method_name_found(L"GetLanguage", 5); |
+ single_method_name_found(L"GetWhitelistDomains", 6); |
+ single_method_name_found(L"AddWhitelistDomain", 7); |
+ single_method_name_found(L"RemoveWhitelistDomain", 8); |
+ single_method_name_found(L"GetAppLocale", 9); |
+ single_method_name_found(L"GetDocumentationLink", 10); |
+ single_method_name_found(L"IsAcceptableAdsEnabled", 11); |
+ single_method_name_found(L"SetAcceptableAdsEnabled", 12); |
+} |
+ |
+TEST(CPluginUserSettings_GetIDsOfNames_Test, undefined_not_found) |
+{ |
+ single_method_name_notfound(L""); |
+ single_method_name_notfound(L"clearly unknown"); |
+ single_method_name_notfound(L"GETMESSAGE"); |
+} |
+ |
+//---------------------------------- |
+// Invoke |
+//---------------------------------- |
+ |
+namespace |
+{ |
+ 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
|
+ { |
+ CPluginUserSettings x; |
+ 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
|
+ params.rgvarg = nullptr; |
+ params.rgdispidNamedArgs = nullptr; |
+ params.cArgs = 0; |
+ params.cNamedArgs = 0; |
+ EXCEPINFO ex; |
sergei
2014/08/14 11:37:26
I would also initialize it.
|
+ HRESULT h = x.Invoke(-1, IID_NULL, 0, 0, ¶ms, 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
|
+ ASSERT_NE(S_OK, h); |
+ // The old version returns a nonstandard error code. |
+ if (h == DISP_E_BADINDEX) |
+ { |
+ return; |
+ } |
+ EXPECT_EQ(DISP_E_MEMBERNOTFOUND, h); |
+ } |
+} |
+ |
+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
|
+{ |
+ invoke_invalid_dispatch_id(-1); |
+} |
+ |
+TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_overflow) |
+{ |
+ invoke_invalid_dispatch_id(13); |
+} |