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

Unified Diff: test/plugin/UserSettingsTest.cpp

Issue 6267413888761856: Issue #1163 - add unit tests for CPluginUserSettings (Closed)
Patch Set: Created Aug. 14, 2014, 3:09 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« adblockplus.gyp ('K') | « adblockplus.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/plugin/UserSettingsTest.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/plugin/UserSettingsTest.cpp
@@ -0,0 +1,123 @@
+/*
+ * 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)
Felix Dahlke 2014/09/30 13:50:59 Camel case here and below please, coding style and
+ {
+ CPluginUserSettings x;
+ wchar_t *names[1];
Eric 2014/10/07 16:58:10 It used to be that this wouldn't compile in Visual
+ 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];
Felix Dahlke 2014/09/30 13:50:59 Spaces around the = please.
+ 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)
+ {
+ CPluginUserSettings x;
+ DISPPARAMS params;
+ params.rgvarg = nullptr;
+ params.rgdispidNamedArgs = nullptr;
+ params.cArgs = 0;
+ params.cNamedArgs = 0;
+ EXCEPINFO ex;
+ HRESULT h = x.Invoke(id, IID_NULL, 0, DISPATCH_METHOD, &params, nullptr, &ex, nullptr);
+ 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);
+ }
+}
+
+/**
+ * Verify that a negative Dispatch ID returns the proper error code.
+ */
+TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_underflow)
+{
+ invoke_invalid_dispatch_id(-1);
+}
+
+/**
+ * Verify that a positive Dispatch ID that's too large returns the proper error code.
+ */
+TEST(CPluginUserSettings_Invoke_Test, invalid_dispatch_id_overflow)
+{
+ invoke_invalid_dispatch_id(13);
+}
« adblockplus.gyp ('K') | « adblockplus.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld