From d7f29e97703b8c69ee9421fdd836948c76fc9b85 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 02:48:52 +0800 Subject: [PATCH 001/562] Applied r3306 and r3307 from lp:~compiz-team/compiz/compiz.gsettings_tests which allows us to safely put mock settings in lists and references them properly. --- compizconfig/libcompizconfig/include/ccs.h | 2 ++ compizconfig/libcompizconfig/src/main.c | 19 +++++++++++++------ .../libcompizconfig/tests/mock-setting.h | 11 ++++++++--- .../libcompizconfig/tests/plugin-mock.cpp | 2 ++ .../libcompizconfig/tests/setting-mock.cpp | 5 ++++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 8a6311961..dafc505f0 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -800,6 +800,7 @@ typedef Bool (*CCSSettingGetList) (CCSSetting *setting, CCSSettingValueList *dat typedef void (*CCSSettingResetToDefault) (CCSSetting *setting, Bool processChanged); typedef Bool (*CCSSettingIsIntegrated) (CCSSetting *setting); typedef Bool (*CCSSettingIsReadOnly) (CCSSetting *setting); +typedef void (*CCSSettingDestructor) (CCSSetting *setting); unsigned int ccsCCSSettingInterfaceGetType (); @@ -845,6 +846,7 @@ struct _CCSSettingInterface CCSSettingResetToDefault settingResetToDefault; CCSSettingIsIntegrated settingIsIntegrated; CCSSettingIsReadOnly settingIsReadOnly; + CCSSettingDestructor settingDestructor; }; struct _CCSSetting diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index bc2b9031d..e8b87b793 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -765,12 +765,9 @@ ccsFreePlugin (CCSPlugin * p) free (p); } -void -ccsFreeSetting (CCSSetting * s) +static void +ccsFreeSettingDefault (CCSSetting *s) { - if (!s) - return; - SETTING_PRIV (s); free (sPrivate->name); @@ -810,6 +807,15 @@ ccsFreeSetting (CCSSetting * s) free (s); } +void +ccsFreeSetting (CCSSetting * s) +{ + if (!s) + return; + + (*(GET_INTERFACE (CCSSettingInterface, s))->settingDestructor) (s); +} + void ccsFreeGroup (CCSGroup * g) { @@ -5018,7 +5024,8 @@ static const CCSSettingInterface ccsDefaultSettingInterface = ccsSettingGetListDefault, ccsSettingResetToDefaultDefault, ccsSettingGetIsIntegratedDefault, - ccsSettingGetIsReadOnlyDefault + ccsSettingGetIsReadOnlyDefault, + ccsFreeSettingDefault }; const CCSInterfaceTable ccsDefaultInterfaceTable = diff --git a/compizconfig/libcompizconfig/tests/mock-setting.h b/compizconfig/libcompizconfig/tests/mock-setting.h index b70d31944..e27dc03c3 100644 --- a/compizconfig/libcompizconfig/tests/mock-setting.h +++ b/compizconfig/libcompizconfig/tests/mock-setting.h @@ -6,6 +6,9 @@ using ::testing::_; using ::testing::Return; +CCSSetting * ccsMockSettingNew (); +void ccsFreeMockSetting (CCSSetting *); + class CCSSettingGMockInterface { public: @@ -345,9 +348,11 @@ class CCSSettingGMock : { return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->setPrivatePtr (ptr); } + + static void ccsSettingFree (CCSSetting *setting) + { + ccsFreeMockSetting (setting); + } }; extern CCSSettingInterface CCSSettingGMockInterface; - -CCSSetting * ccsMockSettingNew (); -void ccsFreeMockSetting (CCSSetting *); diff --git a/compizconfig/libcompizconfig/tests/plugin-mock.cpp b/compizconfig/libcompizconfig/tests/plugin-mock.cpp index c81d76150..aa5598774 100644 --- a/compizconfig/libcompizconfig/tests/plugin-mock.cpp +++ b/compizconfig/libcompizconfig/tests/plugin-mock.cpp @@ -42,6 +42,8 @@ ccsMockPluginNew () ccsObjectSetPrivate (plugin, (CCSPrivate *) mock); ccsObjectAddInterface (plugin, (CCSInterface *) &CCSPluginGMockInterface, GET_INTERFACE_TYPE (CCSPluginInterface)); + ccsPluginRef (plugin); + return plugin; } diff --git a/compizconfig/libcompizconfig/tests/setting-mock.cpp b/compizconfig/libcompizconfig/tests/setting-mock.cpp index 6b752c185..c4bd7efdf 100644 --- a/compizconfig/libcompizconfig/tests/setting-mock.cpp +++ b/compizconfig/libcompizconfig/tests/setting-mock.cpp @@ -46,7 +46,8 @@ CCSSettingInterface CCSSettingGMockInterface = CCSSettingGMock::ccsGetList, CCSSettingGMock::ccsResetToDefault, CCSSettingGMock::ccsSettingIsIntegrated, - CCSSettingGMock::ccsSettingIsReadOnly + CCSSettingGMock::ccsSettingIsReadOnly, + CCSSettingGMock::ccsSettingFree }; CCSSetting * @@ -63,6 +64,8 @@ ccsMockSettingNew () ccsObjectSetPrivate (setting, (CCSPrivate *) mock); ccsObjectAddInterface (setting, (CCSInterface *) &CCSSettingGMockInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); + ccsSettingRef (setting); + return setting; } -- GitLab From d187cad7bd2afa64722e82ca3340e2f13de1f5c1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 03:22:58 +0800 Subject: [PATCH 002/562] Free the setting through ccsSettingUnref as that's how its going to work --- compizconfig/libcompizconfig/tests/test-setting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/tests/test-setting.cpp b/compizconfig/libcompizconfig/tests/test-setting.cpp index 12017e5a0..685e05769 100644 --- a/compizconfig/libcompizconfig/tests/test-setting.cpp +++ b/compizconfig/libcompizconfig/tests/test-setting.cpp @@ -105,5 +105,5 @@ TEST(CCSSettingTest, TestMock) ccsSettingIsIntegrated (setting); ccsSettingIsReadOnly (setting); - ccsFreeMockSetting (setting); + ccsSettingUnref (setting); } -- GitLab From 5123446a7d54da04e45d8bea33bfedd270105ae3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 12:42:25 +0800 Subject: [PATCH 003/562] Make CCSPluginInterface destructor virtual and test free through ccsObjectUnref --- compizconfig/libcompizconfig/include/ccs.h | 3 +++ compizconfig/libcompizconfig/src/main.c | 14 ++++++++++++-- compizconfig/libcompizconfig/tests/mock-plugin.h | 12 +++++++++--- compizconfig/libcompizconfig/tests/plugin-mock.cpp | 3 ++- compizconfig/libcompizconfig/tests/test-plugin.cpp | 2 +- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index dafc505f0..e4b103771 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -431,6 +431,8 @@ typedef CCSGroupList (*CCSPluginGetPluginGroups) (CCSPlugin *plugin); typedef void (*CCSPluginReadPluginSettings) (CCSPlugin *plugin); typedef CCSStrExtensionList (*CCSPluginGetPluginStrExtensions) (CCSPlugin *plugin); +typedef void (*CCSPluginDestructor) (CCSPlugin *plugin); + unsigned int ccsCCSPluginInterfaceGetType (); struct _CCSPluginInterface @@ -454,6 +456,7 @@ struct _CCSPluginInterface CCSPluginGetPluginGroups pluginGetPluginGroups; CCSPluginReadPluginSettings pluginReadPluginSettings; CCSPluginGetPluginStrExtensions pluginGetPluginStrExtensions; + CCSPluginDestructor pluginDestructor; }; /* CCSPlugin accessor functions */ diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index e8b87b793..f9556969d 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -725,7 +725,16 @@ ccsFreeContext (CCSContext * c) } void -ccsFreePlugin (CCSPlugin * p) +ccsFreePlugin (CCSPlugin *p) +{ + if (!p) + return; + + (*(GET_INTERFACE (CCSPluginInterface, p))->pluginDestructor) (p); +} + +static void +ccsFreePluginDefault (CCSPlugin * p) { if (!p) return; @@ -4942,7 +4951,8 @@ static const CCSPluginInterface ccsDefaultPluginInterface = ccsGetPluginSettingsDefault, ccsGetPluginGroupsDefault, ccsReadPluginSettingsDefault, - ccsGetPluginStrExtensionsDefault + ccsGetPluginStrExtensionsDefault, + ccsFreePluginDefault }; static const CCSContextInterface ccsDefaultContextInterface = diff --git a/compizconfig/libcompizconfig/tests/mock-plugin.h b/compizconfig/libcompizconfig/tests/mock-plugin.h index a741bf6f5..bf4333d5e 100644 --- a/compizconfig/libcompizconfig/tests/mock-plugin.h +++ b/compizconfig/libcompizconfig/tests/mock-plugin.h @@ -3,6 +3,9 @@ #include +CCSPlugin * ccsMockPluginNew (); +void ccsFreeMockPlugin (CCSPlugin *); + class CCSPluginGMockInterface { public: @@ -158,9 +161,12 @@ class CCSPluginGMock : { return ((CCSPluginGMock *) ccsObjectGetPrivate (plugin))->getPluginStrExtensions (); } + + static void ccsFreePlugin (CCSPlugin *plugin) + + { + ccsFreeMockPlugin (plugin); + } }; extern CCSPluginInterface CCSPluginGMockInterface; - -CCSPlugin * ccsMockPluginNew (); -void ccsFreeMockPlugin (CCSPlugin *); diff --git a/compizconfig/libcompizconfig/tests/plugin-mock.cpp b/compizconfig/libcompizconfig/tests/plugin-mock.cpp index aa5598774..a7df78918 100644 --- a/compizconfig/libcompizconfig/tests/plugin-mock.cpp +++ b/compizconfig/libcompizconfig/tests/plugin-mock.cpp @@ -25,7 +25,8 @@ CCSPluginInterface CCSPluginGMockInterface = CCSPluginGMock::ccsGetPluginSettings, CCSPluginGMock::ccsGetPluginGroups, CCSPluginGMock::ccsReadPluginSettings, - CCSPluginGMock::ccsGetPluginStrExtensions + CCSPluginGMock::ccsGetPluginStrExtensions, + CCSPluginGMock::ccsFreePlugin }; CCSPlugin * diff --git a/compizconfig/libcompizconfig/tests/test-plugin.cpp b/compizconfig/libcompizconfig/tests/test-plugin.cpp index 52b816fb0..930c68120 100644 --- a/compizconfig/libcompizconfig/tests/test-plugin.cpp +++ b/compizconfig/libcompizconfig/tests/test-plugin.cpp @@ -56,5 +56,5 @@ TEST(CCSPluginTest, TestMock) ccsReadPluginSettings (plugin); ccsGetPluginStrExtensions (plugin); - ccsFreeMockPlugin (plugin); + ccsPluginUnref (plugin); } -- GitLab From 893b060b2c6af258af7ec77a2e622955e04c417b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 12:48:02 +0800 Subject: [PATCH 004/562] Virtual destructor for context and free through virtual destructor --- compizconfig/libcompizconfig/include/ccs.h | 2 ++ compizconfig/libcompizconfig/src/main.c | 14 ++++++++++++-- .../libcompizconfig/tests/context-mock.cpp | 3 ++- compizconfig/libcompizconfig/tests/mock-context.h | 15 ++++++++++++--- .../libcompizconfig/tests/test-context.cpp | 2 +- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index e4b103771..57324f9ed 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -334,6 +334,7 @@ typedef CCSStringList (*CCSContextGetExistingProfiles) (CCSContext *context); typedef void (*CCSContextDeleteProfile) (CCSContext *context, char *name); typedef Bool (*CCSContextCheckForSettingsUpgrade) (CCSContext *context); typedef void (*CCSContextLoadPlugins) (CCSContext *context); +typedef void (*CCSContextDestructor) (CCSContext *context); struct _CCSContextInterface { @@ -371,6 +372,7 @@ struct _CCSContextInterface CCSContextDeleteProfile contextDeleteProfile; CCSContextCheckForSettingsUpgrade contextCheckForSettingsUpgrade; CCSContextLoadPlugins contextLoadPlugins; + CCSContextDestructor contextDestructor; }; unsigned int ccsCCSContextInterfaceGetType (); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index f9556969d..df1f5ddcc 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -702,7 +702,16 @@ collateGroups (CCSPluginPrivate * p) } void -ccsFreeContext (CCSContext * c) +ccsFreeContext (CCSContext *c) +{ + if (!c) + return; + + (*(GET_INTERFACE (CCSContextInterface, c))->contextDestructor) (c); +} + +static void +ccsFreeContextDefault (CCSContext * c) { if (!c) return; @@ -4990,7 +4999,8 @@ static const CCSContextInterface ccsDefaultContextInterface = ccsGetExistingProfilesDefault, ccsDeleteProfileDefault, ccsCheckForSettingsUpgradeDefault, - ccsLoadPluginsDefault + ccsLoadPluginsDefault, + ccsFreeContextDefault }; static const CCSSettingInterface ccsDefaultSettingInterface = diff --git a/compizconfig/libcompizconfig/tests/context-mock.cpp b/compizconfig/libcompizconfig/tests/context-mock.cpp index 4d70bb4ea..c6b6faf70 100644 --- a/compizconfig/libcompizconfig/tests/context-mock.cpp +++ b/compizconfig/libcompizconfig/tests/context-mock.cpp @@ -40,7 +40,8 @@ CCSContextInterface CCSContextGMockInterface = CCSContextGMock::ccsGetExistingProfiles, CCSContextGMock::ccsDeleteProfile, CCSContextGMock::ccsCheckForSettingsUpgrade, - CCSContextGMock::ccsLoadPlugins + CCSContextGMock::ccsLoadPlugins, + CCSContextGMock::ccsFreeContext }; CCSContext * diff --git a/compizconfig/libcompizconfig/tests/mock-context.h b/compizconfig/libcompizconfig/tests/mock-context.h index c3ea63c87..1000d0d90 100644 --- a/compizconfig/libcompizconfig/tests/mock-context.h +++ b/compizconfig/libcompizconfig/tests/mock-context.h @@ -3,6 +3,9 @@ #include +CCSContext * ccsMockContextNew (); +void ccsFreeMockContext (CCSContext *); + class CCSContextGMockInterface { public: @@ -330,9 +333,15 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->loadPlugins (); } + + static void + ccsFreeContext (CCSContext *context) + { + if (!context) + return; + + ccsFreeMockContext (context); + } }; extern CCSContextInterface CCSContextGMockInterface; - -CCSContext * ccsMockContextNew (); -void ccsFreeMockContext (CCSContext *); diff --git a/compizconfig/libcompizconfig/tests/test-context.cpp b/compizconfig/libcompizconfig/tests/test-context.cpp index 197411aa6..d9cdc240c 100644 --- a/compizconfig/libcompizconfig/tests/test-context.cpp +++ b/compizconfig/libcompizconfig/tests/test-context.cpp @@ -90,5 +90,5 @@ TEST(CCSContextTest, TestMock) free (foo); free (bar); - ccsFreeMockContext (context); + ccsFreeContext (context); } -- GitLab From 3390d6eae50339c6d729f90fee5af8667180c741 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 13:10:52 +0800 Subject: [PATCH 005/562] Move mocks to build separately --- .../libcompizconfig/tests/CMakeLists.txt | 87 +++++++------------ ....cpp => compizconfig_test_ccs_context.cpp} | 2 +- ...t.cpp => compizconfig_test_ccs_object.cpp} | 0 ...n.cpp => compizconfig_test_ccs_plugin.cpp} | 2 +- ....cpp => compizconfig_test_ccs_setting.cpp} | 2 +- .../tests/mocks/CMakeLists.txt | 42 +++++++++ .../compizconfig_ccs_context_mock.cpp} | 2 +- .../compizconfig_ccs_context_mock.h} | 0 .../compizconfig_ccs_plugin_mock.cpp} | 2 +- .../compizconfig_ccs_plugin_mock.h} | 0 .../compizconfig_ccs_setting_mock.cpp} | 2 +- .../compizconfig_ccs_setting_mock.h} | 0 12 files changed, 77 insertions(+), 64 deletions(-) rename compizconfig/libcompizconfig/tests/{test-context.cpp => compizconfig_test_ccs_context.cpp} (98%) rename compizconfig/libcompizconfig/tests/{test-ccs-object.cpp => compizconfig_test_ccs_object.cpp} (100%) rename compizconfig/libcompizconfig/tests/{test-plugin.cpp => compizconfig_test_ccs_plugin.cpp} (97%) rename compizconfig/libcompizconfig/tests/{test-setting.cpp => compizconfig_test_ccs_setting.cpp} (98%) create mode 100644 compizconfig/libcompizconfig/tests/mocks/CMakeLists.txt rename compizconfig/libcompizconfig/tests/{context-mock.cpp => mocks/compizconfig_ccs_context_mock.cpp} (98%) rename compizconfig/libcompizconfig/tests/{mock-context.h => mocks/compizconfig_ccs_context_mock.h} (100%) rename compizconfig/libcompizconfig/tests/{plugin-mock.cpp => mocks/compizconfig_ccs_plugin_mock.cpp} (97%) rename compizconfig/libcompizconfig/tests/{mock-plugin.h => mocks/compizconfig_ccs_plugin_mock.h} (100%) rename compizconfig/libcompizconfig/tests/{setting-mock.cpp => mocks/compizconfig_ccs_setting_mock.cpp} (98%) rename compizconfig/libcompizconfig/tests/{mock-setting.h => mocks/compizconfig_ccs_setting_mock.h} (100%) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index df3e04b77..08d580f02 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,27 +1,22 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/mocks) link_directories (${CMAKE_INSTALL_PREFIX}/lib) +link_directories (${CMAKE_CURRENT_BINARY_DIR}/mocks) -add_library (context-mock - ${CMAKE_CURRENT_SOURCE_DIR}/context-mock.cpp) +add_subdirectory (mocks) -add_library (plugin-mock - ${CMAKE_CURRENT_SOURCE_DIR}/plugin-mock.cpp) +add_executable (compizconfig_test_ccs_object + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_object.cpp) -add_library (setting-mock - ${CMAKE_CURRENT_SOURCE_DIR}/setting-mock.cpp) +add_executable (compizconfig_test_ccs_context + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_context.cpp) -add_executable (test-ccs-object - ${CMAKE_CURRENT_SOURCE_DIR}/test-ccs-object.cpp) +add_executable (compizconfig_test_ccs_plugin + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_plugin.cpp) -add_executable (test-context - ${CMAKE_CURRENT_SOURCE_DIR}/test-context.cpp) - -add_executable (test-plugin - ${CMAKE_CURRENT_SOURCE_DIR}/test-plugin.cpp) - -add_executable (test-setting - ${CMAKE_CURRENT_SOURCE_DIR}/test-setting.cpp) +add_executable (compizconfig_test_ccs_setting + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_setting.cpp) if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES @@ -29,31 +24,7 @@ if (HAVE_PROTOBUF) protobuf) endif (HAVE_PROTOBUF) -target_link_libraries (context-mock - ${GTEST_BOTH_LIBRARIES} - ${GMOCK_LIBRARY} - ${GMOCK_MAIN_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig) - -target_link_libraries (plugin-mock - ${GTEST_BOTH_LIBRARIES} - ${GMOCK_LIBRARY} - ${GMOCK_MAIN_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig) - -target_link_libraries (setting-mock - ${GTEST_BOTH_LIBRARIES} - ${GMOCK_LIBRARY} - ${GMOCK_MAIN_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig) - -target_link_libraries (test-ccs-object +target_link_libraries (compizconfig_test_ccs_object ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} @@ -61,40 +32,40 @@ target_link_libraries (test-ccs-object ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig) -target_link_libraries (test-context +target_link_libraries (compizconfig_test_ccs_context ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig - context-mock - plugin-mock - setting-mock) + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock) -target_link_libraries (test-plugin +target_link_libraries (compizconfig_test_ccs_plugin ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig - context-mock - plugin-mock - setting-mock) + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock) -target_link_libraries (test-setting +target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig - context-mock - plugin-mock - setting-mock) - -compiz_discover_tests (test-ccs-object) -compiz_discover_tests (test-context) -compiz_discover_tests (test-plugin) -compiz_discover_tests (test-setting) + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock) + +compiz_discover_tests (compizconfig_test_ccs_object) +compiz_discover_tests (compizconfig_test_ccs_context) +compiz_discover_tests (compizconfig_test_ccs_plugin) +compiz_discover_tests (compizconfig_test_ccs_setting) diff --git a/compizconfig/libcompizconfig/tests/test-context.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_context.cpp similarity index 98% rename from compizconfig/libcompizconfig/tests/test-context.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_context.cpp index d9cdc240c..22d576806 100644 --- a/compizconfig/libcompizconfig/tests/test-context.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_context.cpp @@ -3,7 +3,7 @@ #include -#include "mock-context.h" +#include "compizconfig_ccs_context_mock.h" using ::testing::_; using ::testing::Return; diff --git a/compizconfig/libcompizconfig/tests/test-ccs-object.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp similarity index 100% rename from compizconfig/libcompizconfig/tests/test-ccs-object.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp diff --git a/compizconfig/libcompizconfig/tests/test-plugin.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_plugin.cpp similarity index 97% rename from compizconfig/libcompizconfig/tests/test-plugin.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_plugin.cpp index 930c68120..faead208d 100644 --- a/compizconfig/libcompizconfig/tests/test-plugin.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_plugin.cpp @@ -3,7 +3,7 @@ #include -#include "mock-plugin.h" +#include "compizconfig_ccs_plugin_mock.h" using ::testing::_; using ::testing::Return; diff --git a/compizconfig/libcompizconfig/tests/test-setting.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp similarity index 98% rename from compizconfig/libcompizconfig/tests/test-setting.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp index 685e05769..16773a3ae 100644 --- a/compizconfig/libcompizconfig/tests/test-setting.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp @@ -3,7 +3,7 @@ #include -#include "mock-setting.h" +#include "compizconfig_ccs_setting_mock.h" using ::testing::_; using ::testing::Return; diff --git a/compizconfig/libcompizconfig/tests/mocks/CMakeLists.txt b/compizconfig/libcompizconfig/tests/mocks/CMakeLists.txt new file mode 100644 index 000000000..174af3624 --- /dev/null +++ b/compizconfig/libcompizconfig/tests/mocks/CMakeLists.txt @@ -0,0 +1,42 @@ +include_directories (${GTEST_INCLUDE_DIRS}) +include_directories (${CMAKE_SOURCE_DIR}/include) +link_directories (${CMAKE_INSTALL_PREFIX}/lib) + +if (HAVE_PROTOBUF) + set (LIBCOMPIZCONFIG_LIBRARIES + ${LIBCOMPIZCONFIG_LIBRARIES} + protobuf) +endif (HAVE_PROTOBUF) + +add_library (compizconfig_ccs_context_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_context_mock.cpp) + +add_library (compizconfig_ccs_plugin_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_plugin_mock.cpp) + +add_library (compizconfig_ccs_setting_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_setting_mock.cpp) + +target_link_libraries (compizconfig_ccs_context_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) + +target_link_libraries (compizconfig_ccs_plugin_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) + +target_link_libraries (compizconfig_ccs_setting_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) diff --git a/compizconfig/libcompizconfig/tests/context-mock.cpp b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.cpp similarity index 98% rename from compizconfig/libcompizconfig/tests/context-mock.cpp rename to compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.cpp index c6b6faf70..d2b825597 100644 --- a/compizconfig/libcompizconfig/tests/context-mock.cpp +++ b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.cpp @@ -3,7 +3,7 @@ #include -#include "mock-context.h" +#include "compizconfig_ccs_context_mock.h" CCSContextInterface CCSContextGMockInterface = { diff --git a/compizconfig/libcompizconfig/tests/mock-context.h b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.h similarity index 100% rename from compizconfig/libcompizconfig/tests/mock-context.h rename to compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.h diff --git a/compizconfig/libcompizconfig/tests/plugin-mock.cpp b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.cpp similarity index 97% rename from compizconfig/libcompizconfig/tests/plugin-mock.cpp rename to compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.cpp index a7df78918..209aa3bd6 100644 --- a/compizconfig/libcompizconfig/tests/plugin-mock.cpp +++ b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.cpp @@ -3,7 +3,7 @@ #include -#include "mock-plugin.h" +#include "compizconfig_ccs_plugin_mock.h" CCSPluginInterface CCSPluginGMockInterface = { diff --git a/compizconfig/libcompizconfig/tests/mock-plugin.h b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.h similarity index 100% rename from compizconfig/libcompizconfig/tests/mock-plugin.h rename to compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.h diff --git a/compizconfig/libcompizconfig/tests/setting-mock.cpp b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.cpp similarity index 98% rename from compizconfig/libcompizconfig/tests/setting-mock.cpp rename to compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.cpp index c4bd7efdf..10c2a42ec 100644 --- a/compizconfig/libcompizconfig/tests/setting-mock.cpp +++ b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.cpp @@ -3,7 +3,7 @@ #include -#include "mock-setting.h" +#include "compizconfig_ccs_setting_mock.h" CCSSettingInterface CCSSettingGMockInterface = { diff --git a/compizconfig/libcompizconfig/tests/mock-setting.h b/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.h similarity index 100% rename from compizconfig/libcompizconfig/tests/mock-setting.h rename to compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.h -- GitLab From f45f8b6aaeb66f22a52605524829b8c868cc5482 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 13:16:23 +0800 Subject: [PATCH 006/562] Pull out the mocks into compizconfig/ --- compizconfig/CMakeLists.txt | 4 ++++ compizconfig/libcompizconfig/tests/CMakeLists.txt | 6 ++---- .../tests/mocks => mocks/libcompizconfig}/CMakeLists.txt | 2 +- .../libcompizconfig}/compizconfig_ccs_context_mock.cpp | 0 .../libcompizconfig}/compizconfig_ccs_context_mock.h | 0 .../libcompizconfig}/compizconfig_ccs_plugin_mock.cpp | 0 .../libcompizconfig}/compizconfig_ccs_plugin_mock.h | 0 .../libcompizconfig}/compizconfig_ccs_setting_mock.cpp | 0 .../libcompizconfig}/compizconfig_ccs_setting_mock.h | 0 9 files changed, 7 insertions(+), 5 deletions(-) rename compizconfig/{libcompizconfig/tests/mocks => mocks/libcompizconfig}/CMakeLists.txt (94%) rename compizconfig/{libcompizconfig/tests/mocks => mocks/libcompizconfig}/compizconfig_ccs_context_mock.cpp (100%) rename compizconfig/{libcompizconfig/tests/mocks => mocks/libcompizconfig}/compizconfig_ccs_context_mock.h (100%) rename compizconfig/{libcompizconfig/tests/mocks => mocks/libcompizconfig}/compizconfig_ccs_plugin_mock.cpp (100%) rename compizconfig/{libcompizconfig/tests/mocks => mocks/libcompizconfig}/compizconfig_ccs_plugin_mock.h (100%) rename compizconfig/{libcompizconfig/tests/mocks => mocks/libcompizconfig}/compizconfig_ccs_setting_mock.cpp (100%) rename compizconfig/{libcompizconfig/tests/mocks => mocks/libcompizconfig}/compizconfig_ccs_setting_mock.h (100%) diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index 939aa0178..869e2c490 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -10,6 +10,10 @@ add_subdirectory (ccsm) add_subdirectory (gconf) add_subdirectory (gsettings) +if (COMPIZ_BUILD_TESTING) + add_subdirectory (mocks) +endif (COMPIZ_BUILD_TESTING) + add_custom_target (pyclean) add_dependencies (pyclean pyclean_ccsm pyclean_compizconfig) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 08d580f02..0a51ee5e2 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,10 +1,8 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) -include_directories (${CMAKE_CURRENT_SOURCE_DIR}/mocks) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) link_directories (${CMAKE_INSTALL_PREFIX}/lib) -link_directories (${CMAKE_CURRENT_BINARY_DIR}/mocks) - -add_subdirectory (mocks) +link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../mocks/libcompizconfig) add_executable (compizconfig_test_ccs_object ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_object.cpp) diff --git a/compizconfig/libcompizconfig/tests/mocks/CMakeLists.txt b/compizconfig/mocks/libcompizconfig/CMakeLists.txt similarity index 94% rename from compizconfig/libcompizconfig/tests/mocks/CMakeLists.txt rename to compizconfig/mocks/libcompizconfig/CMakeLists.txt index 174af3624..a8f03b668 100644 --- a/compizconfig/libcompizconfig/tests/mocks/CMakeLists.txt +++ b/compizconfig/mocks/libcompizconfig/CMakeLists.txt @@ -1,5 +1,5 @@ include_directories (${GTEST_INCLUDE_DIRS}) -include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/include) link_directories (${CMAKE_INSTALL_PREFIX}/lib) if (HAVE_PROTOBUF) diff --git a/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp similarity index 100% rename from compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.cpp rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp diff --git a/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h similarity index 100% rename from compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_context_mock.h rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h diff --git a/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp similarity index 100% rename from compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.cpp rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp diff --git a/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h similarity index 100% rename from compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_plugin_mock.h rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h diff --git a/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp similarity index 100% rename from compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.cpp rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp diff --git a/compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h similarity index 100% rename from compizconfig/libcompizconfig/tests/mocks/compizconfig_ccs_setting_mock.h rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h -- GitLab From 0cc86941f8712ef61a9b6dd4e95f9331a09d1f0a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 14:12:49 +0800 Subject: [PATCH 007/562] Pull out the static fields in CCSBackendVTable into functions --- compizconfig/gconf/src/gconf.c | 46 +++++++++++++++++-- compizconfig/gsettings/src/gsettings.c | 46 +++++++++++++++++-- .../libcompizconfig/backend/src/ini.c | 45 ++++++++++++++++-- .../libcompizconfig/include/ccs-backend.h | 14 +++++- compizconfig/libcompizconfig/src/main.c | 18 ++++---- 5 files changed, 144 insertions(+), 25 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index e730231f9..193f9da7e 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -2112,12 +2112,48 @@ deleteProfile (CCSContext *context, return status; } +static char * +getName (CCSBackend *backend) +{ + static char name[] = "gconf"; + + return name; +} + +static char * +getShortDesc (CCSBackend *backend) +{ + static char shortDesc[] = "GConf Configuration Backend"; + + return shortDesc; +} + +static char * +getLongDesc (CCSBackend *backend) +{ + static char longDesc[] = "GConf Configuration Backend for libccs"; + + return longDesc; +} + +static Bool +hasIntegrationSupport (CCSBackend *backend) +{ + return TRUE; +} + +static Bool +hasProfileSupport (CCSBackend *backend) +{ + return TRUE; +} + static CCSBackendVTable gconfVTable = { - "gconf", - "GConf Configuration Backend", - "GConf Configuration Backend for libccs", - TRUE, - TRUE, + getName, + getShortDesc, + getLongDesc, + hasIntegrationSupport, + hasProfileSupport, processEvents, initBackend, finiBackend, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index f58424dd1..3324bab41 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -1242,12 +1242,48 @@ deleteProfile (CCSContext *context, return TRUE; } +static char * +getName (CCSBackend *backend) +{ + static char name[] = "gsettings"; + + return name; +} + +static char * +getShortDesc (CCSBackend *backend) +{ + static char shortDesc[] = "GSettings Configuration Backend"; + + return shortDesc; +} + +static char * +getLongDesc (CCSBackend *backend) +{ + static char longDesc[] = "GSettings Configuration Backend for libccs"; + + return longDesc; +} + +static Bool +hasIntegrationSupport (CCSBackend *backend) +{ + return TRUE; +} + +static Bool +hasProfileSupport (CCSBackend *backend) +{ + return TRUE; +} + static CCSBackendVTable gsettingsVTable = { - "gsettings", - "GSettings Configuration Backend", - "GSettings Configuration Backend for libccs", - TRUE, - TRUE, + getName, + getShortDesc, + getLongDesc, + hasIntegrationSupport, + hasProfileSupport, processEvents, initBackend, finiBackend, diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 1fb83a642..799ce0483 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -704,13 +704,48 @@ deleteProfile (CCSContext * context, char * profile) return TRUE; } +static char * +getName (CCSBackend *backend) +{ + static char name[] = "ini"; + + return name; +} + +static char * +getShortDesc (CCSBackend *backend) +{ + static char shortDesc[] = "Flat-file Configuration Backend"; + + return shortDesc; +} + +static char * +getLongDesc (CCSBackend *backend) +{ + static char longDesc[] = "Flat file Configuration Backend for libccs"; + + return longDesc; +} + +static Bool +hasIntegrationSupport (CCSBackend *backend) +{ + return FALSE; +} + +static Bool +hasProfileSupport (CCSBackend *backend) +{ + return TRUE; +} static CCSBackendVTable iniVTable = { - "ini", - "Flat-file Configuration Backend", - "Flat file Configuration Backend for libccs", - FALSE, - TRUE, + getName, + getShortDesc, + getLongDesc, + hasIntegrationSupport, + hasProfileSupport, NULL, initBackend, finiBackend, diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 1377a64d5..fef95bff4 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -56,13 +56,25 @@ typedef Bool (*CCSGetIsReadOnlyFunc) (CCSSetting * setting); typedef CCSStringList (*CCSGetExistingProfilesFunc) (CCSContext * context); typedef Bool (*CCSDeleteProfileFunc) (CCSContext * context, char * name); +typedef char * (*CCSBackendGetNameFunc) (CCSBackend *); +typedef char * (*CCSBackendGetShortDescFunc) (CCSBackend *); +typedef char * (*CCSBackendGetLongDescFunc) (CCSBackend *); +typedef Bool (*CCSBackendHasIntegrationSupportFunc) (CCSBackend *); +typedef Bool (*CCSBackendHasProfileSupportFunc) (CCSBackend *); + struct _CCSBackendVTable -{ +{/* char *name; char *shortDesc; char *longDesc; Bool integrationSupport; Bool profileSupport; + */ + CCSBackendGetNameFunc getName; + CCSBackendGetShortDescFunc getShortDesc; + CCSBackendGetLongDescFunc getLongDesc; + CCSBackendHasIntegrationSupportFunc hasIntegrationSupport; + CCSBackendHasProfileSupportFunc hasProfileSupport; /* something like a event loop call for the backend, so it can check for file changes (gconf changes in the gconf backend) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index df1f5ddcc..405156c8d 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -319,7 +319,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", cPrivate->backend->vTable->name); + ccsInfo ("Backend : %s", (*cPrivate->backend->vTable->getName) (cPrivate->backend)); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -1072,7 +1072,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) { /* no action needed if the backend is the same */ - if (strcmp (cPrivate->backend->vTable->name, name) == 0) + if (strcmp ((*cPrivate->backend->vTable->getName) (cPrivate->backend), name) == 0) return TRUE; if (cPrivate->backend->vTable->backendFini) @@ -2549,7 +2549,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return cPrivate->backend->vTable->name; + return (*cPrivate->backend->vTable->getName) (cPrivate->backend); } char * @@ -3397,7 +3397,7 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) CCSBackendInfoList l = *bl; while (l) { - if (!strcmp (l->data->name, vt->name)) + if (!strcmp (l->data->name, (*vt->getName) (NULL))) { found = TRUE; break; @@ -3420,11 +3420,11 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) } info->refCount = 1; - info->name = strdup (vt->name); - info->shortDesc = (vt->shortDesc) ? strdup (vt->shortDesc) : strdup (""); - info->longDesc = (vt->longDesc) ? strdup (vt->longDesc) : strdup (""); - info->integrationSupport = vt->integrationSupport; - info->profileSupport = vt->profileSupport; + info->name = strdup ((*vt->getName) (NULL)); + info->shortDesc = (vt->getShortDesc) ? strdup ((*vt->getShortDesc) (NULL)) : strdup (""); + info->longDesc = (vt->getLongDesc) ? strdup ((*vt->getLongDesc) (NULL)) : strdup (""); + info->integrationSupport = (*vt->hasIntegrationSupport) (NULL); + info->profileSupport = (*vt->hasProfileSupport) (NULL); *bl = ccsBackendInfoListAppend (*bl, info); dlclose (dlhand); -- GitLab From 75347878c70632597b31397c863115c01fa81576 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 15:24:06 +0800 Subject: [PATCH 008/562] Make CCSBackend into a CCSObject and hide its private data behind a private ptr --- .../libcompizconfig/include/CMakeLists.txt | 4 + .../libcompizconfig/include/ccs-backend.h | 20 +- .../libcompizconfig/include/ccs-defs.h | 52 +++++ .../libcompizconfig/include/ccs-list.h | 85 ++++++++ .../libcompizconfig/include/ccs-object.h | 127 ++++++++++++ .../libcompizconfig/include/ccs-string.h | 47 +++++ compizconfig/libcompizconfig/include/ccs.h | 186 +----------------- .../libcompizconfig/src/ccs-private.h | 2 + compizconfig/libcompizconfig/src/main.c | 184 ++++++++++++----- 9 files changed, 474 insertions(+), 233 deletions(-) create mode 100644 compizconfig/libcompizconfig/include/ccs-defs.h create mode 100644 compizconfig/libcompizconfig/include/ccs-list.h create mode 100644 compizconfig/libcompizconfig/include/ccs-object.h create mode 100644 compizconfig/libcompizconfig/include/ccs-string.h diff --git a/compizconfig/libcompizconfig/include/CMakeLists.txt b/compizconfig/libcompizconfig/include/CMakeLists.txt index 0544e0169..7fab10dcc 100644 --- a/compizconfig/libcompizconfig/include/CMakeLists.txt +++ b/compizconfig/libcompizconfig/include/CMakeLists.txt @@ -1,5 +1,9 @@ set (_headers ccs-backend.h + ccs-defs.h + ccs-list.h + ccs-object.h + ccs-string.h ccs.h ) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index fef95bff4..99520d555 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -22,17 +22,28 @@ #ifndef CCS_BACKEND_H #define CCS_BACKEND_H -#include +#include +#include typedef struct _CCSBackend CCSBackend; +typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendVTable CCSBackendVTable; -struct _CCSBackend +typedef struct _CCSContext CCSContext; +typedef struct _CCSSetting CCSSetting; + +struct _CCSBackendPrivate { void *dlhand; + CCSContext *context; CCSBackendVTable *vTable; }; +struct _CCSBackend +{ + CCSObject object; +}; + typedef CCSBackendVTable * (*BackendGetInfoProc) (void); typedef void (*CCSExecuteEventsFunc) (unsigned int flags); @@ -100,6 +111,11 @@ struct _CCSBackendVTable CCSDeleteProfileFunc deleteProfile; }; +CCSBackendVTable * ccsBackendGetVTable (CCSBackend *); +void * ccsBackendGetDlHand (CCSBackend *); + +void ccsFreeBackend (CCSBackend *); + CCSBackendVTable* getBackendInfo (void); #endif diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h b/compizconfig/libcompizconfig/include/ccs-defs.h new file mode 100644 index 000000000..5c1bb43d7 --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-defs.h @@ -0,0 +1,52 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_DEFS_H +#define _CCS_DEFS_H + +#include /* for NULL */ + +#ifdef __cplusplus +# define COMPIZCONFIG_BEGIN_DECLS extern "C" { +# define COMPIZCONFIG_END_DECLS } +#else +# define COMPIZCONFIG_BEGIN_DECLS +# define COMPIZCONFIG_END_DECLS +#endif + + +COMPIZCONFIG_BEGIN_DECLS + +#ifndef Bool +#define Bool int +#endif + +#ifndef TRUE +#define TRUE ~0 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-list.h b/compizconfig/libcompizconfig/include/ccs-list.h new file mode 100644 index 000000000..9e758223f --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-list.h @@ -0,0 +1,85 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_LIST_H +#define _CCS_LIST_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +/** + * list functions: + * for each list there is a set of functions, explained using String as example + * + * ccsStringListAppend (list, item) + * Adds an item at the end of the list. Returns the new list. + * + * ccsStringListPrepend (list, item) + * Adds an item at the beginning of the list. Returns the new list. + * + * ccsStringListInsert (list, item, position) + * Adds an item at a given position. Position is 0-based. If position is + * larger than the amount of items in the list, the item is inserted at the + * end of the list. Returns the new list. + * + * ccsStringListInsertBefore (list, sibling, item) + * Inserts item before sibling into the list. If sibling is no list member, + * item is inserted at the end. Returns the new list. + * + * ccsStringListLength (list) + * Returns the amount of items in list. + * + * ccsStringListFind (list, item) + * Finds and returns an item matching . If nothing is found, returns NULL. + * + * ccsStringListGetItem (list, index) + * Returns the list item at position . If index is larger than the + * amount of items in the list, returns NULL. + * + * ccsStringListRemove (list, item, freeObj) + * Removes item from the list. If freeObj is TRUE, also frees the data item. + * Returns the new list. + * + * ccsStringListFree (list, freeObj) + * Frees the complete list. If freeObj is TRUE, also frees the data items. + * Returns the new list (NULL). + */ +#define CCSLIST_HDR(type,dtype) \ + typedef struct _CCS##type##List * CCS##type##List;\ + struct _CCS##type##List \ + { \ + dtype * data; \ + CCS##type##List next; \ + }; \ + CCS##type##List ccs##type##ListAppend (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListPrepend (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListInsert (CCS##type##List list, dtype *data, int position); \ + CCS##type##List ccs##type##ListInsertBefore (CCS##type##List list, CCS##type##List sibling, dtype *data); \ + unsigned int ccs##type##ListLength (CCS##type##List list); \ + CCS##type##List ccs##type##ListFind (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListGetItem (CCS##type##List list, unsigned int index); \ + CCS##type##List ccs##type##ListRemove (CCS##type##List list, dtype *data, Bool freeObj); \ + CCS##type##List ccs##type##ListFree (CCS##type##List list, Bool freeObj); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-object.h b/compizconfig/libcompizconfig/include/ccs-object.h new file mode 100644 index 000000000..a2505de1b --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-object.h @@ -0,0 +1,127 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2012 Canonical Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authored By: Sam Spilsbury + */ + +#ifndef _CCS_OBJECT_H +#define _CCS_OBJECT_H + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ +typedef struct _CCSPrivate CCSPrivate; /* Dummy typedef */ +typedef struct _CCSObject CCSObject; + +typedef void * (*reallocObjectProc) (void *, void *, size_t); +typedef void * (*mallocObjectProc) (void *, size_t); +typedef void * (*callocObjectProc) (void *, size_t, size_t); +typedef void (*freeObjectProc) (void *, void *); + +typedef struct _CCSObjectAllocationInterface +{ + reallocObjectProc realloc_; + mallocObjectProc malloc_; + callocObjectProc calloc_; + freeObjectProc free_; + void *allocator; +} CCSObjectAllocationInterface; + +extern CCSObjectAllocationInterface ccsDefaultObjectAllocator; + +struct _CCSObject +{ + CCSPrivate *priv; /* Private pointer for object storage */ + + const CCSInterface **interfaces; /* An array of interfaces that this object implements */ + int *interface_types; /* An array of interface types */ + unsigned int n_interfaces; + unsigned int n_allocated_interfaces; + + CCSObjectAllocationInterface *object_allocation; + + unsigned int refcnt; /* Reference count of this object */ +}; + +Bool +ccsObjectInit_ (CCSObject *object, CCSObjectAllocationInterface *interface); + +#define ccsObjectInit(o, interface) (ccsObjectInit_) (&(o)->object, interface) + +Bool +ccsObjectAddInterface_ (CCSObject *object, const CCSInterface *interface, int interface_type); + +#define ccsObjectAddInterface(o, interface, type) (ccsObjectAddInterface_) (&(o)->object, interface, type); + +Bool +ccsObjectRemoveInterface_ (CCSObject *object, int interface_type); + +#define ccsObjectRemoveInterface(o, interface_type) (ccsObjectRemoveInterface_) (&(o)->object, interface_type); + +const CCSInterface * ccsObjectGetInterface_ (CCSObject *object, int interface_type); + +#define ccsObjectGetInterface(o, interface_type) (ccsObjectGetInterface_) (&(o)->object, interface_type) + +#define ccsObjectRef(o) \ + do { ((o)->object).refcnt++; } while (FALSE) + +#define ccsObjectUnref(o, freeFunc) \ + do \ + { \ + ((o)->object).refcnt--; \ + if (!((o)->object).refcnt) \ + freeFunc (o); \ + } while (FALSE) + +CCSPrivate * +ccsObjectGetPrivate_ (CCSObject *object); + +#define ccsObjectGetPrivate(o) (ccsObjectGetPrivate_) (&(o)->object) + +void +ccsObjectSetPrivate_ (CCSObject *object, CCSPrivate *priv); + +#define ccsObjectSetPrivate(o, priv) (ccsObjectSetPrivate_) (&(o)->object, priv) + +void +ccsObjectFinalize_ (CCSObject *object); + +#define ccsObjectFinalize(o) (ccsObjectFinalize_) (&(o)->object) + +unsigned int +ccsAllocateType (); + +#define GET_INTERFACE_TYPE(Interface) \ + ccs##Interface##GetType () + +#define INTERFACE_TYPE(Interface) \ + unsigned int ccs##Interface##GetType () \ + { \ + static unsigned int type_id = 0; \ + if (!type_id) \ + type_id = ccsAllocateType (); \ + \ + return type_id; \ + } + +#define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-string.h b/compizconfig/libcompizconfig/include/ccs-string.h new file mode 100644 index 000000000..48dabde5e --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-string.h @@ -0,0 +1,47 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_STRING_H +#define _CCS_STRING_H + +/* Doesn't seem to make sense to have this header + * dependency, but we can only declare a typed list + * once */ +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSString CCSString; + +struct _CCSString +{ + char *value; + unsigned int refCount; +}; + +void ccsFreeString (CCSString *str); + +CCSLIST_HDR (String, CCSString); + +COMPIZCONFIG_END_DECLS + +#endif + diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 57324f9ed..a0c902266 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -23,23 +23,13 @@ #define _CSS_H #include /* for NULL */ +#include +#include +#include +#include +#include -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifndef Bool -#define Bool int -#endif - -#ifndef TRUE -#define TRUE ~0 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif +COMPIZCONFIG_BEGIN_DECLS #ifndef CCS_LOG_DOMAIN #define CCS_LOG_DOMAIN NULL @@ -78,60 +68,6 @@ typedef enum void ccsLog (const char *domain, CCSLogLevel level, const char *fmt, ...); -/** - * list functions: - * for each list there is a set of functions, explained using String as example - * - * ccsStringListAppend (list, item) - * Adds an item at the end of the list. Returns the new list. - * - * ccsStringListPrepend (list, item) - * Adds an item at the beginning of the list. Returns the new list. - * - * ccsStringListInsert (list, item, position) - * Adds an item at a given position. Position is 0-based. If position is - * larger than the amount of items in the list, the item is inserted at the - * end of the list. Returns the new list. - * - * ccsStringListInsertBefore (list, sibling, item) - * Inserts item before sibling into the list. If sibling is no list member, - * item is inserted at the end. Returns the new list. - * - * ccsStringListLength (list) - * Returns the amount of items in list. - * - * ccsStringListFind (list, item) - * Finds and returns an item matching . If nothing is found, returns NULL. - * - * ccsStringListGetItem (list, index) - * Returns the list item at position . If index is larger than the - * amount of items in the list, returns NULL. - * - * ccsStringListRemove (list, item, freeObj) - * Removes item from the list. If freeObj is TRUE, also frees the data item. - * Returns the new list. - * - * ccsStringListFree (list, freeObj) - * Frees the complete list. If freeObj is TRUE, also frees the data items. - * Returns the new list (NULL). - */ -#define CCSLIST_HDR(type,dtype) \ - typedef struct _CCS##type##List * CCS##type##List;\ - struct _CCS##type##List \ - { \ - dtype * data; \ - CCS##type##List next; \ - }; \ - CCS##type##List ccs##type##ListAppend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListPrepend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListInsert (CCS##type##List list, dtype *data, int position); \ - CCS##type##List ccs##type##ListInsertBefore (CCS##type##List list, CCS##type##List sibling, dtype *data); \ - unsigned int ccs##type##ListLength (CCS##type##List list); \ - CCS##type##List ccs##type##ListFind (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListGetItem (CCS##type##List list, unsigned int index); \ - CCS##type##List ccs##type##ListRemove (CCS##type##List list, dtype *data, Bool freeObj); \ - CCS##type##List ccs##type##ListFree (CCS##type##List list, Bool freeObj); - typedef struct _CCSContext CCSContext; typedef struct _CCSPlugin CCSPlugin; typedef struct _CCSSetting CCSSetting; @@ -144,11 +80,9 @@ typedef struct _CCSBackendInfo CCSBackendInfo; typedef struct _CCSIntDesc CCSIntDesc; typedef struct _CCSStrRestriction CCSStrRestriction; typedef struct _CCSStrExtension CCSStrExtension; -typedef struct _CCSString CCSString; CCSLIST_HDR (Plugin, CCSPlugin) CCSLIST_HDR (Setting, CCSSetting) -CCSLIST_HDR (String, CCSString) CCSLIST_HDR (Group, CCSGroup) CCSLIST_HDR (SubGroup, CCSSubGroup) CCSLIST_HDR (SettingValue, CCSSettingValue) @@ -158,102 +92,6 @@ CCSLIST_HDR (IntDesc, CCSIntDesc) CCSLIST_HDR (StrRestriction, CCSStrRestriction) CCSLIST_HDR (StrExtension, CCSStrExtension) -typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ -typedef struct _CCSPrivate CCSPrivate; /* Dummy typedef */ -typedef struct _CCSObject CCSObject; - -typedef void * (*reallocObjectProc) (void *, void *, size_t); -typedef void * (*mallocObjectProc) (void *, size_t); -typedef void * (*callocObjectProc) (void *, size_t, size_t); -typedef void (*freeObjectProc) (void *, void *); - -typedef struct _CCSObjectAllocationInterface -{ - reallocObjectProc realloc_; - mallocObjectProc malloc_; - callocObjectProc calloc_; - freeObjectProc free_; - void *allocator; -} CCSObjectAllocationInterface; - -extern CCSObjectAllocationInterface ccsDefaultObjectAllocator; - -struct _CCSObject -{ - CCSPrivate *priv; /* Private pointer for object storage */ - - const CCSInterface **interfaces; /* An array of interfaces that this object implements */ - int *interface_types; /* An array of interface types */ - unsigned int n_interfaces; - unsigned int n_allocated_interfaces; - - CCSObjectAllocationInterface *object_allocation; - - unsigned int refcnt; /* Reference count of this object */ -}; - -Bool -ccsObjectInit_ (CCSObject *object, CCSObjectAllocationInterface *interface); - -#define ccsObjectInit(o, interface) (ccsObjectInit_) (&(o)->object, interface) - -Bool -ccsObjectAddInterface_ (CCSObject *object, const CCSInterface *interface, int interface_type); - -#define ccsObjectAddInterface(o, interface, type) (ccsObjectAddInterface_) (&(o)->object, interface, type); - -Bool -ccsObjectRemoveInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectRemoveInterface(o, interface_type) (ccsObjectRemoveInterface_) (&(o)->object, interface_type); - -const CCSInterface * ccsObjectGetInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectGetInterface(o, interface_type) (ccsObjectGetInterface_) (&(o)->object, interface_type) - -#define ccsObjectRef(o) \ - do { ((o)->object).refcnt++; } while (FALSE) - -#define ccsObjectUnref(o, freeFunc) \ - do \ - { \ - ((o)->object).refcnt--; \ - if (!((o)->object).refcnt) \ - freeFunc (o); \ - } while (FALSE) - -CCSPrivate * -ccsObjectGetPrivate_ (CCSObject *object); - -#define ccsObjectGetPrivate(o) (ccsObjectGetPrivate_) (&(o)->object) - -void -ccsObjectSetPrivate_ (CCSObject *object, CCSPrivate *priv); - -#define ccsObjectSetPrivate(o, priv) (ccsObjectSetPrivate_) (&(o)->object, priv) - -void -ccsObjectFinalize_ (CCSObject *object); - -#define ccsObjectFinalize(o) (ccsObjectFinalize_) (&(o)->object) - -unsigned int -ccsAllocateType (); - -#define GET_INTERFACE_TYPE(Interface) \ - ccs##Interface##GetType () - -#define INTERFACE_TYPE(Interface) \ - unsigned int ccs##Interface##GetType () \ - { \ - static unsigned int type_id = 0; \ - if (!type_id) \ - type_id = ccsAllocateType (); \ - \ - return type_id; \ - } - -#define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) /** * reference counting @@ -276,6 +114,7 @@ ccsAllocateType (); CCSREF_HDR (Plugin, CCSPlugin) CCSREF_HDR (Setting, CCSSetting) CCSREF_HDR (String, CCSString) +CCSREF_HDR (Backend, CCSBackend) CCSREF_HDR (Group, CCSGroup) CCSREF_HDR (SubGroup, CCSSubGroup) CCSREF_HDR (SettingValue, CCSSettingValue) @@ -543,12 +382,6 @@ struct _CCSPluginConflict union _CCSSettingInfo; -struct _CCSString -{ - char *value; - unsigned int refCount; -}; - struct _CCSIntDesc { int value; /* value the description is assigned to */ @@ -916,7 +749,6 @@ void ccsFreeBackendInfo (CCSBackendInfo *value); void ccsFreeIntDesc (CCSIntDesc *value); void ccsFreeStrRestriction (CCSStrRestriction *restriction); void ccsFreeStrExtension (CCSStrExtension *extension); -void ccsFreeString (CCSString *str); @@ -1271,8 +1103,6 @@ CCSBackendInfoList ccsGetExistingBackends (void); CCSStrExtensionList ccsGetPluginStrExtensions (CCSPlugin *plugin); -#ifdef __cplusplus -} -#endif +COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index c24cef8b3..726343ff8 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -31,6 +31,8 @@ CCSPluginPrivate *pPrivate = (CCSPluginPrivate *) ccsObjectGetPrivate (p); #define SETTING_PRIV(s) \ CCSSettingPrivate *sPrivate = (CCSSettingPrivate *) ccsObjectGetPrivate (s); +#define BACKEND_PRIV(b) \ + CCSBackendPrivate *bPrivate = (CCSBackendPrivate *) ccsObjectGetPrivate (b); extern Bool basicMetadata; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 405156c8d..96653fdad 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -319,7 +319,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", (*cPrivate->backend->vTable->getName) (cPrivate->backend)); + ccsInfo ("Backend : %s", (*(ccsBackendGetVTable (cPrivate->backend)->getName)) (cPrivate->backend)); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -1008,6 +1008,7 @@ CCSREF (StrExtension, CCSStrExtension) CCSREF_OBJ (Plugin, CCSPlugin) CCSREF_OBJ (Setting, CCSSetting) +CCSREF_OBJ (Backend, CCSBackend) static void * openBackend (char *backend) @@ -1062,24 +1063,51 @@ openBackend (char *backend) return dlhand; } +CCSBackendVTable * +ccsBackendGetVTable (CCSBackend *backend) +{ + BACKEND_PRIV (backend); + + return bPrivate->vTable; +} + +void * +ccsBackendGetDlHand (CCSBackend *backend) +{ + BACKEND_PRIV (backend); + + return bPrivate->dlhand; +} + +void +ccsFreeBackend (CCSBackend *backend) +{ + BACKEND_PRIV (backend); + + if (bPrivate->vTable->backendFini) + (*bPrivate->vTable->backendFini) (bPrivate->context); + + dlclose (bPrivate->dlhand); + + ccsObjectFinalize (backend); + free (backend); +} + Bool ccsSetBackendDefault (CCSContext * context, char *name) { Bool fallbackMode = FALSE; + CCSBackendPrivate *bPrivate = NULL; CONTEXT_PRIV (context); if (cPrivate->backend) { /* no action needed if the backend is the same */ - if (strcmp ((*cPrivate->backend->vTable->getName) (cPrivate->backend), name) == 0) + if (strcmp ((*(ccsBackendGetVTable (cPrivate->backend))->getName) (cPrivate->backend), name) == 0) return TRUE; - if (cPrivate->backend->vTable->backendFini) - cPrivate->backend->vTable->backendFini (context); - - dlclose (cPrivate->backend->dlhand); - free (cPrivate->backend); + ccsBackendUnref (cPrivate->backend); cPrivate->backend = NULL; } @@ -1108,17 +1136,37 @@ ccsSetBackendDefault (CCSContext * context, char *name) return FALSE; } - cPrivate->backend = calloc (1, sizeof (CCSBackend)); - if (!cPrivate->backend) + CCSBackend *backend = calloc (1, sizeof (CCSBackend)); + + if (!backend) { dlclose (dlhand); return FALSE; } - cPrivate->backend->dlhand = dlhand; - cPrivate->backend->vTable = vt; - if (cPrivate->backend->vTable->backendInit) - cPrivate->backend->vTable->backendInit (context); + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + ccsBackendRef (backend); + + bPrivate = calloc (1, sizeof (CCSBackendPrivate)); + + if (!bPrivate) + { + ccsBackendUnref (backend); + dlclose (dlhand); + } + + bPrivate->dlhand = dlhand; + bPrivate->context = context; + bPrivate->vTable = vt; + + ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); + + cPrivate->backend = backend; + + CCSInitBackendFunc backendInit = ccsBackendGetVTable (cPrivate->backend)->backendInit; + + if (backendInit) + (*backendInit) (context); ccsDisableFileWatch (cPrivate->configWatchId); if (!fallbackMode) @@ -2310,11 +2358,7 @@ ccsContextDestroy (CCSContext * context) if (cPrivate->backend) { - if (cPrivate->backend->vTable->backendFini) - cPrivate->backend->vTable->backendFini (context); - - dlclose (cPrivate->backend->dlhand); - free (cPrivate->backend); + ccsBackendUnref (cPrivate->backend); cPrivate->backend = NULL; } @@ -2549,7 +2593,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return (*cPrivate->backend->vTable->getName) (cPrivate->backend); + return (*(ccsBackendGetVTable (cPrivate->backend)->getName)) (cPrivate->backend); } char * @@ -2731,8 +2775,10 @@ ccsProcessEventsDefault (CCSContext * context, unsigned int flags) ccsCheckFileWatches (); - if (cPrivate->backend && cPrivate->backend->vTable->executeEvents) - (*cPrivate->backend->vTable->executeEvents) (flags); + CCSExecuteEventsFunc executeEvents = ccsBackendGetVTable (cPrivate->backend)->executeEvents; + + if (cPrivate->backend && executeEvents) + (*executeEvents) (flags); } void @@ -2755,11 +2801,15 @@ ccsReadSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->readSetting) + CCSContextReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; + + if (!readSetting) return; - if (cPrivate->backend->vTable->readInit) - if (!(*cPrivate->backend->vTable->readInit) (context)) + CCSContextReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; + + if (readInit) + if (!(*readInit) (context)) return; CCSPluginList pl = cPrivate->plugins; @@ -2770,15 +2820,17 @@ ccsReadSettingsDefault (CCSContext * context) while (sl) { - (*cPrivate->backend->vTable->readSetting) (context, sl->data); + (*readSetting) (context, sl->data); sl = sl->next; } pl = pl->next; } - if (cPrivate->backend->vTable->readDone) - (*cPrivate->backend->vTable->readDone) (context); + CCSContextReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; + + if (readDone) + (*readDone) (context); } void @@ -2801,11 +2853,15 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->readSetting) + CCSContextReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; + + if (!readSetting) return; - if (cPrivate->backend->vTable->readInit) - if (!(*cPrivate->backend->vTable->readInit) (ccsPluginGetContext (plugin))) + CCSContextReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; + + if (readInit) + if (!(*readInit) (ccsPluginGetContext (plugin))) return; PLUGIN_PRIV (plugin); @@ -2813,12 +2869,14 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) CCSSettingList sl = pPrivate->settings; while (sl) { - (*cPrivate->backend->vTable->readSetting) (ccsPluginGetContext (plugin), sl->data); + (*readSetting) (ccsPluginGetContext (plugin), sl->data); sl = sl->next; } - if (cPrivate->backend->vTable->readDone) - (*cPrivate->backend->vTable->readDone) (ccsPluginGetContext (plugin)); + CCSContextReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; + + if (readDone) + (*readDone) (ccsPluginGetContext (plugin)); } void @@ -2838,11 +2896,15 @@ ccsWriteSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->writeSetting) + CCSContextWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; + + if (!writeSetting) return; - if (cPrivate->backend->vTable->writeInit) - if (!(*cPrivate->backend->vTable->writeInit) (context)) + CCSContextWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; + + if (writeInit) + if (!(*writeInit) (context)) return; CCSPluginList pl = cPrivate->plugins; @@ -2853,15 +2915,17 @@ ccsWriteSettingsDefault (CCSContext * context) while (sl) { - (*cPrivate->backend->vTable->writeSetting) (context, sl->data); + (*writeSetting) (context, sl->data); sl = sl->next; } pl = pl->next; } - if (cPrivate->backend->vTable->writeDone) - (*cPrivate->backend->vTable->writeDone) (context); + CCSContextWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; + + if (writeDone) + (*writeDone) (context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -2887,11 +2951,15 @@ ccsWriteChangedSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->writeSetting) + CCSContextWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; + + if (!writeSetting) return; - if (cPrivate->backend->vTable->writeInit) - if (!(*cPrivate->backend->vTable->writeInit) (context)) + CCSContextWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; + + if (writeInit) + if (!(*writeInit) (context)) return; if (ccsSettingListLength (cPrivate->changedSettings)) @@ -2900,13 +2968,15 @@ ccsWriteChangedSettingsDefault (CCSContext * context) while (l) { - (*cPrivate->backend->vTable->writeSetting) (context, l->data); + (*writeSetting) (context, l->data); l = l->next; } } - if (cPrivate->backend->vTable->writeDone) - (*cPrivate->backend->vTable->writeDone) (context); + CCSContextWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; + + if (writeDone) + (*writeDone) (context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -3317,8 +3387,10 @@ ccsGetExistingProfilesDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - if (cPrivate->backend->vTable->getExistingProfiles) - return (*cPrivate->backend->vTable->getExistingProfiles) (context); + CCSGetExistingProfilesFunc getExistingProfiles = ccsBackendGetVTable (cPrivate->backend)->getExistingProfiles; + + if (getExistingProfiles) + return (*getExistingProfiles) (context); return NULL; } @@ -3352,8 +3424,10 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (strcmp (cPrivate->profile, name) == 0) ccsSetProfile (context, ""); - if (cPrivate->backend->vTable->deleteProfile) - (*cPrivate->backend->vTable->deleteProfile) (context, name); + CCSDeleteProfileFunc deleteProfile = ccsBackendGetVTable (cPrivate->backend)->deleteProfile; + + if (deleteProfile) + (*deleteProfile) (context, name); } void @@ -4803,8 +4877,10 @@ Bool ccsSettingGetIsIntegratedDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - if (cPrivate->backend->vTable->getSettingIsIntegrated) - return (*cPrivate->backend->vTable->getSettingIsIntegrated) (setting); + CCSGetIsIntegratedFunc getSettingIsIntegrated = ccsBackendGetVTable (cPrivate->backend)->getSettingIsIntegrated; + + if (getSettingIsIntegrated) + return (*getSettingIsIntegrated) (setting); return FALSE; } @@ -4819,8 +4895,10 @@ Bool ccsSettingGetIsReadOnlyDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - if (cPrivate->backend->vTable->getSettingIsReadOnly) - return (*cPrivate->backend->vTable->getSettingIsReadOnly) (setting); + CCSGetIsReadOnlyFunc getSettingIsReadOnly = ccsBackendGetVTable (cPrivate->backend)->getSettingIsReadOnly; + + if (getSettingIsReadOnly) + return (*getSettingIsReadOnly) (setting); return FALSE; } -- GitLab From 0ff4db847c1aa508385f57ddc6f9c13e4ed49474 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 15:29:17 +0800 Subject: [PATCH 009/562] Actually hide the private data internally --- compizconfig/libcompizconfig/include/ccs-backend.h | 7 ------- compizconfig/libcompizconfig/src/ccs-private.h | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 99520d555..599db7e42 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -32,13 +32,6 @@ typedef struct _CCSBackendVTable CCSBackendVTable; typedef struct _CCSContext CCSContext; typedef struct _CCSSetting CCSSetting; -struct _CCSBackendPrivate -{ - void *dlhand; - CCSContext *context; - CCSBackendVTable *vTable; -}; - struct _CCSBackend { CCSObject object; diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 726343ff8..63a3b2d70 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -122,6 +122,13 @@ typedef struct _CCSSettingPrivate void *privatePtr; /* private pointer for usage by the caller */ } CCSSettingPrivate; +struct _CCSBackendPrivate +{ + void *dlhand; + CCSContext *context; + CCSBackendVTable *vTable; +}; + typedef struct _CCSSettingsUpgrade { char *profile; -- GitLab From a9b8054f3b80a12c97c30be825d49bdfa3aa219d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 15:33:13 +0800 Subject: [PATCH 010/562] Rename CCSBackendVTable to CCSBackendInterface because it will become a real interface soonish --- compizconfig/gconf/src/gconf.c | 4 ++-- compizconfig/gsettings/src/gsettings.c | 4 ++-- compizconfig/libcompizconfig/backend/src/ini.c | 4 ++-- compizconfig/libcompizconfig/include/ccs-backend.h | 8 ++++---- compizconfig/libcompizconfig/src/ccs-private.h | 2 +- compizconfig/libcompizconfig/src/main.c | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 193f9da7e..3861eaa6e 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -2148,7 +2148,7 @@ hasProfileSupport (CCSBackend *backend) return TRUE; } -static CCSBackendVTable gconfVTable = { +static CCSBackendInterface gconfVTable = { getName, getShortDesc, getLongDesc, @@ -2169,7 +2169,7 @@ static CCSBackendVTable gconfVTable = { deleteProfile }; -CCSBackendVTable * +CCSBackendInterface * getBackendInfo (void) { return &gconfVTable; diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 3324bab41..a38477505 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -1278,7 +1278,7 @@ hasProfileSupport (CCSBackend *backend) return TRUE; } -static CCSBackendVTable gsettingsVTable = { +static CCSBackendInterface gsettingsVTable = { getName, getShortDesc, getLongDesc, @@ -1299,7 +1299,7 @@ static CCSBackendVTable gsettingsVTable = { deleteProfile }; -CCSBackendVTable * +CCSBackendInterface * getBackendInfo (void) { return &gsettingsVTable; diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 799ce0483..7625eb698 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -740,7 +740,7 @@ hasProfileSupport (CCSBackend *backend) return TRUE; } -static CCSBackendVTable iniVTable = { +static CCSBackendInterface iniVTable = { getName, getShortDesc, getLongDesc, @@ -761,7 +761,7 @@ static CCSBackendVTable iniVTable = { deleteProfile }; -CCSBackendVTable * +CCSBackendInterface * getBackendInfo (void) { return &iniVTable; diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 599db7e42..c94649520 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -27,7 +27,7 @@ typedef struct _CCSBackend CCSBackend; typedef struct _CCSBackendPrivate CCSBackendPrivate; -typedef struct _CCSBackendVTable CCSBackendVTable; +typedef struct _CCSBackendVTable CCSBackendInterface; typedef struct _CCSContext CCSContext; typedef struct _CCSSetting CCSSetting; @@ -37,7 +37,7 @@ struct _CCSBackend CCSObject object; }; -typedef CCSBackendVTable * (*BackendGetInfoProc) (void); +typedef CCSBackendInterface * (*BackendGetInfoProc) (void); typedef void (*CCSExecuteEventsFunc) (unsigned int flags); @@ -104,11 +104,11 @@ struct _CCSBackendVTable CCSDeleteProfileFunc deleteProfile; }; -CCSBackendVTable * ccsBackendGetVTable (CCSBackend *); +CCSBackendInterface * ccsBackendGetVTable (CCSBackend *); void * ccsBackendGetDlHand (CCSBackend *); void ccsFreeBackend (CCSBackend *); -CCSBackendVTable* getBackendInfo (void); +CCSBackendInterface* getBackendInfo (void); #endif diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 63a3b2d70..10137ccfe 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -126,7 +126,7 @@ struct _CCSBackendPrivate { void *dlhand; CCSContext *context; - CCSBackendVTable *vTable; + CCSBackendInterface *vTable; }; typedef struct _CCSSettingsUpgrade diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 96653fdad..e67ed32d4 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1063,7 +1063,7 @@ openBackend (char *backend) return dlhand; } -CCSBackendVTable * +CCSBackendInterface * ccsBackendGetVTable (CCSBackend *backend) { BACKEND_PRIV (backend); @@ -1129,7 +1129,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) return FALSE; } - CCSBackendVTable *vt = getInfo (); + CCSBackendInterface *vt = getInfo (); if (!vt) { dlclose (dlhand); @@ -3461,7 +3461,7 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) return; } - CCSBackendVTable *vt = getInfo (); + CCSBackendInterface *vt = getInfo (); if (!vt) { dlclose (dlhand); -- GitLab From 37a242dff4331b0ff11ae0abd68f140fa5a736c4 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 15:39:35 +0800 Subject: [PATCH 011/562] Rename the typedefs to be more appropriate --- .../libcompizconfig/include/ccs-backend.h | 60 +++++++++---------- compizconfig/libcompizconfig/src/main.c | 36 +++++------ 2 files changed, 45 insertions(+), 51 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index c94649520..747475b9b 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -39,26 +39,26 @@ struct _CCSBackend typedef CCSBackendInterface * (*BackendGetInfoProc) (void); -typedef void (*CCSExecuteEventsFunc) (unsigned int flags); +typedef void (*CCSBackendExecuteEventsFunc) (unsigned int flags); -typedef Bool (*CCSInitBackendFunc) (CCSContext * context); -typedef Bool (*CCSFiniBackendFunc) (CCSContext * context); +typedef Bool (*CCSBackendInitFunc) (CCSContext * context); +typedef Bool (*CCSBackendFiniFunc) (CCSContext * context); -typedef Bool (*CCSContextReadInitFunc) (CCSContext * context); -typedef void (*CCSContextReadSettingFunc) +typedef Bool (*CCSBackendReadInitFunc) (CCSContext * context); +typedef void (*CCSBackendReadSettingFunc) (CCSContext * context, CCSSetting * setting); -typedef void (*CCSContextReadDoneFunc) (CCSContext * context); +typedef void (*CCSBackendReadDoneFunc) (CCSContext * context); -typedef Bool (*CCSContextWriteInitFunc) (CCSContext * context); -typedef void (*CCSContextWriteSettingFunc) +typedef Bool (*CCSBackendWriteInitFunc) (CCSContext * context); +typedef void (*CCSBackendWriteSettingFunc) (CCSContext * context, CCSSetting * setting); -typedef void (*CCSContextWriteDoneFunc) (CCSContext * context); +typedef void (*CCSBackendWriteDoneFunc) (CCSContext * context); -typedef Bool (*CCSGetIsIntegratedFunc) (CCSSetting * setting); -typedef Bool (*CCSGetIsReadOnlyFunc) (CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSSetting * setting); -typedef CCSStringList (*CCSGetExistingProfilesFunc) (CCSContext * context); -typedef Bool (*CCSDeleteProfileFunc) (CCSContext * context, char * name); +typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSContext * context); +typedef Bool (*CCSBackendDeleteProfileFunc) (CCSContext * context, char * name); typedef char * (*CCSBackendGetNameFunc) (CCSBackend *); typedef char * (*CCSBackendGetShortDescFunc) (CCSBackend *); @@ -67,13 +67,7 @@ typedef Bool (*CCSBackendHasIntegrationSupportFunc) (CCSBackend *); typedef Bool (*CCSBackendHasProfileSupportFunc) (CCSBackend *); struct _CCSBackendVTable -{/* - char *name; - char *shortDesc; - char *longDesc; - Bool integrationSupport; - Bool profileSupport; - */ +{ CCSBackendGetNameFunc getName; CCSBackendGetShortDescFunc getShortDesc; CCSBackendGetLongDescFunc getLongDesc; @@ -83,25 +77,25 @@ struct _CCSBackendVTable /* something like a event loop call for the backend, so it can check for file changes (gconf changes in the gconf backend) no need for reload settings signals anymore */ - CCSExecuteEventsFunc executeEvents; + CCSBackendExecuteEventsFunc executeEvents; - CCSInitBackendFunc backendInit; - CCSFiniBackendFunc backendFini; + CCSBackendInitFunc backendInit; + CCSBackendFiniFunc backendFini; - CCSContextReadInitFunc readInit; - CCSContextReadSettingFunc readSetting; - CCSContextReadDoneFunc readDone; + CCSBackendReadInitFunc readInit; + CCSBackendReadSettingFunc readSetting; + CCSBackendReadDoneFunc readDone; - CCSContextWriteInitFunc writeInit; - CCSContextWriteSettingFunc writeSetting; - CCSContextWriteDoneFunc writeDone; + CCSBackendWriteInitFunc writeInit; + CCSBackendWriteSettingFunc writeSetting; + CCSBackendWriteDoneFunc writeDone; - CCSGetIsIntegratedFunc getSettingIsIntegrated; - CCSGetIsReadOnlyFunc getSettingIsReadOnly; + CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated; + CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly; - CCSGetExistingProfilesFunc getExistingProfiles; - CCSDeleteProfileFunc deleteProfile; + CCSBackendGetExistingProfilesFunc getExistingProfiles; + CCSBackendDeleteProfileFunc deleteProfile; }; CCSBackendInterface * ccsBackendGetVTable (CCSBackend *); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index e67ed32d4..4bcad1cc5 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1163,7 +1163,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) cPrivate->backend = backend; - CCSInitBackendFunc backendInit = ccsBackendGetVTable (cPrivate->backend)->backendInit; + CCSBackendInitFunc backendInit = ccsBackendGetVTable (cPrivate->backend)->backendInit; if (backendInit) (*backendInit) (context); @@ -2775,7 +2775,7 @@ ccsProcessEventsDefault (CCSContext * context, unsigned int flags) ccsCheckFileWatches (); - CCSExecuteEventsFunc executeEvents = ccsBackendGetVTable (cPrivate->backend)->executeEvents; + CCSBackendExecuteEventsFunc executeEvents = ccsBackendGetVTable (cPrivate->backend)->executeEvents; if (cPrivate->backend && executeEvents) (*executeEvents) (flags); @@ -2801,12 +2801,12 @@ ccsReadSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSContextReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; + CCSBackendReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; if (!readSetting) return; - CCSContextReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; + CCSBackendReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; if (readInit) if (!(*readInit) (context)) @@ -2827,7 +2827,7 @@ ccsReadSettingsDefault (CCSContext * context) pl = pl->next; } - CCSContextReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; + CCSBackendReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; if (readDone) (*readDone) (context); @@ -2853,12 +2853,12 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) if (!cPrivate->backend) return; - CCSContextReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; + CCSBackendReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; if (!readSetting) return; - CCSContextReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; + CCSBackendReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; if (readInit) if (!(*readInit) (ccsPluginGetContext (plugin))) @@ -2873,7 +2873,7 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) sl = sl->next; } - CCSContextReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; + CCSBackendReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; if (readDone) (*readDone) (ccsPluginGetContext (plugin)); @@ -2896,12 +2896,12 @@ ccsWriteSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSContextWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; + CCSBackendWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; if (!writeSetting) return; - CCSContextWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; + CCSBackendWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; if (writeInit) if (!(*writeInit) (context)) @@ -2922,7 +2922,7 @@ ccsWriteSettingsDefault (CCSContext * context) pl = pl->next; } - CCSContextWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; + CCSBackendWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; if (writeDone) (*writeDone) (context); @@ -2951,12 +2951,12 @@ ccsWriteChangedSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSContextWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; + CCSBackendWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; if (!writeSetting) return; - CCSContextWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; + CCSBackendWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; if (writeInit) if (!(*writeInit) (context)) @@ -2973,7 +2973,7 @@ ccsWriteChangedSettingsDefault (CCSContext * context) } } - CCSContextWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; + CCSBackendWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; if (writeDone) (*writeDone) (context); @@ -3387,7 +3387,7 @@ ccsGetExistingProfilesDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - CCSGetExistingProfilesFunc getExistingProfiles = ccsBackendGetVTable (cPrivate->backend)->getExistingProfiles; + CCSBackendGetExistingProfilesFunc getExistingProfiles = ccsBackendGetVTable (cPrivate->backend)->getExistingProfiles; if (getExistingProfiles) return (*getExistingProfiles) (context); @@ -3424,7 +3424,7 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (strcmp (cPrivate->profile, name) == 0) ccsSetProfile (context, ""); - CCSDeleteProfileFunc deleteProfile = ccsBackendGetVTable (cPrivate->backend)->deleteProfile; + CCSBackendDeleteProfileFunc deleteProfile = ccsBackendGetVTable (cPrivate->backend)->deleteProfile; if (deleteProfile) (*deleteProfile) (context, name); @@ -4877,7 +4877,7 @@ Bool ccsSettingGetIsIntegratedDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - CCSGetIsIntegratedFunc getSettingIsIntegrated = ccsBackendGetVTable (cPrivate->backend)->getSettingIsIntegrated; + CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated = ccsBackendGetVTable (cPrivate->backend)->getSettingIsIntegrated; if (getSettingIsIntegrated) return (*getSettingIsIntegrated) (setting); @@ -4895,7 +4895,7 @@ Bool ccsSettingGetIsReadOnlyDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - CCSGetIsReadOnlyFunc getSettingIsReadOnly = ccsBackendGetVTable (cPrivate->backend)->getSettingIsReadOnly; + CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly = ccsBackendGetVTable (cPrivate->backend)->getSettingIsReadOnly; if (getSettingIsReadOnly) return (*getSettingIsReadOnly) (setting); -- GitLab From 11ecca228e6c4c58cc9634604c670a2ef7821b4b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 16:05:55 +0800 Subject: [PATCH 012/562] Make the VTable into a real interface and make CCSBackend implement that interface --- .../libcompizconfig/include/ccs-backend.h | 7 ++- compizconfig/libcompizconfig/src/main.c | 59 +++++++++---------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 747475b9b..5e12e6277 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -27,7 +27,7 @@ typedef struct _CCSBackend CCSBackend; typedef struct _CCSBackendPrivate CCSBackendPrivate; -typedef struct _CCSBackendVTable CCSBackendInterface; +typedef struct _CCSBackendInterface CCSBackendInterface; typedef struct _CCSContext CCSContext; typedef struct _CCSSetting CCSSetting; @@ -66,7 +66,7 @@ typedef char * (*CCSBackendGetLongDescFunc) (CCSBackend *); typedef Bool (*CCSBackendHasIntegrationSupportFunc) (CCSBackend *); typedef Bool (*CCSBackendHasProfileSupportFunc) (CCSBackend *); -struct _CCSBackendVTable +struct _CCSBackendInterface { CCSBackendGetNameFunc getName; CCSBackendGetShortDescFunc getShortDesc; @@ -98,7 +98,8 @@ struct _CCSBackendVTable CCSBackendDeleteProfileFunc deleteProfile; }; -CCSBackendInterface * ccsBackendGetVTable (CCSBackend *); +unsigned int ccsCCSBackendInterfaceGetType (); + void * ccsBackendGetDlHand (CCSBackend *); void ccsFreeBackend (CCSBackend *); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 4bcad1cc5..5be195ac8 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -231,6 +231,7 @@ ccsAllocateType () INTERFACE_TYPE (CCSContextInterface) INTERFACE_TYPE (CCSPluginInterface) INTERFACE_TYPE (CCSSettingInterface) +INTERFACE_TYPE (CCSBackendInterface); Bool basicMetadata = FALSE; @@ -319,7 +320,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", (*(ccsBackendGetVTable (cPrivate->backend)->getName)) (cPrivate->backend)); + ccsInfo ("Backend : %s", (*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) (cPrivate->backend)); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -1063,14 +1064,6 @@ openBackend (char *backend) return dlhand; } -CCSBackendInterface * -ccsBackendGetVTable (CCSBackend *backend) -{ - BACKEND_PRIV (backend); - - return bPrivate->vTable; -} - void * ccsBackendGetDlHand (CCSBackend *backend) { @@ -1084,8 +1077,10 @@ ccsFreeBackend (CCSBackend *backend) { BACKEND_PRIV (backend); - if (bPrivate->vTable->backendFini) - (*bPrivate->vTable->backendFini) (bPrivate->context); + CCSBackendFiniFunc backendFini = (GET_INTERFACE (CCSBackendInterface, backend))->backendFini; + + if (backendFini) + (*backendFini) (bPrivate->context); dlclose (bPrivate->dlhand); @@ -1104,7 +1099,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) { /* no action needed if the backend is the same */ - if (strcmp ((*(ccsBackendGetVTable (cPrivate->backend))->getName) (cPrivate->backend), name) == 0) + if (strcmp ((*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) (cPrivate->backend), name) == 0) return TRUE; ccsBackendUnref (cPrivate->backend); @@ -1157,13 +1152,13 @@ ccsSetBackendDefault (CCSContext * context, char *name) bPrivate->dlhand = dlhand; bPrivate->context = context; - bPrivate->vTable = vt; ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); + ccsObjectAddInterface (backend, (CCSInterface *) vt, GET_INTERFACE_TYPE (CCSBackendInterface)); cPrivate->backend = backend; - CCSBackendInitFunc backendInit = ccsBackendGetVTable (cPrivate->backend)->backendInit; + CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; if (backendInit) (*backendInit) (context); @@ -2593,7 +2588,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return (*(ccsBackendGetVTable (cPrivate->backend)->getName)) (cPrivate->backend); + return (*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) (cPrivate->backend); } char * @@ -2775,7 +2770,7 @@ ccsProcessEventsDefault (CCSContext * context, unsigned int flags) ccsCheckFileWatches (); - CCSBackendExecuteEventsFunc executeEvents = ccsBackendGetVTable (cPrivate->backend)->executeEvents; + CCSBackendExecuteEventsFunc executeEvents = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->executeEvents; if (cPrivate->backend && executeEvents) (*executeEvents) (flags); @@ -2801,12 +2796,12 @@ ccsReadSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSBackendReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; + CCSBackendReadSettingFunc readSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readSetting; if (!readSetting) return; - CCSBackendReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; + CCSBackendReadInitFunc readInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readInit; if (readInit) if (!(*readInit) (context)) @@ -2827,7 +2822,7 @@ ccsReadSettingsDefault (CCSContext * context) pl = pl->next; } - CCSBackendReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; + CCSBackendReadDoneFunc readDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readDone; if (readDone) (*readDone) (context); @@ -2853,12 +2848,12 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) if (!cPrivate->backend) return; - CCSBackendReadSettingFunc readSetting = ccsBackendGetVTable (cPrivate->backend)->readSetting; + CCSBackendReadSettingFunc readSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readSetting; if (!readSetting) return; - CCSBackendReadInitFunc readInit = ccsBackendGetVTable (cPrivate->backend)->readInit; + CCSBackendReadInitFunc readInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readInit; if (readInit) if (!(*readInit) (ccsPluginGetContext (plugin))) @@ -2873,7 +2868,7 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) sl = sl->next; } - CCSBackendReadDoneFunc readDone = ccsBackendGetVTable (cPrivate->backend)->readDone; + CCSBackendReadDoneFunc readDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readDone; if (readDone) (*readDone) (ccsPluginGetContext (plugin)); @@ -2896,12 +2891,12 @@ ccsWriteSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSBackendWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; + CCSBackendWriteSettingFunc writeSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeSetting; if (!writeSetting) return; - CCSBackendWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; + CCSBackendWriteInitFunc writeInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeInit; if (writeInit) if (!(*writeInit) (context)) @@ -2922,7 +2917,7 @@ ccsWriteSettingsDefault (CCSContext * context) pl = pl->next; } - CCSBackendWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; + CCSBackendWriteDoneFunc writeDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeDone; if (writeDone) (*writeDone) (context); @@ -2951,12 +2946,12 @@ ccsWriteChangedSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSBackendWriteSettingFunc writeSetting = ccsBackendGetVTable (cPrivate->backend)->writeSetting; + CCSBackendWriteSettingFunc writeSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeSetting; if (!writeSetting) return; - CCSBackendWriteInitFunc writeInit = ccsBackendGetVTable (cPrivate->backend)->writeInit; + CCSBackendWriteInitFunc writeInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeInit; if (writeInit) if (!(*writeInit) (context)) @@ -2973,7 +2968,7 @@ ccsWriteChangedSettingsDefault (CCSContext * context) } } - CCSBackendWriteDoneFunc writeDone = ccsBackendGetVTable (cPrivate->backend)->writeDone; + CCSBackendWriteDoneFunc writeDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeDone; if (writeDone) (*writeDone) (context); @@ -3387,7 +3382,7 @@ ccsGetExistingProfilesDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - CCSBackendGetExistingProfilesFunc getExistingProfiles = ccsBackendGetVTable (cPrivate->backend)->getExistingProfiles; + CCSBackendGetExistingProfilesFunc getExistingProfiles = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getExistingProfiles; if (getExistingProfiles) return (*getExistingProfiles) (context); @@ -3424,7 +3419,7 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (strcmp (cPrivate->profile, name) == 0) ccsSetProfile (context, ""); - CCSBackendDeleteProfileFunc deleteProfile = ccsBackendGetVTable (cPrivate->backend)->deleteProfile; + CCSBackendDeleteProfileFunc deleteProfile = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->deleteProfile; if (deleteProfile) (*deleteProfile) (context, name); @@ -4877,7 +4872,7 @@ Bool ccsSettingGetIsIntegratedDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated = ccsBackendGetVTable (cPrivate->backend)->getSettingIsIntegrated; + CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getSettingIsIntegrated; if (getSettingIsIntegrated) return (*getSettingIsIntegrated) (setting); @@ -4895,7 +4890,7 @@ Bool ccsSettingGetIsReadOnlyDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly = ccsBackendGetVTable (cPrivate->backend)->getSettingIsReadOnly; + CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getSettingIsReadOnly; if (getSettingIsReadOnly) return (*getSettingIsReadOnly) (setting); -- GitLab From 9533d5bbcf961c7bbb58e2fd97af916255e80047 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 16:33:08 +0800 Subject: [PATCH 013/562] Added convenience wrappers around the interface code for CCSBackend --- .../libcompizconfig/include/ccs-backend.h | 34 +++- compizconfig/libcompizconfig/src/main.c | 145 ++++++++++++++++++ 2 files changed, 176 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 5e12e6277..1165620c2 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -100,9 +100,37 @@ struct _CCSBackendInterface unsigned int ccsCCSBackendInterfaceGetType (); -void * ccsBackendGetDlHand (CCSBackend *); - -void ccsFreeBackend (CCSBackend *); +char * ccsBackendGetName (CCSBackend *backend); +char * ccsBackendGetShortDesc (CCSBackend *backend); +char * ccsBackendGetLongDesc (CCSBackend *backend); +Bool ccsBackendHasIntegrationSupport (CCSBackend *backend); +Bool ccsBackendHasProfileSupport (CCSBackend *backend); + +Bool ccsBackendHasExecuteEvents (CCSBackend *backend); +void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags); +Bool ccsBackendInit (CCSBackend *backend, CCSContext *context); +Bool ccsBackendFini (CCSBackend *backend, CCSContext *context); +Bool ccsBackendHasReadInit (CCSBackend *backend); +Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context); +Bool ccsBackendHasReadSetting (CCSBackend *backend); +void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); +Bool ccsBackendHasReadDone (CCSBackend *backend); +void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); +Bool ccsBackendHasWriteInit (CCSBackend *backend); +Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context); +Bool ccsBackendHasWriteSetting (CCSBackend *backend); +void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); +Bool ccsBackendHasWriteDone (CCSBackend *backend); +void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); +Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend); +Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); +Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend); +Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting); +Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend); +CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context); +Bool ccsBackendHasDeleteProfile (CCSBackend *backend); +Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name); +void ccsFreeBackend (CCSBackend *backend); CCSBackendInterface* getBackendInfo (void); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 5be195ac8..0e883ed73 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1177,6 +1177,151 @@ ccsSetBackend (CCSContext *context, char *name) return (*(GET_INTERFACE (CCSContextInterface, context))->contextSetBackend) (context, name); } +char * ccsBackendGetName (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getName) (backend); +} + +char * ccsBackendGetShortDesc (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getShortDesc) (backend); +} + +char * ccsBackendGetLongDesc (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getLongDesc) (backend); +} + +Bool ccsBackendHasIntegrationSupport (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->hasIntegrationSupport) (backend); +} + +Bool ccsBackendHasProfileSupport (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->hasProfileSupport) (backend); +} + +Bool ccsBackendHasExecuteEvents (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->executeEvents != NULL; +} + +void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags) +{ + (*(GET_INTERFACE (CCSBackendInterface, backend))->executeEvents) (flags); +} + +Bool ccsBackendInit (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendInit) (context); +} + +Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (context); +} + +Bool ccsBackendHasReadInit (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->readInit != NULL; +} + +Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readInit) (context); +} + +Bool ccsBackendHasReadSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->readSetting != NULL; +} + +void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + (*(GET_INTERFACE (CCSBackendInterface, backend))->readSetting) (context, setting); +} + +Bool ccsBackendHasReadDone (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->readDone != NULL; +} + +void ccsBackendReadDone (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readDone) (context); +} + +Bool ccsBackendHasWriteInit (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->writeInit != NULL; +} + +Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeInit) (context); +} + +Bool ccsBackendHasWriteSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->writeSetting != NULL; +} + +void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + (*(GET_INTERFACE (CCSBackendInterface, backend))->writeSetting) (context, setting); +} + +Bool ccsBackendHasWriteDone (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->writeDone != NULL; +} + +void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (context); +} + +Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated != NULL; +} + +Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated) (setting); +} + +Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly != NULL; +} + +Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly) (setting); +} + +Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles != NULL; +} + +CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles) (context); +} + +Bool ccsBackendHasDeleteProfile (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile != NULL; +} + +Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (context, name); +} + static Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, CCSSettingListInfo info) -- GitLab From 614f48bfa9efdb82ad36382c99f4000387df2915 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 8 Jul 2012 16:51:15 +0800 Subject: [PATCH 014/562] Migrate to the convenience functions --- compizconfig/libcompizconfig/src/main.c | 111 ++++++++---------------- 1 file changed, 37 insertions(+), 74 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 0e883ed73..a675ae00d 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -320,7 +320,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", (*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) (cPrivate->backend)); + ccsInfo ("Backend : %s", ccsBackendGetName (cPrivate->backend)); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -1077,10 +1077,7 @@ ccsFreeBackend (CCSBackend *backend) { BACKEND_PRIV (backend); - CCSBackendFiniFunc backendFini = (GET_INTERFACE (CCSBackendInterface, backend))->backendFini; - - if (backendFini) - (*backendFini) (bPrivate->context); + ccsBackendFini (backend, bPrivate->context); dlclose (bPrivate->dlhand); @@ -1099,7 +1096,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) { /* no action needed if the backend is the same */ - if (strcmp ((*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) (cPrivate->backend), name) == 0) + if (strcmp (ccsBackendGetName (cPrivate->backend), name) == 0) return TRUE; ccsBackendUnref (cPrivate->backend); @@ -2915,10 +2912,8 @@ ccsProcessEventsDefault (CCSContext * context, unsigned int flags) ccsCheckFileWatches (); - CCSBackendExecuteEventsFunc executeEvents = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->executeEvents; - - if (cPrivate->backend && executeEvents) - (*executeEvents) (flags); + if (cPrivate->backend && ccsBackendHasExecuteEvents (cPrivate->backend)) + ccsBackendExecuteEvents (cPrivate->backend, flags); } void @@ -2941,15 +2936,11 @@ ccsReadSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSBackendReadSettingFunc readSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readSetting; - - if (!readSetting) + if (!ccsBackendHasReadSetting (cPrivate->backend)) return; - CCSBackendReadInitFunc readInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readInit; - - if (readInit) - if (!(*readInit) (context)) + if (ccsBackendHasReadInit (cPrivate->backend)) + if (!ccsBackendReadInit (cPrivate->backend, context)) return; CCSPluginList pl = cPrivate->plugins; @@ -2960,17 +2951,15 @@ ccsReadSettingsDefault (CCSContext * context) while (sl) { - (*readSetting) (context, sl->data); + ccsBackendReadSetting (cPrivate->backend, context, sl->data); sl = sl->next; } pl = pl->next; } - CCSBackendReadDoneFunc readDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readDone; - - if (readDone) - (*readDone) (context); + if (ccsBackendHasReadDone (cPrivate->backend)) + ccsBackendReadDone (cPrivate->backend, context); } void @@ -2993,15 +2982,11 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) if (!cPrivate->backend) return; - CCSBackendReadSettingFunc readSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readSetting; - - if (!readSetting) + if (!ccsBackendHasReadSetting (cPrivate->backend)) return; - CCSBackendReadInitFunc readInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readInit; - - if (readInit) - if (!(*readInit) (ccsPluginGetContext (plugin))) + if (ccsBackendHasReadInit (cPrivate->backend)) + if (!ccsBackendReadInit (cPrivate->backend, ccsPluginGetContext (plugin))) return; PLUGIN_PRIV (plugin); @@ -3009,14 +2994,12 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) CCSSettingList sl = pPrivate->settings; while (sl) { - (*readSetting) (ccsPluginGetContext (plugin), sl->data); + ccsBackendReadSetting (cPrivate->backend, ccsPluginGetContext (plugin), sl->data); sl = sl->next; } - CCSBackendReadDoneFunc readDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->readDone; - - if (readDone) - (*readDone) (ccsPluginGetContext (plugin)); + if (ccsBackendHasReadDone (cPrivate->backend)) + ccsBackendReadDone (cPrivate->backend, ccsPluginGetContext (plugin)); } void @@ -3036,15 +3019,11 @@ ccsWriteSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSBackendWriteSettingFunc writeSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeSetting; - - if (!writeSetting) + if (!ccsBackendHasWriteSetting (cPrivate->backend)) return; - CCSBackendWriteInitFunc writeInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeInit; - - if (writeInit) - if (!(*writeInit) (context)) + if (ccsBackendHasWriteInit (cPrivate->backend)) + if (!ccsBackendWriteInit (cPrivate->backend, context)) return; CCSPluginList pl = cPrivate->plugins; @@ -3055,17 +3034,15 @@ ccsWriteSettingsDefault (CCSContext * context) while (sl) { - (*writeSetting) (context, sl->data); + ccsBackendWriteSetting (cPrivate->backend, context, sl->data); sl = sl->next; } pl = pl->next; } - CCSBackendWriteDoneFunc writeDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeDone; - - if (writeDone) - (*writeDone) (context); + if (ccsBackendHasWriteDone (cPrivate->backend)) + ccsBackendWriteDone (cPrivate->backend, context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -3091,15 +3068,11 @@ ccsWriteChangedSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - CCSBackendWriteSettingFunc writeSetting = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeSetting; - - if (!writeSetting) + if (!ccsBackendHasWriteSetting (cPrivate->backend)) return; - CCSBackendWriteInitFunc writeInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeInit; - - if (writeInit) - if (!(*writeInit) (context)) + if (ccsBackendHasWriteInit (cPrivate->backend)) + if (!ccsBackendWriteInit (cPrivate->backend, context)) return; if (ccsSettingListLength (cPrivate->changedSettings)) @@ -3108,15 +3081,13 @@ ccsWriteChangedSettingsDefault (CCSContext * context) while (l) { - (*writeSetting) (context, l->data); + ccsBackendWriteSetting (cPrivate->backend, context, l->data); l = l->next; } } - CCSBackendWriteDoneFunc writeDone = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->writeDone; - - if (writeDone) - (*writeDone) (context); + if (ccsBackendHasWriteDone (cPrivate->backend)) + ccsBackendWriteDone (cPrivate->backend,context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -3527,10 +3498,8 @@ ccsGetExistingProfilesDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - CCSBackendGetExistingProfilesFunc getExistingProfiles = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getExistingProfiles; - - if (getExistingProfiles) - return (*getExistingProfiles) (context); + if (ccsBackendHasGetExistingProfiles (cPrivate->backend)) + return ccsBackendGetExistingProfiles (cPrivate->backend, context); return NULL; } @@ -3564,10 +3533,8 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (strcmp (cPrivate->profile, name) == 0) ccsSetProfile (context, ""); - CCSBackendDeleteProfileFunc deleteProfile = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->deleteProfile; - - if (deleteProfile) - (*deleteProfile) (context, name); + if (ccsBackendHasDeleteProfile (cPrivate->backend)) + ccsBackendDeleteProfile (cPrivate->backend, context, name); } void @@ -5017,10 +4984,8 @@ Bool ccsSettingGetIsIntegratedDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getSettingIsIntegrated; - - if (getSettingIsIntegrated) - return (*getSettingIsIntegrated) (setting); + if (ccsBackendHasGetSettingIsIntegrated (cPrivate->backend)) + return ccsBackendGetSettingIsIntegrated (cPrivate->backend, setting); return FALSE; } @@ -5035,10 +5000,8 @@ Bool ccsSettingGetIsReadOnlyDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getSettingIsReadOnly; - - if (getSettingIsReadOnly) - return (*getSettingIsReadOnly) (setting); + if (ccsBackendHasGetSettingIsReadOnly (cPrivate->backend)) + return ccsBackendGetSettingIsReadOnly (cPrivate->backend, setting); return FALSE; } -- GitLab From 118ca23e6e5fa1b42ca31ca6f0316cf1473b724b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 12:16:24 +0800 Subject: [PATCH 015/562] Added wrapper CCSBackendWithCapabilities, make CCSBackend operate like an actual interface, requiring an interface in its calls --- compizconfig/gconf/src/gconf.c | 47 +++-- .../gsettings/src/gconf-integration.c | 12 +- compizconfig/gsettings/src/gsettings.c | 33 +-- compizconfig/gsettings/src/gsettings.h | 6 +- .../libcompizconfig/backend/src/ini.c | 26 ++- .../libcompizconfig/include/ccs-backend.h | 55 +++-- compizconfig/libcompizconfig/include/ccs.h | 2 + .../libcompizconfig/src/ccs-private.h | 7 + compizconfig/libcompizconfig/src/main.c | 197 ++++++++++++++++-- 9 files changed, 300 insertions(+), 85 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 3861eaa6e..8757d1875 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -89,10 +89,10 @@ static guint gnomeNotifyIds[NUM_WATCHED_DIRS]; static char *currentProfile = NULL; /* some forward declarations */ -static Bool readInit (CCSContext * context); -static void readSetting (CCSContext * context, CCSSetting * setting); +static Bool readInit (CCSBackend *backend, CCSContext * context); +static void readSetting (CCSBackend *backend, CCSContext * context, CCSSetting * setting); static Bool readOption (CCSSetting * setting); -static Bool writeInit (CCSContext * context); +static Bool writeInit (CCSBackend *backend, CCSContext * context); static void writeIntegratedOption (CCSContext *context, CCSSetting *setting, int index); @@ -490,14 +490,14 @@ valueChanged (GConfClient *client, if (!setting) return; - readInit (context); + readInit (NULL, context); if (!readOption (setting)) ccsResetToDefault (setting, TRUE); if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (context); + writeInit (NULL, context); writeIntegratedOption (context, setting, index); } } @@ -543,24 +543,24 @@ gnomeValueChanged (GConfClient *client, if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } s = findDisplaySettingForPlugin (context, "core", "window_menu_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "move", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "resize", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); } else { @@ -579,10 +579,10 @@ gnomeValueChanged (GConfClient *client, { if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } - readSetting (context, setting); + readSetting (NULL, context, setting); } /* do not read display settings multiple @@ -1941,7 +1941,7 @@ checkProfile (CCSContext *context) } static void -processEvents (unsigned int flags) +processEvents (CCSBackend *backend, unsigned int flags) { if (!(flags & ProcessEventsNoGlibMainLoopMask)) { @@ -1951,7 +1951,7 @@ processEvents (unsigned int flags) } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { g_type_init (); @@ -1964,7 +1964,7 @@ initBackend (CCSContext * context) } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend *backend, CCSContext * context) { gconf_client_clear_cache (client); finiClient (); @@ -1982,13 +1982,14 @@ finiBackend (CCSContext * context) } static Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, CCSContext * context) { return checkProfile (context); } static void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status; @@ -2007,13 +2008,14 @@ readSetting (CCSContext *context, } static Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { return checkProfile (context); } static void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { int index; @@ -2033,7 +2035,7 @@ writeSetting (CCSContext *context, } static Bool -getSettingIsIntegrated (CCSSetting * setting) +getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { if (!ccsGetIntegrationEnabled (ccsPluginGetContext (ccsSettingGetParent (setting)))) return FALSE; @@ -2045,14 +2047,14 @@ getSettingIsIntegrated (CCSSetting * setting) } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; } static CCSStringList -getExistingProfiles (CCSContext *context) +getExistingProfiles (CCSBackend *backend, CCSContext *context) { GSList *data, *tmp; CCSStringList ret = NULL; @@ -2090,7 +2092,8 @@ getExistingProfiles (CCSContext *context) } static Bool -deleteProfile (CCSContext *context, +deleteProfile (CCSBackend *backend, + CCSContext *context, char *profile) { char path[BUFSIZE]; diff --git a/compizconfig/gsettings/src/gconf-integration.c b/compizconfig/gsettings/src/gconf-integration.c index b13ffa6f8..ebc74cd97 100644 --- a/compizconfig/gsettings/src/gconf-integration.c +++ b/compizconfig/gsettings/src/gconf-integration.c @@ -405,24 +405,24 @@ gnomeGConfValueChanged (GConfClient *client, if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } s = findDisplaySettingForPlugin (context, "core", "window_menu_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "move", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "resize", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); } else { @@ -441,10 +441,10 @@ gnomeGConfValueChanged (GConfClient *client, { if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } - readSetting (context, setting); + readSetting (NULL, context, setting); } /* do not read display settings multiple diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index a38477505..7513bebc9 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -310,7 +310,7 @@ valueChanged (GSettings *settings, return; } - readInit (context); + readInit (NULL, context); if (!readOption (setting)) { ccsResetToDefault (setting, TRUE); @@ -319,7 +319,7 @@ valueChanged (GSettings *settings, if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (context); + writeInit (NULL, context); writeIntegratedOption (context, setting, index); } @@ -1019,7 +1019,7 @@ getCurrentProfileName (void) } static void -processEvents (unsigned int flags) +processEvents (CCSBackend *backend, unsigned int flags) { if (!(flags & ProcessEventsNoGlibMainLoopMask)) { @@ -1029,7 +1029,7 @@ processEvents (unsigned int flags) } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { const char *profilePath = PROFILEPATH; char *currentProfilePath; @@ -1052,11 +1052,11 @@ initBackend (CCSContext * context) } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend *backend, CCSContext * context) { GList *l = settingsList; - processEvents (0); + processEvents (backend, 0); #ifdef USE_GCONF gconf_client_clear_cache (client); @@ -1077,18 +1077,19 @@ finiBackend (CCSContext * context) g_object_unref (G_OBJECT (compizconfigSettings)); - processEvents (0); + processEvents (backend, 0); return TRUE; } Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, CCSContext * context) { return updateProfile (context); } void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status; @@ -1107,13 +1108,14 @@ readSetting (CCSContext *context, } Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { return updateProfile (context); } void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { int index; @@ -1133,7 +1135,7 @@ writeSetting (CCSContext *context, } static Bool -getSettingIsIntegrated (CCSSetting * setting) +getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { if (!ccsGetIntegrationEnabled (ccsPluginGetContext (ccsSettingGetParent (setting)))) return FALSE; @@ -1145,14 +1147,14 @@ getSettingIsIntegrated (CCSSetting * setting) } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; } static CCSStringList -getExistingProfiles (CCSContext *context) +getExistingProfiles (CCSBackend *backend, CCSContext *context) { GVariant *value; char *profile; @@ -1176,7 +1178,8 @@ getExistingProfiles (CCSContext *context) } static Bool -deleteProfile (CCSContext *context, +deleteProfile (CCSBackend *backend, + CCSContext *context, char *profile) { GVariant *plugins; diff --git a/compizconfig/gsettings/src/gsettings.h b/compizconfig/gsettings/src/gsettings.h index ee0d51c3e..1d6ecaf86 100644 --- a/compizconfig/gsettings/src/gsettings.h +++ b/compizconfig/gsettings/src/gsettings.h @@ -98,10 +98,10 @@ typedef enum { char *currentProfile; -Bool readInit (CCSContext * context); -void readSetting (CCSContext * context, CCSSetting * setting); +Bool readInit (CCSBackend *, CCSContext * context); +void readSetting (CCSBackend *, CCSContext * context, CCSSetting * setting); Bool readOption (CCSSetting * setting); -Bool writeInit (CCSContext * context); +Bool writeInit (CCSBackend *, CCSContext * context); void writeOption (CCSSetting *setting); #ifdef USE_GCONF diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 7625eb698..88d4d2ba1 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -180,7 +180,7 @@ setProfile (IniPrivData *data, } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { IniPrivData *newData; @@ -197,7 +197,8 @@ initBackend (CCSContext * context) } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend * backend, + CCSContext * context) { IniPrivData *data; @@ -229,7 +230,8 @@ finiBackend (CCSContext * context) } static Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, + CCSContext * context) { char *currentProfile; IniPrivData *data; @@ -258,7 +260,8 @@ readInit (CCSContext * context) } static void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status = FALSE; @@ -414,12 +417,12 @@ readSetting (CCSContext *context, } static void -readDone (CCSContext * context) +readDone (CCSBackend *backend, CCSContext * context) { } static Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { char *currentProfile; IniPrivData *data; @@ -450,7 +453,8 @@ writeInit (CCSContext * context) } static void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { char *keyName; @@ -569,7 +573,7 @@ writeSetting (CCSContext *context, } static void -writeDone (CCSContext * context) +writeDone (CCSBackend *backend, CCSContext * context) { /* export the data to ensure the changes are on disk */ char *fileName; @@ -599,7 +603,7 @@ writeDone (CCSContext * context) } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; @@ -652,7 +656,7 @@ scanConfigDir (char * filePath) } static CCSStringList -getExistingProfiles (CCSContext * context) +getExistingProfiles (CCSBackend *backend, CCSContext * context) { CCSStringList ret = NULL; char *filePath = NULL; @@ -689,7 +693,7 @@ getExistingProfiles (CCSContext * context) } static Bool -deleteProfile (CCSContext * context, char * profile) +deleteProfile (CCSBackend *backend, CCSContext * context, char * profile) { char *fileName; diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 1165620c2..c5ce524e4 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -39,26 +39,26 @@ struct _CCSBackend typedef CCSBackendInterface * (*BackendGetInfoProc) (void); -typedef void (*CCSBackendExecuteEventsFunc) (unsigned int flags); +typedef void (*CCSBackendExecuteEventsFunc) (CCSBackend *backend, unsigned int flags); -typedef Bool (*CCSBackendInitFunc) (CCSContext * context); -typedef Bool (*CCSBackendFiniFunc) (CCSContext * context); +typedef Bool (*CCSBackendInitFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendFiniFunc) (CCSBackend *, CCSContext * context); -typedef Bool (*CCSBackendReadInitFunc) (CCSContext * context); +typedef Bool (*CCSBackendReadInitFunc) (CCSBackend *, CCSContext * context); typedef void (*CCSBackendReadSettingFunc) -(CCSContext * context, CCSSetting * setting); -typedef void (*CCSBackendReadDoneFunc) (CCSContext * context); +(CCSBackend *, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendReadDoneFunc) (CCSBackend *backend, CCSContext * context); -typedef Bool (*CCSBackendWriteInitFunc) (CCSContext * context); +typedef Bool (*CCSBackendWriteInitFunc) (CCSBackend *backend, CCSContext * context); typedef void (*CCSBackendWriteSettingFunc) -(CCSContext * context, CCSSetting * setting); -typedef void (*CCSBackendWriteDoneFunc) (CCSContext * context); +(CCSBackend *, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendWriteDoneFunc) (CCSBackend *, CCSContext * context); -typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSSetting * setting); -typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSBackend *, CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSBackend *, CCSSetting * setting); -typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSContext * context); -typedef Bool (*CCSBackendDeleteProfileFunc) (CCSContext * context, char * name); +typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendDeleteProfileFunc) (CCSBackend *, CCSContext * context, char * name); typedef char * (*CCSBackendGetNameFunc) (CCSBackend *); typedef char * (*CCSBackendGetShortDescFunc) (CCSBackend *); @@ -132,6 +132,35 @@ Bool ccsBackendHasDeleteProfile (CCSBackend *backend); Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name); void ccsFreeBackend (CCSBackend *backend); +typedef struct _CCSBackendWithCapabilities CCSBackendWithCapabilities; +typedef struct _CCSBackendWithCapabilitiesPrivate CCSBackendWithCapabilitiesPrivate; +typedef struct _CCSBackendCapabilitiesInterface CCSBackendCapabilitiesInterface; + +struct _CCSBackendWithCapabilities +{ + CCSObject object; +}; + +typedef Bool (*CCSBackendCapabilitiesSupportsRead) (CCSBackendWithCapabilities *); +typedef Bool (*CCSBackendCapabilitiesSupportsWrite) (CCSBackendWithCapabilities *); +typedef Bool (*CCSBackendCapabilitiesSupportsProfiles) (CCSBackendWithCapabilities *); +typedef Bool (*CCSBackendCapabilitiesSupportsIntegration) (CCSBackendWithCapabilities *); + +struct _CCSBackendCapabilitiesInterface +{ + CCSBackendCapabilitiesSupportsRead supportsRead; + CCSBackendCapabilitiesSupportsWrite supportsWrite; + CCSBackendCapabilitiesSupportsProfiles supportsProfiles; + CCSBackendCapabilitiesSupportsIntegration supportsIntegration; +}; + +Bool ccsBackendCapabilitiesSupportsRead (CCSBackendWithCapabilities *); +Bool ccsBackendCapabilitiesSupportsWrite (CCSBackendWithCapabilities *); +Bool ccsBackendCapabilitiesSupportsProfiles (CCSBackendWithCapabilities *); +Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *); + +unsigned int ccsCCSBackendCapabilitiesInterfaceGetType (); + CCSBackendInterface* getBackendInfo (void); #endif diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index a0c902266..89220150d 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -128,12 +128,14 @@ typedef struct _CCSInterfaceTable CCSInterfaceTable; typedef struct _CCSContextInterface CCSContextInterface; typedef struct _CCSPluginInterface CCSPluginInterface; typedef struct _CCSSettingInterface CCSSettingInterface; +typedef struct _CCSBackendCapabilitiesInterface CCSBackendCapabilitiesInterface; struct _CCSInterfaceTable { const CCSContextInterface *contextInterface; const CCSPluginInterface *pluginInterface; const CCSSettingInterface *settingInterface; + const CCSBackendCapabilitiesInterface *backendCapabilitiesInterface; }; extern const CCSInterfaceTable ccsDefaultInterfaceTable; diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 10137ccfe..6ea102009 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -33,6 +33,8 @@ CCSSettingPrivate *sPrivate = (CCSSettingPrivate *) ccsObjectGetPrivate (s); #define BACKEND_PRIV(b) \ CCSBackendPrivate *bPrivate = (CCSBackendPrivate *) ccsObjectGetPrivate (b); +#define CAPABILITIES_PRIV(bc) \ + CCSBackendCapabilitiesPrivate *bcPrivate = (CCSBackendCapabilitiesPrivate *) ccsObjectGetPrivate (bc); extern Bool basicMetadata; @@ -129,6 +131,11 @@ struct _CCSBackendPrivate CCSBackendInterface *vTable; }; +typedef struct _CCSBackendCapabilitiesPrivate +{ + CCSBackend *backend; +} CCSBackendCapabilitiesPrivate; + typedef struct _CCSSettingsUpgrade { char *profile; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index a675ae00d..234b7c36e 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -232,6 +232,7 @@ INTERFACE_TYPE (CCSContextInterface) INTERFACE_TYPE (CCSPluginInterface) INTERFACE_TYPE (CCSSettingInterface) INTERFACE_TYPE (CCSBackendInterface); +INTERFACE_TYPE (CCSBackendCapabilitiesInterface); Bool basicMetadata = FALSE; @@ -1158,7 +1159,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; if (backendInit) - (*backendInit) (context); + (*backendInit) (cPrivate->backend, context); ccsDisableFileWatch (cPrivate->configWatchId); if (!fallbackMode) @@ -1199,6 +1200,34 @@ Bool ccsBackendHasProfileSupport (CCSBackend *backend) return (*(GET_INTERFACE (CCSBackendInterface, backend))->hasProfileSupport) (backend); } +static Bool +ccsBackendCapabilitiesSupportsIntegrationDefault (CCSBackendWithCapabilities *capabilities) +{ + CAPABILITIES_PRIV (capabilities); + + return ccsBackendHasIntegrationSupport (bcPrivate->backend); +} + +Bool ccsBackendCapabilitiesSupportsRead (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsRead) (capabilities); +} + +Bool ccsBackendCapabilitiesSupportsWrite (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsWrite) (capabilities); +} + +Bool ccsBackendCapabilitiesSupportsProfiles (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsProfiles) (capabilities); +} + +Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsIntegration) (capabilities); +} + Bool ccsBackendHasExecuteEvents (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->executeEvents != NULL; @@ -1206,17 +1235,17 @@ Bool ccsBackendHasExecuteEvents (CCSBackend *backend) void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags) { - (*(GET_INTERFACE (CCSBackendInterface, backend))->executeEvents) (flags); + (*(GET_INTERFACE (CCSBackendInterface, backend))->executeEvents) (backend, flags); } Bool ccsBackendInit (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendInit) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendInit) (backend, context); } Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (backend, context); } Bool ccsBackendHasReadInit (CCSBackend *backend) @@ -1226,7 +1255,7 @@ Bool ccsBackendHasReadInit (CCSBackend *backend) Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->readInit) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readInit) (backend, context); } Bool ccsBackendHasReadSetting (CCSBackend *backend) @@ -1236,7 +1265,7 @@ Bool ccsBackendHasReadSetting (CCSBackend *backend) void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - (*(GET_INTERFACE (CCSBackendInterface, backend))->readSetting) (context, setting); + (*(GET_INTERFACE (CCSBackendInterface, backend))->readSetting) (backend, context, setting); } Bool ccsBackendHasReadDone (CCSBackend *backend) @@ -1246,7 +1275,7 @@ Bool ccsBackendHasReadDone (CCSBackend *backend) void ccsBackendReadDone (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->readDone) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readDone) (backend, context); } Bool ccsBackendHasWriteInit (CCSBackend *backend) @@ -1256,7 +1285,7 @@ Bool ccsBackendHasWriteInit (CCSBackend *backend) Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeInit) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeInit) (backend, context); } Bool ccsBackendHasWriteSetting (CCSBackend *backend) @@ -1266,7 +1295,7 @@ Bool ccsBackendHasWriteSetting (CCSBackend *backend) void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - (*(GET_INTERFACE (CCSBackendInterface, backend))->writeSetting) (context, setting); + (*(GET_INTERFACE (CCSBackendInterface, backend))->writeSetting) (backend, context, setting); } Bool ccsBackendHasWriteDone (CCSBackend *backend) @@ -1276,7 +1305,7 @@ Bool ccsBackendHasWriteDone (CCSBackend *backend) void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); } Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) @@ -1286,7 +1315,7 @@ Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated) (setting); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated) (backend, setting); } Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) @@ -1296,7 +1325,7 @@ Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly) (setting); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly) (backend, setting); } Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) @@ -1306,7 +1335,7 @@ Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles) (backend, context); } Bool ccsBackendHasDeleteProfile (CCSBackend *backend) @@ -1316,7 +1345,114 @@ Bool ccsBackendHasDeleteProfile (CCSBackend *backend) Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (context, name); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (backend, context, name); +} + +static Bool +ccsBackendCapabilitiesSupportsReadDefault (CCSBackendWithCapabilities *capabilities) +{ + CAPABILITIES_PRIV (capabilities); + + return ccsBackendHasReadSetting (bcPrivate->backend); +} + +static Bool +ccsBackendCapabilitiesSupportsWriteDefault (CCSBackendWithCapabilities *capabilities) +{ + CAPABILITIES_PRIV (capabilities); + + return ccsBackendHasWriteSetting (bcPrivate->backend); +} + +static Bool +ccsBackendCapabilitiesSupportsProfilesDefault (CCSBackendWithCapabilities *capabilities) +{ + CAPABILITIES_PRIV (capabilities); + + return ccsBackendHasProfileSupport (bcPrivate->backend); +} + +static void ccsBackendCapabilitiesExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) +{ + if (ccsBackendHasExecuteEvents (backend)) + ccsBackendExecuteEvents (backend, flags); +} + +static Bool ccsBackendCapabilitiesReadInitWrapper (CCSBackend *backend, CCSContext *context) +{ + if (ccsBackendHasReadInit (backend)) + return ccsBackendReadInit (backend, context); + + return TRUE; +} + +static void ccsBackendCapabilitiesReadSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + if (ccsBackendHasReadSetting (backend)) + ccsBackendReadSetting (backend, context, setting); +} + +static void ccsBackendCapabilitiesReadDoneWrapper (CCSBackend *backend, CCSContext *context) +{ + if (ccsBackendHasReadDone (backend)) + ccsBackendReadDone (backend, context); +} + +static Bool ccsBackendCapabilitiesWriteInitWrapper (CCSBackend *backend, CCSContext *context) +{ + if (ccsBackendHasWriteInit (backend)) + return ccsBackendWriteInit (backend, context); + + return TRUE; +} + +static void ccsBackendCapabilitiesWriteSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + if (ccsBackendHasWriteSetting (backend)) + ccsBackendWriteSetting (backend, context, setting); +} + +static void ccsBackendCapabilitiesWriteDoneWrapper (CCSBackend *backend, CCSContext *context) +{ + if (ccsBackendHasWriteDone (backend)) + ccsBackendWriteDone (backend, context); +} + +static Bool ccsBackendCapabilitiesGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) +{ + if (ccsBackendHasGetSettingIsIntegrated (backend) && + ccsBackendHasIntegrationSupport (backend)) + return ccsBackendGetSettingIsIntegrated (backend, setting); + + return FALSE; +} + +static Bool ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper (CCSBackend *backend, CCSSetting *setting) +{ + if (ccsBackendHasGetSettingIsReadOnly (backend)) + return ccsBackendGetSettingIsReadOnly (backend, setting); + + return FALSE; +} + +static CCSStringList ccsBackendCapabilitiesGetExistingProfilesWrapper (CCSBackend *backend, CCSContext *context) +{ + if (ccsBackendHasGetExistingProfiles (backend) && + ccsBackendHasProfileSupport (backend)) + return ccsBackendGetExistingProfiles (backend, context); + + static CCSStringList sl = NULL; + + return sl; +} + +static Bool ccsBackendCapabilitiesDeleteProfileWrapper (CCSBackend *backend, CCSContext *context, char *profile) +{ + if (ccsBackendHasDeleteProfile (backend) && + ccsBackendHasProfileSupport (backend)) + return ccsBackendDeleteProfile (backend, context, profile); + + return FALSE; } static Bool @@ -5229,9 +5365,40 @@ static const CCSSettingInterface ccsDefaultSettingInterface = ccsFreeSettingDefault }; +const CCSBackendInterface ccsBackendCapabilitiesInterfaceWrapper = +{ + ccsBackendGetName, + ccsBackendGetShortDesc, + ccsBackendGetLongDesc, + ccsBackendHasIntegrationSupport, + ccsBackendHasProfileSupport, + ccsBackendCapabilitiesExecuteEventsWrapper, + ccsBackendInit, + ccsBackendFini, + ccsBackendCapabilitiesReadInitWrapper, + ccsBackendCapabilitiesReadSettingWrapper, + ccsBackendCapabilitiesReadDoneWrapper, + ccsBackendCapabilitiesWriteInitWrapper, + ccsBackendCapabilitiesWriteSettingWrapper, + ccsBackendCapabilitiesWriteDoneWrapper, + ccsBackendCapabilitiesGetSettingIsIntegratedWrapper, + ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper, + ccsBackendCapabilitiesGetExistingProfilesWrapper, + ccsBackendCapabilitiesDeleteProfileWrapper +}; + +const CCSBackendCapabilitiesInterface ccsDefaultBackendCapabilitiesInterface = +{ + ccsBackendCapabilitiesSupportsReadDefault, + ccsBackendCapabilitiesSupportsWriteDefault, + ccsBackendCapabilitiesSupportsIntegrationDefault, + ccsBackendCapabilitiesSupportsProfilesDefault +}; + const CCSInterfaceTable ccsDefaultInterfaceTable = { &ccsDefaultContextInterface, &ccsDefaultPluginInterface, - &ccsDefaultSettingInterface + &ccsDefaultSettingInterface, + &ccsDefaultBackendCapabilitiesInterface }; -- GitLab From a2dcb2af9218a419ebb8c820873a064e53b1841b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 14:00:15 +0800 Subject: [PATCH 016/562] Create a constructor for CCSBackend --- compizconfig/libcompizconfig/src/main.c | 49 +++++++++++++++---------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 234b7c36e..7a0e83559 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1086,11 +1086,39 @@ ccsFreeBackend (CCSBackend *backend) free (backend); } +static CCSBackend * +ccsBackendNewWithInterface (CCSContext *context, CCSBackendInterface *interface, void *dlhand) +{ + CCSBackend *backend = calloc (1, sizeof (CCSBackend)); + CCSBackendPrivate *bPrivate = NULL; + + if (!backend) + return NULL; + + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + ccsBackendRef (backend); + + bPrivate = calloc (1, sizeof (CCSBackendPrivate)); + + if (!bPrivate) + { + ccsBackendUnref (backend); + return NULL; + } + + bPrivate->dlhand = dlhand; + bPrivate->context = context; + + ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); + ccsObjectAddInterface (backend, (CCSInterface *) interface, GET_INTERFACE_TYPE (CCSBackendInterface)); + + return backend; +} + Bool ccsSetBackendDefault (CCSContext * context, char *name) { Bool fallbackMode = FALSE; - CCSBackendPrivate *bPrivate = NULL; CONTEXT_PRIV (context); if (cPrivate->backend) @@ -1129,7 +1157,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) return FALSE; } - CCSBackend *backend = calloc (1, sizeof (CCSBackend)); + CCSBackend *backend = ccsBackendNewWithInterface (context, vt, dlhand); if (!backend) { @@ -1137,23 +1165,6 @@ ccsSetBackendDefault (CCSContext * context, char *name) return FALSE; } - ccsObjectInit (backend, &ccsDefaultObjectAllocator); - ccsBackendRef (backend); - - bPrivate = calloc (1, sizeof (CCSBackendPrivate)); - - if (!bPrivate) - { - ccsBackendUnref (backend); - dlclose (dlhand); - } - - bPrivate->dlhand = dlhand; - bPrivate->context = context; - - ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); - ccsObjectAddInterface (backend, (CCSInterface *) vt, GET_INTERFACE_TYPE (CCSBackendInterface)); - cPrivate->backend = backend; CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; -- GitLab From fd4bfececbde30d463234732a7e2103bc6847b12 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 14:57:23 +0800 Subject: [PATCH 017/562] Indirect backend through CCSBackendCapabilitiesInterface --- .../libcompizconfig/include/ccs-backend.h | 2 + compizconfig/libcompizconfig/include/ccs.h | 1 + .../libcompizconfig/src/ccs-private.h | 8 +- compizconfig/libcompizconfig/src/main.c | 275 +++++++++++++----- 4 files changed, 202 insertions(+), 84 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index c5ce524e4..1d2ccbb3b 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -161,6 +161,8 @@ Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *); unsigned int ccsCCSBackendCapabilitiesInterfaceGetType (); +void ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *); + CCSBackendInterface* getBackendInfo (void); #endif diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 89220150d..ff22c1276 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -135,6 +135,7 @@ struct _CCSInterfaceTable const CCSContextInterface *contextInterface; const CCSPluginInterface *pluginInterface; const CCSSettingInterface *settingInterface; + const CCSBackendInterface *backendCapabilitiesWrapperInterface; const CCSBackendCapabilitiesInterface *backendCapabilitiesInterface; }; diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 6ea102009..7a93dcb83 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -34,13 +34,13 @@ #define BACKEND_PRIV(b) \ CCSBackendPrivate *bPrivate = (CCSBackendPrivate *) ccsObjectGetPrivate (b); #define CAPABILITIES_PRIV(bc) \ - CCSBackendCapabilitiesPrivate *bcPrivate = (CCSBackendCapabilitiesPrivate *) ccsObjectGetPrivate (bc); + CCSBackendWithCapabilitiesPrivate *bcPrivate = (CCSBackendWithCapabilitiesPrivate *) ccsObjectGetPrivate (bc); extern Bool basicMetadata; typedef struct _CCSContextPrivate { - CCSBackend *backend; + CCSBackendWithCapabilities *backend; CCSPluginList plugins; /* list of plugins settings were loaded for */ CCSPluginCategory *categories; /* list of plugin categories */ @@ -131,10 +131,10 @@ struct _CCSBackendPrivate CCSBackendInterface *vTable; }; -typedef struct _CCSBackendCapabilitiesPrivate +typedef struct _CCSBackendWithCapabilitiesPrivate { CCSBackend *backend; -} CCSBackendCapabilitiesPrivate; +} CCSBackendWithCapabilitiesPrivate; typedef struct _CCSSettingsUpgrade { diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 7a0e83559..4bc6671ca 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -321,7 +321,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", ccsBackendGetName (cPrivate->backend)); + ccsInfo ("Backend : %s", ccsBackendGetName ((CCSBackend *) cPrivate->backend)); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -1011,6 +1011,7 @@ CCSREF (StrExtension, CCSStrExtension) CCSREF_OBJ (Plugin, CCSPlugin) CCSREF_OBJ (Setting, CCSSetting) CCSREF_OBJ (Backend, CCSBackend) +CCSREF_OBJ (BackendWithCapabilities, CCSBackendWithCapabilities) static void * openBackend (char *backend) @@ -1080,14 +1081,26 @@ ccsFreeBackend (CCSBackend *backend) ccsBackendFini (backend, bPrivate->context); - dlclose (bPrivate->dlhand); + if (bPrivate->dlhand) + dlclose (bPrivate->dlhand); ccsObjectFinalize (backend); free (backend); } -static CCSBackend * -ccsBackendNewWithInterface (CCSContext *context, CCSBackendInterface *interface, void *dlhand) +void +ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *backendCapabilities) +{ + CAPABILITIES_PRIV (backendCapabilities); + + ccsBackendUnref (bcPrivate->backend); + + ccsObjectFinalize (backendCapabilities); + free (backendCapabilities); +} + +CCSBackend * +ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand) { CCSBackend *backend = calloc (1, sizeof (CCSBackend)); CCSBackendPrivate *bPrivate = NULL; @@ -1115,6 +1128,35 @@ ccsBackendNewWithInterface (CCSContext *context, CCSBackendInterface *interface, return backend; } +CCSBackendWithCapabilities * +ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend) +{ + CCSBackendWithCapabilities *backendCapabilities = calloc (1, sizeof (CCSBackendWithCapabilities)); + CCSBackendWithCapabilitiesPrivate *bcPrivate = NULL; + + if (!backendCapabilities) + return NULL; + + ccsObjectInit (backendCapabilities, &ccsDefaultObjectAllocator); + ccsBackendWithCapabilitiesRef (backendCapabilities); + + bcPrivate = calloc (1, sizeof (CCSBackendWithCapabilitiesPrivate)); + + if (!bcPrivate) + { + ccsBackendWithCapabilitiesUnref (backendCapabilities); + return NULL; + } + + bcPrivate->backend = backend; + + ccsObjectSetPrivate (backendCapabilities, (CCSPrivate *) bcPrivate); + ccsObjectAddInterface (backendCapabilities, (CCSInterface *) interfaces->backendCapabilitiesWrapperInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); + ccsObjectAddInterface (backendCapabilities, (CCSInterface *) interfaces->backendCapabilitiesInterface, GET_INTERFACE_TYPE (CCSBackendCapabilitiesInterface)); + + return backendCapabilities; +} + Bool ccsSetBackendDefault (CCSContext * context, char *name) { @@ -1125,10 +1167,10 @@ ccsSetBackendDefault (CCSContext * context, char *name) { /* no action needed if the backend is the same */ - if (strcmp (ccsBackendGetName (cPrivate->backend), name) == 0) + if (strcmp (ccsBackendGetName ((CCSBackend *) cPrivate->backend), name) == 0) return TRUE; - ccsBackendUnref (cPrivate->backend); + ccsBackendWithCapabilitiesUnref (cPrivate->backend); cPrivate->backend = NULL; } @@ -1165,12 +1207,20 @@ ccsSetBackendDefault (CCSContext * context, char *name) return FALSE; } - cPrivate->backend = backend; + CCSBackendWithCapabilities *backendWrapper = ccsBackendWithCapabilitiesWrapBackend (cPrivate->object_interfaces, backend); + + if (!backendWrapper) + { + ccsBackendUnref (backend); + return FALSE; + } + + cPrivate->backend = backendWrapper; CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; if (backendInit) - (*backendInit) (cPrivate->backend, context); + (*backendInit) ((CCSBackend *) cPrivate->backend, context); ccsDisableFileWatch (cPrivate->configWatchId); if (!fallbackMode) @@ -1383,74 +1433,143 @@ ccsBackendCapabilitiesSupportsProfilesDefault (CCSBackendWithCapabilities *capab return ccsBackendHasProfileSupport (bcPrivate->backend); } +static Bool ccsBackendCapabilitiesInitWrapper (CCSBackend *backend, CCSContext *context) +{ + CAPABILITIES_PRIV (backend); + + return ccsBackendInit (bcPrivate->backend, context); +} + +static char * ccsBackendCapabilitiesGetNameWrapper (CCSBackend *backend) +{ + CAPABILITIES_PRIV (backend); + + return ccsBackendGetName (bcPrivate->backend); +} + +static char * ccsBackendCapabilitiesGetShortDescWrapper (CCSBackend *backend) +{ + CAPABILITIES_PRIV (backend); + + return ccsBackendGetShortDesc (bcPrivate->backend); +} + +static char * ccsBackendCapabilitiesGetLongDescWrapper (CCSBackend *backend) +{ + CAPABILITIES_PRIV (backend); + + return ccsBackendGetName (bcPrivate->backend); +} + +static Bool ccsBackendCapabilitiesHasIntegrationSupportWrapper (CCSBackend *backend) +{ + CAPABILITIES_PRIV (backend); + + return ccsBackendHasIntegrationSupport (bcPrivate->backend); +} + +static Bool ccsBackendCapabilitiesHasProfileSupportWrapper (CCSBackend *backend) +{ + CAPABILITIES_PRIV (backend); + + return ccsBackendHasProfileSupport (bcPrivate->backend); +} + +static Bool ccsBackendCapabilitiesFiniWrapper (CCSBackend *backend, CCSContext *context) +{ + CAPABILITIES_PRIV (backend); + + return ccsBackendFini (bcPrivate->backend, context); +} + static void ccsBackendCapabilitiesExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) { - if (ccsBackendHasExecuteEvents (backend)) - ccsBackendExecuteEvents (backend, flags); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasExecuteEvents (bcPrivate->backend)) + ccsBackendExecuteEvents (bcPrivate->backend, flags); } static Bool ccsBackendCapabilitiesReadInitWrapper (CCSBackend *backend, CCSContext *context) { - if (ccsBackendHasReadInit (backend)) - return ccsBackendReadInit (backend, context); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasReadInit (bcPrivate->backend)) + return ccsBackendReadInit (bcPrivate->backend, context); return TRUE; } static void ccsBackendCapabilitiesReadSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - if (ccsBackendHasReadSetting (backend)) - ccsBackendReadSetting (backend, context, setting); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasReadSetting (bcPrivate->backend)) + ccsBackendReadSetting (bcPrivate->backend, context, setting); } static void ccsBackendCapabilitiesReadDoneWrapper (CCSBackend *backend, CCSContext *context) { - if (ccsBackendHasReadDone (backend)) - ccsBackendReadDone (backend, context); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasReadDone (bcPrivate->backend)) + ccsBackendReadDone (bcPrivate->backend, context); } static Bool ccsBackendCapabilitiesWriteInitWrapper (CCSBackend *backend, CCSContext *context) { - if (ccsBackendHasWriteInit (backend)) - return ccsBackendWriteInit (backend, context); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasWriteInit (bcPrivate->backend)) + return ccsBackendWriteInit (bcPrivate->backend, context); return TRUE; } static void ccsBackendCapabilitiesWriteSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - if (ccsBackendHasWriteSetting (backend)) - ccsBackendWriteSetting (backend, context, setting); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasWriteSetting (bcPrivate->backend)) + ccsBackendWriteSetting (bcPrivate->backend, context, setting); } static void ccsBackendCapabilitiesWriteDoneWrapper (CCSBackend *backend, CCSContext *context) { - if (ccsBackendHasWriteDone (backend)) - ccsBackendWriteDone (backend, context); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasWriteDone (bcPrivate->backend)) + ccsBackendWriteDone (bcPrivate->backend, context); } static Bool ccsBackendCapabilitiesGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) { - if (ccsBackendHasGetSettingIsIntegrated (backend) && - ccsBackendHasIntegrationSupport (backend)) - return ccsBackendGetSettingIsIntegrated (backend, setting); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasGetSettingIsIntegrated (bcPrivate->backend) && + ccsBackendHasIntegrationSupport (bcPrivate->backend)) + return ccsBackendGetSettingIsIntegrated (bcPrivate->backend, setting); return FALSE; } static Bool ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper (CCSBackend *backend, CCSSetting *setting) { - if (ccsBackendHasGetSettingIsReadOnly (backend)) - return ccsBackendGetSettingIsReadOnly (backend, setting); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasGetSettingIsReadOnly (bcPrivate->backend)) + return ccsBackendGetSettingIsReadOnly (bcPrivate->backend, setting); return FALSE; } static CCSStringList ccsBackendCapabilitiesGetExistingProfilesWrapper (CCSBackend *backend, CCSContext *context) { - if (ccsBackendHasGetExistingProfiles (backend) && - ccsBackendHasProfileSupport (backend)) - return ccsBackendGetExistingProfiles (backend, context); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasGetExistingProfiles (bcPrivate->backend) && + ccsBackendHasProfileSupport (bcPrivate->backend)) + return ccsBackendGetExistingProfiles (bcPrivate->backend, context); static CCSStringList sl = NULL; @@ -1459,9 +1578,11 @@ static CCSStringList ccsBackendCapabilitiesGetExistingProfilesWrapper (CCSBacken static Bool ccsBackendCapabilitiesDeleteProfileWrapper (CCSBackend *backend, CCSContext *context, char *profile) { - if (ccsBackendHasDeleteProfile (backend) && - ccsBackendHasProfileSupport (backend)) - return ccsBackendDeleteProfile (backend, context, profile); + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasDeleteProfile (bcPrivate->backend) && + ccsBackendHasProfileSupport (bcPrivate->backend)) + return ccsBackendDeleteProfile (bcPrivate->backend, context, profile); return FALSE; } @@ -2642,7 +2763,7 @@ ccsContextDestroy (CCSContext * context) if (cPrivate->backend) { - ccsBackendUnref (cPrivate->backend); + ccsBackendWithCapabilitiesUnref (cPrivate->backend); cPrivate->backend = NULL; } @@ -2877,7 +2998,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return (*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) (cPrivate->backend); + return (*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) ((CCSBackend *) cPrivate->backend); } char * @@ -3059,8 +3180,8 @@ ccsProcessEventsDefault (CCSContext * context, unsigned int flags) ccsCheckFileWatches (); - if (cPrivate->backend && ccsBackendHasExecuteEvents (cPrivate->backend)) - ccsBackendExecuteEvents (cPrivate->backend, flags); + if (cPrivate->backend) + ccsBackendExecuteEvents ((CCSBackend *) cPrivate->backend, flags); } void @@ -3083,12 +3204,11 @@ ccsReadSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!ccsBackendHasReadSetting (cPrivate->backend)) + if (!ccsBackendCapabilitiesSupportsRead (cPrivate->backend)) return; - if (ccsBackendHasReadInit (cPrivate->backend)) - if (!ccsBackendReadInit (cPrivate->backend, context)) - return; + if (!ccsBackendReadInit ((CCSBackend *) cPrivate->backend, context)) + return; CCSPluginList pl = cPrivate->plugins; while (pl) @@ -3098,15 +3218,14 @@ ccsReadSettingsDefault (CCSContext * context) while (sl) { - ccsBackendReadSetting (cPrivate->backend, context, sl->data); + ccsBackendReadSetting ((CCSBackend *) cPrivate->backend, context, sl->data); sl = sl->next; } pl = pl->next; } - if (ccsBackendHasReadDone (cPrivate->backend)) - ccsBackendReadDone (cPrivate->backend, context); + ccsBackendReadDone ((CCSBackend *) cPrivate->backend, context); } void @@ -3129,24 +3248,22 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) if (!cPrivate->backend) return; - if (!ccsBackendHasReadSetting (cPrivate->backend)) + if (!ccsBackendCapabilitiesSupportsRead (cPrivate->backend)) return; - if (ccsBackendHasReadInit (cPrivate->backend)) - if (!ccsBackendReadInit (cPrivate->backend, ccsPluginGetContext (plugin))) - return; + if (!ccsBackendReadInit ((CCSBackend *) cPrivate->backend, ccsPluginGetContext (plugin))) + return; PLUGIN_PRIV (plugin); CCSSettingList sl = pPrivate->settings; while (sl) { - ccsBackendReadSetting (cPrivate->backend, ccsPluginGetContext (plugin), sl->data); + ccsBackendReadSetting ((CCSBackend *) cPrivate->backend, ccsPluginGetContext (plugin), sl->data); sl = sl->next; } - if (ccsBackendHasReadDone (cPrivate->backend)) - ccsBackendReadDone (cPrivate->backend, ccsPluginGetContext (plugin)); + ccsBackendReadDone ((CCSBackend *) cPrivate->backend, ccsPluginGetContext (plugin)); } void @@ -3166,12 +3283,11 @@ ccsWriteSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!ccsBackendHasWriteSetting (cPrivate->backend)) + if (!ccsBackendCapabilitiesSupportsWrite (cPrivate->backend)) return; - if (ccsBackendHasWriteInit (cPrivate->backend)) - if (!ccsBackendWriteInit (cPrivate->backend, context)) - return; + if (!ccsBackendWriteInit ((CCSBackend *) cPrivate->backend, context)) + return; CCSPluginList pl = cPrivate->plugins; while (pl) @@ -3181,15 +3297,14 @@ ccsWriteSettingsDefault (CCSContext * context) while (sl) { - ccsBackendWriteSetting (cPrivate->backend, context, sl->data); + ccsBackendWriteSetting ((CCSBackend *) cPrivate->backend, context, sl->data); sl = sl->next; } pl = pl->next; } - if (ccsBackendHasWriteDone (cPrivate->backend)) - ccsBackendWriteDone (cPrivate->backend, context); + ccsBackendWriteDone ((CCSBackend *) cPrivate->backend, context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -3215,12 +3330,11 @@ ccsWriteChangedSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!ccsBackendHasWriteSetting (cPrivate->backend)) + if (!ccsBackendCapabilitiesSupportsWrite (cPrivate->backend)) return; - if (ccsBackendHasWriteInit (cPrivate->backend)) - if (!ccsBackendWriteInit (cPrivate->backend, context)) - return; + if (!ccsBackendWriteInit ((CCSBackend *) cPrivate->backend, context)) + return; if (ccsSettingListLength (cPrivate->changedSettings)) { @@ -3228,13 +3342,12 @@ ccsWriteChangedSettingsDefault (CCSContext * context) while (l) { - ccsBackendWriteSetting (cPrivate->backend, context, l->data); + ccsBackendWriteSetting ((CCSBackend *) cPrivate->backend, context, l->data); l = l->next; } } - if (ccsBackendHasWriteDone (cPrivate->backend)) - ccsBackendWriteDone (cPrivate->backend,context); + ccsBackendWriteDone ((CCSBackend *) cPrivate->backend,context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -3645,8 +3758,8 @@ ccsGetExistingProfilesDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - if (ccsBackendHasGetExistingProfiles (cPrivate->backend)) - return ccsBackendGetExistingProfiles (cPrivate->backend, context); + if (ccsBackendCapabilitiesSupportsProfiles (cPrivate->backend)) + return ccsBackendGetExistingProfiles ((CCSBackend *) cPrivate->backend, context); return NULL; } @@ -3671,6 +3784,9 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (!cPrivate->backend) return; + if (!ccsBackendCapabilitiesSupportsProfiles (cPrivate->backend)) + return; + /* never ever delete default profile */ if (!name || !strlen (name)) return; @@ -3680,8 +3796,7 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (strcmp (cPrivate->profile, name) == 0) ccsSetProfile (context, ""); - if (ccsBackendHasDeleteProfile (cPrivate->backend)) - ccsBackendDeleteProfile (cPrivate->backend, context, name); + ccsBackendDeleteProfile ((CCSBackend *) cPrivate->backend, context, name); } void @@ -5131,8 +5246,8 @@ Bool ccsSettingGetIsIntegratedDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - if (ccsBackendHasGetSettingIsIntegrated (cPrivate->backend)) - return ccsBackendGetSettingIsIntegrated (cPrivate->backend, setting); + if (ccsBackendCapabilitiesSupportsIntegration (cPrivate->backend)) + return ccsBackendGetSettingIsIntegrated ((CCSBackend *) cPrivate->backend, setting); return FALSE; } @@ -5147,8 +5262,7 @@ Bool ccsSettingGetIsReadOnlyDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - if (ccsBackendHasGetSettingIsReadOnly (cPrivate->backend)) - return ccsBackendGetSettingIsReadOnly (cPrivate->backend, setting); + return ccsBackendGetSettingIsReadOnly ((CCSBackend *) cPrivate->backend, setting); return FALSE; } @@ -5378,14 +5492,14 @@ static const CCSSettingInterface ccsDefaultSettingInterface = const CCSBackendInterface ccsBackendCapabilitiesInterfaceWrapper = { - ccsBackendGetName, - ccsBackendGetShortDesc, - ccsBackendGetLongDesc, - ccsBackendHasIntegrationSupport, - ccsBackendHasProfileSupport, + ccsBackendCapabilitiesGetNameWrapper, + ccsBackendCapabilitiesGetShortDescWrapper, + ccsBackendCapabilitiesGetLongDescWrapper, + ccsBackendCapabilitiesHasIntegrationSupportWrapper, + ccsBackendCapabilitiesHasProfileSupportWrapper, ccsBackendCapabilitiesExecuteEventsWrapper, - ccsBackendInit, - ccsBackendFini, + ccsBackendCapabilitiesInitWrapper, + ccsBackendCapabilitiesFiniWrapper, ccsBackendCapabilitiesReadInitWrapper, ccsBackendCapabilitiesReadSettingWrapper, ccsBackendCapabilitiesReadDoneWrapper, @@ -5411,5 +5525,6 @@ const CCSInterfaceTable ccsDefaultInterfaceTable = &ccsDefaultContextInterface, &ccsDefaultPluginInterface, &ccsDefaultSettingInterface, + &ccsBackendCapabilitiesInterfaceWrapper, &ccsDefaultBackendCapabilitiesInterface }; -- GitLab From 61f6944b98a50e0ba10a553eebe5c096b1d16924 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 15:01:14 +0800 Subject: [PATCH 018/562] Added a constructor method to get a CCSBackend * from a CCSBackendInterface --- compizconfig/libcompizconfig/include/ccs-backend.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 1d2ccbb3b..0bd992a15 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -163,6 +163,10 @@ unsigned int ccsCCSBackendCapabilitiesInterfaceGetType (); void ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *); +/* Constructor method */ +CCSBackend * +ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); + CCSBackendInterface* getBackendInfo (void); #endif -- GitLab From 9682318fb16a5c2c00b9ec4745631636f04b819d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 15:14:55 +0800 Subject: [PATCH 019/562] Add a convenience method to open a backend and fill an interface --- .../libcompizconfig/include/ccs-backend.h | 4 ++ compizconfig/libcompizconfig/src/main.c | 56 ++++++++++++------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 0bd992a15..0423abca8 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -163,6 +163,10 @@ unsigned int ccsCCSBackendCapabilitiesInterfaceGetType (); void ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *); +/* Backend opener method */ +void * +ccsBackendOpen (char *name, CCSBackendInterface **interface, Bool *fellback); + /* Constructor method */ CCSBackend * ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 4bc6671ca..a63a61cd6 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1157,6 +1157,38 @@ ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSB return backendCapabilities; } +void * +ccsOpenBackend (char *name, CCSBackendInterface **vt, Bool *fellback) +{ + void *dlhand = openBackend (name); + if (!dlhand) + { + *fellback = TRUE; + name = "ini"; + dlhand = openBackend (name); + } + + if (!dlhand) + return NULL; + + BackendGetInfoProc getInfo = dlsym (dlhand, "getBackendInfo"); + if (!getInfo) + { + dlclose (dlhand); + return NULL; + } + + *vt = getInfo (); + if (!*vt) + { + dlclose (dlhand); + *vt = NULL; + return NULL; + } + + return dlhand; +} + Bool ccsSetBackendDefault (CCSContext * context, char *name) { @@ -1174,30 +1206,12 @@ ccsSetBackendDefault (CCSContext * context, char *name) cPrivate->backend = NULL; } - void *dlhand = openBackend (name); - if (!dlhand) - { - fallbackMode = TRUE; - name = "ini"; - dlhand = openBackend (name); - } - - if (!dlhand) - return FALSE; + CCSBackendInterface *vt = NULL; - BackendGetInfoProc getInfo = dlsym (dlhand, "getBackendInfo"); - if (!getInfo) - { - dlclose (dlhand); - return FALSE; - } + void *dlhand = ccsOpenBackend (name, &vt, &fallbackMode); - CCSBackendInterface *vt = getInfo (); - if (!vt) - { - dlclose (dlhand); + if (!dlhand) return FALSE; - } CCSBackend *backend = ccsBackendNewWithInterface (context, vt, dlhand); -- GitLab From 510c2d86ae35fdfea60b679df76ee839a77f20d6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 16:28:02 +0800 Subject: [PATCH 020/562] Added Google Mock for CCSBackend --- .../libcompizconfig/include/ccs-backend.h | 4 + .../libcompizconfig/tests/CMakeLists.txt | 15 ++ .../tests/compizconfig_test_ccs_backend.cpp | 60 +++++++ compizconfig/mocks/CMakeLists.txt | 1 + .../mocks/libcompizconfig/CMakeLists.txt | 11 ++ .../compizconfig_ccs_backend_mock.cpp | 62 +++++++ .../compizconfig_ccs_backend_mock.h | 155 ++++++++++++++++++ 7 files changed, 308 insertions(+) create mode 100644 compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp create mode 100644 compizconfig/mocks/CMakeLists.txt create mode 100644 compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp create mode 100644 compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 0423abca8..164f75496 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -25,6 +25,8 @@ #include #include +COMPIZCONFIG_BEGIN_DECLS + typedef struct _CCSBackend CCSBackend; typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendInterface CCSBackendInterface; @@ -173,4 +175,6 @@ ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *inte CCSBackendInterface* getBackendInfo (void); +COMPIZCONFIG_END_DECLS + #endif diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 0a51ee5e2..fce0334d8 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -16,6 +16,9 @@ add_executable (compizconfig_test_ccs_plugin add_executable (compizconfig_test_ccs_setting ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_setting.cpp) +add_executable (compizconfig_test_ccs_backend + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) + if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES ${LIBCOMPIZCONFIG_LIBRARIES} @@ -52,6 +55,18 @@ target_link_libraries (compizconfig_test_ccs_plugin compizconfig_ccs_plugin_mock compizconfig_ccs_setting_mock) +target_link_libraries (compizconfig_test_ccs_backend + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock + compizconfig_ccs_backend_mock) + target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp new file mode 100644 index 000000000..06502e624 --- /dev/null +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp @@ -0,0 +1,60 @@ +#include +#include + +#include + +#include "compizconfig_ccs_backend_mock.h" + +using ::testing::_; +using ::testing::Return; + +class CCSBackendTest : + public ::testing::Test +{ +}; + +TEST(CCSBackendTest, TestMock) +{ + CCSBackend *backend = ccsMockBackendNew (); + CCSBackendGMock *mock = (CCSBackendGMock *) ccsObjectGetPrivate (backend); + + CCSStringList profiles = NULL; + + EXPECT_CALL (*mock, getName ()); + EXPECT_CALL (*mock, getShortDesc ()); + EXPECT_CALL (*mock, getLongDesc ()); + EXPECT_CALL (*mock, hasProfileSupport ()); + EXPECT_CALL (*mock, hasIntegrationSupport ()); + EXPECT_CALL (*mock, executeEvents (_)); + EXPECT_CALL (*mock, init (_)); + EXPECT_CALL (*mock, fini (_)); + EXPECT_CALL (*mock, readInit (_)); + EXPECT_CALL (*mock, readSetting (_,_)); + EXPECT_CALL (*mock, readDone (_)); + EXPECT_CALL (*mock, writeInit (_)); + EXPECT_CALL (*mock, writeSetting (_, _)); + EXPECT_CALL (*mock, writeDone (_)); + EXPECT_CALL (*mock, getSettingIsIntegrated (_)); + EXPECT_CALL (*mock, getSettingIsReadOnly (_)); + EXPECT_CALL (*mock, getExistingProfiles (_)).WillRepeatedly (Return (profiles)); + EXPECT_CALL (*mock, deleteProfile (_, _)); + + ccsBackendGetName (backend); + ccsBackendGetShortDesc (backend); + ccsBackendGetLongDesc (backend); + ccsBackendHasProfileSupport (backend); + ccsBackendHasIntegrationSupport (backend); + ccsBackendExecuteEvents (backend, 0); + ccsBackendInit (backend, NULL); + ccsBackendFini (backend, NULL); + ccsBackendReadInit (backend, NULL); + ccsBackendReadSetting (backend, NULL, NULL); + ccsBackendReadDone (backend, NULL); + ccsBackendWriteInit (backend, NULL); + ccsBackendWriteSetting (backend, NULL, NULL); + ccsBackendGetSettingIsIntegrated (backend, NULL); + ccsBackendGetExistingProfiles (backend, NULL); + ccsBackendDeleteProfile (backend, NULL, NULL); + + ccsBackendUnref (backend); +} diff --git a/compizconfig/mocks/CMakeLists.txt b/compizconfig/mocks/CMakeLists.txt new file mode 100644 index 000000000..b288ae8e1 --- /dev/null +++ b/compizconfig/mocks/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (libcompizconfig) diff --git a/compizconfig/mocks/libcompizconfig/CMakeLists.txt b/compizconfig/mocks/libcompizconfig/CMakeLists.txt index a8f03b668..1e87fc709 100644 --- a/compizconfig/mocks/libcompizconfig/CMakeLists.txt +++ b/compizconfig/mocks/libcompizconfig/CMakeLists.txt @@ -17,6 +17,9 @@ add_library (compizconfig_ccs_plugin_mock add_library (compizconfig_ccs_setting_mock ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_setting_mock.cpp) +add_library (compizconfig_ccs_backend_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_backend_mock.cpp) + target_link_libraries (compizconfig_ccs_context_mock ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} @@ -40,3 +43,11 @@ target_link_libraries (compizconfig_ccs_setting_mock ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig) + +target_link_libraries (compizconfig_ccs_backend_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp new file mode 100644 index 000000000..a87c120c9 --- /dev/null +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp @@ -0,0 +1,62 @@ +#include +#include + +#include + +#include "compizconfig_ccs_backend_mock.h" + +CCSBackendInterface CCSBackendGMockInterface = +{ + CCSBackendGMock::ccsBackendGetName, + CCSBackendGMock::ccsBackendGetShortDesc, + CCSBackendGMock::ccsBackendGetLongDesc, + CCSBackendGMock::ccsBackendHasIntegrationSupport, + CCSBackendGMock::ccsBackendHasProfileSupport, + CCSBackendGMock::ccsBackendExecuteEvents, + CCSBackendGMock::ccsBackendInit, + CCSBackendGMock::ccsBackendFini, + CCSBackendGMock::ccsBackendReadInit, + CCSBackendGMock::ccsBackendReadSetting, + CCSBackendGMock::ccsBackendReadDone, + CCSBackendGMock::ccsBackendWriteInit, + CCSBackendGMock::ccsBackendWriteSetting, + CCSBackendGMock::ccsBackendWriteDone, + CCSBackendGMock::ccsBackendGetSettingIsIntegrated, + CCSBackendGMock::ccsBackendGetSettingIsReadOnly, + CCSBackendGMock::ccsBackendGetExistingProfiles, + CCSBackendGMock::ccsBackendDeleteProfile +}; + +CCSBackend * +ccsMockBackendNew () +{ + CCSBackend *backend = (CCSBackend *) calloc (1, sizeof (CCSBackend)); + + if (!backend) + return NULL; + + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + + CCSBackendGMock *mock = new CCSBackendGMock (); + ccsObjectSetPrivate (backend, (CCSPrivate *) mock); + ccsObjectAddInterface (backend, (CCSInterface *) &CCSBackendGMockInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); + + ccsBackendRef (backend); + + return backend; +} + +void +ccsFreeMockBackend (CCSBackend *backend) +{ + /* Need to delete the mock correctly */ + + CCSBackendGMock *mock = (CCSBackendGMock *) ccsObjectGetPrivate (backend); + + delete mock; + + ccsObjectSetPrivate (backend, NULL); + ccsObjectFinalize (backend); + + free (backend); +} diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h new file mode 100644 index 000000000..9f5be6622 --- /dev/null +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -0,0 +1,155 @@ +#include +#include + +#include + +CCSBackend * ccsMockBackendNew (); +void ccsFreeMockBackend (CCSBackend *); + +class CCSBackendGMockInterface +{ + public: + + virtual ~CCSBackendGMockInterface () {}; + + virtual char * getName () = 0; + virtual char * getShortDesc () = 0; + virtual char * getLongDesc () = 0; + virtual Bool hasProfileSupport () = 0; + virtual Bool hasIntegrationSupport () = 0; + virtual void executeEvents (unsigned int) = 0; + virtual Bool init (CCSContext *context) = 0; + virtual Bool fini (CCSContext *context) = 0; + virtual Bool readInit (CCSContext *context) = 0; + virtual void readSetting (CCSContext *context, CCSSetting *setting) = 0; + virtual void readDone (CCSContext *context) = 0; + virtual Bool writeInit (CCSContext *conxtext) = 0; + virtual void writeSetting (CCSContext *context, CCSSetting *setting) = 0; + virtual void writeDone (CCSContext *context) = 0; + virtual Bool getSettingIsIntegrated (CCSSetting *setting) = 0; + virtual Bool getSettingIsReadOnly (CCSSetting *setting) = 0; + virtual CCSStringList getExistingProfiles (CCSContext *context) = 0; + virtual Bool deleteProfile (CCSContext *context, char *name) = 0; +}; + +class CCSBackendGMock : + public CCSBackendGMockInterface +{ + public: + + /* Mock implementations */ + MOCK_METHOD0 (getName, char * ()); + MOCK_METHOD0 (getShortDesc, char * ()); + MOCK_METHOD0 (getLongDesc, char * ()); + MOCK_METHOD0 (hasProfileSupport, Bool ()); + MOCK_METHOD0 (hasIntegrationSupport, Bool ()); + MOCK_METHOD1 (executeEvents, void (unsigned int)); + MOCK_METHOD1 (init, Bool (CCSContext *)); + MOCK_METHOD1 (fini, Bool (CCSContext *)); + MOCK_METHOD1 (readInit, Bool (CCSContext *)); + MOCK_METHOD2 (readSetting, void (CCSContext *, CCSSetting *)); + MOCK_METHOD1 (readDone, void (CCSContext *)); + MOCK_METHOD1 (writeInit, Bool (CCSContext *)); + MOCK_METHOD2 (writeSetting, void (CCSContext *, CCSSetting *)); + MOCK_METHOD1 (writeDone, void (CCSContext *)); + MOCK_METHOD1 (getSettingIsIntegrated, Bool (CCSSetting *)); + MOCK_METHOD1 (getSettingIsReadOnly, Bool (CCSSetting *)); + MOCK_METHOD1 (getExistingProfiles, CCSStringList (CCSContext *)); + MOCK_METHOD2 (deleteProfile, Bool (CCSContext *, char *name)); + + public: + + /* Thunking C to C++ */ + static char * ccsBackendGetName (CCSBackend *backend) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getName (); + } + + static char * ccsBackendGetShortDesc (CCSBackend *backend) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getShortDesc (); + } + + static char * ccsBackendGetLongDesc (CCSBackend *backend) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getLongDesc (); + } + + static Bool ccsBackendHasIntegrationSupport (CCSBackend *backend) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->hasIntegrationSupport (); + } + + static Bool ccsBackendHasProfileSupport (CCSBackend *backend) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->hasProfileSupport (); + } + + static void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->executeEvents (flags); + } + + static Bool ccsBackendInit (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->init (context); + } + + static Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->fini (context); + } + + static Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->readInit (context); + } + + static void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->readSetting (context, setting); + } + + static void ccsBackendReadDone (CCSBackend *backend, CCSContext *context) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->readDone (context); + } + + static Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeInit (context); + } + + static void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeSetting (context, setting); + } + + static void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeDone (context); + } + + static Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getSettingIsIntegrated (setting); + } + + static Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getSettingIsReadOnly (setting); + } + + static CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getExistingProfiles (context); + } + + static Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->deleteProfile (context, name); + } + +}; + +extern CCSBackendInterface CCSBackendGMockInterface; -- GitLab From 8c5f380883405a4673d7284a925b4421dcf5e6ce Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 16:31:53 +0800 Subject: [PATCH 021/562] Make ccsBackendHas* private --- .../libcompizconfig/include/ccs-backend.h | 10 ---- compizconfig/libcompizconfig/src/main.c | 48 +++++++++++++++---- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 0423abca8..6d4c7767b 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -106,29 +106,19 @@ char * ccsBackendGetLongDesc (CCSBackend *backend); Bool ccsBackendHasIntegrationSupport (CCSBackend *backend); Bool ccsBackendHasProfileSupport (CCSBackend *backend); -Bool ccsBackendHasExecuteEvents (CCSBackend *backend); void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags); Bool ccsBackendInit (CCSBackend *backend, CCSContext *context); Bool ccsBackendFini (CCSBackend *backend, CCSContext *context); -Bool ccsBackendHasReadInit (CCSBackend *backend); Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context); -Bool ccsBackendHasReadSetting (CCSBackend *backend); void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); -Bool ccsBackendHasReadDone (CCSBackend *backend); void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); -Bool ccsBackendHasWriteInit (CCSBackend *backend); Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context); -Bool ccsBackendHasWriteSetting (CCSBackend *backend); void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); -Bool ccsBackendHasWriteDone (CCSBackend *backend); void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend); Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); -Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend); Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting); -Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend); CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context); -Bool ccsBackendHasDeleteProfile (CCSBackend *backend); Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name); void ccsFreeBackend (CCSBackend *backend); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index a63a61cd6..1083fb872 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1303,6 +1303,34 @@ Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *capa return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsIntegration) (capabilities); } +static Bool +ccsBackendCapabilitiesSupportsIntegrationDefault (CCSBackendWithCapabilities *capabilities) +{ + CAPABILITIES_PRIV (capabilities); + + return ccsBackendHasIntegrationSupport (bcPrivate->backend); +} + +Bool ccsBackendCapabilitiesSupportsRead (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsRead) (capabilities); +} + +Bool ccsBackendCapabilitiesSupportsWrite (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsWrite) (capabilities); +} + +Bool ccsBackendCapabilitiesSupportsProfiles (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsProfiles) (capabilities); +} + +Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *capabilities) +{ + return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsIntegration) (capabilities); +} + Bool ccsBackendHasExecuteEvents (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->executeEvents != NULL; @@ -1323,7 +1351,7 @@ Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (backend, context); } -Bool ccsBackendHasReadInit (CCSBackend *backend) +static Bool ccsBackendHasReadInit (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->readInit != NULL; } @@ -1333,7 +1361,7 @@ Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) return (*(GET_INTERFACE (CCSBackendInterface, backend))->readInit) (backend, context); } -Bool ccsBackendHasReadSetting (CCSBackend *backend) +static Bool ccsBackendHasReadSetting (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->readSetting != NULL; } @@ -1343,7 +1371,7 @@ void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting (*(GET_INTERFACE (CCSBackendInterface, backend))->readSetting) (backend, context, setting); } -Bool ccsBackendHasReadDone (CCSBackend *backend) +static Bool ccsBackendHasReadDone (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->readDone != NULL; } @@ -1353,7 +1381,7 @@ void ccsBackendReadDone (CCSBackend *backend, CCSContext *context) return (*(GET_INTERFACE (CCSBackendInterface, backend))->readDone) (backend, context); } -Bool ccsBackendHasWriteInit (CCSBackend *backend) +static Bool ccsBackendHasWriteInit (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->writeInit != NULL; } @@ -1363,7 +1391,7 @@ Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context) return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeInit) (backend, context); } -Bool ccsBackendHasWriteSetting (CCSBackend *backend) +static Bool ccsBackendHasWriteSetting (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->writeSetting != NULL; } @@ -1373,7 +1401,7 @@ void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSettin (*(GET_INTERFACE (CCSBackendInterface, backend))->writeSetting) (backend, context, setting); } -Bool ccsBackendHasWriteDone (CCSBackend *backend) +static Bool ccsBackendHasWriteDone (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->writeDone != NULL; } @@ -1383,7 +1411,7 @@ void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); } -Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) +static Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated != NULL; } @@ -1393,7 +1421,7 @@ Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated) (backend, setting); } -Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) +static Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly != NULL; } @@ -1403,7 +1431,7 @@ Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting) return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly) (backend, setting); } -Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) +static Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles != NULL; } @@ -1413,7 +1441,7 @@ CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *co return (*(GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles) (backend, context); } -Bool ccsBackendHasDeleteProfile (CCSBackend *backend) +static Bool ccsBackendHasDeleteProfile (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile != NULL; } -- GitLab From 614b7a221c2dcabe55cce28b0d706a4769877c1c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 16:33:04 +0800 Subject: [PATCH 022/562] add libcompizconfig subdir --- compizconfig/mocks/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 compizconfig/mocks/CMakeLists.txt diff --git a/compizconfig/mocks/CMakeLists.txt b/compizconfig/mocks/CMakeLists.txt new file mode 100644 index 000000000..b288ae8e1 --- /dev/null +++ b/compizconfig/mocks/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (libcompizconfig) -- GitLab From fee0c2ca53395622c043512663d815c968beb23c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 16:47:13 +0800 Subject: [PATCH 023/562] Remove conflict --- .../libcompizconfig/include/ccs-backend.h | 1 - compizconfig/libcompizconfig/src/main.c | 28 ------------------- 2 files changed, 29 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 6d4c7767b..e97b74ef1 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -115,7 +115,6 @@ void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context); void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); -Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend); Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting); CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 1083fb872..4efca5da8 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1303,34 +1303,6 @@ Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *capa return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsIntegration) (capabilities); } -static Bool -ccsBackendCapabilitiesSupportsIntegrationDefault (CCSBackendWithCapabilities *capabilities) -{ - CAPABILITIES_PRIV (capabilities); - - return ccsBackendHasIntegrationSupport (bcPrivate->backend); -} - -Bool ccsBackendCapabilitiesSupportsRead (CCSBackendWithCapabilities *capabilities) -{ - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsRead) (capabilities); -} - -Bool ccsBackendCapabilitiesSupportsWrite (CCSBackendWithCapabilities *capabilities) -{ - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsWrite) (capabilities); -} - -Bool ccsBackendCapabilitiesSupportsProfiles (CCSBackendWithCapabilities *capabilities) -{ - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsProfiles) (capabilities); -} - -Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *capabilities) -{ - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsIntegration) (capabilities); -} - Bool ccsBackendHasExecuteEvents (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->executeEvents != NULL; -- GitLab From 73cb40546ea7fceacd16bc822b211614c95717e1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 9 Jul 2012 17:13:49 +0800 Subject: [PATCH 024/562] Fix backend test --- .../libcompizconfig/tests/compizconfig_test_ccs_backend.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp index 06502e624..9a31f7f3e 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp @@ -52,9 +52,11 @@ TEST(CCSBackendTest, TestMock) ccsBackendReadDone (backend, NULL); ccsBackendWriteInit (backend, NULL); ccsBackendWriteSetting (backend, NULL, NULL); + ccsBackendWriteDone (backend, NULL); ccsBackendGetSettingIsIntegrated (backend, NULL); + ccsBackendGetSettingIsReadOnly (backend, NULL); ccsBackendGetExistingProfiles (backend, NULL); ccsBackendDeleteProfile (backend, NULL, NULL); - ccsBackendUnref (backend); + ccsFreeMockBackend (backend); } -- GitLab From 6704f1d31dc97c7ee9606bca287e3463d78da01d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 02:35:44 +0800 Subject: [PATCH 025/562] First test in the conformance testsuite --- .../libcompizconfig/tests/CMakeLists.txt | 16 +++++++++ ...nfig_test_ccs_mock_backend_conformance.cpp | 34 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index fce0334d8..5f3c6cda1 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,6 +1,7 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../mocks/libcompizconfig) @@ -19,6 +20,9 @@ add_executable (compizconfig_test_ccs_setting add_executable (compizconfig_test_ccs_backend ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) +add_executable (compizconfig_test_ccs_mock_backend_conformance + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) + if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES ${LIBCOMPIZCONFIG_LIBRARIES} @@ -67,6 +71,18 @@ target_link_libraries (compizconfig_test_ccs_backend compizconfig_ccs_setting_mock compizconfig_ccs_backend_mock) +target_link_libraries (compizconfig_test_ccs_mock_backend_conformance + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock + compizconfig_ccs_backend_mock) + target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp new file mode 100644 index 000000000..1f67c8adb --- /dev/null +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include + +#include +#include + +#include "compizconfig_ccs_backend_mock.h" + +using ::testing::_; +using ::testing::Return; + +class MockCCSBackendConceptTestEnvironment : + public CCSBackendConceptTestEnvironmentInterface +{ + public: + + CCSBackend * SetUp (); + void TearDown (CCSBackend *backend); +}; + +CCSBackend * +MockCCSBackendConceptTestEnvironment::SetUp () +{ + CCSBackend *backend = ccsMockBackendNew (); + return backend; +} + +static MockCCSBackendConceptTestEnvironment mockBackendEnv; + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, ::testing::Values (&mockBackendEnv)); + + -- GitLab From 56c94849b16f97379ab6da55982e4072270d87ab Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 03:03:30 +0800 Subject: [PATCH 026/562] Working concept test fixture --- compizconfig/CMakeLists.txt | 1 + .../libcompizconfig/include/ccs-backend.h | 1 + .../libcompizconfig/include/ccs-object.h | 2 + .../libcompizconfig/tests/CMakeLists.txt | 7 +++- ...nfig_test_ccs_mock_backend_conformance.cpp | 9 ++++- .../compizconfig_ccs_backend_mock.h | 5 +++ compizconfig/tests/CMakeLists.txt | 15 ++++++++ .../compizconfig_backend_concept_test.cpp | 5 +++ .../tests/compizconfig_backend_concept_test.h | 38 +++++++++++++++++++ 9 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 compizconfig/tests/CMakeLists.txt create mode 100644 compizconfig/tests/compizconfig_backend_concept_test.cpp create mode 100644 compizconfig/tests/compizconfig_backend_concept_test.h diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index 869e2c490..c21e8902d 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -12,6 +12,7 @@ add_subdirectory (gsettings) if (COMPIZ_BUILD_TESTING) add_subdirectory (mocks) + add_subdirectory (tests) endif (COMPIZ_BUILD_TESTING) add_custom_target (pyclean) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 3e514b605..2c6b2b009 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -23,6 +23,7 @@ #define CCS_BACKEND_H #include +#include #include COMPIZCONFIG_BEGIN_DECLS diff --git a/compizconfig/libcompizconfig/include/ccs-object.h b/compizconfig/libcompizconfig/include/ccs-object.h index a2505de1b..c01f0fc2e 100644 --- a/compizconfig/libcompizconfig/include/ccs-object.h +++ b/compizconfig/libcompizconfig/include/ccs-object.h @@ -23,6 +23,8 @@ #ifndef _CCS_OBJECT_H #define _CCS_OBJECT_H +#include + COMPIZCONFIG_BEGIN_DECLS typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 5f3c6cda1..d899460a5 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../mocks/libcompizconfig) +link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../tests/) add_executable (compizconfig_test_ccs_object ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_object.cpp) @@ -21,7 +22,8 @@ add_executable (compizconfig_test_ccs_backend ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) add_executable (compizconfig_test_ccs_mock_backend_conformance - ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/compizconfig_backend_concept_test.cpp) if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES @@ -82,6 +84,7 @@ target_link_libraries (compizconfig_test_ccs_mock_backend_conformance compizconfig_ccs_plugin_mock compizconfig_ccs_setting_mock compizconfig_ccs_backend_mock) + #compizconfig_ccs_backend_conformance_test) target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} @@ -98,3 +101,5 @@ compiz_discover_tests (compizconfig_test_ccs_object) compiz_discover_tests (compizconfig_test_ccs_context) compiz_discover_tests (compizconfig_test_ccs_plugin) compiz_discover_tests (compizconfig_test_ccs_setting) +compiz_discover_tests (compizconfig_test_ccs_backend) +compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 1f67c8adb..b3c0d1e48 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -27,8 +27,15 @@ MockCCSBackendConceptTestEnvironment::SetUp () return backend; } +void +MockCCSBackendConceptTestEnvironment::TearDown (CCSBackend *backend) +{ + ccsFreeMockBackend (backend); +} + static MockCCSBackendConceptTestEnvironment mockBackendEnv; +static CCSBackendConceptTestEnvironmentInterface *backendEnv = &mockBackendEnv; -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, ::testing::Values (&mockBackendEnv)); +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, ::testing::Values (backendEnv)); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index 9f5be6622..3f39f3f71 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -1,3 +1,6 @@ +#ifndef _COMPIZCONFIG_CCS_BACKEND_MOCK_H +#define _COMPIZCONFIG_CCS_BACKEND_MOCK_H + #include #include @@ -153,3 +156,5 @@ class CCSBackendGMock : }; extern CCSBackendInterface CCSBackendGMockInterface; + +#endif diff --git a/compizconfig/tests/CMakeLists.txt b/compizconfig/tests/CMakeLists.txt new file mode 100644 index 000000000..03fcb9b11 --- /dev/null +++ b/compizconfig/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories (${GTEST_INCLUDE_DIRS}) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../libcompizconfig/include) +link_directories (${CMAKE_INSTALL_PREFIX}/lib) + +add_library (compizconfig_ccs_backend_conformance_test + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_backend_concept_test.cpp) + +target_link_libraries (compizconfig_ccs_backend_conformance_test + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.cpp b/compizconfig/tests/compizconfig_backend_concept_test.cpp new file mode 100644 index 000000000..e4bd09e2e --- /dev/null +++ b/compizconfig/tests/compizconfig_backend_concept_test.cpp @@ -0,0 +1,5 @@ +#include + +TEST_P (CCSBackendConformanceTest, TestSetup) +{ +} diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h new file mode 100644 index 000000000..ad25515a6 --- /dev/null +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -0,0 +1,38 @@ +#include +#include + +#include + +class CCSBackendConceptTestEnvironmentInterface +{ + public: + + virtual ~CCSBackendConceptTestEnvironmentInterface () {}; + virtual CCSBackend * SetUp () = 0; + virtual void TearDown (CCSBackend *) = 0; +}; + +class CCSBackendConformanceTest : + public ::testing::TestWithParam +{ + public: + + CCSBackend * GetBackend () + { + return mBackend; + } + + void SetUp () + { + mBackend = GetParam ()->SetUp (); + } + + void TearDown () + { + GetParam ()->TearDown (mBackend); + } + private: + + CCSBackend *mBackend; +}; + -- GitLab From 3186d9ce0dcce2914eb9d4f0ecae3a054fb96f39 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 07:46:27 +0800 Subject: [PATCH 027/562] Basic conformance tests for backend, covered by mock backend --- compizconfig/CMakeLists.txt | 1 - .../libcompizconfig/tests/CMakeLists.txt | 4 +- ...nfig_test_ccs_mock_backend_conformance.cpp | 131 +++++++++++++-- compizconfig/tests/CMakeLists.txt | 15 -- .../compizconfig_backend_concept_test.cpp | 5 - .../tests/compizconfig_backend_concept_test.h | 150 ++++++++++++++++++ 6 files changed, 269 insertions(+), 37 deletions(-) delete mode 100644 compizconfig/tests/CMakeLists.txt delete mode 100644 compizconfig/tests/compizconfig_backend_concept_test.cpp diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index c21e8902d..869e2c490 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -12,7 +12,6 @@ add_subdirectory (gsettings) if (COMPIZ_BUILD_TESTING) add_subdirectory (mocks) - add_subdirectory (tests) endif (COMPIZ_BUILD_TESTING) add_custom_target (pyclean) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index d899460a5..9e7a43eb7 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -22,8 +22,7 @@ add_executable (compizconfig_test_ccs_backend ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) add_executable (compizconfig_test_ccs_mock_backend_conformance - ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/compizconfig_backend_concept_test.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp) if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES @@ -84,7 +83,6 @@ target_link_libraries (compizconfig_test_ccs_mock_backend_conformance compizconfig_ccs_plugin_mock compizconfig_ccs_setting_mock compizconfig_ccs_backend_mock) - #compizconfig_ccs_backend_conformance_test) target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index b3c0d1e48..e2277a857 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -10,28 +10,133 @@ using ::testing::_; using ::testing::Return; +using ::testing::Invoke; +using ::testing::WithArgs; -class MockCCSBackendConceptTestEnvironment : - public CCSBackendConceptTestEnvironmentInterface +template +class ValueForKeyRetreival { public: - CCSBackend * SetUp (); - void TearDown (CCSBackend *backend); + T GetValueForKey (const std::string &key, + const std::map &map) + { + typename std::map ::const_iterator it = map.find (key); + + if (it != map.end ()) + return it->second; + else + throw std::exception (); + } }; -CCSBackend * -MockCCSBackendConceptTestEnvironment::SetUp () +template <> +class ValueForKeyRetreival { - CCSBackend *backend = ccsMockBackendNew (); - return backend; -} + public: + + const char * GetValueForKey (const std::string &key, + const std::map &map) + { + std::map ::const_iterator it = map.find (key); -void -MockCCSBackendConceptTestEnvironment::TearDown (CCSBackend *backend) + if (it != map.end ()) + return it->second.c_str (); + else + throw std::exception (); + } +}; + +class MockCCSBackendConceptTestEnvironment : + public CCSBackendConceptTestEnvironmentInterface { - ccsFreeMockBackend (backend); -} + public: + + CCSBackend * SetUp () + { + mBackend = ccsMockBackendNew (); + mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); + + ON_CALL (*mBackendGMock, readSetting (_,_)) + .WillByDefault ( + WithArgs<1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::WriteValueToSetting))); + + return mBackend; + } + + void TearDown (CCSBackend *backend) + { + ccsFreeMockBackend (backend); + + + } + + void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + int value) + + { + mIntMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + + void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + float value) + { + mFloatMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + + void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const std::string &value) + { + mStringMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + + protected: + + void WriteValueToSetting (CCSSetting *setting) + { + std::string key (std::string (ccsPluginGetName (ccsSettingGetParent (setting))) + + "/" + std::string (ccsSettingGetName (setting))); + + switch (ccsSettingGetType (setting)) + { + case TypeInt: + + ccsSetInt (setting, ValueForKeyRetreival ().GetValueForKey (key, mIntMap), FALSE); + break; + + case TypeFloat: + + ccsSetFloat (setting, ValueForKeyRetreival ().GetValueForKey (key, mFloatMap), FALSE); + break; + + case TypeString: + + ccsSetString (setting, ValueForKeyRetreival ().GetValueForKey (key, mStringMap), FALSE); + break; + + default: + + throw std::exception (); + } + } + + private: + + CCSBackend *mBackend; + CCSBackendGMock *mBackendGMock; + std::map mIntMap; + std::map mFloatMap; + std::map mStringMap; +}; static MockCCSBackendConceptTestEnvironment mockBackendEnv; static CCSBackendConceptTestEnvironmentInterface *backendEnv = &mockBackendEnv; diff --git a/compizconfig/tests/CMakeLists.txt b/compizconfig/tests/CMakeLists.txt deleted file mode 100644 index 03fcb9b11..000000000 --- a/compizconfig/tests/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -include_directories (${GTEST_INCLUDE_DIRS}) -include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../libcompizconfig/include) -link_directories (${CMAKE_INSTALL_PREFIX}/lib) - -add_library (compizconfig_ccs_backend_conformance_test - ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_backend_concept_test.cpp) - -target_link_libraries (compizconfig_ccs_backend_conformance_test - ${GTEST_BOTH_LIBRARIES} - ${GMOCK_LIBRARY} - ${GMOCK_MAIN_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.cpp b/compizconfig/tests/compizconfig_backend_concept_test.cpp deleted file mode 100644 index e4bd09e2e..000000000 --- a/compizconfig/tests/compizconfig_backend_concept_test.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -TEST_P (CCSBackendConformanceTest, TestSetup) -{ -} diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index ad25515a6..9a6b59e3a 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1,7 +1,17 @@ +#ifndef _COMPIZCONFIG_CCS_BACKEND_CONCEPT_TEST +#define _COMPIZCONFIG_CCS_BACKEND_CONCEPT_TEST + +#include + #include #include #include +#include + +#include +#include +#include class CCSBackendConceptTestEnvironmentInterface { @@ -10,6 +20,15 @@ class CCSBackendConceptTestEnvironmentInterface virtual ~CCSBackendConceptTestEnvironmentInterface () {}; virtual CCSBackend * SetUp () = 0; virtual void TearDown (CCSBackend *) = 0; + virtual void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + int value) = 0; + virtual void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + float value) = 0; + virtual void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const std::string &value) = 0; }; class CCSBackendConformanceTest : @@ -30,9 +49,140 @@ class CCSBackendConformanceTest : void TearDown () { GetParam ()->TearDown (mBackend); + + for (std::list ::iterator it = mSpawnedContexts.begin (); + it != mSpawnedContexts.end (); + it++) + ccsFreeMockContext (*it); + + for (std::list ::iterator it = mSpawnedPlugins.begin (); + it != mSpawnedPlugins.end (); + it++) + ccsFreeMockPlugin (*it); + + for (std::list ::iterator it = mSpawnedSettings.begin (); + it != mSpawnedSettings.end (); + it++) + ccsFreeMockSetting (*it); + } + + protected: + + CCSContext * + SpawnContext () + { + CCSContext *context = ccsMockContextNew (); + mSpawnedContexts.push_back (context); + return context; + } + + CCSPlugin * + SpawnPlugin (const std::string &name = "") + { + CCSPlugin *plugin = ccsMockPluginNew (); + mSpawnedPlugins.push_back (plugin); + + CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); + + if (!name.empty ()) + EXPECT_CALL (*gmockPlugin, getName ()).WillRepeatedly (Return ((char *) name.c_str ())); + + return plugin; } + + CCSSetting * + SpawnSetting (const std::string &name = "", + CCSSettingType type = TypeNum, + CCSPlugin *plugin = NULL) + { + CCSSetting *setting = ccsMockSettingNew (); + mSpawnedSettings.push_back (setting); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + if (!name.empty ()) + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return ((char *) name.c_str ())); + + if (type != TypeNum) + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (type)); + + if (plugin) + EXPECT_CALL (*gmockSetting, getParent ()).WillRepeatedly (Return (plugin)); + + return setting; + } + private: + std::list mSpawnedContexts; + std::list mSpawnedPlugins; + std::list mSpawnedSettings; + CCSBackend *mBackend; }; +TEST_P (CCSBackendConformanceTest, TestSetup) +{ +} + +TEST_P (CCSBackendConformanceTest, TestReadInteger) +{ + std::string pluginName ("plugin"); + std::string settingName ("integer_setting"); + const int VALUE = 1; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeInt, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteIntegerAtKey (pluginName, settingName, VALUE); + + EXPECT_CALL (*gmockSetting, setInt (VALUE, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + +TEST_P (CCSBackendConformanceTest, TestReadFloat) +{ + std::string pluginName ("plugin"); + std::string settingName ("float_setting"); + const float VALUE = 1.0; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeFloat, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteFloatAtKey (pluginName, settingName, VALUE); + + EXPECT_CALL (*gmockSetting, setFloat (VALUE, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + +TEST_P (CCSBackendConformanceTest, TestReadString) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + const std::string VALUE ("foo"); + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeString, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteStringAtKey (pluginName, settingName, VALUE); + + EXPECT_CALL (*gmockSetting, setString (VALUE.c_str (), _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + + + +#endif + -- GitLab From cd966325fdd8c413625d62f97e5d2688c5b90ddb Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 09:15:44 +0800 Subject: [PATCH 028/562] Added conformance test for reading back colors --- ...nfig_test_ccs_mock_backend_conformance.cpp | 14 +++++++ .../tests/compizconfig_backend_concept_test.h | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index e2277a857..f7f428a2a 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -99,6 +99,14 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } + void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingColorValue &value) + { + mColorMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + protected: void WriteValueToSetting (CCSSetting *setting) @@ -123,6 +131,11 @@ class MockCCSBackendConceptTestEnvironment : ccsSetString (setting, ValueForKeyRetreival ().GetValueForKey (key, mStringMap), FALSE); break; + case TypeColor: + + ccsSetColor (setting, ValueForKeyRetreival ().GetValueForKey (key, mColorMap), FALSE); + break; + default: throw std::exception (); @@ -136,6 +149,7 @@ class MockCCSBackendConceptTestEnvironment : std::map mIntMap; std::map mFloatMap; std::map mStringMap; + std::map mColorMap; }; static MockCCSBackendConceptTestEnvironment mockBackendEnv; diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 9a6b59e3a..0a5d0afb8 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -29,6 +29,9 @@ class CCSBackendConceptTestEnvironmentInterface virtual void WriteStringAtKey (const std::string &plugin, const std::string &key, const std::string &value) = 0; + virtual void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingColorValue &value) = 0; }; class CCSBackendConformanceTest : @@ -182,6 +185,44 @@ TEST_P (CCSBackendConformanceTest, TestReadString) ccsBackendReadSetting (GetBackend (), context, setting); } +namespace +{ + bool + operator== (const CCSSettingColorValue &lhs, + const CCSSettingColorValue &rhs) + { + return (lhs.color.red == rhs.color.red && + lhs.color.green == rhs.color.green && + lhs.color.blue == rhs.color.blue && + lhs.color.alpha == lhs.color.alpha); + } +} + +TEST_P (CCSBackendConformanceTest, TestReadColor) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingColorValue VALUE; + + VALUE.color.red = 100; + VALUE.color.blue = 100; + VALUE.color.green = 100; + VALUE.color.alpha = 100; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeColor, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteColorAtKey (pluginName, settingName, VALUE); + + /* FIXME: We can't verify right now that the color returned is correct */ + EXPECT_CALL (*gmockSetting, setColor (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + #endif -- GitLab From 528627a9c565d877a5a877b40cc1726669283a6b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 09:50:38 +0800 Subject: [PATCH 029/562] Tests to read the other nontrivial settings --- ...nfig_test_ccs_mock_backend_conformance.cpp | 84 ++++++++++++++++ .../tests/compizconfig_backend_concept_test.h | 99 +++++++++++++++++++ 2 files changed, 183 insertions(+) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index f7f428a2a..172da2d09 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -74,6 +74,14 @@ class MockCCSBackendConceptTestEnvironment : } + void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const Bool &value) + { + mBoolMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + void WriteIntegerAtKey (const std::string &plugin, const std::string &key, int value) @@ -91,6 +99,14 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } + void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const std::string &value) + { + mMatchMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + void WriteStringAtKey (const std::string &plugin, const std::string &key, const std::string &value) @@ -107,6 +123,38 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } + void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingKeyValue &keyValue) + { + mKeyMap[plugin + "/" + key] = keyValue; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + + void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingButtonValue &buttonValue) + { + mButtonMap[plugin + "/" + key] = buttonValue; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + + void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const unsigned int &value) + { + mEdgeMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + + void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const Bool &value) + { + mBellMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + protected: void WriteValueToSetting (CCSSetting *setting) @@ -116,6 +164,11 @@ class MockCCSBackendConceptTestEnvironment : switch (ccsSettingGetType (setting)) { + case TypeBool: + + ccsSetBool (setting, ValueForKeyRetreival ().GetValueForKey (key, mBoolMap), FALSE); + break; + case TypeInt: ccsSetInt (setting, ValueForKeyRetreival ().GetValueForKey (key, mIntMap), FALSE); @@ -131,11 +184,36 @@ class MockCCSBackendConceptTestEnvironment : ccsSetString (setting, ValueForKeyRetreival ().GetValueForKey (key, mStringMap), FALSE); break; + case TypeMatch: + + ccsSetMatch (setting, ValueForKeyRetreival ().GetValueForKey (key, mMatchMap), FALSE); + break; + case TypeColor: ccsSetColor (setting, ValueForKeyRetreival ().GetValueForKey (key, mColorMap), FALSE); break; + case TypeKey: + + ccsSetKey (setting, ValueForKeyRetreival ().GetValueForKey (key, mKeyMap), FALSE); + break; + + case TypeButton: + + ccsSetButton (setting, ValueForKeyRetreival ().GetValueForKey (key, mButtonMap), FALSE); + break; + + case TypeEdge: + + ccsSetEdge (setting, ValueForKeyRetreival ().GetValueForKey (key, mEdgeMap), FALSE); + break; + + case TypeBell: + + ccsSetBell (setting, ValueForKeyRetreival ().GetValueForKey (key, mBellMap), FALSE); + break; + default: throw std::exception (); @@ -149,7 +227,13 @@ class MockCCSBackendConceptTestEnvironment : std::map mIntMap; std::map mFloatMap; std::map mStringMap; + std::map mMatchMap; std::map mColorMap; + std::map mKeyMap; + std::map mButtonMap; + std::map mEdgeMap; + std::map mBoolMap; + std::map mBellMap; }; static MockCCSBackendConceptTestEnvironment mockBackendEnv; diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 0a5d0afb8..0511916d7 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -32,6 +32,18 @@ class CCSBackendConceptTestEnvironmentInterface virtual void WriteColorAtKey (const std::string &plugin, const std::string &key, const CCSSettingColorValue &value) = 0; + virtual void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingKeyValue &value) = 0; + virtual void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingButtonValue &value) = 0; + virtual void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const unsigned int &value) = 0; + virtual void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const Bool &value) = 0; }; class CCSBackendConformanceTest : @@ -223,6 +235,93 @@ TEST_P (CCSBackendConformanceTest, TestReadColor) ccsBackendReadSetting (GetBackend (), context, setting); } +TEST_P (CCSBackendConformanceTest, TestReadKey) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingKeyValue VALUE; + + VALUE.keyModMask = (1 << 0) | (1 << 1); + VALUE.keysym = 1; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeKey, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteKeyAtKey (pluginName, settingName, VALUE); + + /* FIXME: We can't verify right now that the key returned is correct */ + EXPECT_CALL (*gmockSetting, setKey (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + +TEST_P (CCSBackendConformanceTest, TestReadButton) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingButtonValue VALUE; + + VALUE.buttonModMask = (1 << 0) | (1 << 1); + VALUE.button = 1; + VALUE.edgeMask = (1 << 0); + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeButton, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteButtonAtKey (pluginName, settingName, VALUE); + + /* FIXME: We can't verify right now that the button returned is correct */ + EXPECT_CALL (*gmockSetting, setButton (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + +TEST_P (CCSBackendConformanceTest, TestReadEdge) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + unsigned int VALUE; + + VALUE = 1; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeEdge, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteEdgeAtKey (pluginName, settingName, VALUE); + + EXPECT_CALL (*gmockSetting, setEdge (VALUE, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + +TEST_P (CCSBackendConformanceTest, TestReadBell) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + Bool VALUE = TRUE; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeBell, plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteBellAtKey (pluginName, settingName, VALUE); + + EXPECT_CALL (*gmockSetting, setBell (VALUE, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + #endif -- GitLab From 0cc9520fce3c773e15c7f8fffaadcc4683c70264 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 10:47:22 +0800 Subject: [PATCH 030/562] Basic test for reading bool values from lists --- ...nfig_test_ccs_mock_backend_conformance.cpp | 14 +++++++++ .../tests/compizconfig_backend_concept_test.h | 29 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 172da2d09..dbc3985ef 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -155,6 +155,14 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } + void WriteListAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingValueList &value) + { + mListMap[plugin + "/" + key] = value; + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + } + protected: void WriteValueToSetting (CCSSetting *setting) @@ -214,6 +222,11 @@ class MockCCSBackendConceptTestEnvironment : ccsSetBell (setting, ValueForKeyRetreival ().GetValueForKey (key, mBellMap), FALSE); break; + case TypeList: + + ccsSetList (setting, ValueForKeyRetreival ().GetValueForKey (key, mListMap), FALSE); + break; + default: throw std::exception (); @@ -234,6 +247,7 @@ class MockCCSBackendConceptTestEnvironment : std::map mEdgeMap; std::map mBoolMap; std::map mBellMap; + std::map mListMap; }; static MockCCSBackendConceptTestEnvironment mockBackendEnv; diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 0511916d7..bb901d138 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -44,6 +44,10 @@ class CCSBackendConceptTestEnvironmentInterface virtual void WriteBellAtKey (const std::string &plugin, const std::string &key, const Bool &value) = 0; + + virtual void WriteListAtKey (const std::string &plugin, + const std::string &key, + const CCSSettingValueList &list) = 0; }; class CCSBackendConformanceTest : @@ -322,6 +326,31 @@ TEST_P (CCSBackendConformanceTest, TestReadBell) ccsBackendReadSetting (GetBackend (), context, setting); } +TEST_P (CCSBackendConformanceTest, TestReadListBool) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingValueList VALUE; + Bool VBool[3] = { FALSE, TRUE, FALSE }; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); + + VALUE = ccsGetValueListFromBoolArray (VBool, 3, setting); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); + + /* No matcher for lists yet */ + EXPECT_CALL (*gmockSetting, setList (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); + + ccsSettingValueListFree (VALUE, FALSE); +} + #endif -- GitLab From 6d1909eb440c55feafba02fecf911b83dc5c1821 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 16:26:22 +0800 Subject: [PATCH 031/562] Added tests for reading the rest of the lists --- compizconfig/gconf/src/gconf.c | 4 +- compizconfig/gsettings/src/gsettings.c | 6 +- compizconfig/libcompizconfig/include/ccs.h | 4 +- compizconfig/libcompizconfig/src/ini.c | 2 +- compizconfig/libcompizconfig/src/lists.c | 4 +- .../tests/compizconfig_backend_concept_test.h | 135 ++++++++++++++++++ 6 files changed, 145 insertions(+), 10 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 8757d1875..4f233c543 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -868,7 +868,7 @@ readListValue (CCSSetting *setting, case TypeString: case TypeMatch: { - char **array = malloc (nItems * sizeof (char*)); + const char **array = malloc (nItems * sizeof (char*)); if (!array) break; @@ -877,7 +877,7 @@ readListValue (CCSSetting *setting, list = ccsGetValueListFromStringArray (array, nItems, setting); for (i = 0; i < nItems; i++) if (array[i]) - free (array[i]); + free ((char *) array[i]); free (array); } break; diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 7513bebc9..470ca9145 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -410,8 +410,8 @@ readListValue (CCSSetting *setting) case TypeString: case TypeMatch: { - gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); - gchar **arrayCounter = array; + const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); + const gchar **arrayCounter = array; gchar *value; if (!array) @@ -424,7 +424,7 @@ readListValue (CCSSetting *setting) *arrayCounter++ = value; list = ccsGetValueListFromStringArray (array, nItems, setting); - g_strfreev (array); + g_strfreev ((char **) array); } break; case TypeColor: diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index ff22c1276..70ccace01 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -806,10 +806,10 @@ CCSSettingColorValue* ccsGetColorArrayFromValueList (CCSSettingValueList list, /* Converts an array of data items to a setting value list. Behaves similar to ccsGetListFromStringArray */ -CCSSettingValueList ccsGetValueListFromStringArray (char **array, +CCSSettingValueList ccsGetValueListFromStringArray (const char **array, int num, CCSSetting *parent); -CCSSettingValueList ccsGetValueListFromMatchArray (char **array, +CCSSettingValueList ccsGetValueListFromMatchArray (const char **array, int num, CCSSetting *parent); CCSSettingValueList ccsGetValueListFromIntArray (int *array, diff --git a/compizconfig/libcompizconfig/src/ini.c b/compizconfig/libcompizconfig/src/ini.c index 6e44619bb..1284e836b 100644 --- a/compizconfig/libcompizconfig/src/ini.c +++ b/compizconfig/libcompizconfig/src/ini.c @@ -397,7 +397,7 @@ ccsIniParseList (const char *str, token = strsep (&valueString, ";"); } - list = ccsGetValueListFromStringArray (array, nItems, parent); + list = ccsGetValueListFromStringArray ((const char **) array, nItems, parent); for (i = 0; i < nItems; i++) free (array[i]); diff --git a/compizconfig/libcompizconfig/src/lists.c b/compizconfig/libcompizconfig/src/lists.c index 1c8081782..4470177c0 100644 --- a/compizconfig/libcompizconfig/src/lists.c +++ b/compizconfig/libcompizconfig/src/lists.c @@ -392,7 +392,7 @@ CCSSettingColorValue * ccsGetColorArrayFromValueList (CCSSettingValueList list, return rv; } -CCSSettingValueList ccsGetValueListFromStringArray (char ** array, int num, +CCSSettingValueList ccsGetValueListFromStringArray (const char ** array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; @@ -414,7 +414,7 @@ CCSSettingValueList ccsGetValueListFromStringArray (char ** array, int num, return l; } -CCSSettingValueList ccsGetValueListFromMatchArray (char ** array, int num, +CCSSettingValueList ccsGetValueListFromMatchArray (const char **array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index bb901d138..fdbd83cef 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -3,6 +3,8 @@ #include +#include + #include #include @@ -351,6 +353,139 @@ TEST_P (CCSBackendConformanceTest, TestReadListBool) ccsSettingValueListFree (VALUE, FALSE); } +TEST_P (CCSBackendConformanceTest, TestReadListInt) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingValueList VALUE; + int VInt[3] = { 1, 2, 3 }; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); + + VALUE = ccsGetValueListFromIntArray (VInt, 3, setting); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); + + /* No matcher for lists yet */ + EXPECT_CALL (*gmockSetting, setList (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); + + ccsSettingValueListFree (VALUE, FALSE); +} + +TEST_P (CCSBackendConformanceTest, TestReadListFloat) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingValueList VALUE; + float VFloat[3] = { 1.0, 2.0, 3.0 }; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); + + VALUE = ccsGetValueListFromFloatArray (VFloat, 3, setting); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); + + /* No matcher for lists yet */ + EXPECT_CALL (*gmockSetting, setList (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); + + ccsSettingValueListFree (VALUE, FALSE); +} + +TEST_P (CCSBackendConformanceTest, TestReadListString) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingValueList VALUE; + const char * VString[3] = { "foo", + "bar", + "baz" }; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); + + VALUE = ccsGetValueListFromStringArray (VString, 3, setting); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); + + /* No matcher for lists yet */ + EXPECT_CALL (*gmockSetting, setList (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); + + ccsSettingValueListFree (VALUE, FALSE); +} + +TEST_P (CCSBackendConformanceTest, TestReadListMatch) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingValueList VALUE; + const char * VMatch[3] = { "foo", + "bar", + "baz" }; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); + + VALUE = ccsGetValueListFromMatchArray (VMatch, 3, setting); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); + + /* No matcher for lists yet */ + EXPECT_CALL (*gmockSetting, setList (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); + + ccsSettingValueListFree (VALUE, FALSE); +} + +TEST_P (CCSBackendConformanceTest, TestReadListColor) +{ + std::string pluginName ("plugin"); + std::string settingName ("string_setting"); + CCSSettingValueList VALUE; + CCSSettingColorValue VColor[3] = { { .color = { 100, 200, 300, 100 } }, + { .color = { 50, 100, 200, 300 } }, + { .color = { 10, 20, 30, 40 } } + }; + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); + + VALUE = ccsGetValueListFromColorArray (VColor, 3, setting); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); + + /* No matcher for lists yet */ + EXPECT_CALL (*gmockSetting, setList (_, _)); + + ccsBackendReadSetting (GetBackend (), context, setting); + + ccsSettingValueListFree (VALUE, FALSE); +} + + #endif -- GitLab From 890cba970c464c7ac6db31083beabc24e8644b41 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 10 Jul 2012 18:19:15 +0800 Subject: [PATCH 032/562] Even more generic tests for each type (basic types) --- ...nfig_test_ccs_mock_backend_conformance.cpp | 89 +++++++--- .../tests/compizconfig_backend_concept_test.h | 152 ++++++++++++++++-- 2 files changed, 204 insertions(+), 37 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index dbc3985ef..ad6ac5140 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -12,6 +12,9 @@ using ::testing::_; using ::testing::Return; using ::testing::Invoke; using ::testing::WithArgs; +using ::testing::Combine; +using ::testing::ValuesIn; +using ::testing::Values; template class ValueForKeyRetreival @@ -76,90 +79,90 @@ class MockCCSBackendConceptTestEnvironment : void WriteBoolAtKey (const std::string &plugin, const std::string &key, - const Bool &value) + const VariantTypes &value) { - mBoolMap[plugin + "/" + key] = value; + mBoolMap[plugin + "/" + key] = boolToBool (boost::get (value)); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteIntegerAtKey (const std::string &plugin, const std::string &key, - int value) + const VariantTypes &value) { - mIntMap[plugin + "/" + key] = value; + mIntMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteFloatAtKey (const std::string &plugin, const std::string &key, - float value) + const VariantTypes &value) { - mFloatMap[plugin + "/" + key] = value; + mFloatMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteMatchAtKey (const std::string &plugin, const std::string &key, - const std::string &value) + const VariantTypes &value) { - mMatchMap[plugin + "/" + key] = value; + mMatchMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteStringAtKey (const std::string &plugin, const std::string &key, - const std::string &value) + const VariantTypes &value) { - mStringMap[plugin + "/" + key] = value; + mStringMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteColorAtKey (const std::string &plugin, const std::string &key, - const CCSSettingColorValue &value) + const VariantTypes &value) { - mColorMap[plugin + "/" + key] = value; + mColorMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteKeyAtKey (const std::string &plugin, const std::string &key, - const CCSSettingKeyValue &keyValue) + const VariantTypes &value) { - mKeyMap[plugin + "/" + key] = keyValue; + mKeyMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteButtonAtKey (const std::string &plugin, const std::string &key, - const CCSSettingButtonValue &buttonValue) + const VariantTypes &value) { - mButtonMap[plugin + "/" + key] = buttonValue; + mButtonMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteEdgeAtKey (const std::string &plugin, const std::string &key, - const unsigned int &value) + const VariantTypes &value) { - mEdgeMap[plugin + "/" + key] = value; + mEdgeMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteBellAtKey (const std::string &plugin, const std::string &key, - const Bool &value) + const VariantTypes &value) { - mBellMap[plugin + "/" + key] = value; + mBellMap[plugin + "/" + key] = boolToBool (boost::get (value)); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteListAtKey (const std::string &plugin, const std::string &key, - const CCSSettingValueList &value) + const VariantTypes &value) { - mListMap[plugin + "/" + key] = value; + mListMap[plugin + "/" + key] = boost::get (value); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -253,6 +256,46 @@ class MockCCSBackendConceptTestEnvironment : static MockCCSBackendConceptTestEnvironment mockBackendEnv; static CCSBackendConceptTestEnvironmentInterface *backendEnv = &mockBackendEnv; -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, ::testing::Values (backendEnv)); +static CCSBackendConceptTestParam::Ptr testParam[] = +{ + boost::make_shared (VariantTypes (1), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, backendEnv, _1, _2, _3), + TypeInt, + "integer_setting", + boost::bind (SetIntExpectation, _1, _2), + "TestRetreiveInt"), + boost::make_shared (VariantTypes (true), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, backendEnv, _1, _2, _3), + TypeBool, + "boolean_setting", + boost::bind (SetBoolExpectation, _1, _2), + "TestRetreiveBool"), + boost::make_shared (VariantTypes (static_cast (3.0)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, backendEnv, _1, _2, _3), + TypeFloat, + "float_setting", + boost::bind (SetFloatExpectation, _1, _2), + "TestRetreiveFloat"), + boost::make_shared (VariantTypes (static_cast ("foo")), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, backendEnv, _1, _2, _3), + TypeString, + "string_setting", + boost::bind (SetStringExpectation, _1, _2), + "TestRetreiveString"), + boost::make_shared (VariantTypes (static_cast ("foo=bar")), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, backendEnv, _1, _2, _3), + TypeMatch, + "match_setting", + boost::bind (SetMatchExpectation, _1, _2), + "TestRetreiveMatch"), + boost::make_shared (VariantTypes (true), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, backendEnv, _1, _2, _3), + TypeBell, + "bell_setting", + boost::bind (SetBellExpectation, _1, _2), + "TestRetreiveBell") +}; + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, Combine (Values (backendEnv), ValuesIn (testParam))); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index fdbd83cef..5a5133bf7 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -3,7 +3,11 @@ #include -#include +#include +#include +#include +#include +#include #include #include @@ -15,6 +19,17 @@ #include #include +using ::testing::Eq; + +typedef boost::variant VariantTypes; + class CCSBackendConceptTestEnvironmentInterface { public: @@ -22,38 +37,125 @@ class CCSBackendConceptTestEnvironmentInterface virtual ~CCSBackendConceptTestEnvironmentInterface () {}; virtual CCSBackend * SetUp () = 0; virtual void TearDown (CCSBackend *) = 0; + virtual void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; virtual void WriteIntegerAtKey (const std::string &plugin, const std::string &key, - int value) = 0; + const VariantTypes &value) = 0; virtual void WriteFloatAtKey (const std::string &plugin, const std::string &key, - float value) = 0; + const VariantTypes &value) = 0; virtual void WriteStringAtKey (const std::string &plugin, const std::string &key, - const std::string &value) = 0; + const VariantTypes &value) = 0; virtual void WriteColorAtKey (const std::string &plugin, const std::string &key, - const CCSSettingColorValue &value) = 0; + const VariantTypes &value) = 0; virtual void WriteKeyAtKey (const std::string &plugin, const std::string &key, - const CCSSettingKeyValue &value) = 0; + const VariantTypes &value) = 0; virtual void WriteButtonAtKey (const std::string &plugin, const std::string &key, - const CCSSettingButtonValue &value) = 0; + const VariantTypes &value) = 0; virtual void WriteEdgeAtKey (const std::string &plugin, const std::string &key, - const unsigned int &value) = 0; + const VariantTypes &value) = 0; + virtual void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; virtual void WriteBellAtKey (const std::string &plugin, const std::string &key, - const Bool &value) = 0; + const VariantTypes &value) = 0; virtual void WriteListAtKey (const std::string &plugin, const std::string &key, - const CCSSettingValueList &list) = 0; + const VariantTypes &value) = 0; +}; + +namespace +{ +Bool boolToBool (bool v) { return v ? TRUE : FALSE; } + +void SetIntExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setInt (boost::get (value), _)); +} + +void SetBoolExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setBool (boolToBool (boost::get (value)), _)); +} + +void SetBellExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setBell (boolToBool (boost::get (value)), _)); +} + +void SetFloatExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setFloat (boost::get (value), _)); +} + +void SetStringExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setString (Eq (std::string (boost::get (value))), _)); +} + +void SetMatchExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setMatch (Eq (std::string (boost::get (value))), _)); +} +} + +class CCSBackendConceptTestParam +{ + public: + + typedef boost::shared_ptr Ptr; + + typedef boost::function NativeWrite; + typedef boost::function SetExpectation; + + CCSBackendConceptTestParam (const VariantTypes &value, + const NativeWrite &write, + const CCSSettingType &type, + const std::string &keyname, + const SetExpectation &setExpectation, + const std::string &what) : + mValue (value), + mNativeWrite (write), + mType (type), + mKeyname (keyname), + mSetExpectation (setExpectation), + mWhat (what) + { + } + + VariantTypes & value () { return mValue; } + NativeWrite & nativeWrite () { return mNativeWrite; } + CCSSettingType & type () { return mType; } + std::string & keyname () { return mKeyname; } + SetExpectation & setExpectation () { return mSetExpectation; } + std::string & what () { return mWhat; } + + private: + + VariantTypes mValue; + NativeWrite mNativeWrite; + CCSSettingType mType; + std::string mKeyname; + SetExpectation mSetExpectation; + std::string mWhat; + }; class CCSBackendConformanceTest : - public ::testing::TestWithParam + public ::testing::TestWithParam > { public: @@ -64,12 +166,12 @@ class CCSBackendConformanceTest : void SetUp () { - mBackend = GetParam ()->SetUp (); + mBackend = std::tr1::get<0> (GetParam ())->SetUp (); } void TearDown () { - GetParam ()->TearDown (mBackend); + std::tr1::get<0> (GetParam ())->TearDown (mBackend); for (std::list ::iterator it = mSpawnedContexts.begin (); it != mSpawnedContexts.end (); @@ -146,6 +248,28 @@ TEST_P (CCSBackendConformanceTest, TestSetup) { } +TEST_P (CCSBackendConformanceTest, TestReadValue) +{ + SCOPED_TRACE (std::tr1::get <1> (GetParam ())->what ()); + + std::string pluginName ("plugin"); + const std::string &settingName (std::tr1::get <1> (GetParam ())->keyname ()); + const VariantTypes &VALUE (std::tr1::get <1> (GetParam ())->value ()); + + CCSContext *context = SpawnContext (); + CCSPlugin *plugin = SpawnPlugin (pluginName); + CCSSetting *setting = SpawnSetting (settingName, std::tr1::get <1> (GetParam ())->type (), plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + std::tr1::get <1> (GetParam ())->nativeWrite () (pluginName, settingName, VALUE); + std::tr1::get <1> (GetParam ())->setExpectation () (gmockSetting, VALUE); + + ccsBackendReadSetting (GetBackend (), context, setting); +} + +#if 0 + TEST_P (CCSBackendConformanceTest, TestReadInteger) { std::string pluginName ("plugin"); @@ -485,7 +609,7 @@ TEST_P (CCSBackendConformanceTest, TestReadListColor) ccsSettingValueListFree (VALUE, FALSE); } - +#endif #endif -- GitLab From b119a41869bc4970fbab25fb5ac944900189b414 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 13:51:18 +0800 Subject: [PATCH 033/562] Replace a bunch of repeated tests with some template magic --- ...nfig_test_ccs_mock_backend_conformance.cpp | 46 +- .../tests/compizconfig_backend_concept_test.h | 501 +++++------------- 2 files changed, 147 insertions(+), 400 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index ad6ac5140..9a63227f7 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -253,49 +253,7 @@ class MockCCSBackendConceptTestEnvironment : std::map mListMap; }; -static MockCCSBackendConceptTestEnvironment mockBackendEnv; -static CCSBackendConceptTestEnvironmentInterface *backendEnv = &mockBackendEnv; - -static CCSBackendConceptTestParam::Ptr testParam[] = -{ - boost::make_shared (VariantTypes (1), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, backendEnv, _1, _2, _3), - TypeInt, - "integer_setting", - boost::bind (SetIntExpectation, _1, _2), - "TestRetreiveInt"), - boost::make_shared (VariantTypes (true), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, backendEnv, _1, _2, _3), - TypeBool, - "boolean_setting", - boost::bind (SetBoolExpectation, _1, _2), - "TestRetreiveBool"), - boost::make_shared (VariantTypes (static_cast (3.0)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, backendEnv, _1, _2, _3), - TypeFloat, - "float_setting", - boost::bind (SetFloatExpectation, _1, _2), - "TestRetreiveFloat"), - boost::make_shared (VariantTypes (static_cast ("foo")), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, backendEnv, _1, _2, _3), - TypeString, - "string_setting", - boost::bind (SetStringExpectation, _1, _2), - "TestRetreiveString"), - boost::make_shared (VariantTypes (static_cast ("foo=bar")), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, backendEnv, _1, _2, _3), - TypeMatch, - "match_setting", - boost::bind (SetMatchExpectation, _1, _2), - "TestRetreiveMatch"), - boost::make_shared (VariantTypes (true), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, backendEnv, _1, _2, _3), - TypeBell, - "bell_setting", - boost::bind (SetBellExpectation, _1, _2), - "TestRetreiveBell") -}; - -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, Combine (Values (backendEnv), ValuesIn (testParam))); +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, + compizconfig::test::GenerateTestingParametersForBackendInterface ()); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 5a5133bf7..57dd5f52e 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -106,26 +106,61 @@ void SetMatchExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setMatch (Eq (std::string (boost::get (value))), _)); } + +void SetColorExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setColor (_, _)); // can't match +} + +void SetKeyExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setKey (_, _)); // can't match } -class CCSBackendConceptTestParam +void SetButtonExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setButton (_, _)); // can't match +} + +} + +class CCSBackendConceptTestParamInterface { public: - typedef boost::shared_ptr Ptr; + typedef boost::shared_ptr Ptr; - typedef boost::function NativeWrite; + typedef boost::function NativeWriteMethod; typedef boost::function SetExpectation; - CCSBackendConceptTestParam (const VariantTypes &value, - const NativeWrite &write, + virtual CCSBackendConceptTestEnvironmentInterface * testEnv () = 0; + virtual VariantTypes & value () = 0; + virtual NativeWriteMethod & nativeWrite () = 0; + virtual CCSSettingType & type () = 0; + virtual std::string & keyname () = 0; + virtual SetExpectation & setExpectation () = 0; + virtual std::string & what () = 0; +}; + +template +class CCSBackendConceptTestParam : + public CCSBackendConceptTestParamInterface +{ + public: + + typedef boost::shared_ptr > Ptr; + + CCSBackendConceptTestParam (CCSBackendConceptTestEnvironmentInterface *testEnv, + const VariantTypes &value, + const NativeWriteMethod &write, const CCSSettingType &type, const std::string &keyname, const SetExpectation &setExpectation, const std::string &what) : + mTestEnv (testEnv), mValue (value), mNativeWrite (write), mType (type), @@ -135,17 +170,19 @@ class CCSBackendConceptTestParam { } + CCSBackendConceptTestEnvironmentInterface * testEnv () { return mTestEnv; } VariantTypes & value () { return mValue; } - NativeWrite & nativeWrite () { return mNativeWrite; } + CCSBackendConceptTestParamInterface::NativeWriteMethod & nativeWrite () { return mNativeWrite; } CCSSettingType & type () { return mType; } std::string & keyname () { return mKeyname; } - SetExpectation & setExpectation () { return mSetExpectation; } + CCSBackendConceptTestParamInterface::SetExpectation & setExpectation () { return mSetExpectation; } std::string & what () { return mWhat; } private: + CCSBackendConceptTestEnvironmentInterface *mTestEnv; VariantTypes mValue; - NativeWrite mNativeWrite; + NativeWriteMethod mNativeWrite; CCSSettingType mType; std::string mKeyname; SetExpectation mSetExpectation; @@ -154,8 +191,7 @@ class CCSBackendConceptTestParam }; class CCSBackendConformanceTest : - public ::testing::TestWithParam > + public ::testing::TestWithParam { public: @@ -166,12 +202,12 @@ class CCSBackendConformanceTest : void SetUp () { - mBackend = std::tr1::get<0> (GetParam ())->SetUp (); + mBackend = GetParam ()->testEnv ()->SetUp (); } void TearDown () { - std::tr1::get<0> (GetParam ())->TearDown (mBackend); + CCSBackendConformanceTest::GetParam ()->testEnv ()->TearDown (mBackend); for (std::list ::iterator it = mSpawnedContexts.begin (); it != mSpawnedContexts.end (); @@ -244,373 +280,126 @@ class CCSBackendConformanceTest : CCSBackend *mBackend; }; -TEST_P (CCSBackendConformanceTest, TestSetup) +namespace compizconfig { -} - -TEST_P (CCSBackendConformanceTest, TestReadValue) -{ - SCOPED_TRACE (std::tr1::get <1> (GetParam ())->what ()); - - std::string pluginName ("plugin"); - const std::string &settingName (std::tr1::get <1> (GetParam ())->keyname ()); - const VariantTypes &VALUE (std::tr1::get <1> (GetParam ())->value ()); - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, std::tr1::get <1> (GetParam ())->type (), plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - std::tr1::get <1> (GetParam ())->nativeWrite () (pluginName, settingName, VALUE); - std::tr1::get <1> (GetParam ())->setExpectation () (gmockSetting, VALUE); - - ccsBackendReadSetting (GetBackend (), context, setting); -} - -#if 0 - -TEST_P (CCSBackendConformanceTest, TestReadInteger) +namespace test { - std::string pluginName ("plugin"); - std::string settingName ("integer_setting"); - const int VALUE = 1; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeInt, plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteIntegerAtKey (pluginName, settingName, VALUE); - - EXPECT_CALL (*gmockSetting, setInt (VALUE, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); -} - -TEST_P (CCSBackendConformanceTest, TestReadFloat) +namespace impl { - std::string pluginName ("plugin"); - std::string settingName ("float_setting"); - const float VALUE = 1.0; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeFloat, plugin); - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteFloatAtKey (pluginName, settingName, VALUE); +CCSSettingColorValue colorValues[3] = { { .color = { 100, 200, 300, 100 } }, + { .color = { 50, 100, 200, 300 } }, + { .color = { 10, 20, 30, 40 } } + }; - EXPECT_CALL (*gmockSetting, setFloat (VALUE, _)); +CCSSettingKeyValue keyValue = { (1 << 0) | (1 << 1), + 1 }; - ccsBackendReadSetting (GetBackend (), context, setting); +CCSSettingButtonValue buttonValue = { (1 << 0) | (1 << 1), + 1, + (1 << 1) }; } -TEST_P (CCSBackendConformanceTest, TestReadString) +template +::testing::internal::ParamGenerator +GenerateTestingParametersForBackendInterface () { - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - const std::string VALUE ("foo"); - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeString, plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteStringAtKey (pluginName, settingName, VALUE); + static I interface; + static CCSBackendConceptTestEnvironmentInterface *backendEnv = &interface; - EXPECT_CALL (*gmockSetting, setString (VALUE.c_str (), _)); + typedef CCSBackendConceptTestParam ConceptParam; - ccsBackendReadSetting (GetBackend (), context, setting); -} - -namespace -{ - bool - operator== (const CCSSettingColorValue &lhs, - const CCSSettingColorValue &rhs) + static typename CCSBackendConceptTestParamInterface::Ptr testParam[] = { - return (lhs.color.red == rhs.color.red && - lhs.color.green == rhs.color.green && - lhs.color.blue == rhs.color.blue && - lhs.color.alpha == lhs.color.alpha); - } -} - -TEST_P (CCSBackendConformanceTest, TestReadColor) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingColorValue VALUE; - - VALUE.color.red = 100; - VALUE.color.blue = 100; - VALUE.color.green = 100; - VALUE.color.alpha = 100; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeColor, plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteColorAtKey (pluginName, settingName, VALUE); - - /* FIXME: We can't verify right now that the color returned is correct */ - EXPECT_CALL (*gmockSetting, setColor (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); -} - -TEST_P (CCSBackendConformanceTest, TestReadKey) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingKeyValue VALUE; - - VALUE.keyModMask = (1 << 0) | (1 << 1); - VALUE.keysym = 1; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeKey, plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteKeyAtKey (pluginName, settingName, VALUE); - - /* FIXME: We can't verify right now that the key returned is correct */ - EXPECT_CALL (*gmockSetting, setKey (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); -} - -TEST_P (CCSBackendConformanceTest, TestReadButton) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingButtonValue VALUE; - - VALUE.buttonModMask = (1 << 0) | (1 << 1); - VALUE.button = 1; - VALUE.edgeMask = (1 << 0); - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeButton, plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteButtonAtKey (pluginName, settingName, VALUE); - - /* FIXME: We can't verify right now that the button returned is correct */ - EXPECT_CALL (*gmockSetting, setButton (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); + boost::make_shared (backendEnv, + VariantTypes (1), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, backendEnv, _1, _2, _3), + TypeInt, + "integer_setting", + boost::bind (SetIntExpectation, _1, _2), + "TestRetreiveInt"), + boost::make_shared (backendEnv, + VariantTypes (true), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, backendEnv, _1, _2, _3), + TypeBool, + "boolean_setting", + boost::bind (SetBoolExpectation, _1, _2), + "TestRetreiveBool"), + boost::make_shared (backendEnv, + VariantTypes (static_cast (3.0)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, backendEnv, _1, _2, _3), + TypeFloat, + "float_setting", + boost::bind (SetFloatExpectation, _1, _2), + "TestRetreiveFloat"), + boost::make_shared (backendEnv, + VariantTypes (static_cast ("foo")), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, backendEnv, _1, _2, _3), + TypeString, + "string_setting", + boost::bind (SetStringExpectation, _1, _2), + "TestRetreiveString"), + boost::make_shared (backendEnv, + VariantTypes (static_cast ("foo=bar")), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, backendEnv, _1, _2, _3), + TypeMatch, + "match_setting", + boost::bind (SetMatchExpectation, _1, _2), + "TestRetreiveMatch"), + boost::make_shared (backendEnv, + VariantTypes (true), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, backendEnv, _1, _2, _3), + TypeBell, + "bell_setting", + boost::bind (SetBellExpectation, _1, _2), + "TestRetreiveBell"), + boost::make_shared (backendEnv, + VariantTypes (impl::colorValues[0]), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, backendEnv, _1, _2, _3), + TypeColor, + "color_setting", + boost::bind (SetColorExpectation, _1, _2), + "TestRetreiveColor"), + boost::make_shared (backendEnv, + VariantTypes (impl::keyValue), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, backendEnv, _1, _2, _3), + TypeKey, + "key_setting", + boost::bind (SetKeyExpectation, _1, _2), + "TestRetreiveKey"), + boost::make_shared (backendEnv, + VariantTypes (impl::buttonValue), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, backendEnv, _1, _2, _3), + TypeButton, + "button_setting", + boost::bind (SetButtonExpectation, _1, _2), + "TestRetreiveButton") + }; + + return ::testing::ValuesIn (testParam); } - -TEST_P (CCSBackendConformanceTest, TestReadEdge) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - unsigned int VALUE; - - VALUE = 1; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeEdge, plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteEdgeAtKey (pluginName, settingName, VALUE); - - EXPECT_CALL (*gmockSetting, setEdge (VALUE, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); -} - -TEST_P (CCSBackendConformanceTest, TestReadBell) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - Bool VALUE = TRUE; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeBell, plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteBellAtKey (pluginName, settingName, VALUE); - - EXPECT_CALL (*gmockSetting, setBell (VALUE, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); -} - -TEST_P (CCSBackendConformanceTest, TestReadListBool) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingValueList VALUE; - Bool VBool[3] = { FALSE, TRUE, FALSE }; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); - - VALUE = ccsGetValueListFromBoolArray (VBool, 3, setting); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); - - /* No matcher for lists yet */ - EXPECT_CALL (*gmockSetting, setList (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); - - ccsSettingValueListFree (VALUE, FALSE); } - -TEST_P (CCSBackendConformanceTest, TestReadListInt) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingValueList VALUE; - int VInt[3] = { 1, 2, 3 }; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); - - VALUE = ccsGetValueListFromIntArray (VInt, 3, setting); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); - - /* No matcher for lists yet */ - EXPECT_CALL (*gmockSetting, setList (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); - - ccsSettingValueListFree (VALUE, FALSE); } -TEST_P (CCSBackendConformanceTest, TestReadListFloat) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingValueList VALUE; - float VFloat[3] = { 1.0, 2.0, 3.0 }; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); - - VALUE = ccsGetValueListFromFloatArray (VFloat, 3, setting); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); - - /* No matcher for lists yet */ - EXPECT_CALL (*gmockSetting, setList (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); - - ccsSettingValueListFree (VALUE, FALSE); -} - -TEST_P (CCSBackendConformanceTest, TestReadListString) -{ - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingValueList VALUE; - const char * VString[3] = { "foo", - "bar", - "baz" }; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); - - VALUE = ccsGetValueListFromStringArray (VString, 3, setting); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); - - /* No matcher for lists yet */ - EXPECT_CALL (*gmockSetting, setList (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); - - ccsSettingValueListFree (VALUE, FALSE); -} - -TEST_P (CCSBackendConformanceTest, TestReadListMatch) +TEST_P (CCSBackendConformanceTest, TestReadValue) { - std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingValueList VALUE; - const char * VMatch[3] = { "foo", - "bar", - "baz" }; + SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what ()); - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); - - VALUE = ccsGetValueListFromMatchArray (VMatch, 3, setting); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); - - /* No matcher for lists yet */ - EXPECT_CALL (*gmockSetting, setList (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); - - ccsSettingValueListFree (VALUE, FALSE); -} - -TEST_P (CCSBackendConformanceTest, TestReadListColor) -{ std::string pluginName ("plugin"); - std::string settingName ("string_setting"); - CCSSettingValueList VALUE; - CCSSettingColorValue VColor[3] = { { .color = { 100, 200, 300, 100 } }, - { .color = { 50, 100, 200, 300 } }, - { .color = { 10, 20, 30, 40 } } - }; - - CCSContext *context = SpawnContext (); - CCSPlugin *plugin = SpawnPlugin (pluginName); - CCSSetting *setting = SpawnSetting (settingName, TypeList, plugin); + const std::string &settingName (GetParam ()->keyname ()); + const VariantTypes &VALUE (GetParam ()->value ()); - VALUE = ccsGetValueListFromColorArray (VColor, 3, setting); + CCSContext *context = CCSBackendConformanceTest::SpawnContext (); + CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); + CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - GetParam ()->WriteListAtKey (pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->nativeWrite () (pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->setExpectation () (gmockSetting, VALUE); - /* No matcher for lists yet */ - EXPECT_CALL (*gmockSetting, setList (_, _)); - - ccsBackendReadSetting (GetBackend (), context, setting); - - ccsSettingValueListFree (VALUE, FALSE); + ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context, setting); } #endif - -#endif - -- GitLab From fd78545d5c404083e8eae65625b83e29cab53a50 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 14:25:12 +0800 Subject: [PATCH 034/562] Added test for int lists --- ...nfig_test_ccs_mock_backend_conformance.cpp | 2 +- .../tests/compizconfig_backend_concept_test.h | 55 ++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 9a63227f7..b113e01c9 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -162,7 +162,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mListMap[plugin + "/" + key] = boost::get (value); + mListMap[plugin + "/" + key] = *(boost::get > (value)); EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 57dd5f52e..7de34ec71 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,39 @@ using ::testing::Eq; +class CCSListWrapper : + boost::noncopyable +{ + public: + + typedef boost::shared_ptr Ptr; + + CCSListWrapper (CCSSettingValueList list, bool freeItems) : + mList (list), + mFreeItems (freeItems) + { + } + + operator CCSSettingValueList () + { + return mList; + } + + operator CCSSettingValueList () const + { + return mList; + } + + ~CCSListWrapper () + { + ccsSettingValueListFree (mList, mFreeItems ? TRUE : FALSE); + } + private: + + CCSSettingValueList mList; + bool mFreeItems; +}; + typedef boost::variant VariantTypes; + CCSListWrapper::Ptr> VariantTypes; class CCSBackendConceptTestEnvironmentInterface { @@ -122,6 +156,11 @@ void SetButtonExpectation (CCSSettingGMock *gmock, const VariantTypes &value) EXPECT_CALL (*gmock, setButton (_, _)); // can't match } +void SetListExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setList (_, _)); // can't match +} + } class CCSBackendConceptTestParamInterface @@ -287,6 +326,9 @@ namespace test namespace impl { +Bool boolValues[] = { TRUE, FALSE, TRUE }; +int intValues[] = { 1, 2, 3 }; + CCSSettingColorValue colorValues[3] = { { .color = { 100, 200, 300, 100 } }, { .color = { 50, 100, 200, 300 } }, { .color = { 10, 20, 30, 40 } } @@ -373,7 +415,16 @@ GenerateTestingParametersForBackendInterface () TypeButton, "button_setting", boost::bind (SetButtonExpectation, _1, _2), - "TestRetreiveButton") + "TestRetreiveButton"), + boost::make_shared (backendEnv, + VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, + sizeof (impl::intValues) / sizeof (impl::intValues[0]), + NULL), false)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + TypeList, + "int_list_setting", + boost::bind (SetListExpectation, _1, _2), + "TestRetreiveListInt") }; return ::testing::ValuesIn (testParam); -- GitLab From 72c38940832f27efbc24ad976b9fc3399689437d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 14:31:11 +0800 Subject: [PATCH 035/562] Added tests for the other remaining list types --- .../tests/compizconfig_backend_concept_test.h | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 7de34ec71..19fca5697 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -328,6 +328,8 @@ namespace impl Bool boolValues[] = { TRUE, FALSE, TRUE }; int intValues[] = { 1, 2, 3 }; +float floatValues[] = { 1.0, 2.0, 3.0 }; +const char * stringValues[] = { "foo", "grill", "bar" }; CCSSettingColorValue colorValues[3] = { { .color = { 100, 200, 300, 100 } }, { .color = { 50, 100, 200, 300 } }, @@ -424,7 +426,43 @@ GenerateTestingParametersForBackendInterface () TypeList, "int_list_setting", boost::bind (SetListExpectation, _1, _2), - "TestRetreiveListInt") + "TestRetreiveListInt"), + boost::make_shared (backendEnv, + VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, + sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), + NULL), false)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + TypeList, + "float_list_setting", + boost::bind (SetListExpectation, _1, _2), + "TestRetreiveListInt"), + boost::make_shared (backendEnv, + VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, + sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), + NULL), false)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + TypeList, + "bool_list_setting", + boost::bind (SetListExpectation, _1, _2), + "TestRetreiveListBool"), + boost::make_shared (backendEnv, + VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, + sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), + NULL), false)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + TypeList, + "string_list_setting", + boost::bind (SetListExpectation, _1, _2), + "TestRetreiveListString"), + boost::make_shared (backendEnv, + VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, + sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), + NULL), false)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + TypeList, + "color_list_setting", + boost::bind (SetListExpectation, _1, _2), + "TestRetreiveListColor") }; return ::testing::ValuesIn (testParam); -- GitLab From fb7b68a608b600cdf0b194bba417f8bd1ebe4375 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 14:54:28 +0800 Subject: [PATCH 036/562] Added support for edges, removed all the typed maps --- ...nfig_test_ccs_mock_backend_conformance.cpp | 79 ++++++------------- .../tests/compizconfig_backend_concept_test.h | 13 +++ 2 files changed, 39 insertions(+), 53 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index b113e01c9..db8152f5b 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -22,29 +22,12 @@ class ValueForKeyRetreival public: T GetValueForKey (const std::string &key, - const std::map &map) + const std::map &map) { - typename std::map ::const_iterator it = map.find (key); + std::map ::const_iterator it = map.find (key); if (it != map.end ()) - return it->second; - else - throw std::exception (); - } -}; - -template <> -class ValueForKeyRetreival -{ - public: - - const char * GetValueForKey (const std::string &key, - const std::map &map) - { - std::map ::const_iterator it = map.find (key); - - if (it != map.end ()) - return it->second.c_str (); + return boost::get (it->second); else throw std::exception (); } @@ -81,7 +64,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mBoolMap[plugin + "/" + key] = boolToBool (boost::get (value)); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -90,7 +73,7 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { - mIntMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -98,7 +81,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mFloatMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -106,7 +89,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mMatchMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -114,7 +97,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mStringMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -122,7 +105,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mColorMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -130,7 +113,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mKeyMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -138,7 +121,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mButtonMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -146,7 +129,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mEdgeMap[plugin + "/" + key] = boost::get (value); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -154,7 +137,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mBellMap[plugin + "/" + key] = boolToBool (boost::get (value)); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -162,7 +145,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mListMap[plugin + "/" + key] = *(boost::get > (value)); + mValues[plugin + "/" + key] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -177,57 +160,57 @@ class MockCCSBackendConceptTestEnvironment : { case TypeBool: - ccsSetBool (setting, ValueForKeyRetreival ().GetValueForKey (key, mBoolMap), FALSE); + ccsSetBool (setting, boolToBool (ValueForKeyRetreival ().GetValueForKey (key, mValues)), FALSE); break; case TypeInt: - ccsSetInt (setting, ValueForKeyRetreival ().GetValueForKey (key, mIntMap), FALSE); + ccsSetInt (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeFloat: - ccsSetFloat (setting, ValueForKeyRetreival ().GetValueForKey (key, mFloatMap), FALSE); + ccsSetFloat (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeString: - ccsSetString (setting, ValueForKeyRetreival ().GetValueForKey (key, mStringMap), FALSE); + ccsSetString (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeMatch: - ccsSetMatch (setting, ValueForKeyRetreival ().GetValueForKey (key, mMatchMap), FALSE); + ccsSetMatch (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeColor: - ccsSetColor (setting, ValueForKeyRetreival ().GetValueForKey (key, mColorMap), FALSE); + ccsSetColor (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeKey: - ccsSetKey (setting, ValueForKeyRetreival ().GetValueForKey (key, mKeyMap), FALSE); + ccsSetKey (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeButton: - ccsSetButton (setting, ValueForKeyRetreival ().GetValueForKey (key, mButtonMap), FALSE); + ccsSetButton (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeEdge: - ccsSetEdge (setting, ValueForKeyRetreival ().GetValueForKey (key, mEdgeMap), FALSE); + ccsSetEdge (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); break; case TypeBell: - ccsSetBell (setting, ValueForKeyRetreival ().GetValueForKey (key, mBellMap), FALSE); + ccsSetBell (setting, boolToBool (ValueForKeyRetreival ().GetValueForKey (key, mValues)), FALSE); break; case TypeList: - ccsSetList (setting, ValueForKeyRetreival ().GetValueForKey (key, mListMap), FALSE); + ccsSetList (setting, *(ValueForKeyRetreival > ().GetValueForKey (key, mValues)), FALSE); break; default: @@ -240,17 +223,7 @@ class MockCCSBackendConceptTestEnvironment : CCSBackend *mBackend; CCSBackendGMock *mBackendGMock; - std::map mIntMap; - std::map mFloatMap; - std::map mStringMap; - std::map mMatchMap; - std::map mColorMap; - std::map mKeyMap; - std::map mButtonMap; - std::map mEdgeMap; - std::map mBoolMap; - std::map mBellMap; - std::map mListMap; + std::map mValues; }; INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 19fca5697..9c9ff9426 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -62,6 +62,7 @@ typedef boost::variant VariantTypes; class CCSBackendConceptTestEnvironmentInterface @@ -156,6 +157,11 @@ void SetButtonExpectation (CCSSettingGMock *gmock, const VariantTypes &value) EXPECT_CALL (*gmock, setButton (_, _)); // can't match } +void SetEdgeExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setEdge (boost::get (value), _)); +} + void SetListExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setList (_, _)); // can't match @@ -418,6 +424,13 @@ GenerateTestingParametersForBackendInterface () "button_setting", boost::bind (SetButtonExpectation, _1, _2), "TestRetreiveButton"), + boost::make_shared (backendEnv, + VariantTypes (static_cast (1)), + boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, backendEnv, _1, _2, _3), + TypeEdge, + "edge_setting", + boost::bind (SetEdgeExpectation, _1, _2), + "TestRetreiveEdge"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, sizeof (impl::intValues) / sizeof (impl::intValues[0]), -- GitLab From 8c269f0e11203e321e65e8a49e879fefcd8c697d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 15:15:28 +0800 Subject: [PATCH 037/562] Require key reading functions in the interface and implement them in MockBackendConformance and implement the generic read function in terms of those read functions --- ...nfig_test_ccs_mock_backend_conformance.cpp | 123 ++++++++++++++---- .../tests/compizconfig_backend_concept_test.h | 24 +++- 2 files changed, 122 insertions(+), 25 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index db8152f5b..96aab4822 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -16,6 +16,15 @@ using ::testing::Combine; using ::testing::ValuesIn; using ::testing::Values; +namespace +{ +std::string keynameFromPluginKey (const std::string &plugin, + const std::string &key) +{ + return plugin + "/" + key; +} +} + template class ValueForKeyRetreival { @@ -64,7 +73,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -73,7 +82,7 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -81,7 +90,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -89,7 +98,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -97,7 +106,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -105,7 +114,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -113,7 +122,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -121,7 +130,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -129,7 +138,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -137,7 +146,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } @@ -145,72 +154,138 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[plugin + "/" + key] = value; + mValues[keynameFromPluginKey (plugin, key)] = value; EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } + virtual Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) + { + return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + } + + virtual int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual float ReadFloatAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) + { + return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + } + + virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key) + { + return *(ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + } + protected: void WriteValueToSetting (CCSSetting *setting) { - std::string key (std::string (ccsPluginGetName (ccsSettingGetParent (setting))) + - "/" + std::string (ccsSettingGetName (setting))); + std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); + std::string key (ccsSettingGetName (setting)); switch (ccsSettingGetType (setting)) { case TypeBool: - ccsSetBool (setting, boolToBool (ValueForKeyRetreival ().GetValueForKey (key, mValues)), FALSE); + ccsSetBool (setting, ReadBoolAtKey (plugin, key), FALSE); break; case TypeInt: - ccsSetInt (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetInt (setting, ReadIntegerAtKey (plugin, key), FALSE); break; case TypeFloat: - ccsSetFloat (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetFloat (setting, ReadFloatAtKey (plugin, key), FALSE); break; case TypeString: - ccsSetString (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetString (setting, ReadStringAtKey (plugin, key), FALSE); break; case TypeMatch: - ccsSetMatch (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetMatch (setting, ReadMatchAtKey (plugin, key), FALSE); break; case TypeColor: - ccsSetColor (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetColor (setting, ReadColorAtKey (plugin, key), FALSE); break; case TypeKey: - ccsSetKey (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetKey (setting, ReadKeyAtKey (plugin, key), FALSE); break; case TypeButton: - ccsSetButton (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetButton (setting, ReadButtonAtKey (plugin, key), FALSE); break; case TypeEdge: - ccsSetEdge (setting, ValueForKeyRetreival ().GetValueForKey (key, mValues), FALSE); + ccsSetEdge (setting, ReadEdgeAtKey (plugin, key), FALSE); break; case TypeBell: - ccsSetBell (setting, boolToBool (ValueForKeyRetreival ().GetValueForKey (key, mValues)), FALSE); + ccsSetBell (setting, ReadBellAtKey (plugin, key), FALSE); break; case TypeList: - ccsSetList (setting, *(ValueForKeyRetreival > ().GetValueForKey (key, mValues)), FALSE); + ccsSetList (setting, ReadListAtKey (plugin, key), FALSE); break; default: diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 9c9ff9426..7a80c0ef4 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -102,10 +102,32 @@ class CCSBackendConceptTestEnvironmentInterface virtual void WriteBellAtKey (const std::string &plugin, const std::string &key, const VariantTypes &value) = 0; - virtual void WriteListAtKey (const std::string &plugin, const std::string &key, const VariantTypes &value) = 0; + + virtual Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual float ReadFloatAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key) = 0; }; namespace -- GitLab From 6096edb6c150d073ce928cfa0ffba0bc770e5701 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 15:33:10 +0800 Subject: [PATCH 038/562] Added generic dispatch to the mock to write values to a map, renamed the read expectation functions --- ...nfig_test_ccs_mock_backend_conformance.cpp | 102 +++++++++++++++++- .../tests/compizconfig_backend_concept_test.h | 52 ++++----- 2 files changed, 125 insertions(+), 29 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 96aab4822..02dff282e 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -52,12 +52,19 @@ class MockCCSBackendConceptTestEnvironment : mBackend = ccsMockBackendNew (); mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); - ON_CALL (*mBackendGMock, readSetting (_,_)) + ON_CALL (*mBackendGMock, readSetting (_, _)) .WillByDefault ( WithArgs<1> ( Invoke ( this, - &MockCCSBackendConceptTestEnvironment::WriteValueToSetting))); + &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + + ON_CALL (*mBackendGMock, writeSetting (_, _)) + .WillByDefault ( + WithArgs<1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::WriteValueToMap))); return mBackend; } @@ -226,7 +233,7 @@ class MockCCSBackendConceptTestEnvironment : protected: - void WriteValueToSetting (CCSSetting *setting) + void ReadValueIntoSetting (CCSSetting *setting) { std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); std::string key (ccsSettingGetName (setting)); @@ -294,6 +301,95 @@ class MockCCSBackendConceptTestEnvironment : } } + void WriteValueToMap (CCSSetting *setting) + { + std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); + std::string key (ccsSettingGetName (setting)); + + Bool vBool; + int vInt; + float vFloat; + char *vString; + CCSSettingColorValue vColor; + CCSSettingKeyValue vKey; + CCSSettingButtonValue vButton; + unsigned int vEdge; + CCSSettingValueList vList; + + switch (ccsSettingGetType (setting)) + { + case TypeBool: + + ccsGetBool (setting, &vBool); + WriteBoolAtKey (plugin, key, VariantTypes (vBool ? true : false)); + break; + + case TypeInt: + + ccsGetInt (setting, &vInt); + WriteIntegerAtKey (plugin, key, VariantTypes (vInt)); + break; + + case TypeFloat: + + ccsGetFloat (setting, &vFloat); + WriteFloatAtKey (plugin, key, VariantTypes (vFloat)); + break; + + case TypeString: + + ccsGetString (setting, &vString); + WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); + break; + + case TypeMatch: + + ccsGetMatch (setting, &vString); + WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); + break; + + case TypeColor: + + ccsGetColor (setting, &vColor); + WriteColorAtKey (plugin, key, VariantTypes (vColor)); + break; + + case TypeKey: + + ccsGetKey (setting, &vKey); + WriteKeyAtKey (plugin, key, VariantTypes (vKey)); + break; + + case TypeButton: + + ccsGetButton (setting, &vButton); + WriteButtonAtKey (plugin, key, VariantTypes (vButton)); + break; + + case TypeEdge: + + ccsGetEdge (setting, &vEdge); + WriteEdgeAtKey (plugin, key, VariantTypes (vEdge)); + break; + + case TypeBell: + + ccsGetBell (setting, &vBool); + WriteBellAtKey (plugin, key, VariantTypes (vBool ? true : false)); + break; + + case TypeList: + + ccsGetList (setting, &vList); + WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (vList, false))); + break; + + default: + + throw std::exception (); + } + } + private: CCSBackend *mBackend; diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 7a80c0ef4..7d84f0ad5 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -134,57 +134,57 @@ namespace { Bool boolToBool (bool v) { return v ? TRUE : FALSE; } -void SetIntExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setInt (boost::get (value), _)); } -void SetBoolExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetBoolReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setBool (boolToBool (boost::get (value)), _)); } -void SetBellExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetBellReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setBell (boolToBool (boost::get (value)), _)); } -void SetFloatExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetFloatReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setFloat (boost::get (value), _)); } -void SetStringExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetStringReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setString (Eq (std::string (boost::get (value))), _)); } -void SetMatchExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetMatchReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setMatch (Eq (std::string (boost::get (value))), _)); } -void SetColorExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetColorReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setColor (_, _)); // can't match } -void SetKeyExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetKeyReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setKey (_, _)); // can't match } -void SetButtonExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetButtonReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setButton (_, _)); // can't match } -void SetEdgeExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetEdgeReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setEdge (boost::get (value), _)); } -void SetListExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +void SetListReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setList (_, _)); // can't match } @@ -388,70 +388,70 @@ GenerateTestingParametersForBackendInterface () boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, backendEnv, _1, _2, _3), TypeInt, "integer_setting", - boost::bind (SetIntExpectation, _1, _2), + boost::bind (SetIntReadExpectation, _1, _2), "TestRetreiveInt"), boost::make_shared (backendEnv, VariantTypes (true), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, backendEnv, _1, _2, _3), TypeBool, "boolean_setting", - boost::bind (SetBoolExpectation, _1, _2), + boost::bind (SetBoolReadExpectation, _1, _2), "TestRetreiveBool"), boost::make_shared (backendEnv, VariantTypes (static_cast (3.0)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, backendEnv, _1, _2, _3), TypeFloat, "float_setting", - boost::bind (SetFloatExpectation, _1, _2), + boost::bind (SetFloatReadExpectation, _1, _2), "TestRetreiveFloat"), boost::make_shared (backendEnv, VariantTypes (static_cast ("foo")), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, backendEnv, _1, _2, _3), TypeString, "string_setting", - boost::bind (SetStringExpectation, _1, _2), + boost::bind (SetStringReadExpectation, _1, _2), "TestRetreiveString"), boost::make_shared (backendEnv, VariantTypes (static_cast ("foo=bar")), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, backendEnv, _1, _2, _3), TypeMatch, "match_setting", - boost::bind (SetMatchExpectation, _1, _2), + boost::bind (SetMatchReadExpectation, _1, _2), "TestRetreiveMatch"), boost::make_shared (backendEnv, VariantTypes (true), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, backendEnv, _1, _2, _3), TypeBell, "bell_setting", - boost::bind (SetBellExpectation, _1, _2), + boost::bind (SetBellReadExpectation, _1, _2), "TestRetreiveBell"), boost::make_shared (backendEnv, VariantTypes (impl::colorValues[0]), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, backendEnv, _1, _2, _3), TypeColor, "color_setting", - boost::bind (SetColorExpectation, _1, _2), + boost::bind (SetColorReadExpectation, _1, _2), "TestRetreiveColor"), boost::make_shared (backendEnv, VariantTypes (impl::keyValue), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, backendEnv, _1, _2, _3), TypeKey, "key_setting", - boost::bind (SetKeyExpectation, _1, _2), + boost::bind (SetKeyReadExpectation, _1, _2), "TestRetreiveKey"), boost::make_shared (backendEnv, VariantTypes (impl::buttonValue), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, backendEnv, _1, _2, _3), TypeButton, "button_setting", - boost::bind (SetButtonExpectation, _1, _2), + boost::bind (SetButtonReadExpectation, _1, _2), "TestRetreiveButton"), boost::make_shared (backendEnv, VariantTypes (static_cast (1)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, backendEnv, _1, _2, _3), TypeEdge, "edge_setting", - boost::bind (SetEdgeExpectation, _1, _2), + boost::bind (SetEdgeReadExpectation, _1, _2), "TestRetreiveEdge"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, @@ -460,7 +460,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "int_list_setting", - boost::bind (SetListExpectation, _1, _2), + boost::bind (SetListReadExpectation, _1, _2), "TestRetreiveListInt"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, @@ -469,7 +469,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "float_list_setting", - boost::bind (SetListExpectation, _1, _2), + boost::bind (SetListReadExpectation, _1, _2), "TestRetreiveListInt"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, @@ -478,7 +478,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "bool_list_setting", - boost::bind (SetListExpectation, _1, _2), + boost::bind (SetListReadExpectation, _1, _2), "TestRetreiveListBool"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, @@ -487,7 +487,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "string_list_setting", - boost::bind (SetListExpectation, _1, _2), + boost::bind (SetListReadExpectation, _1, _2), "TestRetreiveListString"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, @@ -496,7 +496,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "color_list_setting", - boost::bind (SetListExpectation, _1, _2), + boost::bind (SetListReadExpectation, _1, _2), "TestRetreiveListColor") }; -- GitLab From 6528878386f41b1d343528b96c5a5f341d90a239 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 16:29:57 +0800 Subject: [PATCH 039/562] Implemented setting write tests --- ...nfig_test_ccs_mock_backend_conformance.cpp | 27 +- .../tests/compizconfig_backend_concept_test.h | 283 ++++++++++++++++-- 2 files changed, 277 insertions(+), 33 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 02dff282e..46858f5ce 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -76,12 +76,20 @@ class MockCCSBackendConceptTestEnvironment : } + void PreWrite () + { + EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); + } + + void PostWrite () + { + } + void WriteBoolAtKey (const std::string &plugin, const std::string &key, const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteIntegerAtKey (const std::string &plugin, @@ -90,7 +98,6 @@ class MockCCSBackendConceptTestEnvironment : { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteFloatAtKey (const std::string &plugin, @@ -98,7 +105,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteMatchAtKey (const std::string &plugin, @@ -106,7 +112,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteStringAtKey (const std::string &plugin, @@ -114,7 +119,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteColorAtKey (const std::string &plugin, @@ -122,7 +126,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteKeyAtKey (const std::string &plugin, @@ -130,7 +133,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteButtonAtKey (const std::string &plugin, @@ -138,7 +140,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteEdgeAtKey (const std::string &plugin, @@ -146,7 +147,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteBellAtKey (const std::string &plugin, @@ -154,7 +154,6 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } void WriteListAtKey (const std::string &plugin, @@ -162,9 +161,17 @@ class MockCCSBackendConceptTestEnvironment : const VariantTypes &value) { mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void PreRead () + { EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } + void PostRead () + { + } + virtual Bool ReadBoolAtKey (const std::string &plugin, const std::string &key) { diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 7d84f0ad5..3e69b1d1c 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -21,6 +21,9 @@ #include using ::testing::Eq; +using ::testing::SetArgPointee; +using ::testing::DoAll; +using ::testing::Return; class CCSListWrapper : boost::noncopyable @@ -72,6 +75,10 @@ class CCSBackendConceptTestEnvironmentInterface virtual ~CCSBackendConceptTestEnvironmentInterface () {}; virtual CCSBackend * SetUp () = 0; virtual void TearDown (CCSBackend *) = 0; + + virtual void PreWrite () = 0; + virtual void PostWrite () = 0; + virtual void WriteBoolAtKey (const std::string &plugin, const std::string &key, const VariantTypes &value) = 0; @@ -106,6 +113,9 @@ class CCSBackendConceptTestEnvironmentInterface const std::string &key, const VariantTypes &value) = 0; + virtual void PreRead () = 0; + virtual void PostRead () = 0; + virtual Bool ReadBoolAtKey (const std::string &plugin, const std::string &key) = 0; virtual int ReadIntegerAtKey (const std::string &plugin, @@ -132,8 +142,178 @@ class CCSBackendConceptTestEnvironmentInterface namespace { + +typedef boost::function WriteFunc; + Bool boolToBool (bool v) { return v ? TRUE : FALSE; } +void SetIntWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getInt (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadIntegerAtKey (plugin, setting), boost::get (value)); +} + +void SetBoolWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getBool (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boolToBool (boost::get (value))), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadBoolAtKey (plugin, setting), boolToBool (boost::get (value))); +} + +void SetFloatWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getFloat (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadFloatAtKey (plugin, setting), boost::get (value)); +} + +void SetStringWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getString (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + const_cast (boost::get (value))), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadStringAtKey (plugin, setting), boost::get (value)); +} + +void SetColorWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getColor (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + //EXPECT_EQ (env->ReadColorAtKey (plugin, setting), boost::get (value)); +} + +void SetKeyWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getKey (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + //EXPECT_EQ (env->ReadKeyAtKey (plugin, setting), boost::get (value)); +} + +void SetButtonWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getButton (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + //EXPECT_EQ (env->ReadButtonAtKey (plugin, setting), boost::get (value)); +} + +void SetEdgeWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getEdge (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadEdgeAtKey (plugin, setting), boost::get (value)); +} + +void SetBellWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getBell (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boolToBool (boost::get (value))), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadBellAtKey (plugin, setting), boolToBool (boost::get (value))); +} + +void SetMatchWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + EXPECT_CALL (*gmock, getMatch (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + const_cast (boost::get (value))), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadMatchAtKey (plugin, setting), boost::get (value)); +} + +void SetListWriteExpectation (const std::string &plugin, + const std::string &setting, + const VariantTypes &value, + CCSSettingGMock *gmock, + const WriteFunc &write, + CCSBackendConceptTestEnvironmentInterface *env) +{ + CCSSettingValueList list = *(boost::get > (value)); + + EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + list), + Return (TRUE))); + write (); + //EXPECT_EQ (env->ReadListAtKey (plugin, setting), boost::get (value)); +} + void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { EXPECT_CALL (*gmock, setInt (boost::get (value), _)); @@ -201,14 +381,21 @@ class CCSBackendConceptTestParamInterface const std::string &keyname, const VariantTypes &value)> NativeWriteMethod; typedef boost::function SetExpectation; + const VariantTypes &)> SetReadExpectation; + typedef boost::function SetWriteExpectation; virtual CCSBackendConceptTestEnvironmentInterface * testEnv () = 0; virtual VariantTypes & value () = 0; virtual NativeWriteMethod & nativeWrite () = 0; virtual CCSSettingType & type () = 0; virtual std::string & keyname () = 0; - virtual SetExpectation & setExpectation () = 0; + virtual SetWriteExpectation & setWriteExpectationAndWrite () = 0; + virtual SetReadExpectation & setReadExpectation () = 0; virtual std::string & what () = 0; }; @@ -225,14 +412,16 @@ class CCSBackendConceptTestParam : const NativeWriteMethod &write, const CCSSettingType &type, const std::string &keyname, - const SetExpectation &setExpectation, + const SetReadExpectation &setReadExpectation, + const SetWriteExpectation &setWriteExpectation, const std::string &what) : mTestEnv (testEnv), mValue (value), mNativeWrite (write), mType (type), mKeyname (keyname), - mSetExpectation (setExpectation), + mSetReadExpectation (setReadExpectation), + mSetWriteExpectation (setWriteExpectation), mWhat (what) { } @@ -242,7 +431,8 @@ class CCSBackendConceptTestParam : CCSBackendConceptTestParamInterface::NativeWriteMethod & nativeWrite () { return mNativeWrite; } CCSSettingType & type () { return mType; } std::string & keyname () { return mKeyname; } - CCSBackendConceptTestParamInterface::SetExpectation & setExpectation () { return mSetExpectation; } + CCSBackendConceptTestParamInterface::SetReadExpectation & setReadExpectation () { return mSetReadExpectation; } + CCSBackendConceptTestParamInterface::SetWriteExpectation & setWriteExpectationAndWrite () { return mSetWriteExpectation; } std::string & what () { return mWhat; } private: @@ -252,7 +442,8 @@ class CCSBackendConceptTestParam : NativeWriteMethod mNativeWrite; CCSSettingType mType; std::string mKeyname; - SetExpectation mSetExpectation; + SetReadExpectation mSetReadExpectation; + SetWriteExpectation mSetWriteExpectation; std::string mWhat; }; @@ -389,70 +580,80 @@ GenerateTestingParametersForBackendInterface () TypeInt, "integer_setting", boost::bind (SetIntReadExpectation, _1, _2), - "TestRetreiveInt"), + boost::bind (SetIntWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestInt"), boost::make_shared (backendEnv, VariantTypes (true), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, backendEnv, _1, _2, _3), TypeBool, "boolean_setting", boost::bind (SetBoolReadExpectation, _1, _2), - "TestRetreiveBool"), + boost::bind (SetBoolWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestBool"), boost::make_shared (backendEnv, VariantTypes (static_cast (3.0)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, backendEnv, _1, _2, _3), TypeFloat, "float_setting", boost::bind (SetFloatReadExpectation, _1, _2), - "TestRetreiveFloat"), + boost::bind (SetFloatWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestFloat"), boost::make_shared (backendEnv, VariantTypes (static_cast ("foo")), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, backendEnv, _1, _2, _3), TypeString, "string_setting", boost::bind (SetStringReadExpectation, _1, _2), - "TestRetreiveString"), + boost::bind (SetStringWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestString"), boost::make_shared (backendEnv, VariantTypes (static_cast ("foo=bar")), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, backendEnv, _1, _2, _3), TypeMatch, "match_setting", boost::bind (SetMatchReadExpectation, _1, _2), - "TestRetreiveMatch"), + boost::bind (SetMatchWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestMatch"), boost::make_shared (backendEnv, VariantTypes (true), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, backendEnv, _1, _2, _3), TypeBell, "bell_setting", boost::bind (SetBellReadExpectation, _1, _2), - "TestRetreiveBell"), + boost::bind (SetBellWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestBell"), boost::make_shared (backendEnv, VariantTypes (impl::colorValues[0]), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, backendEnv, _1, _2, _3), TypeColor, "color_setting", boost::bind (SetColorReadExpectation, _1, _2), - "TestRetreiveColor"), + boost::bind (SetColorWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestColor"), boost::make_shared (backendEnv, VariantTypes (impl::keyValue), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, backendEnv, _1, _2, _3), TypeKey, "key_setting", boost::bind (SetKeyReadExpectation, _1, _2), - "TestRetreiveKey"), + boost::bind (SetKeyWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestKey"), boost::make_shared (backendEnv, VariantTypes (impl::buttonValue), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, backendEnv, _1, _2, _3), TypeButton, "button_setting", boost::bind (SetButtonReadExpectation, _1, _2), - "TestRetreiveButton"), + boost::bind (SetButtonWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestButton"), boost::make_shared (backendEnv, VariantTypes (static_cast (1)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, backendEnv, _1, _2, _3), TypeEdge, "edge_setting", boost::bind (SetEdgeReadExpectation, _1, _2), - "TestRetreiveEdge"), + boost::bind (SetEdgeWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestEdge"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, sizeof (impl::intValues) / sizeof (impl::intValues[0]), @@ -461,7 +662,8 @@ GenerateTestingParametersForBackendInterface () TypeList, "int_list_setting", boost::bind (SetListReadExpectation, _1, _2), - "TestRetreiveListInt"), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListInt"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), @@ -470,7 +672,8 @@ GenerateTestingParametersForBackendInterface () TypeList, "float_list_setting", boost::bind (SetListReadExpectation, _1, _2), - "TestRetreiveListInt"), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListInt"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), @@ -479,7 +682,8 @@ GenerateTestingParametersForBackendInterface () TypeList, "bool_list_setting", boost::bind (SetListReadExpectation, _1, _2), - "TestRetreiveListBool"), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListBool"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), @@ -488,7 +692,8 @@ GenerateTestingParametersForBackendInterface () TypeList, "string_list_setting", boost::bind (SetListReadExpectation, _1, _2), - "TestRetreiveListString"), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListString"), boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), @@ -497,7 +702,8 @@ GenerateTestingParametersForBackendInterface () TypeList, "color_list_setting", boost::bind (SetListReadExpectation, _1, _2), - "TestRetreiveListColor") + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListColor") }; return ::testing::ValuesIn (testParam); @@ -507,7 +713,7 @@ GenerateTestingParametersForBackendInterface () TEST_P (CCSBackendConformanceTest, TestReadValue) { - SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what ()); + SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); std::string pluginName ("plugin"); const std::string &settingName (GetParam ()->keyname ()); @@ -519,11 +725,42 @@ TEST_P (CCSBackendConformanceTest, TestReadValue) CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (); CCSBackendConformanceTest::GetParam ()->nativeWrite () (pluginName, settingName, VALUE); - CCSBackendConformanceTest::GetParam ()->setExpectation () (gmockSetting, VALUE); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (); + CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context, setting); } +TEST_P (CCSBackendConformanceTest, TestWriteValue) +{ + SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); + + std::string pluginName ("plugin"); + const std::string &settingName (GetParam ()->keyname ()); + const VariantTypes &VALUE (GetParam ()->value ()); + + CCSContext *context = CCSBackendConformanceTest::SpawnContext (); + CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); + CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (); + CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, + settingName, + VALUE, + gmockSetting, + boost::bind (ccsBackendWriteSetting, + CCSBackendConformanceTest::GetBackend (), + context, + setting), + GetParam ()->testEnv ()); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostWrite (); + +} + + #endif -- GitLab From b678e80ed82b79e32062d4a2869626aa653eacaf Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 17:13:09 +0800 Subject: [PATCH 040/562] Match the button values --- compizconfig/libcompizconfig/include/ccs.h | 4 ++ compizconfig/libcompizconfig/src/main.c | 2 +- ...nfig_test_ccs_mock_backend_conformance.cpp | 1 - .../tests/compizconfig_backend_concept_test.h | 39 ++++++++++++++++--- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 70ccace01..1b752a1c5 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -764,6 +764,10 @@ Bool ccsIsEqualKey (CCSSettingKeyValue c1, Bool ccsIsEqualButton (CCSSettingButtonValue c1, CCSSettingButtonValue c2); +/* Compares lists */ +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, + CCSSettingListInfo info); + /* Retrieves a list of settings in a plugin */ CCSSettingList ccsGetPluginSettings (CCSPlugin *plugin); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 4efca5da8..857322d69 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1601,7 +1601,7 @@ static Bool ccsBackendCapabilitiesDeleteProfileWrapper (CCSBackend *backend, CCS return FALSE; } -static Bool +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, CCSSettingListInfo info) { diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 46858f5ce..7d8909fd9 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -73,7 +73,6 @@ class MockCCSBackendConceptTestEnvironment : { ccsFreeMockBackend (backend); - } void PreWrite () diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 3e69b1d1c..a327807df 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -25,6 +25,33 @@ using ::testing::SetArgPointee; using ::testing::DoAll; using ::testing::Return; +bool +operator== (const CCSSettingColorValue &lhs, + const CCSSettingColorValue &rhs) +{ + if (ccsIsEqualColor (lhs, rhs)) + return true; + return false; +} + +bool +operator== (const CCSSettingKeyValue &lhs, + const CCSSettingKeyValue &rhs) +{ + if (ccsIsEqualKey (lhs, rhs)) + return true; + return false; +} + +bool +operator== (const CCSSettingButtonValue &lhs, + const CCSSettingButtonValue &rhs) +{ + if (ccsIsEqualButton (lhs, rhs)) + return true; + return false; +} + class CCSListWrapper : boost::noncopyable { @@ -219,7 +246,7 @@ void SetColorWriteExpectation (const std::string &plugin, boost::get (value)), Return (TRUE))); write (); - //EXPECT_EQ (env->ReadColorAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadColorAtKey (plugin, setting), boost::get (value)); } void SetKeyWriteExpectation (const std::string &plugin, @@ -234,7 +261,7 @@ void SetKeyWriteExpectation (const std::string &plugin, boost::get (value)), Return (TRUE))); write (); - //EXPECT_EQ (env->ReadKeyAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadKeyAtKey (plugin, setting), boost::get (value)); } void SetButtonWriteExpectation (const std::string &plugin, @@ -249,7 +276,7 @@ void SetButtonWriteExpectation (const std::string &plugin, boost::get (value)), Return (TRUE))); write (); - //EXPECT_EQ (env->ReadButtonAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadButtonAtKey (plugin, setting), boost::get (value)); } void SetEdgeWriteExpectation (const std::string &plugin, @@ -346,17 +373,17 @@ void SetMatchReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) void SetColorReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setColor (_, _)); // can't match + EXPECT_CALL (*gmock, setColor (boost::get (value), _)); // can't match } void SetKeyReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setKey (_, _)); // can't match + EXPECT_CALL (*gmock, setKey (boost::get (value), _)); // can't match } void SetButtonReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setButton (_, _)); // can't match + EXPECT_CALL (*gmock, setButton (boost::get (value), _)); // can't match } void SetEdgeReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) -- GitLab From 5a6ef19190142453b3d3e950a3cb74ea0d6648bd Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 18:18:09 +0800 Subject: [PATCH 041/562] Match lists correctly --- ...nfig_test_ccs_mock_backend_conformance.cpp | 2 +- .../tests/compizconfig_backend_concept_test.h | 157 +++++++++++++----- 2 files changed, 113 insertions(+), 46 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 7d8909fd9..a4f0b110e 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -387,7 +387,7 @@ class MockCCSBackendConceptTestEnvironment : case TypeList: ccsGetList (setting, &vList); - WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (vList, false))); + WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (vList, false, ccsSettingGetInfo (setting)->forList.listType))); break; default: diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index a327807df..572035929 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -24,6 +24,49 @@ using ::testing::Eq; using ::testing::SetArgPointee; using ::testing::DoAll; using ::testing::Return; +using ::testing::MakeMatcher; +using ::testing::Matcher; +using ::testing::MatcherInterface; +using ::testing::MatchResultListener; + +class ListEqualityMatcher : + public MatcherInterface +{ + public: + + ListEqualityMatcher (CCSSettingListInfo info, + CCSSettingValueList cmp) : + mInfo (info), + mCmp (cmp) + { + } + + virtual bool MatchAndExplain (CCSSettingValueList x, MatchResultListener *listener) const + { + return ccsCompareLists (x, mCmp, mInfo); + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "lists are equal"; + } + + virtual void DescribeNegationTo (std::ostream *os) const + { + *os << "lists are not equal"; + } + + private: + + CCSSettingListInfo mInfo; + CCSSettingValueList mCmp; +}; + +Matcher ListEqual (CCSSettingListInfo info, + CCSSettingValueList cmp) +{ + return MakeMatcher (new ListEqualityMatcher (info, cmp)); +} bool operator== (const CCSSettingColorValue &lhs, @@ -59,12 +102,15 @@ class CCSListWrapper : typedef boost::shared_ptr Ptr; - CCSListWrapper (CCSSettingValueList list, bool freeItems) : + CCSListWrapper (CCSSettingValueList list, bool freeItems, CCSSettingType type) : mList (list), - mFreeItems (freeItems) + mFreeItems (freeItems), + mType (type) { } + CCSSettingType type () { return mType; } + operator CCSSettingValueList () { return mList; @@ -83,6 +129,7 @@ class CCSListWrapper : CCSSettingValueList mList; bool mFreeItems; + CCSSettingType mType; }; typedef boost::variant WriteFunc; Bool boolToBool (bool v) { return v ? TRUE : FALSE; } +CCSSettingGMock * getSettingGMockFromSetting (CCSSetting *setting) { return (CCSSettingGMock *) ccsObjectGetPrivate (setting); } + void SetIntWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getInt (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boost::get (value)), Return (TRUE))); write (); - EXPECT_EQ (env->ReadIntegerAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadIntegerAtKey (plugin, key), boost::get (value)); } void SetBoolWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getBool (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boolToBool (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadBoolAtKey (plugin, setting), boolToBool (boost::get (value))); + EXPECT_EQ (env->ReadBoolAtKey (plugin, key), boolToBool (boost::get (value))); } void SetFloatWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getFloat (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boost::get (value)), Return (TRUE))); write (); - EXPECT_EQ (env->ReadFloatAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadFloatAtKey (plugin, key), boost::get (value)); } void SetStringWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getString (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( const_cast (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadStringAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadStringAtKey (plugin, key), boost::get (value)); } void SetColorWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getColor (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boost::get (value)), Return (TRUE))); write (); - EXPECT_EQ (env->ReadColorAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadColorAtKey (plugin, key), boost::get (value)); } void SetKeyWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getKey (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boost::get (value)), Return (TRUE))); write (); - EXPECT_EQ (env->ReadKeyAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadKeyAtKey (plugin, key), boost::get (value)); } void SetButtonWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getButton (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boost::get (value)), Return (TRUE))); write (); - EXPECT_EQ (env->ReadButtonAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadButtonAtKey (plugin, key), boost::get (value)); } void SetEdgeWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getEdge (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boost::get (value)), Return (TRUE))); write (); - EXPECT_EQ (env->ReadEdgeAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadEdgeAtKey (plugin, key), boost::get (value)); } void SetBellWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getBell (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( boolToBool (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadBellAtKey (plugin, setting), boolToBool (boost::get (value))); + EXPECT_EQ (env->ReadBellAtKey (plugin, key), boolToBool (boost::get (value))); } void SetMatchWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getMatch (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( const_cast (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadMatchAtKey (plugin, setting), boost::get (value)); + EXPECT_EQ (env->ReadMatchAtKey (plugin, key), boost::get (value)); } void SetListWriteExpectation (const std::string &plugin, - const std::string &setting, + const std::string &key, const VariantTypes &value, - CCSSettingGMock *gmock, + CCSSetting *setting, const WriteFunc &write, CCSBackendConceptTestEnvironmentInterface *env) { + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); CCSSettingValueList list = *(boost::get > (value)); + boost::shared_ptr info (boost::make_shared ()); + info->forList.listType = (boost::get > (value))->type (); + + EXPECT_CALL (*gmock, getInfo ()).WillRepeatedly (Return (info.get ())); EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( list), Return (TRUE))); write (); - //EXPECT_EQ (env->ReadListAtKey (plugin, setting), boost::get (value)); + EXPECT_THAT (env->ReadListAtKey (plugin, key), ListEqual (ccsSettingGetInfo (setting)->forList, list)); } void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) @@ -393,7 +457,12 @@ void SetEdgeReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) void SetListReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setList (_, _)); // can't match + CCSSettingInfo info; + + info.forList.listType = (boost::get > (value))->type (); + info.forList.listInfo = NULL; + + EXPECT_CALL (*gmock, setList (ListEqual (info.forList, *(boost::get > (value))), _)); // can't match } } @@ -412,7 +481,7 @@ class CCSBackendConceptTestParamInterface typedef boost::function SetWriteExpectation; @@ -684,7 +753,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, sizeof (impl::intValues) / sizeof (impl::intValues[0]), - NULL), false)), + NULL), false, TypeInt)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "int_list_setting", @@ -694,7 +763,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), - NULL), false)), + NULL), false, TypeFloat)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "float_list_setting", @@ -704,7 +773,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), - NULL), false)), + NULL), false, TypeBool)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "bool_list_setting", @@ -714,7 +783,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), - NULL), false)), + NULL), false, TypeString)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "string_list_setting", @@ -724,7 +793,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnv, VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), - NULL), false)), + NULL), false, TypeColor)), boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), TypeList, "color_list_setting", @@ -772,13 +841,11 @@ TEST_P (CCSBackendConformanceTest, TestWriteValue) CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (); CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, settingName, VALUE, - gmockSetting, + setting, boost::bind (ccsBackendWriteSetting, CCSBackendConformanceTest::GetBackend (), context, -- GitLab From 8c4a986bb0c213bf5976858731066ab342777bb2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 11 Jul 2012 18:42:04 +0800 Subject: [PATCH 042/562] Adjust GSettings tests for shifting around of files --- compizconfig/gsettings/tests/CMakeLists.txt | 5 +++-- compizconfig/gsettings/tests/gsettings_mocks.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 29ba72919..57f6ceb30 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,6 +1,7 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src - ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests) + ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests + ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) @@ -15,7 +16,7 @@ link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) target_link_libraries (compizconfig_test_gsettings gsettings_backend_shared - setting-mock + compizconfig_ccs_setting_mock ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) diff --git a/compizconfig/gsettings/tests/gsettings_mocks.h b/compizconfig/gsettings/tests/gsettings_mocks.h index c63b62083..5cbcaea60 100644 --- a/compizconfig/gsettings/tests/gsettings_mocks.h +++ b/compizconfig/gsettings/tests/gsettings_mocks.h @@ -2,7 +2,7 @@ #define _COMPIZ_COMPIZCONFIG_GSETTINGS_MOCKS #include -#include +#include G_BEGIN_DECLS -- GitLab From 7f6effcc0ec789405f509306d030bf6fe1749b25 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 01:37:22 +0800 Subject: [PATCH 043/562] We can in fact, match the incoming values. Remove outdated comment --- compizconfig/tests/compizconfig_backend_concept_test.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 572035929..b09b366c3 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -437,17 +437,17 @@ void SetMatchReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) void SetColorReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setColor (boost::get (value), _)); // can't match + EXPECT_CALL (*gmock, setColor (boost::get (value), _)); } void SetKeyReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setKey (boost::get (value), _)); // can't match + EXPECT_CALL (*gmock, setKey (boost::get (value), _)); } void SetButtonReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setButton (boost::get (value), _)); // can't match + EXPECT_CALL (*gmock, setButton (boost::get (value), _)); } void SetEdgeReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) @@ -462,7 +462,7 @@ void SetListReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) info.forList.listType = (boost::get > (value))->type (); info.forList.listInfo = NULL; - EXPECT_CALL (*gmock, setList (ListEqual (info.forList, *(boost::get > (value))), _)); // can't match + EXPECT_CALL (*gmock, setList (ListEqual (info.forList, *(boost::get > (value))), _)); } } -- GitLab From 7c8b777642e0024c6ecdaa06273d448c07b298a6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 01:54:34 +0800 Subject: [PATCH 044/562] Moved key read into a separate function --- compizconfig/gsettings/src/gsettings.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index bdb18f0ac..d43db7a83 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -363,12 +363,11 @@ readIntegratedOption (CCSContext *context, #endif } -Bool -readOption (CCSSetting * setting) +GVariant * +getVariantAtKeyForSetting (CCSSetting *setting) { GSettings *settings = getSettingsObjectForCCSSetting (setting); GVariant *gsettingsValue = NULL; - Bool ret = FALSE; /* It is impossible for certain settings to have a schema, * such as actions and read only settings, so in that case @@ -378,7 +377,7 @@ readOption (CCSSetting * setting) if (ccsSettingGetType (setting) == TypeAction || ccsSettingIsReadOnly (setting)) { - return FALSE; + return NULL; } char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); @@ -389,7 +388,7 @@ readOption (CCSSetting * setting) if (!gsettingsValue) { free (cleanSettingName); - return FALSE; + return NULL; } if (!variantIsValidForCCSType (gsettingsValue, ccsSettingGetType (setting))) @@ -405,6 +404,19 @@ readOption (CCSSetting * setting) return FALSE; } + free (cleanSettingName); + return gsettingsValue; +} + +Bool +readOption (CCSSetting * setting) +{ + Bool ret = FALSE; + GVariant *gsettingsValue = getVariantAtKeyForSetting (setting); + + if (!gsettingsValue) + return FALSE; + switch (ccsSettingGetType (setting)) { case TypeString: @@ -527,7 +539,6 @@ readOption (CCSSetting * setting) break; } - free (cleanSettingName); g_variant_unref (gsettingsValue); return ret; -- GitLab From a7c742952f40ed44b27096bb776fb0ba62ce0f7e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 02:18:25 +0800 Subject: [PATCH 045/562] Refactored out some of the gvariant reading code --- .../gsettings_backend_shared/gsettings_util.c | 5 ++ .../gsettings_backend_shared/gsettings_util.h | 3 + compizconfig/gsettings/src/gsettings.c | 75 ++++++++++++------- .../gsettings/tests/test_gsettings_tests.cpp | 21 ++++++ 4 files changed, 75 insertions(+), 29 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 688771918..46a5326e1 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -340,3 +340,8 @@ makeCompizPluginPath (const gchar *profileName, const gchar *pluginName) "plugins", pluginName, "/", NULL); } +gchar * +getNameForCCSSetting (CCSSetting *setting) +{ + return translateKeyForGSettings (ccsSettingGetName (setting)); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 944f172ca..57722a01d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -65,4 +65,7 @@ makeCompizProfilePath (const gchar *profilename); gchar * makeCompizPluginPath (const gchar *profileName, const gchar *pluginName); +gchar * +getNameForCCSSetting (CCSSetting *setting); + #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index d43db7a83..820e8a821 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -363,47 +363,44 @@ readIntegratedOption (CCSContext *context, #endif } -GVariant * -getVariantAtKeyForSetting (CCSSetting *setting) +Bool +checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, gchar *pathName) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); - GVariant *gsettingsValue = NULL; - - /* It is impossible for certain settings to have a schema, - * such as actions and read only settings, so in that case - * just return FALSE since compizconfig doesn't expect us - * to read them anyways */ - - if (ccsSettingGetType (setting) == TypeAction || - ccsSettingIsReadOnly (setting)) - { - return NULL; - } - - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - /* first check if the key is set */ - gsettingsValue = g_settings_get_value (settings, cleanSettingName); - if (!gsettingsValue) { - free (cleanSettingName); - return NULL; + ccsWarning ("There is no key at the path %s. " + "Settings from this path won't be read. Try to remove " + "that value so that operation can continue properly.", + pathName); + return FALSE; } - if (!variantIsValidForCCSType (gsettingsValue, ccsSettingGetType (setting))) + if (!variantIsValidForCCSType (gsettingsValue, type)) { - gchar *pathName = makeSettingPath (setting); ccsWarning ("There is an unsupported value at path %s. " "Settings from this path won't be read. Try to remove " "that value so that operation can continue properly.", pathName); - g_free (pathName); - free (cleanSettingName); - g_variant_unref (gsettingsValue); return FALSE; } + return TRUE; +} + +GVariant * +getVariantAtKey (GSettings *settings, char *key) +{ + return g_settings_get_value (settings, key); +} + +GVariant * +getVariantForCCSSetting (CCSSetting *setting) +{ + GSettings *settings = getSettingsObjectForCCSSetting (setting); + char *cleanSettingName = getNameForCCSSetting (setting); + GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName); + free (cleanSettingName); return gsettingsValue; } @@ -412,10 +409,29 @@ Bool readOption (CCSSetting * setting) { Bool ret = FALSE; - GVariant *gsettingsValue = getVariantAtKeyForSetting (setting); + GVariant *gsettingsValue = NULL; - if (!gsettingsValue) + /* It is impossible for certain settings to have a schema, + * such as actions and read only settings, so in that case + * just return FALSE since compizconfig doesn't expect us + * to read them anyways */ + + if (ccsSettingGetType (setting) == TypeAction || + ccsSettingIsReadOnly (setting)) + { + return FALSE; + } + + gsettingsValue = getVariantForCCSSetting (setting); + + gchar *pathName = makeSettingPath (setting); + + if (!checkReadVariantIsValid (gsettingsValue, ccsSettingGetType (setting), pathName)) + { + g_free (pathName); + g_variant_unref (gsettingsValue); return FALSE; + } switch (ccsSettingGetType (setting)) { @@ -539,6 +555,7 @@ readOption (CCSSetting * setting) break; } + g_free (pathName); g_variant_unref (gsettingsValue); return ret; diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 9a7d42e35..278a00427 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -869,3 +869,24 @@ TEST_P(CCSGSettingsTestVariantTypeToCCSTypeListFixture, TestVariantTypesInListTe INSTANTIATE_TEST_CASE_P(CCSGSettingsTestVariantTypeToCCSTypeListInstantiation, CCSGSettingsTestVariantTypeToCCSTypeListFixture, ValuesIn (variantTypeToListOfCCSTypes)); + +TEST_F(CCSGSettingsTestIndependent, TestGetNameForCCSSetting) +{ + CCSSetting *setting = ccsMockSettingNew (); + CCSSettingGMock *gmock = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + char *rawSettingName = strdup ("FoO_BaR"); + char *properSettingName = translateKeyForGSettings (rawSettingName); + + EXPECT_CALL (*gmock, getName ()).WillOnce (Return (rawSettingName)); + + char *translatedSettingName = getNameForCCSSetting (setting); + + EXPECT_EQ (std::string (translatedSettingName), std::string (properSettingName)); + EXPECT_NE (std::string (translatedSettingName), std::string (rawSettingName)); + + free (translatedSettingName); + free (properSettingName); + free (rawSettingName); + + ccsSettingUnref (setting); +} -- GitLab From c7d13cdf7cef1b51cb5afc19fc5bfd55214eccd9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 02:26:19 +0800 Subject: [PATCH 046/562] Refactor the read code a bit more --- compizconfig/gsettings/src/gsettings.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 820e8a821..ee06e5b72 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -389,9 +389,17 @@ checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, gchar *p } GVariant * -getVariantAtKey (GSettings *settings, char *key) +getVariantAtKey (GSettings *settings, char *key, char *pathName, CCSSettingType type) { - return g_settings_get_value (settings, key); + GVariant *gsettingsValue = g_settings_get_value (settings, key); + + if (!checkReadVariantIsValid (gsettingsValue, type, pathName)) + { + g_variant_unref (gsettingsValue); + return NULL; + } + + return gsettingsValue; } GVariant * @@ -399,9 +407,11 @@ getVariantForCCSSetting (CCSSetting *setting) { GSettings *settings = getSettingsObjectForCCSSetting (setting); char *cleanSettingName = getNameForCCSSetting (setting); - GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName); + gchar *pathName = makeSettingPath (setting); + GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName, pathName, ccsSettingGetType (setting)); free (cleanSettingName); + free (pathName); return gsettingsValue; } @@ -424,15 +434,6 @@ readOption (CCSSetting * setting) gsettingsValue = getVariantForCCSSetting (setting); - gchar *pathName = makeSettingPath (setting); - - if (!checkReadVariantIsValid (gsettingsValue, ccsSettingGetType (setting), pathName)) - { - g_free (pathName); - g_variant_unref (gsettingsValue); - return FALSE; - } - switch (ccsSettingGetType (setting)) { case TypeString: @@ -555,7 +556,6 @@ readOption (CCSSetting * setting) break; } - g_free (pathName); g_variant_unref (gsettingsValue); return ret; -- GitLab From 47957d4e54af166d09e3a6c29bf5e5dd5bbb8a35 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 02:33:57 +0800 Subject: [PATCH 047/562] Move some util functions into util library --- .../gsettings_backend_shared/gsettings_util.c | 39 ++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 7 ++++ compizconfig/gsettings/src/gsettings.c | 41 +------------------ .../gsettings/tests/test_gsettings_tests.cpp | 23 +++++++++++ 4 files changed, 70 insertions(+), 40 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 46a5326e1..d2e532e34 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -345,3 +345,42 @@ getNameForCCSSetting (CCSSetting *setting) { return translateKeyForGSettings (ccsSettingGetName (setting)); } + +Bool +checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName) +{ + /* first check if the key is set */ + if (!gsettingsValue) + { + ccsWarning ("There is no key at the path %s. " + "Settings from this path won't be read. Try to remove " + "that value so that operation can continue properly.", + pathName); + return FALSE; + } + + if (!variantIsValidForCCSType (gsettingsValue, type)) + { + ccsWarning ("There is an unsupported value at path %s. " + "Settings from this path won't be read. Try to remove " + "that value so that operation can continue properly.", + pathName); + return FALSE; + } + + return TRUE; +} + +GVariant * +getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettingType type) +{ + GVariant *gsettingsValue = g_settings_get_value (settings, key); + + if (!checkReadVariantIsValid (gsettingsValue, type, pathName)) + { + g_variant_unref (gsettingsValue); + return NULL; + } + + return gsettingsValue; +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 57722a01d..e13a9a539 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -3,6 +3,7 @@ #include #include +#include #include gchar * @@ -68,4 +69,10 @@ makeCompizPluginPath (const gchar *profileName, const gchar *pluginName); gchar * getNameForCCSSetting (CCSSetting *setting); +Bool +checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName); + +GVariant * +getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettingType type); + #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index ee06e5b72..a7d4fcf06 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -363,46 +363,7 @@ readIntegratedOption (CCSContext *context, #endif } -Bool -checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, gchar *pathName) -{ - /* first check if the key is set */ - if (!gsettingsValue) - { - ccsWarning ("There is no key at the path %s. " - "Settings from this path won't be read. Try to remove " - "that value so that operation can continue properly.", - pathName); - return FALSE; - } - - if (!variantIsValidForCCSType (gsettingsValue, type)) - { - ccsWarning ("There is an unsupported value at path %s. " - "Settings from this path won't be read. Try to remove " - "that value so that operation can continue properly.", - pathName); - return FALSE; - } - - return TRUE; -} - -GVariant * -getVariantAtKey (GSettings *settings, char *key, char *pathName, CCSSettingType type) -{ - GVariant *gsettingsValue = g_settings_get_value (settings, key); - - if (!checkReadVariantIsValid (gsettingsValue, type, pathName)) - { - g_variant_unref (gsettingsValue); - return NULL; - } - - return gsettingsValue; -} - -GVariant * +static GVariant * getVariantForCCSSetting (CCSSetting *setting) { GSettings *settings = getSettingsObjectForCCSSetting (setting); diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 278a00427..7c9858ea0 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -890,3 +890,26 @@ TEST_F(CCSGSettingsTestIndependent, TestGetNameForCCSSetting) ccsSettingUnref (setting); } + +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidNULL) +{ + EXPECT_FALSE (checkReadVariantIsValid (NULL, TypeNum, "foo/bar")); +} + +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeBad) +{ + GVariant *v = g_variant_new ("i", 1); + + EXPECT_FALSE (checkReadVariantIsValid (v, TypeString, "foo/bar")); + + g_variant_unref (v); +} + +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeGood) +{ + GVariant *v = g_variant_new ("i", 1); + + EXPECT_FALSE (checkReadVariantIsValid (v, TypeInt, "foo/bar")); + + g_variant_unref (v); +} -- GitLab From c4c5e41a63014f3a5b3d312797bde4c3be6d8474 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 02:49:07 +0800 Subject: [PATCH 048/562] Refactored out all the variant read functions (except lists) --- compizconfig/gsettings/src/gsettings.c | 130 ++++++++++++++++++------- 1 file changed, 97 insertions(+), 33 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index a7d4fcf06..2cc5da8da 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -376,6 +376,79 @@ getVariantForCCSSetting (CCSSetting *setting) return gsettingsValue; } +const char * readStringFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_string (gsettingsValue, NULL); +} + +int readIntFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_int32 (gsettingsValue); +} + +Bool readBoolFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_boolean (gsettingsValue) ? TRUE : FALSE; +} + +float readFloatFromVariant (GVariant *gsettingsValue) +{ + return (float) g_variant_get_double (gsettingsValue); +} + +CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingColorValue color; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToColor (value, &color); + else + *success = FALSE; + + return color; +} + +CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingKeyValue key; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToKeyBinding (value, &key); + else + *success = FALSE; + + return key; +} + +CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingButtonValue button; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToButtonBinding (value, &button); + else + *success = FALSE; + + return button; +} + +unsigned int readEdgeFromVariant (GVariant *gsettingsValue) +{ + const char *value; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + return ccsStringToEdges (value); + + return 0; +} + Bool readOption (CCSSetting * setting) { @@ -400,7 +473,7 @@ readOption (CCSSetting * setting) case TypeString: { const char *value; - value = g_variant_get_string (gsettingsValue, NULL); + value = readStringFromVariant (gsettingsValue); if (value) { ccsSetString (setting, value, TRUE); @@ -411,7 +484,7 @@ readOption (CCSSetting * setting) case TypeMatch: { const char * value; - value = g_variant_get_string (gsettingsValue, NULL); + value = readStringFromVariant (gsettingsValue); if (value) { ccsSetMatch (setting, value, TRUE); @@ -422,7 +495,7 @@ readOption (CCSSetting * setting) case TypeInt: { int value; - value = g_variant_get_int32 (gsettingsValue); + value = readIntFromVariant (gsettingsValue); ccsSetInt (setting, value, TRUE); ret = TRUE; @@ -430,29 +503,28 @@ readOption (CCSSetting * setting) break; case TypeBool: { - gboolean value; - value = g_variant_get_boolean (gsettingsValue); + Bool value; + value = readBoolFromVariant (gsettingsValue); - ccsSetBool (setting, value ? TRUE : FALSE, TRUE); + ccsSetBool (setting, value, TRUE); ret = TRUE; } break; case TypeFloat: { - double value; - value = g_variant_get_double (gsettingsValue); + float value; + value = readFloatFromVariant (gsettingsValue); - ccsSetFloat (setting, (float)value, TRUE); + ccsSetFloat (setting, value, TRUE); ret = TRUE; } break; case TypeColor: { - const char *value; - CCSSettingColorValue color; - value = g_variant_get_string (gsettingsValue, NULL); + Bool success = FALSE; + CCSSettingColorValue color = readColorFromVariant (gsettingsValue, &success); - if (value && ccsStringToColor (value, &color)) + if (success) { ccsSetColor (setting, color, TRUE); ret = TRUE; @@ -461,11 +533,10 @@ readOption (CCSSetting * setting) break; case TypeKey: { - const char *value; - CCSSettingKeyValue key; - value = g_variant_get_string (gsettingsValue, NULL); + Bool success = FALSE; + CCSSettingKeyValue key = readKeyFromVariant (gsettingsValue, &success); - if (value && ccsStringToKeyBinding (value, &key)) + if (success) { ccsSetKey (setting, key, TRUE); ret = TRUE; @@ -474,11 +545,10 @@ readOption (CCSSetting * setting) break; case TypeButton: { - const char *value; - CCSSettingButtonValue button; - value = g_variant_get_string (gsettingsValue, NULL); + Bool success = FALSE; + CCSSettingButtonValue button = readButtonFromVariant (gsettingsValue, &success); - if (value && ccsStringToButtonBinding (value, &button)) + if (success) { ccsSetButton (setting, button, TRUE); ret = TRUE; @@ -487,24 +557,18 @@ readOption (CCSSetting * setting) break; case TypeEdge: { - const char *value; - value = g_variant_get_string (gsettingsValue, NULL); + unsigned int edges = readEdgeFromVariant (gsettingsValue); - if (value) - { - unsigned int edges; - edges = ccsStringToEdges (value); - ccsSetEdge (setting, edges, TRUE); - ret = TRUE; - } + ccsSetEdge (setting, edges, TRUE); + ret = TRUE; } break; case TypeBell: { - gboolean value; - value = g_variant_get_boolean (gsettingsValue); + Bool value; + value = readBoolFromVariant (gsettingsValue); - ccsSetBell (setting, value ? TRUE : FALSE, TRUE); + ccsSetBell (setting, value, TRUE); ret = TRUE; } break; -- GitLab From ee212f4153b0e8285b1c670d0d0c8d165df10ad5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 03:02:20 +0800 Subject: [PATCH 049/562] Implement readListValue in terms of GVariant --- compizconfig/gsettings/src/gsettings.c | 63 ++++++++++++-------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 2cc5da8da..6d8212435 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -217,34 +217,23 @@ valueChanged (GSettings *settings, g_free (pathOrig); } -static Bool -readListValue (CCSSetting *setting) +static CCSSettingValueList +readListValue (GVariant *gsettingsValue, CCSSettingType listType) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); gboolean hasVariantType; unsigned int nItems, i = 0; CCSSettingValueList list = NULL; - GVariant *value; GVariantIter iter; - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - hasVariantType = compizconfigTypeHasVariantType (ccsSettingGetInfo (setting)->forList.listType); + hasVariantType = compizconfigTypeHasVariantType (listType); if (!hasVariantType) - return FALSE; - - value = g_settings_get_value (settings, cleanSettingName); - if (!value) - { - ccsSetList (setting, NULL, TRUE); - return TRUE; - } + return NULL; - g_variant_iter_init (&iter, value); + g_variant_iter_init (&iter, gsettingsValue); nItems = g_variant_iter_n_children (&iter); - switch (ccsSettingGetInfo (setting)->forList.listType) + switch (listType) { case TypeBool: { @@ -259,7 +248,7 @@ readListValue (CCSSetting *setting) while (g_variant_iter_loop (&iter, "b", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromBoolArray (array, nItems, setting); + list = ccsGetValueListFromBoolArray (array, nItems, NULL); free (array); } break; @@ -276,7 +265,7 @@ readListValue (CCSSetting *setting) while (g_variant_iter_loop (&iter, "i", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromIntArray (array, nItems, setting); + list = ccsGetValueListFromIntArray (array, nItems, NULL); free (array); } break; @@ -293,7 +282,7 @@ readListValue (CCSSetting *setting) while (g_variant_iter_loop (&iter, "d", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromFloatArray ((float *) array, nItems, setting); + list = ccsGetValueListFromFloatArray ((float *) array, nItems, NULL); free (array); } break; @@ -313,7 +302,7 @@ readListValue (CCSSetting *setting) while (g_variant_iter_next (&iter, "s", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromStringArray (array, nItems, setting); + list = ccsGetValueListFromStringArray (array, nItems, NULL); g_strfreev ((char **) array); } break; @@ -331,7 +320,7 @@ readListValue (CCSSetting *setting) ccsStringToColor (colorValue, &array[i]); } - list = ccsGetValueListFromColorArray (array, nItems, setting); + list = ccsGetValueListFromColorArray (array, nItems, NULL); free (array); } break; @@ -339,16 +328,7 @@ readListValue (CCSSetting *setting) break; } - free (cleanSettingName); - - if (list) - { - ccsSetList (setting, list, TRUE); - ccsSettingValueListFree (list, TRUE); - return TRUE; - } - - return FALSE; + return list; } static Bool @@ -573,7 +553,24 @@ readOption (CCSSetting * setting) } break; case TypeList: - ret = readListValue (setting); + { + CCSSettingValueList list = readListValue (gsettingsValue, ccsSettingGetInfo (setting)->forList.listType); + + if (list) + { + CCSSettingValueList iter = list; + + while (iter) + { + ((CCSSettingValue *) iter->data)->parent = setting; + iter = iter->next; + } + + ccsSetList (setting, list, TRUE); + ccsSettingValueListFree (list, TRUE); + ret = TRUE; + } + } break; default: ccsWarning ("Attempt to read unsupported setting type %d!", -- GitLab From aaf2eb278834c633bd95cadbb158e917789f1ea8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 03:05:03 +0800 Subject: [PATCH 050/562] Move readListValue closer to the other variant readers --- compizconfig/gsettings/src/gsettings.c | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 6d8212435..2ef153154 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -217,7 +217,32 @@ valueChanged (GSettings *settings, g_free (pathOrig); } -static CCSSettingValueList +static Bool +readIntegratedOption (CCSContext *context, + CCSSetting *setting, + int index) +{ +#ifdef USE_GCONF + return readGConfIntegratedOption (context, setting, index); +#else + return FALSE; +#endif +} + +static GVariant * +getVariantForCCSSetting (CCSSetting *setting) +{ + GSettings *settings = getSettingsObjectForCCSSetting (setting); + char *cleanSettingName = getNameForCCSSetting (setting); + gchar *pathName = makeSettingPath (setting); + GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName, pathName, ccsSettingGetType (setting)); + + free (cleanSettingName); + free (pathName); + return gsettingsValue; +} + +CCSSettingValueList readListValue (GVariant *gsettingsValue, CCSSettingType listType) { gboolean hasVariantType; @@ -315,7 +340,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) break; while (g_variant_iter_loop (&iter, "s", &colorValue)) - { + { memset (&array[i], 0, sizeof (CCSSettingColorValue)); ccsStringToColor (colorValue, &array[i]); @@ -331,31 +356,6 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) return list; } -static Bool -readIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index) -{ -#ifdef USE_GCONF - return readGConfIntegratedOption (context, setting, index); -#else - return FALSE; -#endif -} - -static GVariant * -getVariantForCCSSetting (CCSSetting *setting) -{ - GSettings *settings = getSettingsObjectForCCSSetting (setting); - char *cleanSettingName = getNameForCCSSetting (setting); - gchar *pathName = makeSettingPath (setting); - GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName, pathName, ccsSettingGetType (setting)); - - free (cleanSettingName); - free (pathName); - return gsettingsValue; -} - const char * readStringFromVariant (GVariant *gsettingsValue) { return g_variant_get_string (gsettingsValue, NULL); -- GitLab From 7fc99fbbacceec9cb606af71f8eca31eaf1ed40c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 03:08:48 +0800 Subject: [PATCH 051/562] Move it all to gsettings_util --- .../gsettings_backend_shared/gsettings_util.c | 188 ++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 19 ++ compizconfig/gsettings/src/gsettings.c | 187 ----------------- 3 files changed, 207 insertions(+), 187 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index d2e532e34..f26513b4a 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1,5 +1,6 @@ #define CCS_LOG_DOMAIN "gsettings" #include +#include #include #include "gsettings_shared.h" @@ -384,3 +385,190 @@ getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettin return gsettingsValue; } + +CCSSettingValueList +readListValue (GVariant *gsettingsValue, CCSSettingType listType) +{ + gboolean hasVariantType; + unsigned int nItems, i = 0; + CCSSettingValueList list = NULL; + GVariantIter iter; + + hasVariantType = compizconfigTypeHasVariantType (listType); + + if (!hasVariantType) + return NULL; + + g_variant_iter_init (&iter, gsettingsValue); + nItems = g_variant_iter_n_children (&iter); + + switch (listType) + { + case TypeBool: + { + Bool *array = malloc (nItems * sizeof (Bool)); + Bool *arrayCounter = array; + gboolean value; + + if (!array) + break; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (&iter, "b", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromBoolArray (array, nItems, NULL); + free (array); + } + break; + case TypeInt: + { + int *array = malloc (nItems * sizeof (int)); + int *arrayCounter = array; + gint value; + + if (!array) + break; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (&iter, "i", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromIntArray (array, nItems, NULL); + free (array); + } + break; + case TypeFloat: + { + double *array = malloc (nItems * sizeof (double)); + double *arrayCounter = array; + gdouble value; + + if (!array) + break; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (&iter, "d", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromFloatArray ((float *) array, nItems, NULL); + free (array); + } + break; + case TypeString: + case TypeMatch: + { + const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); + const gchar **arrayCounter = array; + gchar *value; + + if (!array) + break; + + array[nItems] = NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_next (&iter, "s", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromStringArray (array, nItems, NULL); + g_strfreev ((char **) array); + } + break; + case TypeColor: + { + CCSSettingColorValue *array; + char *colorValue; + array = malloc (nItems * sizeof (CCSSettingColorValue)); + if (!array) + break; + + while (g_variant_iter_loop (&iter, "s", &colorValue)) + { + memset (&array[i], 0, sizeof (CCSSettingColorValue)); + ccsStringToColor (colorValue, + &array[i]); + } + list = ccsGetValueListFromColorArray (array, nItems, NULL); + free (array); + } + break; + default: + break; + } + + return list; +} + +const char * readStringFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_string (gsettingsValue, NULL); +} + +int readIntFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_int32 (gsettingsValue); +} + +Bool readBoolFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_boolean (gsettingsValue) ? TRUE : FALSE; +} + +float readFloatFromVariant (GVariant *gsettingsValue) +{ + return (float) g_variant_get_double (gsettingsValue); +} + +CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingColorValue color; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToColor (value, &color); + else + *success = FALSE; + + return color; +} + +CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingKeyValue key; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToKeyBinding (value, &key); + else + *success = FALSE; + + return key; +} + +CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingButtonValue button; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToButtonBinding (value, &button); + else + *success = FALSE; + + return button; +} + +unsigned int readEdgeFromVariant (GVariant *gsettingsValue) +{ + const char *value; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + return ccsStringToEdges (value); + + return 0; +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index e13a9a539..fc005a1d1 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -75,4 +75,23 @@ checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gc GVariant * getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettingType type); +const char * readStringFromVariant (GVariant *gsettingsValue); + +int readIntFromVariant (GVariant *gsettingsValue); + +Bool readBoolFromVariant (GVariant *gsettingsValue); + +float readFloatFromVariant (GVariant *gsettingsValue); + +CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success); + +CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success); + +CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success); + +unsigned int readEdgeFromVariant (GVariant *gsettingsValue); + +CCSSettingValueList +readListValue (GVariant *gsettingsValue, CCSSettingType listType); + #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 2ef153154..d607b030d 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -242,193 +242,6 @@ getVariantForCCSSetting (CCSSetting *setting) return gsettingsValue; } -CCSSettingValueList -readListValue (GVariant *gsettingsValue, CCSSettingType listType) -{ - gboolean hasVariantType; - unsigned int nItems, i = 0; - CCSSettingValueList list = NULL; - GVariantIter iter; - - hasVariantType = compizconfigTypeHasVariantType (listType); - - if (!hasVariantType) - return NULL; - - g_variant_iter_init (&iter, gsettingsValue); - nItems = g_variant_iter_n_children (&iter); - - switch (listType) - { - case TypeBool: - { - Bool *array = malloc (nItems * sizeof (Bool)); - Bool *arrayCounter = array; - gboolean value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "b", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromBoolArray (array, nItems, NULL); - free (array); - } - break; - case TypeInt: - { - int *array = malloc (nItems * sizeof (int)); - int *arrayCounter = array; - gint value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "i", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromIntArray (array, nItems, NULL); - free (array); - } - break; - case TypeFloat: - { - double *array = malloc (nItems * sizeof (double)); - double *arrayCounter = array; - gdouble value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "d", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromFloatArray ((float *) array, nItems, NULL); - free (array); - } - break; - case TypeString: - case TypeMatch: - { - const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); - const gchar **arrayCounter = array; - gchar *value; - - if (!array) - break; - - array[nItems] = NULL; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_next (&iter, "s", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromStringArray (array, nItems, NULL); - g_strfreev ((char **) array); - } - break; - case TypeColor: - { - CCSSettingColorValue *array; - char *colorValue; - array = malloc (nItems * sizeof (CCSSettingColorValue)); - if (!array) - break; - - while (g_variant_iter_loop (&iter, "s", &colorValue)) - { - memset (&array[i], 0, sizeof (CCSSettingColorValue)); - ccsStringToColor (colorValue, - &array[i]); - } - list = ccsGetValueListFromColorArray (array, nItems, NULL); - free (array); - } - break; - default: - break; - } - - return list; -} - -const char * readStringFromVariant (GVariant *gsettingsValue) -{ - return g_variant_get_string (gsettingsValue, NULL); -} - -int readIntFromVariant (GVariant *gsettingsValue) -{ - return g_variant_get_int32 (gsettingsValue); -} - -Bool readBoolFromVariant (GVariant *gsettingsValue) -{ - return g_variant_get_boolean (gsettingsValue) ? TRUE : FALSE; -} - -float readFloatFromVariant (GVariant *gsettingsValue) -{ - return (float) g_variant_get_double (gsettingsValue); -} - -CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success) -{ - const char *value; - CCSSettingColorValue color; - value = g_variant_get_string (gsettingsValue, NULL); - - if (value) - *success = ccsStringToColor (value, &color); - else - *success = FALSE; - - return color; -} - -CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success) -{ - const char *value; - CCSSettingKeyValue key; - value = g_variant_get_string (gsettingsValue, NULL); - - if (value) - *success = ccsStringToKeyBinding (value, &key); - else - *success = FALSE; - - return key; -} - -CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success) -{ - const char *value; - CCSSettingButtonValue button; - value = g_variant_get_string (gsettingsValue, NULL); - - if (value) - *success = ccsStringToButtonBinding (value, &button); - else - *success = FALSE; - - return button; -} - -unsigned int readEdgeFromVariant (GVariant *gsettingsValue) -{ - const char *value; - value = g_variant_get_string (gsettingsValue, NULL); - - if (value) - return ccsStringToEdges (value); - - return 0; -} - Bool readOption (CCSSetting * setting) { -- GitLab From 745540ce3f350a106b58745fd2d14e1018b441af Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 03:52:11 +0800 Subject: [PATCH 052/562] Implement writeListValue in terms of GVariant --- compizconfig/gsettings/src/gsettings.c | 45 +++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index d607b030d..a15e45f68 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -397,19 +397,13 @@ readOption (CCSSetting * setting) } static void -writeListValue (CCSSetting *setting, - char *pathName) +writeListValue (CCSSettingValueList list, + CCSSettingType listType, + GVariant **gsettingsValue) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); - GVariant *value = NULL; - CCSSettingValueList list; + GVariant *value = NULL; - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - if (!ccsGetList (setting, &list)) - return; - - switch (ccsSettingGetInfo (setting)->forList.listType) + switch (listType) { case TypeBool: { @@ -487,17 +481,11 @@ writeListValue (CCSSetting *setting, break; default: ccsWarning ("Attempt to write unsupported list type %d!", - ccsSettingGetInfo (setting)->forList.listType); + listType); break; } - if (value) - { - g_settings_set_value (settings, cleanSettingName, value); - g_variant_unref (value); - } - - free (cleanSettingName); + *gsettingsValue = value; } static void @@ -651,9 +639,22 @@ writeOption (CCSSetting * setting) break; case TypeList: { - gchar *pathName = makeSettingPath (setting); - writeListValue (setting, pathName); - g_free (pathName); + GVariant *value = NULL; + CCSSettingValueList list = NULL; + + if (!ccsGetList (setting, &list)) + return; + + writeListValue (list, + ccsSettingGetInfo (setting)->forList.listType, + &value); + + if (value) + { + /* g_settings_set_value will consume the reference + * so there is no need to unref value here */ + g_settings_set_value (settings, cleanSettingName, value); + } } break; default: -- GitLab From d9c0e17a7f63633231785415ce3254594e5192ff Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 07:10:54 +0800 Subject: [PATCH 053/562] Abstract away the other gvariant write functions --- compizconfig/gsettings/src/gsettings.c | 148 +++++++++++++++++-------- 1 file changed, 103 insertions(+), 45 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index a15e45f68..c6b6ab3db 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -396,7 +396,7 @@ readOption (CCSSetting * setting) return ret; } -static void +Bool writeListValue (CCSSettingValueList list, CCSSettingType listType, GVariant **gsettingsValue) @@ -482,10 +482,12 @@ writeListValue (CCSSettingValueList list, default: ccsWarning ("Attempt to write unsupported list type %d!", listType); + return FALSE; break; } *gsettingsValue = value; + return TRUE; } static void @@ -512,11 +514,91 @@ resetOptionToDefault (CCSSetting * setting) free (cleanSettingName); } +Bool writeStringToVariant (char *value, GVariant **variant) +{ + *variant = g_variant_new_string (value); + return TRUE; +} + +Bool writeFloatToVariant (float value, GVariant **variant) +{ + *variant = g_variant_new_double ((double) value); + return TRUE; +} + +Bool writeIntToVariant (int value, GVariant **variant) +{ + *variant = g_variant_new_int32 (value); + return TRUE; +} + +Bool writeBoolToVariant (Bool value, GVariant **variant) +{ + *variant = g_variant_new_boolean (value); + return TRUE; +} + +Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant) +{ + char *colString; + + colString = ccsColorToString (&value); + if (!colString) + return FALSE; + + *variant = g_variant_new_string (colString); + free (colString); + + return TRUE; +} + +Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant) +{ + char *keyString; + + keyString = ccsKeyBindingToString (&key); + if (!keyString) + return FALSE; + + *variant = g_variant_new_string (keyString); + free (keyString); + + return TRUE; +} + +Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant) +{ + char *buttonString; + + buttonString = ccsButtonBindingToString (&button); + if (!buttonString) + return FALSE; + + *variant = g_variant_new_string (buttonString); + free (buttonString); + return TRUE; +} + +Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) +{ + char *edgeString; + + edgeString = ccsEdgesToString (edges); + if (!edgeString) + return FALSE; + + *variant = g_variant_new_string (edgeString); + free (edgeString); + return TRUE; +} + void writeOption (CCSSetting * setting) { GSettings *settings = getSettingsObjectForCCSSetting (setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); + GVariant *gsettingsValue = NULL; + Bool success = FALSE; switch (ccsSettingGetType (setting)) { @@ -525,7 +607,7 @@ writeOption (CCSSetting * setting) char *value; if (ccsGetString (setting, &value)) { - g_settings_set (settings, cleanSettingName, "s", value, NULL); + success = writeStringToVariant (value, &gsettingsValue); } } break; @@ -534,7 +616,7 @@ writeOption (CCSSetting * setting) char *value; if (ccsGetMatch (setting, &value)) { - g_settings_set (settings, cleanSettingName, "s", value, NULL); + success = writeStringToVariant (value, &gsettingsValue); } } case TypeFloat: @@ -542,7 +624,7 @@ writeOption (CCSSetting * setting) float value; if (ccsGetFloat (setting, &value)) { - g_settings_set (settings, cleanSettingName, "d", (double) value, NULL); + success = writeFloatToVariant (value, &gsettingsValue); } } break; @@ -551,7 +633,7 @@ writeOption (CCSSetting * setting) int value; if (ccsGetInt (setting, &value)) { - g_settings_set (settings, cleanSettingName, "i", value, NULL); + success = writeIntToVariant (value, &gsettingsValue); } } break; @@ -560,72 +642,48 @@ writeOption (CCSSetting * setting) Bool value; if (ccsGetBool (setting, &value)) { - g_settings_set (settings, cleanSettingName, "b", value, NULL); + success = writeBoolToVariant (value, &gsettingsValue); } } break; case TypeColor: { CCSSettingColorValue value; - char *colString; if (!ccsGetColor (setting, &value)) break; - colString = ccsColorToString (&value); - if (!colString) - break; - - g_settings_set (settings, cleanSettingName, "s", colString, NULL); - free (colString); + success = writeColorToVariant (value, &gsettingsValue); } break; case TypeKey: { CCSSettingKeyValue key; - char *keyString; if (!ccsGetKey (setting, &key)) break; - keyString = ccsKeyBindingToString (&key); - if (!keyString) - break; - - g_settings_set (settings, cleanSettingName, "s", keyString, NULL); - free (keyString); + success = writeKeyToVariant (key, &gsettingsValue); } break; case TypeButton: { CCSSettingButtonValue button; - char *buttonString; if (!ccsGetButton (setting, &button)) break; - buttonString = ccsButtonBindingToString (&button); - if (!buttonString) - break; - - g_settings_set (settings, cleanSettingName, "s", buttonString, NULL); - free (buttonString); + success = writeButtonToVariant (button, &gsettingsValue); } break; case TypeEdge: { unsigned int edges; - char *edgeString; if (!ccsGetEdge (setting, &edges)) break; - edgeString = ccsEdgesToString (edges); - if (!edgeString) - break; - - g_settings_set (settings, cleanSettingName, "s", edgeString, NULL); - free (edgeString); + success = writeEdgeToVariant (edges, &gsettingsValue); } break; case TypeBell: @@ -633,7 +691,7 @@ writeOption (CCSSetting * setting) Bool value; if (ccsGetBell (setting, &value)) { - g_settings_set (settings, cleanSettingName, "s", value, NULL); + success = writeBoolToVariant (value, &gsettingsValue); } } break; @@ -645,16 +703,9 @@ writeOption (CCSSetting * setting) if (!ccsGetList (setting, &list)) return; - writeListValue (list, - ccsSettingGetInfo (setting)->forList.listType, - &value); - - if (value) - { - /* g_settings_set_value will consume the reference - * so there is no need to unref value here */ - g_settings_set_value (settings, cleanSettingName, value); - } + success = writeListValue (list, + ccsSettingGetInfo (setting)->forList.listType, + &value); } break; default: @@ -663,6 +714,13 @@ writeOption (CCSSetting * setting) break; } + if (success && gsettingsValue) + { + /* g_settings_set_value will consume the reference + * so there is no need to unref value here */ + g_settings_set_value (settings, cleanSettingName, gsettingsValue); + } + free (cleanSettingName); } -- GitLab From 487d1d5c075e4ba2755a92ec8ab0858af5a5bd30 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 07:13:10 +0800 Subject: [PATCH 054/562] Move writeListValue closer to the other gvariant writers --- compizconfig/gsettings/src/gsettings.c | 52 +++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index c6b6ab3db..8d4fc0f49 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -396,6 +396,30 @@ readOption (CCSSetting * setting) return ret; } +static void +writeIntegratedOption (CCSContext *context, + CCSSetting *setting, + int index) +{ +#ifdef USE_GCONF + writeGConfIntegratedOption (context, setting, index); +#endif + + return; +} + +static void +resetOptionToDefault (CCSSetting * setting) +{ + GSettings *settings = getSettingsObjectForCCSSetting (setting); + + char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); + + g_settings_reset (settings, cleanSettingName); + + free (cleanSettingName); +} + Bool writeListValue (CCSSettingValueList list, CCSSettingType listType, @@ -424,8 +448,8 @@ writeListValue (CCSSettingValueList list, { g_variant_builder_add (builder, "i", list->data->value.asInt); list = list->next; - } - value = g_variant_new ("ai", builder); + } + value = g_variant_new ("ai", builder); g_variant_builder_unref (builder); } break; @@ -490,30 +514,6 @@ writeListValue (CCSSettingValueList list, return TRUE; } -static void -writeIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index) -{ -#ifdef USE_GCONF - writeGConfIntegratedOption (context, setting, index); -#endif - - return; -} - -static void -resetOptionToDefault (CCSSetting * setting) -{ - GSettings *settings = getSettingsObjectForCCSSetting (setting); - - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - g_settings_reset (settings, cleanSettingName); - - free (cleanSettingName); -} - Bool writeStringToVariant (char *value, GVariant **variant) { *variant = g_variant_new_string (value); -- GitLab From 76aa391e095804a9d93314ab5b02658acd0b87d7 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 07:18:30 +0800 Subject: [PATCH 055/562] Move write funcs to utility library --- .../gsettings_backend_shared/gsettings_util.c | 172 ++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 21 +++ compizconfig/gsettings/src/gsettings.c | 172 ------------------ 3 files changed, 193 insertions(+), 172 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index f26513b4a..b271b53ae 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -572,3 +572,175 @@ unsigned int readEdgeFromVariant (GVariant *gsettingsValue) return 0; } + +Bool +writeListValue (CCSSettingValueList list, + CCSSettingType listType, + GVariant **gsettingsValue) +{ + GVariant *value = NULL; + + switch (listType) + { + case TypeBool: + { + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); + while (list) + { + g_variant_builder_add (builder, "b", list->data->value.asBool); + list = list->next; + } + value = g_variant_new ("ab", builder); + g_variant_builder_unref (builder); + } + break; + case TypeInt: + { + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); + while (list) + { + g_variant_builder_add (builder, "i", list->data->value.asInt); + list = list->next; + } + value = g_variant_new ("ai", builder); + g_variant_builder_unref (builder); + } + break; + case TypeFloat: + { + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); + while (list) + { + g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); + list = list->next; + } + value = g_variant_new ("ad", builder); + g_variant_builder_unref (builder); + } + break; + case TypeString: + { + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + while (list) + { + g_variant_builder_add (builder, "s", list->data->value.asString); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + } + break; + case TypeMatch: + { + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + while (list) + { + g_variant_builder_add (builder, "s", list->data->value.asMatch); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + } + break; + case TypeColor: + { + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + char *item; + while (list) + { + item = ccsColorToString (&list->data->value.asColor); + g_variant_builder_add (builder, "s", item); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + } + break; + default: + ccsWarning ("Attempt to write unsupported list type %d!", + listType); + return FALSE; + break; + } + + *gsettingsValue = value; + return TRUE; +} + +Bool writeStringToVariant (char *value, GVariant **variant) +{ + *variant = g_variant_new_string (value); + return TRUE; +} + +Bool writeFloatToVariant (float value, GVariant **variant) +{ + *variant = g_variant_new_double ((double) value); + return TRUE; +} + +Bool writeIntToVariant (int value, GVariant **variant) +{ + *variant = g_variant_new_int32 (value); + return TRUE; +} + +Bool writeBoolToVariant (Bool value, GVariant **variant) +{ + *variant = g_variant_new_boolean (value); + return TRUE; +} + +Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant) +{ + char *colString; + + colString = ccsColorToString (&value); + if (!colString) + return FALSE; + + *variant = g_variant_new_string (colString); + free (colString); + + return TRUE; +} + +Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant) +{ + char *keyString; + + keyString = ccsKeyBindingToString (&key); + if (!keyString) + return FALSE; + + *variant = g_variant_new_string (keyString); + free (keyString); + + return TRUE; +} + +Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant) +{ + char *buttonString; + + buttonString = ccsButtonBindingToString (&button); + if (!buttonString) + return FALSE; + + *variant = g_variant_new_string (buttonString); + free (buttonString); + return TRUE; +} + +Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) +{ + char *edgeString; + + edgeString = ccsEdgesToString (edges); + if (!edgeString) + return FALSE; + + *variant = g_variant_new_string (edgeString); + free (edgeString); + return TRUE; +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index fc005a1d1..e8a22366b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -94,4 +94,25 @@ unsigned int readEdgeFromVariant (GVariant *gsettingsValue); CCSSettingValueList readListValue (GVariant *gsettingsValue, CCSSettingType listType); +Bool +writeListValue (CCSSettingValueList list, + CCSSettingType listType, + GVariant **gsettingsValue); + +Bool writeStringToVariant (char *value, GVariant **variant); + +Bool writeFloatToVariant (float value, GVariant **variant); + +Bool writeIntToVariant (int value, GVariant **variant); + +Bool writeBoolToVariant (Bool value, GVariant **variant); + +Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant); + +Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant); + +Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant); + +Bool writeEdgeToVariant (unsigned int edges, GVariant **variant); + #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 8d4fc0f49..594b1b994 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -420,178 +420,6 @@ resetOptionToDefault (CCSSetting * setting) free (cleanSettingName); } -Bool -writeListValue (CCSSettingValueList list, - CCSSettingType listType, - GVariant **gsettingsValue) -{ - GVariant *value = NULL; - - switch (listType) - { - case TypeBool: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); - while (list) - { - g_variant_builder_add (builder, "b", list->data->value.asBool); - list = list->next; - } - value = g_variant_new ("ab", builder); - g_variant_builder_unref (builder); - } - break; - case TypeInt: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); - while (list) - { - g_variant_builder_add (builder, "i", list->data->value.asInt); - list = list->next; - } - value = g_variant_new ("ai", builder); - g_variant_builder_unref (builder); - } - break; - case TypeFloat: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); - while (list) - { - g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); - list = list->next; - } - value = g_variant_new ("ad", builder); - g_variant_builder_unref (builder); - } - break; - case TypeString: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - while (list) - { - g_variant_builder_add (builder, "s", list->data->value.asString); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } - break; - case TypeMatch: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - while (list) - { - g_variant_builder_add (builder, "s", list->data->value.asMatch); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } - break; - case TypeColor: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - char *item; - while (list) - { - item = ccsColorToString (&list->data->value.asColor); - g_variant_builder_add (builder, "s", item); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } - break; - default: - ccsWarning ("Attempt to write unsupported list type %d!", - listType); - return FALSE; - break; - } - - *gsettingsValue = value; - return TRUE; -} - -Bool writeStringToVariant (char *value, GVariant **variant) -{ - *variant = g_variant_new_string (value); - return TRUE; -} - -Bool writeFloatToVariant (float value, GVariant **variant) -{ - *variant = g_variant_new_double ((double) value); - return TRUE; -} - -Bool writeIntToVariant (int value, GVariant **variant) -{ - *variant = g_variant_new_int32 (value); - return TRUE; -} - -Bool writeBoolToVariant (Bool value, GVariant **variant) -{ - *variant = g_variant_new_boolean (value); - return TRUE; -} - -Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant) -{ - char *colString; - - colString = ccsColorToString (&value); - if (!colString) - return FALSE; - - *variant = g_variant_new_string (colString); - free (colString); - - return TRUE; -} - -Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant) -{ - char *keyString; - - keyString = ccsKeyBindingToString (&key); - if (!keyString) - return FALSE; - - *variant = g_variant_new_string (keyString); - free (keyString); - - return TRUE; -} - -Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant) -{ - char *buttonString; - - buttonString = ccsButtonBindingToString (&button); - if (!buttonString) - return FALSE; - - *variant = g_variant_new_string (buttonString); - free (buttonString); - return TRUE; -} - -Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) -{ - char *edgeString; - - edgeString = ccsEdgesToString (edges); - if (!edgeString) - return FALSE; - - *variant = g_variant_new_string (edgeString); - free (edgeString); - return TRUE; -} - void writeOption (CCSSetting * setting) { -- GitLab From e14ca69caad23e7930d16ed943210d077be4fec3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 13:00:53 +0800 Subject: [PATCH 056/562] First cut at gsettings backend integrated into the test fixture, all tests currently failing --- .../gsettings_backend_shared/gsettings_util.h | 7 +- compizconfig/gsettings/src/gsettings.c | 15 +- compizconfig/gsettings/tests/CMakeLists.txt | 34 ++++- .../tests/backend-conformance-config.h.in | 2 + .../tests/org.compiz.mock.gschema.xml | 8 + .../tests/test_gsettings_conformance.cpp | 139 ++++++++++++++++++ .../libcompizconfig/include/ccs-backend.h | 8 +- compizconfig/libcompizconfig/src/main.c | 4 +- 8 files changed, 209 insertions(+), 8 deletions(-) create mode 100644 compizconfig/gsettings/tests/backend-conformance-config.h.in create mode 100644 compizconfig/gsettings/tests/org.compiz.mock.gschema.xml create mode 100644 compizconfig/gsettings/tests/test_gsettings_conformance.cpp diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index e8a22366b..2e7ffcf8e 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -1,10 +1,13 @@ #ifndef _COMPIZ_GSETTINGS_UTIL_H #define _COMPIZ_GSETTINGS_UTIL_H +#include + +COMPIZCONFIG_BEGIN_DECLS + #include #include #include -#include gchar * getSchemaNameForPlugin (const char *plugin); @@ -115,4 +118,6 @@ Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant); Bool writeEdgeToVariant (unsigned int edges, GVariant **variant); +COMPIZCONFIG_END_DECLS + #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 594b1b994..a7ffc6b71 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -235,7 +235,10 @@ getVariantForCCSSetting (CCSSetting *setting) GSettings *settings = getSettingsObjectForCCSSetting (setting); char *cleanSettingName = getNameForCCSSetting (setting); gchar *pathName = makeSettingPath (setting); - GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName, pathName, ccsSettingGetType (setting)); + GVariant *gsettingsValue = getVariantAtKey (settings, + cleanSettingName, + pathName, + ccsSettingGetType (setting)); free (cleanSettingName); free (pathName); @@ -420,6 +423,14 @@ resetOptionToDefault (CCSSetting * setting) free (cleanSettingName); } +void +writeVariantToKey (GSettings *settings, + const char *key, + GVariant *value) +{ + g_settings_set_value (settings, key, value); +} + void writeOption (CCSSetting * setting) { @@ -546,7 +557,7 @@ writeOption (CCSSetting * setting) { /* g_settings_set_value will consume the reference * so there is no need to unref value here */ - g_settings_set_value (settings, cleanSettingName, gsettingsValue); + writeVariantToKey (settings, cleanSettingName, gsettingsValue); } free (cleanSettingName); diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 57f6ceb30..506d0ae4f 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,10 +1,16 @@ +include (CompizGSettings) + include_directories (${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests - ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) + ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig + ${CMAKE_CURRENT_SOURCE_DIR}/../../tests) pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) +link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) + add_executable (compizconfig_test_gsettings ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.cpp @@ -12,7 +18,8 @@ add_executable (compizconfig_test_gsettings ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.h ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.h) -link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) +add_executable (compizconfig_test_gsettings_conformance + ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_conformance.cpp) target_link_libraries (compizconfig_test_gsettings gsettings_backend_shared @@ -21,4 +28,27 @@ target_link_libraries (compizconfig_test_gsettings ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/backend-conformance-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/backend-conformance-config.h) + +add_custom_command (OUTPUT ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml + COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml + VERBATIM) + +add_custom_target (compiz_gsettings_mock_schema ALL + DEPENDS ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml) + +add_gsettings_schema_to_recompilation_list (compiz_gsettings_mock_schema) + +target_link_libraries (compizconfig_test_gsettings_conformance + gsettings_backend_shared + compizconfig_ccs_setting_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_context_mock + ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_MAIN_LIBRARY}) + compiz_discover_tests (compizconfig_test_gsettings) +compiz_discover_tests (compizconfig_test_gsettings_conformance) diff --git a/compizconfig/gsettings/tests/backend-conformance-config.h.in b/compizconfig/gsettings/tests/backend-conformance-config.h.in new file mode 100644 index 000000000..95a2a8a40 --- /dev/null +++ b/compizconfig/gsettings/tests/backend-conformance-config.h.in @@ -0,0 +1,2 @@ +#define BACKEND_BINARY_PATH "@CMAKE_BINARY_DIR@/compizconfig/gsettings" +#define MOCK_SCHEMA_PATH "@CMAKE_BINARY_DIR@/generated/glib-2.0/schemas" diff --git a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml new file mode 100644 index 000000000..857b54e6e --- /dev/null +++ b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml @@ -0,0 +1,8 @@ + + + + + 1 + + + diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp new file mode 100644 index 000000000..de453e310 --- /dev/null +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -0,0 +1,139 @@ +#include +#include + +#include + +#include + +#include "backend-conformance-config.h" + +#include +#include + +#include + +namespace +{ +const std::string MOCK_SCHEMA ("org.compiz.mock"); +const std::string MOCK_PATH (MOCK_SCHEMA_PATH); +} + +class CCSGSettingsBackendEnv : + public CCSBackendConceptTestEnvironmentInterface +{ + public: + + CCSGSettingsBackendEnv () + { + g_type_init (); + } + + CCSBackend * SetUp () + { + CCSBackendInterface *interface = NULL; + Bool fallback = FALSE; + + std::cout << MOCK_PATH << std::endl; + + g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); + g_setenv ("GSETTINGS_BACKEND", "memory", true); + + mSettings = g_settings_new_with_path (MOCK_SCHEMA.c_str (), makeCompizPluginPath ("mock", "mock")); + mContext = ccsMockContextNew (); + + std::string path (BACKEND_BINARY_PATH "/libgsettings.so"); + + void *dlhand = ccsOpenBackend (path.c_str (), &interface, &fallback); + + EXPECT_FALSE (fallback); + EXPECT_TRUE (dlhand); + + CCSBackend *backend = ccsBackendNewWithInterface (mContext, interface, dlhand); + mBackend = ccsBackendWithCapabilitiesWrapBackend (&ccsDefaultInterfaceTable, backend); + + return (CCSBackend *) mBackend; + } + + void TearDown (CCSBackend *) + { + g_unsetenv ("XDG_DATA_DIRS"); + g_unsetenv ("GSETTINGS_BACKEND"); + + ccsFreeBackendWithCapabilities (mBackend); + + g_object_unref (mSettings); + ccsFreeMockContext (mContext); + } + + void PreWrite () {} + void PostWrite () {} + + void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + void WriteListAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) {} + + void PreRead () {} + void PostRead () {} + + Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) { return FALSE; } + int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) { return 0; } + float ReadFloatAtKey (const std::string &plugin, + const std::string &key) { return 0.0; } + const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) { return ""; } + CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) { CCSSettingColorValue v; return v;} + CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) { CCSSettingKeyValue v; return v; } + CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) { CCSSettingButtonValue v; return v; } + unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) { return 0; } + const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) { return ""; } + Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) { return FALSE; } + CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key) { return NULL; } + private: + + GSettings *mSettings; + CCSContext *mContext; + CCSBackendWithCapabilities *mBackend; +}; + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTest, + compizconfig::test::GenerateTestingParametersForBackendInterface ()); + diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 2c6b2b009..cbf7aecd2 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -157,12 +157,18 @@ void ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *); /* Backend opener method */ void * -ccsBackendOpen (char *name, CCSBackendInterface **interface, Bool *fellback); +ccsOpenBackend (const char *name, CCSBackendInterface **interface, Bool *fellback); /* Constructor method */ CCSBackend * ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); +typedef struct _CCSInterfaceTable CCSInterfaceTable; + +/* Constructor method */ +CCSBackendWithCapabilities * +ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend); + CCSBackendInterface* getBackendInfo (void); COMPIZCONFIG_END_DECLS diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 3b15dea4a..922793178 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1014,7 +1014,7 @@ CCSREF_OBJ (Backend, CCSBackend) CCSREF_OBJ (BackendWithCapabilities, CCSBackendWithCapabilities) static void * -openBackend (char *backend) +openBackend (const char *backend) { char *home = getenv ("HOME"); char *override_backend = getenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); @@ -1158,7 +1158,7 @@ ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSB } void * -ccsOpenBackend (char *name, CCSBackendInterface **vt, Bool *fellback) +ccsOpenBackend (const char *name, CCSBackendInterface **vt, Bool *fellback) { void *dlhand = openBackend (name); if (!dlhand) -- GitLab From 637dba09ecff603a38c2ac1acba9c0703247af66 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 12 Jul 2012 15:28:25 +0800 Subject: [PATCH 057/562] Work (with failing tests, but no crashing) on reading, still crashes on writing --- cmake/copy_file_install_user_env.cmake | 6 ++- .../gsettings_backend_shared/gsettings_util.c | 10 +++- .../gsettings_backend_shared/gsettings_util.h | 6 ++- compizconfig/gsettings/src/gsettings.c | 12 ++--- .../tests/org.compiz.mock.gschema.xml | 44 ++++++++++++++- .../tests/test_gsettings_conformance.cpp | 33 +++++++++--- .../tests/compizconfig_backend_concept_test.h | 54 +++++++++++++++---- 7 files changed, 136 insertions(+), 29 deletions(-) diff --git a/cmake/copy_file_install_user_env.cmake b/cmake/copy_file_install_user_env.cmake index 2d257f969..fdf20482e 100644 --- a/cmake/copy_file_install_user_env.cmake +++ b/cmake/copy_file_install_user_env.cmake @@ -2,7 +2,11 @@ set (FILE "" CACHE FORCE "File to Install") set (INSTALLDIR_USER "" CACHE FORCE "Installation dir if user") set (INSTALLDIR_ROOT "" CACHE FORCE "Installation dir if root") -set (USERNAME $ENV{USER}) +if (ENV{USER}) + set (USERNAME $ENV{USER}) +else (ENV${USER}) + set (USERNAME "user") +endif (ENV{USER}) if (${USERNAME} STREQUAL "root") set (INSTALLDIR ${INSTALLDIR_ROOT}) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index b271b53ae..58f633b7d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -373,7 +373,7 @@ checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gc } GVariant * -getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettingType type) +getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCSSettingType type) { GVariant *gsettingsValue = g_settings_get_value (settings, key); @@ -744,3 +744,11 @@ Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) free (edgeString); return TRUE; } + +void +writeVariantToKey (GSettings *settings, + const char *key, + GVariant *value) +{ + g_settings_set_value (settings, key, value); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 2e7ffcf8e..f14845112 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -76,7 +76,7 @@ Bool checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName); GVariant * -getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettingType type); +getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCSSettingType type); const char * readStringFromVariant (GVariant *gsettingsValue); @@ -118,6 +118,10 @@ Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant); Bool writeEdgeToVariant (unsigned int edges, GVariant **variant); +void writeVariantToKey (GSettings *settings, + const char *key, + GVariant *value); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index a7ffc6b71..751195d04 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -423,14 +423,6 @@ resetOptionToDefault (CCSSetting * setting) free (cleanSettingName); } -void -writeVariantToKey (GSettings *settings, - const char *key, - GVariant *value) -{ - g_settings_set_value (settings, key, value); -} - void writeOption (CCSSetting * setting) { @@ -701,6 +693,8 @@ finiBackend (CCSBackend *backend, CCSContext * context) l = g_list_next (l); } + settingsList = NULL; + if (currentProfileSettings) { g_object_unref (currentProfileSettings); @@ -709,6 +703,8 @@ finiBackend (CCSBackend *backend, CCSContext * context) g_object_unref (G_OBJECT (compizconfigSettings)); + compizconfigSettings = NULL; + processEvents (backend, 0); return TRUE; } diff --git a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml index 857b54e6e..5eefd5ea1 100644 --- a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml +++ b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml @@ -1,8 +1,50 @@ - + 1 + + true + + + 1.0 + + + "" + + + "" + + + true + + + "" + + + "" + + + "" + + + "" + + + [0] + + + [0.0] + + + [true] + + + [""] + + + [""] + diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index de453e310..80a5ae67b 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -33,15 +33,14 @@ class CCSGSettingsBackendEnv : CCSBackendInterface *interface = NULL; Bool fallback = FALSE; - std::cout << MOCK_PATH << std::endl; - g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); g_setenv ("GSETTINGS_BACKEND", "memory", true); + g_setenv ("LIBCOMPIZCONFIG_BACKEND_PATH", BACKEND_BINARY_PATH, true); mSettings = g_settings_new_with_path (MOCK_SCHEMA.c_str (), makeCompizPluginPath ("mock", "mock")); mContext = ccsMockContextNew (); - std::string path (BACKEND_BINARY_PATH "/libgsettings.so"); + std::string path ("gsettings"); void *dlhand = ccsOpenBackend (path.c_str (), &interface, &fallback); @@ -51,12 +50,17 @@ class CCSGSettingsBackendEnv : CCSBackend *backend = ccsBackendNewWithInterface (mContext, interface, dlhand); mBackend = ccsBackendWithCapabilitiesWrapBackend (&ccsDefaultInterfaceTable, backend); + CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, mBackend))->backendInit; + + if (backendInit) + (*backendInit) ((CCSBackend *) mBackend, mContext); + return (CCSBackend *) mBackend; } void TearDown (CCSBackend *) { - g_unsetenv ("XDG_DATA_DIRS"); + g_unsetenv ("GSETTINGS_SCHEMA_DIR"); g_unsetenv ("GSETTINGS_BACKEND"); ccsFreeBackendWithCapabilities (mBackend); @@ -69,8 +73,16 @@ class CCSGSettingsBackendEnv : void PostWrite () {} void WriteBoolAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) {} + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeBoolToVariant (boolToBool (boost::get (value)), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteIntegerAtKey (const std::string &plugin, const std::string &key, const VariantTypes &value) {} @@ -106,7 +118,14 @@ class CCSGSettingsBackendEnv : void PostRead () {} Bool ReadBoolAtKey (const std::string &plugin, - const std::string &key) { return FALSE; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("default", plugin.c_str ())), + TypeBool); + return readBoolFromVariant (variant); + } int ReadIntegerAtKey (const std::string &plugin, const std::string &key) { return 0; } float ReadFloatAtKey (const std::string &plugin, diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index b09b366c3..cb76b661b 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -95,6 +95,36 @@ operator== (const CCSSettingButtonValue &lhs, return false; } +class CharacterWrapper : + boost::noncopyable +{ + public: + + explicit CharacterWrapper (char *c) : + mChar (c) + { + } + + ~CharacterWrapper () + { + free (mChar); + } + + operator char * () + { + return mChar; + } + + operator const char * () const + { + return mChar; + } + + private: + + char *mChar; +}; + class CCSListWrapper : boost::noncopyable { @@ -455,14 +485,15 @@ void SetEdgeReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) EXPECT_CALL (*gmock, setEdge (boost::get (value), _)); } +CCSSettingInfo globalListInfo; + void SetListReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - CCSSettingInfo info; + globalListInfo.forList.listType = (boost::get > (value))->type (); + globalListInfo.forList.listInfo = NULL; - info.forList.listType = (boost::get > (value))->type (); - info.forList.listInfo = NULL; - - EXPECT_CALL (*gmock, setList (ListEqual (info.forList, *(boost::get > (value))), _)); + ON_CALL (*gmock, getInfo ()).WillByDefault (Return (&globalListInfo)); + EXPECT_CALL (*gmock, setList (ListEqual (globalListInfo.forList, *(boost::get > (value))), _)); } } @@ -590,7 +621,7 @@ class CCSBackendConformanceTest : } CCSPlugin * - SpawnPlugin (const std::string &name = "") + SpawnPlugin (const std::string &name = "", CCSContext *parent = NULL) { CCSPlugin *plugin = ccsMockPluginNew (); mSpawnedPlugins.push_back (plugin); @@ -600,6 +631,9 @@ class CCSBackendConformanceTest : if (!name.empty ()) EXPECT_CALL (*gmockPlugin, getName ()).WillRepeatedly (Return ((char *) name.c_str ())); + if (parent) + ON_CALL (*gmockPlugin, getContext ()).WillByDefault (Return (parent)); + return plugin; } @@ -811,12 +845,12 @@ TEST_P (CCSBackendConformanceTest, TestReadValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); - std::string pluginName ("plugin"); + std::string pluginName ("mock"); const std::string &settingName (GetParam ()->keyname ()); const VariantTypes &VALUE (GetParam ()->value ()); CCSContext *context = CCSBackendConformanceTest::SpawnContext (); - CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); + CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName, context); CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); @@ -833,12 +867,12 @@ TEST_P (CCSBackendConformanceTest, TestWriteValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); - std::string pluginName ("plugin"); + std::string pluginName ("mock"); const std::string &settingName (GetParam ()->keyname ()); const VariantTypes &VALUE (GetParam ()->value ()); CCSContext *context = CCSBackendConformanceTest::SpawnContext (); - CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); + CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName, context); CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (); -- GitLab From 6e4b7913cba8deb69158b2a078ae278f2fdd5070 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:11:11 +0800 Subject: [PATCH 058/562] Provide the mocks in the Pre/Post Write/Read functions --- ...nfig_test_ccs_mock_backend_conformance.cpp | 20 ++++++++--- .../tests/compizconfig_backend_concept_test.h | 34 ++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index a4f0b110e..ea8136ec4 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -75,12 +75,18 @@ class MockCCSBackendConceptTestEnvironment : } - void PreWrite () + void PreWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) { EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); } - void PostWrite () + void PostWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) { } @@ -162,12 +168,18 @@ class MockCCSBackendConceptTestEnvironment : mValues[keynameFromPluginKey (plugin, key)] = value; } - void PreRead () + void PreRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) { EXPECT_CALL (*mBackendGMock, readSetting (_, _)); } - void PostRead () + void PostRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) { } diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index b09b366c3..32feda997 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -150,8 +150,14 @@ class CCSBackendConceptTestEnvironmentInterface virtual CCSBackend * SetUp () = 0; virtual void TearDown (CCSBackend *) = 0; - virtual void PreWrite () = 0; - virtual void PostWrite () = 0; + virtual void PreWrite (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + virtual void PostWrite (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; virtual void WriteBoolAtKey (const std::string &plugin, const std::string &key, @@ -187,8 +193,14 @@ class CCSBackendConceptTestEnvironmentInterface const std::string &key, const VariantTypes &value) = 0; - virtual void PreRead () = 0; - virtual void PostRead () = 0; + virtual void PreRead (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + virtual void PostRead (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; virtual Bool ReadBoolAtKey (const std::string &plugin, const std::string &key) = 0; @@ -819,11 +831,13 @@ TEST_P (CCSBackendConformanceTest, TestReadValue) CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); + CCSContextGMock *gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); + CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->nativeWrite () (pluginName, settingName, VALUE); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context, setting); @@ -841,7 +855,11 @@ TEST_P (CCSBackendConformanceTest, TestWriteValue) CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (); + CCSContextGMock *gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); + CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, settingName, VALUE, @@ -851,7 +869,7 @@ TEST_P (CCSBackendConformanceTest, TestWriteValue) context, setting), GetParam ()->testEnv ()); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PostWrite (); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); } -- GitLab From f670d155aaddb0803662711391250a4fe52b1542 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:23:09 +0800 Subject: [PATCH 059/562] Require the backend specific fixture to set implementation specific expectations, all the conformance test really cares about is that the settings are set correctly, the backend specific fixture cares about how this is done --- ...nfig_test_ccs_mock_backend_conformance.cpp | 8 ++ .../tests/compizconfig_backend_concept_test.h | 76 ++++++++++--------- 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index ea8136ec4..f383ccc91 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -81,6 +81,10 @@ class MockCCSBackendConceptTestEnvironment : CCSSettingType type) { EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getType ()); + EXPECT_CALL (*gmockSetting, getParent ()); } void PostWrite (CCSContextGMock *gmockContext, @@ -174,6 +178,10 @@ class MockCCSBackendConceptTestEnvironment : CCSSettingType type) { EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getType ()); + EXPECT_CALL (*gmockSetting, getParent ()); } void PostRead (CCSContextGMock *gmockContext, diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 32feda997..89c60b3a5 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -593,48 +593,48 @@ class CCSBackendConformanceTest : protected: - CCSContext * - SpawnContext () + /* Having the returned context, setting and plugin + * as out params is awkward, but GTest doesn't let + * you use ASSERT_* unless the function returns void + */ + void + SpawnContext (CCSContext **context) { - CCSContext *context = ccsMockContextNew (); - mSpawnedContexts.push_back (context); - return context; + *context = ccsMockContextNew (); + mSpawnedContexts.push_back (*context); } - CCSPlugin * - SpawnPlugin (const std::string &name = "") + void + SpawnPlugin (const std::string &name, CCSPlugin **plugin) { - CCSPlugin *plugin = ccsMockPluginNew (); - mSpawnedPlugins.push_back (plugin); + *plugin = ccsMockPluginNew (); + mSpawnedPlugins.push_back (*plugin); - CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); + CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (*plugin); - if (!name.empty ()) - EXPECT_CALL (*gmockPlugin, getName ()).WillRepeatedly (Return ((char *) name.c_str ())); + ASSERT_FALSE (name.empty ()); - return plugin; + ON_CALL (*gmockPlugin, getName ()).WillByDefault (Return ((char *) name.c_str ())); } - CCSSetting * - SpawnSetting (const std::string &name = "", - CCSSettingType type = TypeNum, - CCSPlugin *plugin = NULL) + void + SpawnSetting (const std::string &name, + CCSSettingType type, + CCSPlugin *plugin, + CCSSetting **setting) { - CCSSetting *setting = ccsMockSettingNew (); - mSpawnedSettings.push_back (setting); + *setting = ccsMockSettingNew (); + mSpawnedSettings.push_back (*setting); - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (*setting); - if (!name.empty ()) - EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return ((char *) name.c_str ())); + ASSERT_FALSE (name.empty ()); + ASSERT_NE (type, TypeNum); + ASSERT_TRUE (plugin); - if (type != TypeNum) - EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (type)); - - if (plugin) - EXPECT_CALL (*gmockSetting, getParent ()).WillRepeatedly (Return (plugin)); - - return setting; + ON_CALL (*gmockSetting, getName ()).WillByDefault (Return ((char *) name.c_str ())); + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (type)); + ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin)); } private: @@ -827,9 +827,12 @@ TEST_P (CCSBackendConformanceTest, TestReadValue) const std::string &settingName (GetParam ()->keyname ()); const VariantTypes &VALUE (GetParam ()->value ()); - CCSContext *context = CCSBackendConformanceTest::SpawnContext (); - CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); - CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); + CCSContext *context; + CCSBackendConformanceTest::SpawnContext (&context); + CCSPlugin *plugin; + CCSBackendConformanceTest::SpawnPlugin (pluginName, &plugin); + CCSSetting *setting; + CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); CCSContextGMock *gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); @@ -851,9 +854,12 @@ TEST_P (CCSBackendConformanceTest, TestWriteValue) const std::string &settingName (GetParam ()->keyname ()); const VariantTypes &VALUE (GetParam ()->value ()); - CCSContext *context = CCSBackendConformanceTest::SpawnContext (); - CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName); - CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); + CCSContext *context; + CCSBackendConformanceTest::SpawnContext (&context); + CCSPlugin *plugin; + CCSBackendConformanceTest::SpawnPlugin (pluginName, &plugin); + CCSSetting *setting; + CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); CCSContextGMock *gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); -- GitLab From fcfecbc2fb54595e6406304776810e9b81d7edf4 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:27:46 +0800 Subject: [PATCH 060/562] Put the read/write tests into a superclass --- ...nfig_test_ccs_mock_backend_conformance.cpp | 2 +- .../tests/compizconfig_backend_concept_test.h | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index f383ccc91..c269042dd 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -423,7 +423,7 @@ class MockCCSBackendConceptTestEnvironment : std::map mValues; }; -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTest, +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWrite, compizconfig::test::GenerateTestingParametersForBackendInterface ()); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 89c60b3a5..6011d521b 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -561,17 +561,19 @@ class CCSBackendConformanceTest : { public: + virtual ~CCSBackendConformanceTest () {} + CCSBackend * GetBackend () { return mBackend; } - void SetUp () + virtual void SetUp () { mBackend = GetParam ()->testEnv ()->SetUp (); } - void TearDown () + virtual void TearDown () { CCSBackendConformanceTest::GetParam ()->testEnv ()->TearDown (mBackend); @@ -819,7 +821,25 @@ GenerateTestingParametersForBackendInterface () } } -TEST_P (CCSBackendConformanceTest, TestReadValue) +class CCSBackendConformanceTestReadWrite : + public CCSBackendConformanceTest +{ + public: + + virtual ~CCSBackendConformanceTestReadWrite () {} + + virtual void SetUp () + { + CCSBackendConformanceTest::SetUp (); + } + + virtual void TearDown () + { + CCSBackendConformanceTest::TearDown (); + } +}; + +TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); @@ -846,7 +866,7 @@ TEST_P (CCSBackendConformanceTest, TestReadValue) ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context, setting); } -TEST_P (CCSBackendConformanceTest, TestWriteValue) +TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); -- GitLab From 4b2e4adefc2e948a6416e0c6ea626f499fb69cac Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:31:19 +0800 Subject: [PATCH 061/562] Put common data into that fixture --- .../tests/compizconfig_backend_concept_test.h | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 6011d521b..22c33bf15 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -831,33 +831,44 @@ class CCSBackendConformanceTestReadWrite : virtual void SetUp () { CCSBackendConformanceTest::SetUp (); + + pluginName = "plugin"; + settingName = GetParam ()->keyname (); + VALUE = GetParam ()->value (); + + + CCSBackendConformanceTest::SpawnContext (&context); + CCSBackendConformanceTest::SpawnPlugin (pluginName, &plugin); + CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); + + gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); + gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); + gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); } virtual void TearDown () { CCSBackendConformanceTest::TearDown (); } + + protected: + + std::string pluginName; + std::string settingName; + VariantTypes VALUE; + CCSContext *context; + CCSPlugin *plugin; + CCSSetting *setting; + CCSContextGMock *gmockContext; + CCSPluginGMock *gmockPlugin; + CCSSettingGMock *gmockSetting; + }; TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); - std::string pluginName ("plugin"); - const std::string &settingName (GetParam ()->keyname ()); - const VariantTypes &VALUE (GetParam ()->value ()); - - CCSContext *context; - CCSBackendConformanceTest::SpawnContext (&context); - CCSPlugin *plugin; - CCSBackendConformanceTest::SpawnPlugin (pluginName, &plugin); - CCSSetting *setting; - CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); - - CCSContextGMock *gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); - CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->nativeWrite () (pluginName, settingName, VALUE); CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); @@ -870,21 +881,6 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); - std::string pluginName ("plugin"); - const std::string &settingName (GetParam ()->keyname ()); - const VariantTypes &VALUE (GetParam ()->value ()); - - CCSContext *context; - CCSBackendConformanceTest::SpawnContext (&context); - CCSPlugin *plugin; - CCSBackendConformanceTest::SpawnPlugin (pluginName, &plugin); - CCSSetting *setting; - CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); - - CCSContextGMock *gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); - CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, settingName, -- GitLab From 0347b2c80bb8b950d5c71efbd8ee9bd2f8fb8694 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:32:48 +0800 Subject: [PATCH 062/562] Make the plugin know about the context by default --- compizconfig/tests/compizconfig_backend_concept_test.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 22c33bf15..2d94d119f 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -607,7 +607,7 @@ class CCSBackendConformanceTest : } void - SpawnPlugin (const std::string &name, CCSPlugin **plugin) + SpawnPlugin (const std::string &name, CCSContext *context, CCSPlugin **plugin) { *plugin = ccsMockPluginNew (); mSpawnedPlugins.push_back (*plugin); @@ -615,8 +615,10 @@ class CCSBackendConformanceTest : CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (*plugin); ASSERT_FALSE (name.empty ()); + ASSERT_TRUE (context); ON_CALL (*gmockPlugin, getName ()).WillByDefault (Return ((char *) name.c_str ())); + ON_CALL (*gmockPlugin, getContext ()).WillByDefault (Return (context)); } void @@ -838,7 +840,7 @@ class CCSBackendConformanceTestReadWrite : CCSBackendConformanceTest::SpawnContext (&context); - CCSBackendConformanceTest::SpawnPlugin (pluginName, &plugin); + CCSBackendConformanceTest::SpawnPlugin (pluginName, context, &plugin); CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); -- GitLab From d070c966555f606f9d55b084af7f5f1ba5f85db6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:40:06 +0800 Subject: [PATCH 063/562] Correclty overload functions, remove other merge markers --- .../tests/test_gsettings_conformance.cpp | 20 +++++++++++--- .../tests/compizconfig_backend_concept_test.h | 27 ------------------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 80a5ae67b..48a651d8b 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -69,8 +69,14 @@ class CCSGSettingsBackendEnv : ccsFreeMockContext (mContext); } - void PreWrite () {} - void PostWrite () {} + void PreWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} + void PostWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} void WriteBoolAtKey (const std::string &plugin, const std::string &key, @@ -114,8 +120,14 @@ class CCSGSettingsBackendEnv : const std::string &key, const VariantTypes &value) {} - void PreRead () {} - void PostRead () {} + void PreRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} + void PostRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} Bool ReadBoolAtKey (const std::string &plugin, const std::string &key) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 33829719a..ef65fea92 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -670,7 +670,6 @@ class CCSBackendConformanceTest : ON_CALL (*gmockSetting, getName ()).WillByDefault (Return ((char *) name.c_str ())); ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (type)); ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin)); ->>>>>>> MERGE-SOURCE } private: @@ -903,21 +902,7 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); -<<<<<<< TREE - std::string pluginName ("mock"); - const std::string &settingName (GetParam ()->keyname ()); - const VariantTypes &VALUE (GetParam ()->value ()); - - CCSContext *context = CCSBackendConformanceTest::SpawnContext (); - CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName, context); - CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); - - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); - - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (); -======= CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); ->>>>>>> MERGE-SOURCE CCSBackendConformanceTest::GetParam ()->nativeWrite () (pluginName, settingName, VALUE); CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); @@ -929,19 +914,7 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); -<<<<<<< TREE - std::string pluginName ("mock"); - const std::string &settingName (GetParam ()->keyname ()); - const VariantTypes &VALUE (GetParam ()->value ()); - - CCSContext *context = CCSBackendConformanceTest::SpawnContext (); - CCSPlugin *plugin = CCSBackendConformanceTest::SpawnPlugin (pluginName, context); - CCSSetting *setting = CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin); - - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (); -======= CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); ->>>>>>> MERGE-SOURCE CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, settingName, VALUE, -- GitLab From a1efc426e8af5b0f144f99c4fc73bebf8005fb57 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:44:26 +0800 Subject: [PATCH 064/562] Pull up context generation into CCSBackendConformanceTest There is only one context really --- .../tests/compizconfig_backend_concept_test.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 2d94d119f..8af938393 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -570,6 +570,9 @@ class CCSBackendConformanceTest : virtual void SetUp () { + CCSBackendConformanceTest::SpawnContext (&context); + gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); + mBackend = GetParam ()->testEnv ()->SetUp (); } @@ -641,6 +644,11 @@ class CCSBackendConformanceTest : ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin)); } + protected: + + CCSContext *context; + CCSContextGMock *gmockContext; + private: std::list mSpawnedContexts; @@ -838,12 +846,9 @@ class CCSBackendConformanceTestReadWrite : settingName = GetParam ()->keyname (); VALUE = GetParam ()->value (); - - CCSBackendConformanceTest::SpawnContext (&context); CCSBackendConformanceTest::SpawnPlugin (pluginName, context, &plugin); CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); - gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); } @@ -858,10 +863,8 @@ class CCSBackendConformanceTestReadWrite : std::string pluginName; std::string settingName; VariantTypes VALUE; - CCSContext *context; CCSPlugin *plugin; CCSSetting *setting; - CCSContextGMock *gmockContext; CCSPluginGMock *gmockPlugin; CCSSettingGMock *gmockSetting; -- GitLab From 8757008632028a5d696f2772423d9b3eb0df5ea9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 14:46:46 +0800 Subject: [PATCH 065/562] Provide the mock CCSContext to CCSBackendConceptTestEnvironmentInterface::SetUp as the backend constructor may need to use it --- .../tests/compizconfig_test_ccs_mock_backend_conformance.cpp | 2 +- compizconfig/tests/compizconfig_backend_concept_test.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index c269042dd..cf2b62aaf 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -47,7 +47,7 @@ class MockCCSBackendConceptTestEnvironment : { public: - CCSBackend * SetUp () + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { mBackend = ccsMockBackendNew (); mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 8af938393..988a9d1bd 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -147,7 +147,8 @@ class CCSBackendConceptTestEnvironmentInterface public: virtual ~CCSBackendConceptTestEnvironmentInterface () {}; - virtual CCSBackend * SetUp () = 0; + virtual CCSBackend * SetUp (CCSContext *context, + CCSContextGMock *gmockContext) = 0; virtual void TearDown (CCSBackend *) = 0; virtual void PreWrite (CCSContextGMock *, @@ -573,7 +574,7 @@ class CCSBackendConformanceTest : CCSBackendConformanceTest::SpawnContext (&context); gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); - mBackend = GetParam ()->testEnv ()->SetUp (); + mBackend = GetParam ()->testEnv ()->SetUp (context, gmockContext); } virtual void TearDown () -- GitLab From 4aefadf9fe7ef3227c97fbf28e8848aa45deed58 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 15:00:31 +0800 Subject: [PATCH 066/562] Attach to the correct test fixture --- .../gsettings/tests/test_gsettings_conformance.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 48a651d8b..aa8fefcbf 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -28,7 +28,7 @@ class CCSGSettingsBackendEnv : g_type_init (); } - CCSBackend * SetUp () + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { CCSBackendInterface *interface = NULL; Bool fallback = FALSE; @@ -38,7 +38,7 @@ class CCSGSettingsBackendEnv : g_setenv ("LIBCOMPIZCONFIG_BACKEND_PATH", BACKEND_BINARY_PATH, true); mSettings = g_settings_new_with_path (MOCK_SCHEMA.c_str (), makeCompizPluginPath ("mock", "mock")); - mContext = ccsMockContextNew (); + mContext = context; std::string path ("gsettings"); @@ -66,7 +66,6 @@ class CCSGSettingsBackendEnv : ccsFreeBackendWithCapabilities (mBackend); g_object_unref (mSettings); - ccsFreeMockContext (mContext); } void PreWrite (CCSContextGMock *gmockContext, @@ -165,6 +164,6 @@ class CCSGSettingsBackendEnv : CCSBackendWithCapabilities *mBackend; }; -INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTest, +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestReadWrite, compizconfig::test::GenerateTestingParametersForBackendInterface ()); -- GitLab From d0fc8702b564793207016330f125087743d45a5f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 14 Jul 2012 15:05:10 +0800 Subject: [PATCH 067/562] Rename "plugin" to "mock" --- compizconfig/tests/compizconfig_backend_concept_test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 988a9d1bd..cfda2d84a 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -843,7 +843,7 @@ class CCSBackendConformanceTestReadWrite : { CCSBackendConformanceTest::SetUp (); - pluginName = "plugin"; + pluginName = "mock"; settingName = GetParam ()->keyname (); VALUE = GetParam ()->value (); -- GitLab From 2b5c572f2a9890d848127282ab6ed4b798959e0e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 15 Jul 2012 02:15:14 +0800 Subject: [PATCH 068/562] Set appropriate expectaitons for gsettings backend conformance --- .../tests/test_gsettings_conformance.cpp | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index aa8fefcbf..b002b5e98 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -12,6 +12,8 @@ #include +using ::testing::AtLeast; + namespace { const std::string MOCK_SCHEMA ("org.compiz.mock"); @@ -71,7 +73,18 @@ class CCSGSettingsBackendEnv : void PreWrite (CCSContextGMock *gmockContext, CCSPluginGMock *gmockPlugin, CCSSettingGMock *gmockSetting, - CCSSettingType type) {} + CCSSettingType type) + { + EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockContext, findPlugin (Pointee ("mock"))).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getIsDefault ()).WillRepeatedly (Return (FALSE)); + } + void PostWrite (CCSContextGMock *gmockContext, CCSPluginGMock *gmockPlugin, CCSSettingGMock *gmockSetting, @@ -122,7 +135,17 @@ class CCSGSettingsBackendEnv : void PreRead (CCSContextGMock *gmockContext, CCSPluginGMock *gmockPlugin, CCSSettingGMock *gmockSetting, - CCSSettingType type) {} + CCSSettingType type) + { + EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, isReadOnly ()).WillRepeatedly (Return (FALSE)); + } + void PostRead (CCSContextGMock *gmockContext, CCSPluginGMock *gmockPlugin, CCSSettingGMock *gmockSetting, -- GitLab From 527ccfddd605334c556b013cbcde6577a1a9a30f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 15 Jul 2012 02:26:20 +0800 Subject: [PATCH 069/562] Make the gmocks take the interface pointer so that they can provide it so their users --- .../compizconfig_ccs_backend_mock.cpp | 2 +- .../compizconfig_ccs_backend_mock.h | 11 +++++++++++ .../compizconfig_ccs_context_mock.cpp | 2 +- .../compizconfig_ccs_context_mock.h | 11 +++++++++++ .../compizconfig_ccs_plugin_mock.cpp | 2 +- .../compizconfig_ccs_plugin_mock.h | 12 ++++++++++++ .../compizconfig_ccs_setting_mock.cpp | 2 +- .../compizconfig_ccs_setting_mock.h | 17 ++++++++++++----- 8 files changed, 50 insertions(+), 9 deletions(-) diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp index a87c120c9..deb19ab70 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp @@ -37,7 +37,7 @@ ccsMockBackendNew () ccsObjectInit (backend, &ccsDefaultObjectAllocator); - CCSBackendGMock *mock = new CCSBackendGMock (); + CCSBackendGMock *mock = new CCSBackendGMock (backend); ccsObjectSetPrivate (backend, (CCSPrivate *) mock); ccsObjectAddInterface (backend, (CCSInterface *) &CCSBackendGMockInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index 3f39f3f71..8ba01bb09 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -40,6 +40,13 @@ class CCSBackendGMock : { public: + CCSBackendGMock (CCSBackend *b) : + mBackend (b) + { + } + + CCSBackend * backend () { return mBackend; } + /* Mock implementations */ MOCK_METHOD0 (getName, char * ()); MOCK_METHOD0 (getShortDesc, char * ()); @@ -60,6 +67,10 @@ class CCSBackendGMock : MOCK_METHOD1 (getExistingProfiles, CCSStringList (CCSContext *)); MOCK_METHOD2 (deleteProfile, Bool (CCSContext *, char *name)); + private: + + CCSBackend *mBackend; + public: /* Thunking C to C++ */ diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp index d2b825597..2c483dc78 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp @@ -54,7 +54,7 @@ ccsMockContextNew () ccsObjectInit (context, &ccsDefaultObjectAllocator); - CCSContextGMock *mock = new CCSContextGMock (); + CCSContextGMock *mock = new CCSContextGMock (context); ccsObjectSetPrivate (context, (CCSPrivate *) mock); ccsObjectAddInterface (context, (CCSInterface *) &CCSContextGMockInterface, GET_INTERFACE_TYPE (CCSContextInterface)); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h index 1000d0d90..03e074495 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h @@ -53,6 +53,13 @@ class CCSContextGMock : { public: + CCSContextGMock (CCSContext *c) : + mContext (c) + { + } + + CCSContext * context () { return mContext; } + MOCK_METHOD0 (getPlugins, CCSPluginList ()); MOCK_METHOD0 (getCategories, CCSPluginCategory * ()); MOCK_METHOD0 (getChangedSettings, CCSSettingList ()); @@ -88,6 +95,10 @@ class CCSContextGMock : MOCK_METHOD0 (checkForSettingsUpgrade, Bool ()); MOCK_METHOD0 (loadPlugins, void ()); + private: + + CCSContext *mContext; + public: /* Thunking from C interface callbacks to the virtual functions ... */ diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp index 209aa3bd6..c4abc268f 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp @@ -39,7 +39,7 @@ ccsMockPluginNew () ccsObjectInit (plugin, &ccsDefaultObjectAllocator); - CCSPluginGMock *mock = new CCSPluginGMock (); + CCSPluginGMock *mock = new CCSPluginGMock (plugin); ccsObjectSetPrivate (plugin, (CCSPrivate *) mock); ccsObjectAddInterface (plugin, (CCSInterface *) &CCSPluginGMockInterface, GET_INTERFACE_TYPE (CCSPluginInterface)); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h index bf4333d5e..36c9d6c0b 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h @@ -38,6 +38,14 @@ class CCSPluginGMock : { public: + CCSPluginGMock (CCSPlugin *p) : + mPlugin (p) + { + } + + CCSPlugin * + plugin () { return mPlugin; } + /* Mock implementations */ MOCK_METHOD0 (getName, char * ()); MOCK_METHOD0 (getShortDesc, char * ()); @@ -59,6 +67,10 @@ class CCSPluginGMock : MOCK_METHOD0 (readPluginSettings, void ()); MOCK_METHOD0 (getPluginStrExtensions, CCSStrExtensionList ()); + private: + + CCSPlugin *mPlugin; + public: /* Thunking C to C++ */ diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp index 10c2a42ec..8b3d5d0c4 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp @@ -60,7 +60,7 @@ ccsMockSettingNew () ccsObjectInit (setting, &ccsDefaultObjectAllocator); - CCSSettingGMock *mock = new CCSSettingGMock (); + CCSSettingGMock *mock = new CCSSettingGMock (setting); ccsObjectSetPrivate (setting, (CCSPrivate *) mock); ccsObjectAddInterface (setting, (CCSInterface *) &CCSSettingGMockInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h index e27dc03c3..14d02de22 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h @@ -64,6 +64,15 @@ class CCSSettingGMock : /* Mock implementations */ + CCSSettingGMock (CCSSetting *s) : + mSetting (s) + { + /* Teach GMock how to handle it */ + ON_CALL (*this, getType ()).WillByDefault (Return (TypeNum)); + } + + CCSSetting * setting () { return mSetting; } + MOCK_METHOD0 (getName, char * ()); MOCK_METHOD0 (getShortDesc, char * ()); MOCK_METHOD0 (getLongDesc, char * ()); @@ -105,11 +114,9 @@ class CCSSettingGMock : MOCK_METHOD0 (isIntegrated, Bool ()); MOCK_METHOD0 (isReadOnly, Bool ()); - CCSSettingGMock () - { - /* Teach GMock how to handle it */ - ON_CALL (*this, getType ()).WillByDefault (Return (TypeNum)); - } + private: + + CCSSetting *mSetting; public: -- GitLab From 5db76bdc9fb7c46f37f5b949e99cfa8be5f40fd0 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 15 Jul 2012 03:07:24 +0800 Subject: [PATCH 070/562] Make the tests not crash --- .../gsettings/tests/test_gsettings_conformance.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index b002b5e98..270e3c635 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -13,6 +13,7 @@ #include using ::testing::AtLeast; +using ::testing::Pointee; namespace { @@ -25,7 +26,8 @@ class CCSGSettingsBackendEnv : { public: - CCSGSettingsBackendEnv () + CCSGSettingsBackendEnv () : + pluginToMatch ("mock") { g_type_init (); } @@ -76,7 +78,8 @@ class CCSGSettingsBackendEnv : CCSSettingType type) { EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillOnce (Return (FALSE)); - EXPECT_CALL (*gmockContext, findPlugin (Pointee ("mock"))).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (gmockPlugin->plugin ())); + EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (gmockSetting->setting ())); EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); @@ -185,6 +188,7 @@ class CCSGSettingsBackendEnv : GSettings *mSettings; CCSContext *mContext; CCSBackendWithCapabilities *mBackend; + std::string pluginToMatch; }; INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestReadWrite, -- GitLab From 3bb4599a33a99c83da2dcf45b6d67a13fd40e8cf Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 15 Jul 2012 03:22:16 +0800 Subject: [PATCH 071/562] Make getProfile return "mock" by default and convert CCSContextGetProfile to return const char * --- compizconfig/gconf/src/gconf.c | 9 ++++--- .../libcompizconfig/backend/src/ini.c | 25 +++++++++++-------- compizconfig/libcompizconfig/include/ccs.h | 4 +-- compizconfig/libcompizconfig/src/main.c | 4 +-- .../compizconfig_ccs_context_mock.h | 6 ++--- .../tests/compizconfig_backend_concept_test.h | 9 +++++++ 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 4f233c543..28d994871 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -1885,15 +1885,16 @@ getCurrentProfileName (void) static Bool checkProfile (CCSContext *context) { - char *profile, *lastProfile; + const char *profileCCS; + char *lastProfile; lastProfile = currentProfile; - profile = ccsGetProfile (context); - if (!profile || !strlen (profile)) + profileCCS = ccsGetProfile (context); + if (!profileCCS || !strlen (profileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (profile); + currentProfile = strdup (profileCCS); if (!lastProfile || strcmp (lastProfile, currentProfile) != 0) { diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 88d4d2ba1..f00c18cde 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -233,7 +233,8 @@ static Bool readInit (CCSBackend *backend, CCSContext * context) { - char *currentProfile; + const char *currentProfileCCS; + char *currentProfile; IniPrivData *data; data = findPrivFromContext (context); @@ -241,12 +242,12 @@ readInit (CCSBackend *backend, if (!data) return FALSE; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); if (!data->lastProfile || (strcmp (data->lastProfile, currentProfile) != 0)) setProfile (data, currentProfile); @@ -424,6 +425,7 @@ readDone (CCSBackend *backend, CCSContext * context) static Bool writeInit (CCSBackend *backend, CCSContext * context) { + const char *currentProfileCCS; char *currentProfile; IniPrivData *data; @@ -432,12 +434,12 @@ writeInit (CCSBackend *backend, CCSContext * context) if (!data) return FALSE; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); if (!data->lastProfile || (strcmp (data->lastProfile, currentProfile) != 0)) setProfile (data, currentProfile); @@ -577,19 +579,20 @@ writeDone (CCSBackend *backend, CCSContext * context) { /* export the data to ensure the changes are on disk */ char *fileName; - char *currentProfile; + const char *currentProfileCCS; + char *currentProfile; IniPrivData *data; data = findPrivFromContext (context); if (!data) return; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); fileName = getIniFileName (currentProfile); diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 1b752a1c5..0376c4220 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -161,7 +161,7 @@ typedef char * (*CCSContextGetBackend) (CCSContext *context); typedef void (*CCSContextSetIntegrationEnabled) (CCSContext *context, Bool value); typedef void (*CCSContextSetProfile) (CCSContext *context, char *name); typedef void (*CCSContextSetPluginListAutoSort) (CCSContext *context, Bool value); -typedef char * (*CCSContextGetProfile) (CCSContext *context); +typedef const char * (*CCSContextGetProfile) (CCSContext *context); typedef Bool (*CCSContextGetIntegrationEnabled) (CCSContext *context); typedef Bool (*CCSContextGetPluginListAutoSort) (CCSContext *context); typedef void (*CCSContextProcessEvents) (CCSContext *context, unsigned int flags); @@ -856,7 +856,7 @@ void ccsSetPluginListAutoSort (CCSContext *context, Bool value); /* Retrieve current profile of the context. */ -char * ccsGetProfile (CCSContext *context); +const char *ccsGetProfile (CCSContext *context); /* Retrieves current DE integration status for a context */ Bool ccsGetIntegrationEnabled (CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 3b15dea4a..bda4732ab 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -3041,7 +3041,7 @@ ccsGetIntegrationEnabled (CCSContext *context) return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetIntegrationEnabled) (context); } -char * +const char * ccsGetProfileDefault (CCSContext * context) { if (!context) @@ -3052,7 +3052,7 @@ ccsGetProfileDefault (CCSContext * context) return cPrivate->profile; } -char * +const char * ccsGetProfile (CCSContext *context) { if (!context) diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h index 03e074495..f7c28f7b4 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h @@ -31,7 +31,7 @@ class CCSContextGMockInterface virtual void setIntegrationEnabled (Bool value) = 0; virtual void setProfile (char *name) = 0; virtual void setPluginListAutoSort (Bool value) = 0; - virtual char * getProfile () = 0; + virtual const char * getProfile () = 0; virtual Bool getIntegrationEnabled () = 0; virtual Bool getPluginListAutoSort () = 0; virtual void processEvents (unsigned int flags) = 0; @@ -79,7 +79,7 @@ class CCSContextGMock : MOCK_METHOD1 (setIntegrationEnabled, void (Bool)); MOCK_METHOD1 (setProfile, void (char *)); MOCK_METHOD1 (setPluginListAutoSort, void (Bool)); - MOCK_METHOD0 (getProfile, char * ()); + MOCK_METHOD0 (getProfile, const char * ()); MOCK_METHOD0 (getIntegrationEnabled, Bool ()); MOCK_METHOD0 (getPluginListAutoSort, Bool ()); MOCK_METHOD1 (processEvents, void (unsigned int)); @@ -201,7 +201,7 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getIntegrationEnabled (); } - static char * + static const char * ccsGetProfile (CCSContext *context) { if (!context) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index cfda2d84a..fd145602d 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -564,6 +564,11 @@ class CCSBackendConformanceTest : virtual ~CCSBackendConformanceTest () {} + CCSBackendConformanceTest () : + profileName ("mock") + { + } + CCSBackend * GetBackend () { return mBackend; @@ -574,6 +579,8 @@ class CCSBackendConformanceTest : CCSBackendConformanceTest::SpawnContext (&context); gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); + mBackend = GetParam ()->testEnv ()->SetUp (context, gmockContext); } @@ -657,6 +664,8 @@ class CCSBackendConformanceTest : std::list mSpawnedSettings; CCSBackend *mBackend; + + std::string profileName; }; namespace compizconfig -- GitLab From c9110a47b33643c8eb0cf62ad2a87de025577af0 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 15 Jul 2012 03:35:32 +0800 Subject: [PATCH 072/562] Make the write tests pass with a little less noise --- .../gsettings/tests/test_gsettings_conformance.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 270e3c635..fbdb0c087 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -77,8 +77,9 @@ class CCSGSettingsBackendEnv : CCSSettingGMock *gmockSetting, CCSSettingType type) { - EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillRepeatedly (Return (FALSE)); EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (gmockPlugin->plugin ())); + EXPECT_CALL (*gmockContext, getProfile ()); EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (gmockSetting->setting ())); EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); @@ -86,6 +87,10 @@ class CCSGSettingsBackendEnv : EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getIsDefault ()).WillRepeatedly (Return (FALSE)); + + /* This is just a temporary workaround so that we don't go read in the setting */ + EXPECT_CALL (*gmockSetting, isReadOnly ()).WillOnce (Return (TRUE)); + EXPECT_CALL (*gmockSetting, resetToDefault (TRUE)); } void PostWrite (CCSContextGMock *gmockContext, -- GitLab From 8fc093d7f7ac4a8a947df338df2affe2b51a4c42 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 15 Jul 2012 09:41:06 +0800 Subject: [PATCH 073/562] Add integer expectations --- .../tests/test_gsettings_conformance.cpp | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index fbdb0c087..16cac994d 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -110,8 +110,16 @@ class CCSGSettingsBackendEnv : } void WriteIntegerAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) {} + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeIntToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteFloatAtKey (const std::string &plugin, const std::string &key, const VariantTypes &value) {} @@ -164,12 +172,21 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("default", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), TypeBool); return readBoolFromVariant (variant); } + int ReadIntegerAtKey (const std::string &plugin, - const std::string &key) { return 0; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeInt); + return readIntFromVariant (variant); + } + float ReadFloatAtKey (const std::string &plugin, const std::string &key) { return 0.0; } const char * ReadStringAtKey (const std::string &plugin, -- GitLab From 0ccf9bd1f3fdd2617d9d367b26f44ab6b8ce7c67 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 15 Jul 2012 09:41:20 +0800 Subject: [PATCH 074/562] Change mock settings so that they are always different from the settings we change the values to in the tests --- compizconfig/gsettings/tests/org.compiz.mock.gschema.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml index 5eefd5ea1..d6c0187ad 100644 --- a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml +++ b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml @@ -2,13 +2,13 @@ - 1 + 0 - true + false - 1.0 + 0.0 "" @@ -17,7 +17,7 @@ "" - true + false "" -- GitLab From 2f5fc429083846736c246cad3505d397b993080d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 09:09:34 +0800 Subject: [PATCH 075/562] Provide CCSBackend to callers of translateKeyForGSettings so that we can get the backend when we are going to register the callback --- .../gsettings_backend_shared/gsettings_util.c | 8 ++ .../gsettings_backend_shared/gsettings_util.h | 20 +++++ .../gsettings/src/gconf-integration.c | 8 +- compizconfig/gsettings/src/gsettings.c | 85 ++++++++++++------- compizconfig/gsettings/src/gsettings.h | 10 ++- 5 files changed, 94 insertions(+), 37 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 58f633b7d..6523936fc 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -4,6 +4,8 @@ #include #include "gsettings_shared.h" +INTERFACE_TYPE (CCSGSettingsBackendInterface); + GList * variantTypeToPossibleSettingType (const gchar *vt) { @@ -752,3 +754,9 @@ writeVariantToKey (GSettings *settings, { g_settings_set_value (settings, key, value); } + +CCSContext * +ccsGSettingsBackendGetContext (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetContext) (backend); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index f14845112..d416128b4 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -9,6 +9,23 @@ COMPIZCONFIG_BEGIN_DECLS #include #include +typedef struct _CCSGSettingsBackendPrivate CCSGettingsBackendPrivate; +typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; + +typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); + +struct _CCSGSettingsBackendInterface +{ + CCSGSettingsBackendGetContext gsettingsBackendGetContext; +}; + +struct _CCSGSettingsBackendPrivate +{ + CCSContext *context; +}; + +unsigned int ccsCCSGSettingsBackendInterfaceGetType (); + gchar * getSchemaNameForPlugin (const char *plugin); @@ -122,6 +139,9 @@ void writeVariantToKey (GSettings *settings, const char *key, GVariant *value); +CCSContext * +ccsGSettingsBackendGetContext (CCSBackend *backend); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gconf-integration.c b/compizconfig/gsettings/src/gconf-integration.c index ebc74cd97..085a75fa0 100644 --- a/compizconfig/gsettings/src/gconf-integration.c +++ b/compizconfig/gsettings/src/gconf-integration.c @@ -537,7 +537,8 @@ getButtonBindingForSetting (CCSContext *context, } Bool -readGConfIntegratedOption (CCSContext *context, +readGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { @@ -545,7 +546,7 @@ readGConfIntegratedOption (CCSContext *context, GError *err = NULL; Bool ret = FALSE; - ret = readOption (setting); + ret = readOption (backend, setting); gconfValue = gconf_client_get (client, specialOptions[index].gnomeName, @@ -765,7 +766,8 @@ setButtonBindingForSetting (CCSContext *context, } void -writeGConfIntegratedOption (CCSContext *context, +writeGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 751195d04..6906ee21d 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -46,15 +46,20 @@ static GSettings *currentProfileSettings = NULL; char *currentProfile = NULL; +/* This will need to be rempved */ +CCSContext *storedContext = NULL; + /* some forward declarations */ -static void writeIntegratedOption (CCSContext *context, +static void writeIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index); static GSettings * -getSettingsObjectForPluginWithPath (const char *plugin, - const char *path, - CCSContext *context) +getSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) { GSettings *settingsObj = NULL; gchar *schemaName = getSchemaNameForPlugin (plugin); @@ -74,7 +79,7 @@ getSettingsObjectForPluginWithPath (const char *plugin, settingsObj = g_settings_new_with_path (schemaName, path); - g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) context); + g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) backend); settingsList = g_list_append (settingsList, (void *) settingsObj); @@ -104,14 +109,15 @@ makeSettingPath (CCSSetting *setting) } static GSettings * -getSettingsObjectForCCSSetting (CCSSetting *setting) +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) { GSettings *ret = NULL; gchar *pathName = makeSettingPath (setting); - ret = getSettingsObjectForPluginWithPath (ccsPluginGetName (ccsSettingGetParent (setting)), - pathName, - ccsPluginGetContext (ccsSettingGetParent (setting))); + ret = getSettingsObjectForPluginWithPath (backend, + ccsPluginGetName (ccsSettingGetParent (setting)), + pathName, + ccsPluginGetContext (ccsSettingGetParent (setting))); g_free (pathName); return ret; @@ -133,7 +139,8 @@ valueChanged (GSettings *settings, gchar *keyName, gpointer user_data) { - CCSContext *context = (CCSContext *)user_data; + CCSBackend *backend = (CCSBackend *)user_data; + CCSContext *context = ccsGSettingsBackendGetContext (backend); char *uncleanKeyName; char *path, *pathOrig; char *pluginName; @@ -200,7 +207,7 @@ valueChanged (GSettings *settings, } readInit (NULL, context); - if (!readOption (setting)) + if (!readOption (backend, setting)) { ccsResetToDefault (setting, TRUE); } @@ -209,7 +216,7 @@ valueChanged (GSettings *settings, isIntegratedOption (setting, &index)) { writeInit (NULL, context); - writeIntegratedOption (context, setting, index); + writeIntegratedOption (backend, context, setting, index); } g_free (pluginName); @@ -218,21 +225,22 @@ valueChanged (GSettings *settings, } static Bool -readIntegratedOption (CCSContext *context, +readIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { #ifdef USE_GCONF - return readGConfIntegratedOption (context, setting, index); + return readGConfIntegratedOption (backend, context, setting, index); #else return FALSE; #endif } static GVariant * -getVariantForCCSSetting (CCSSetting *setting) +getVariantForCCSSetting (CCSBackend *backend, CCSSetting *setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); + GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = getNameForCCSSetting (setting); gchar *pathName = makeSettingPath (setting); GVariant *gsettingsValue = getVariantAtKey (settings, @@ -246,7 +254,7 @@ getVariantForCCSSetting (CCSSetting *setting) } Bool -readOption (CCSSetting * setting) +readOption (CCSBackend *backend, CCSSetting * setting) { Bool ret = FALSE; GVariant *gsettingsValue = NULL; @@ -262,7 +270,7 @@ readOption (CCSSetting * setting) return FALSE; } - gsettingsValue = getVariantForCCSSetting (setting); + gsettingsValue = getVariantForCCSSetting (backend, setting); switch (ccsSettingGetType (setting)) { @@ -400,21 +408,22 @@ readOption (CCSSetting * setting) } static void -writeIntegratedOption (CCSContext *context, +writeIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { #ifdef USE_GCONF - writeGConfIntegratedOption (context, setting, index); + writeGConfIntegratedOption (backend, context, setting, index); #endif return; } static void -resetOptionToDefault (CCSSetting * setting) +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); + GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); @@ -424,9 +433,9 @@ resetOptionToDefault (CCSSetting * setting) } void -writeOption (CCSSetting * setting) +writeOption (CCSBackend *backend, CCSSetting * setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); + GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); GVariant *gsettingsValue = NULL; Bool success = FALSE; @@ -647,6 +656,16 @@ processEvents (CCSBackend *backend, unsigned int flags) } } +static CCSContext * +ccsGSettingsBackendGetContextDefault (CCSBackend *backend) +{ + return storedContext; +} + +static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { + ccsGSettingsBackendGetContextDefault +}; + static Bool initBackend (CCSBackend *backend, CCSContext * context) { @@ -666,6 +685,10 @@ initBackend (CCSBackend *backend, CCSContext * context) g_free (currentProfilePath); + storedContext = context; + + ccsObjectAddInterface (backend, (CCSInterface *) &gsettingsAdditionalDefaultInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + return TRUE; } @@ -726,10 +749,10 @@ readSetting (CCSBackend *backend, if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - status = readIntegratedOption (context, setting, index); + status = readIntegratedOption (backend, context, setting, index); } else - status = readOption (setting); + status = readOption (backend, setting); if (!status) ccsResetToDefault (setting, TRUE); @@ -751,14 +774,14 @@ writeSetting (CCSBackend *backend, if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeIntegratedOption (context, setting, index); + writeIntegratedOption (backend, context, setting, index); } else if (ccsSettingGetIsDefault (setting)) { - resetOptionToDefault (setting); + resetOptionToDefault (backend, setting); } else - writeOption (setting); + writeOption (backend, setting); } @@ -828,7 +851,7 @@ deleteProfile (CCSBackend *backend, GSettings *settings; gchar *pathName = makeCompizPluginPath (currentProfile, plugin); - settings = getSettingsObjectForPluginWithPath (plugin, pathName, context); + settings = getSettingsObjectForPluginWithPath (backend, plugin, pathName, context); g_free (pathName); /* The GSettings documentation says not to use this API @@ -929,6 +952,8 @@ static CCSBackendInterface gsettingsVTable = { deleteProfile }; + + CCSBackendInterface * getBackendInfo (void) { diff --git a/compizconfig/gsettings/src/gsettings.h b/compizconfig/gsettings/src/gsettings.h index 000a4dbca..718504355 100644 --- a/compizconfig/gsettings/src/gsettings.h +++ b/compizconfig/gsettings/src/gsettings.h @@ -68,9 +68,9 @@ char *currentProfile; Bool readInit (CCSBackend *, CCSContext * context); void readSetting (CCSBackend *, CCSContext * context, CCSSetting * setting); -Bool readOption (CCSSetting * setting); +Bool readOption (CCSBackend *backend, CCSSetting * setting); Bool writeInit (CCSBackend *, CCSContext * context); -void writeOption (CCSSetting *setting); +void writeOption (CCSBackend *backend, CCSSetting *setting); #ifdef USE_GCONF @@ -106,12 +106,14 @@ void finiGConfClient (void); Bool -readGConfIntegratedOption (CCSContext *context, +readGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index); void -writeGConfIntegratedOption (CCSContext *context, +writeGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index); -- GitLab From d9c30250d13e51f6595866b1f27eaccba7fb4ae0 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 09:32:25 +0800 Subject: [PATCH 076/562] Hide signal connection behind interface --- .../gsettings_backend_shared/gsettings_util.c | 8 ++++++++ .../gsettings_backend_shared/gsettings_util.h | 5 +++++ compizconfig/gsettings/src/gsettings.c | 11 +++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 6523936fc..76c73e8e1 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -760,3 +760,11 @@ ccsGSettingsBackendGetContext (CCSBackend *backend) { return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetContext) (backend); } + + +void +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, + GObject *object) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendConnectToChangedSignal) (backend, object); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index d416128b4..a9f4c18a6 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -13,10 +13,12 @@ typedef struct _CCSGSettingsBackendPrivate CCSGettingsBackendPrivate; typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); +typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, GObject *); struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; + CCSGSettingsBackendConnectToChangedSignal gsettingsBackendConnectToChangedSignal; }; struct _CCSGSettingsBackendPrivate @@ -142,6 +144,9 @@ void writeVariantToKey (GSettings *settings, CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend); +void +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, GObject *object); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 6906ee21d..5463ba639 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -79,7 +79,7 @@ getSettingsObjectForPluginWithPath (CCSBackend *backend, settingsObj = g_settings_new_with_path (schemaName, path); - g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) backend); + ccsGSettingsBackendConnectToChangedSignal (backend, G_OBJECT (settingsObj)); settingsList = g_list_append (settingsList, (void *) settingsObj); @@ -662,8 +662,15 @@ ccsGSettingsBackendGetContextDefault (CCSBackend *backend) return storedContext; } +static void +ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, GObject *object) +{ + g_signal_connect (object, "changed", (GCallback) valueChanged, (gpointer) backend); +} + static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { - ccsGSettingsBackendGetContextDefault + ccsGSettingsBackendGetContextDefault, + ccsGSettingsBackendConnectToValueChangedSignalDefault }; static Bool -- GitLab From adf796e902a6e3b78aa4063555b47d2beb71be12 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 10:33:54 +0800 Subject: [PATCH 077/562] Neutralize the signal connection --- .../gsettings/tests/test_gsettings_conformance.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 16cac994d..6e3010389 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -32,6 +32,11 @@ class CCSGSettingsBackendEnv : g_type_init (); } + /* A wrapper to prevent signals from being added */ + static void connectToSignalWrapper (CCSBackend *backend, GObject *object) + { + }; + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { CCSBackendInterface *interface = NULL; @@ -59,6 +64,12 @@ class CCSGSettingsBackendEnv : if (backendInit) (*backendInit) ((CCSBackend *) mBackend, mContext); + overloadedInterface = *(GET_INTERFACE (CCSGSettingsBackendInterface, backend)); + overloadedInterface.gsettingsBackendConnectToChangedSignal = CCSGSettingsBackendEnv::connectToSignalWrapper; + + ccsObjectRemoveInterface (backend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + ccsObjectAddInterface (backend, (CCSInterface *) &overloadedInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + return (CCSBackend *) mBackend; } @@ -211,6 +222,7 @@ class CCSGSettingsBackendEnv : CCSContext *mContext; CCSBackendWithCapabilities *mBackend; std::string pluginToMatch; + CCSGSettingsBackendInterface overloadedInterface; }; INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestReadWrite, -- GitLab From 66f0094531d2113eed35e7579ee99d83516776ad Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 10:38:44 +0800 Subject: [PATCH 078/562] Reduce the amount of noise when calling the write functions --- .../gsettings/tests/test_gsettings_conformance.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 6e3010389..ef754bc9d 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -89,19 +89,12 @@ class CCSGSettingsBackendEnv : CCSSettingType type) { EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillRepeatedly (Return (FALSE)); - EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (gmockPlugin->plugin ())); - EXPECT_CALL (*gmockContext, getProfile ()); - EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (gmockSetting->setting ())); EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getIsDefault ()).WillRepeatedly (Return (FALSE)); - - /* This is just a temporary workaround so that we don't go read in the setting */ - EXPECT_CALL (*gmockSetting, isReadOnly ()).WillOnce (Return (TRUE)); - EXPECT_CALL (*gmockSetting, resetToDefault (TRUE)); } void PostWrite (CCSContextGMock *gmockContext, -- GitLab From 8a14d3302c7892c8b17ef61f2d7bef532af643d6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 11:10:52 +0800 Subject: [PATCH 079/562] Added float writing and reading funcs --- .../tests/test_gsettings_conformance.cpp | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index ef754bc9d..6db51f735 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -43,7 +43,10 @@ class CCSGSettingsBackendEnv : Bool fallback = FALSE; g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); - g_setenv ("GSETTINGS_BACKEND", "memory", true); + + /* For some reason a number of tests fail when using + * this GSettings backend */ + //g_setenv ("GSETTINGS_BACKEND", "memory", true); g_setenv ("LIBCOMPIZCONFIG_BACKEND_PATH", BACKEND_BINARY_PATH, true); mSettings = g_settings_new_with_path (MOCK_SCHEMA.c_str (), makeCompizPluginPath ("mock", "mock")); @@ -76,7 +79,7 @@ class CCSGSettingsBackendEnv : void TearDown (CCSBackend *) { g_unsetenv ("GSETTINGS_SCHEMA_DIR"); - g_unsetenv ("GSETTINGS_BACKEND"); + //g_unsetenv ("GSETTINGS_BACKEND"); ccsFreeBackendWithCapabilities (mBackend); @@ -126,7 +129,15 @@ class CCSGSettingsBackendEnv : void WriteFloatAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeFloatToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteStringAtKey (const std::string &plugin, const std::string &key, const VariantTypes &value) {} @@ -192,7 +203,15 @@ class CCSGSettingsBackendEnv : } float ReadFloatAtKey (const std::string &plugin, - const std::string &key) { return 0.0; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeInt); + return readFloatFromVariant (variant); + } + const char * ReadStringAtKey (const std::string &plugin, const std::string &key) { return ""; } CCSSettingColorValue ReadColorAtKey (const std::string &plugin, -- GitLab From 069a73a2022cfb02044575a52fd3880e94f325a5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 15:06:28 +0800 Subject: [PATCH 080/562] Fill in the other read and write constructs, only some of the tests pass --- .../gsettings_backend_shared/gsettings_util.c | 2 +- .../gsettings_backend_shared/gsettings_util.h | 2 +- .../tests/test_gsettings_conformance.cpp | 172 ++++++++++++++++-- 3 files changed, 157 insertions(+), 19 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 76c73e8e1..333e17b88 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -669,7 +669,7 @@ writeListValue (CCSSettingValueList list, return TRUE; } -Bool writeStringToVariant (char *value, GVariant **variant) +Bool writeStringToVariant (const char *value, GVariant **variant) { *variant = g_variant_new_string (value); return TRUE; diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index a9f4c18a6..be9928dea 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -121,7 +121,7 @@ writeListValue (CCSSettingValueList list, CCSSettingType listType, GVariant **gsettingsValue); -Bool writeStringToVariant (char *value, GVariant **variant); +Bool writeStringToVariant (const char *value, GVariant **variant); Bool writeFloatToVariant (float value, GVariant **variant); diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 6db51f735..9c1c366be 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -140,28 +140,94 @@ class CCSGSettingsBackendEnv : void WriteStringAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeStringToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteColorAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeColorToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteKeyAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeKeyToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteButtonAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeButtonToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteEdgeAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeEdgeToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteMatchAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeStringToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteBellAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeBoolToVariant (boolToBool (boost::get (value)), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + void WriteListAtKey (const std::string &plugin, const std::string &key, - const VariantTypes &value) {} + const VariantTypes &value) + { + GVariant *variant = NULL; + + const CCSListWrapper::Ptr &lw (boost::get (value)); + + if (writeListValue (*lw, lw->type (), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } void PreRead (CCSContextGMock *gmockContext, CCSPluginGMock *gmockPlugin, @@ -208,26 +274,98 @@ class CCSGSettingsBackendEnv : GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), - TypeInt); + TypeFloat); return readFloatFromVariant (variant); } const char * ReadStringAtKey (const std::string &plugin, - const std::string &key) { return ""; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeString); + return readStringFromVariant (variant); + } + CCSSettingColorValue ReadColorAtKey (const std::string &plugin, - const std::string &key) { CCSSettingColorValue v; return v;} + const std::string &key) + { + Bool success = FALSE; + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeColor); + CCSSettingColorValue value = readColorFromVariant (variant, &success); + EXPECT_TRUE (success); + return value; + } + CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, - const std::string &key) { CCSSettingKeyValue v; return v; } + const std::string &key) + { + Bool success = FALSE; + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeKey); + CCSSettingKeyValue value = readKeyFromVariant (variant, &success); + EXPECT_TRUE (success); + return value; + } + CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, - const std::string &key) { CCSSettingButtonValue v; return v; } + const std::string &key) + { + Bool success = FALSE; + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeButton); + CCSSettingButtonValue value = readButtonFromVariant (variant, &success); + EXPECT_TRUE (success); + return value; + } + unsigned int ReadEdgeAtKey (const std::string &plugin, - const std::string &key) { return 0; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeEdge); + return readEdgeFromVariant (variant); + } + const char * ReadMatchAtKey (const std::string &plugin, - const std::string &key) { return ""; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeMatch); + return readStringFromVariant (variant); + } + Bool ReadBellAtKey (const std::string &plugin, - const std::string &key) { return FALSE; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeInt); + return readBoolFromVariant (variant); + } + CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key) { return NULL; } + const std::string &key) + { + GVariant *variant = getVariantAtKey (mSettings, + CharacterWrapper (translateKeyForGSettings (key.c_str ())), + CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + TypeList); + return readListValue (variant, TypeNum); + } private: GSettings *mSettings; -- GitLab From 0f9bfc8bb060c4feca7232b14b40480b9d10a5dd Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 15:27:09 +0800 Subject: [PATCH 081/562] Fix Bool/gboolean difference for read and write expecations --- .../tests/compizconfig_backend_concept_test.h | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 52a5352a1..79368c5f7 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -29,6 +29,9 @@ using ::testing::Matcher; using ::testing::MatcherInterface; using ::testing::MatchResultListener; +MATCHER(IsTrue, "Is True") { if (arg) return true; else return false; } +MATCHER(IsFalse, "Is False") { if (!arg) return true; else return false; } + class ListEqualityMatcher : public MatcherInterface { @@ -295,7 +298,13 @@ void SetBoolWriteExpectation (const std::string &plugin, boolToBool (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadBoolAtKey (plugin, key), boolToBool (boost::get (value))); + + bool v (boost::get (value)); + + if (v) + EXPECT_THAT (env->ReadBoolAtKey (plugin, key), IsTrue ()); + else + EXPECT_THAT (env->ReadBoolAtKey (plugin, key), IsFalse ()); } void SetFloatWriteExpectation (const std::string &plugin, @@ -407,7 +416,12 @@ void SetBellWriteExpectation (const std::string &plugin, boolToBool (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadBellAtKey (plugin, key), boolToBool (boost::get (value))); + bool v (boost::get (value)); + + if (v) + EXPECT_THAT (env->ReadBellAtKey (plugin, key), IsTrue ()); + else + EXPECT_THAT (env->ReadBellAtKey (plugin, key), IsFalse ()); } void SetMatchWriteExpectation (const std::string &plugin, @@ -455,12 +469,22 @@ void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) void SetBoolReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setBool (boolToBool (boost::get (value)), _)); + bool v (boost::get (value)); + + if (v) + EXPECT_CALL (*gmock, setBool (IsTrue (), _)); + else + EXPECT_CALL (*gmock, setBool (IsFalse (), _)); } void SetBellReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setBell (boolToBool (boost::get (value)), _)); + bool v (boost::get (value)); + + if (v) + EXPECT_CALL (*gmock, setBell (IsTrue (), _)); + else + EXPECT_CALL (*gmock, setBell (IsFalse (), _)); } void SetFloatReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) -- GitLab From 95b91730e90bdd540ddc509d5776f033097a1151 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 16 Jul 2012 15:40:37 +0800 Subject: [PATCH 082/562] Fix string and match write tests, match is still being wonky... --- compizconfig/tests/compizconfig_backend_concept_test.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 79368c5f7..a50262218 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -336,7 +336,7 @@ void SetStringWriteExpectation (const std::string &plugin, const_cast (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadStringAtKey (plugin, key), boost::get (value)); + EXPECT_EQ (std::string (env->ReadStringAtKey (plugin, key)), std::string (boost::get (value))); } void SetColorWriteExpectation (const std::string &plugin, @@ -437,7 +437,7 @@ void SetMatchWriteExpectation (const std::string &plugin, const_cast (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadMatchAtKey (plugin, key), boost::get (value)); + EXPECT_EQ (std::string (env->ReadMatchAtKey (plugin, key)), std::string (boost::get (value))); } void SetListWriteExpectation (const std::string &plugin, -- GitLab From 1826037fa8e96adb36eb109d6ffb0a8ae65853b6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 18 Jul 2012 03:39:17 +0800 Subject: [PATCH 083/562] Use the same GSettings object in the tests and in the backend and also fix the color tests failing because of the lossy string conversion (simulate this behaviour in the tests too and add a note saying that we expect it). --- .../gsettings_backend_shared/gsettings_util.c | 9 +++++ .../gsettings_backend_shared/gsettings_util.h | 11 ++++++ compizconfig/gsettings/src/gsettings.c | 21 +++++----- .../tests/test_gsettings_conformance.cpp | 5 +-- .../tests/compizconfig_backend_concept_test.h | 38 ++++++++++++++++--- 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 333e17b88..9aefc981b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -768,3 +768,12 @@ ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, { (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendConnectToChangedSignal) (backend, object); } + +GSettings * +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetSettingsObjectForPluginWithPath) (backend, plugin, path, context); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index be9928dea..ae5779195 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -14,11 +14,16 @@ typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, GObject *); +typedef GSettings * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context); struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; CCSGSettingsBackendConnectToChangedSignal gsettingsBackendConnectToChangedSignal; + CCSGSettingsBackendGetSettingsObjectForPluginWithPath gsettingsBackendGetSettingsObjectForPluginWithPath; }; struct _CCSGSettingsBackendPrivate @@ -147,6 +152,12 @@ ccsGSettingsBackendGetContext (CCSBackend *backend); void ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, GObject *object); +GSettings * +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 5463ba639..f7aea2c92 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -56,10 +56,10 @@ static void writeIntegratedOption (CCSBackend *backend, int index); static GSettings * -getSettingsObjectForPluginWithPath (CCSBackend *backend, - const char *plugin, - const char *path, - CCSContext *context) +ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) { GSettings *settingsObj = NULL; gchar *schemaName = getSchemaNameForPlugin (plugin); @@ -114,10 +114,10 @@ getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) GSettings *ret = NULL; gchar *pathName = makeSettingPath (setting); - ret = getSettingsObjectForPluginWithPath (backend, - ccsPluginGetName (ccsSettingGetParent (setting)), - pathName, - ccsPluginGetContext (ccsSettingGetParent (setting))); + ret = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, + ccsPluginGetName (ccsSettingGetParent (setting)), + pathName, + ccsPluginGetContext (ccsSettingGetParent (setting))); g_free (pathName); return ret; @@ -670,7 +670,8 @@ ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, GObj static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendGetContextDefault, - ccsGSettingsBackendConnectToValueChangedSignalDefault + ccsGSettingsBackendConnectToValueChangedSignalDefault, + ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault }; static Bool @@ -858,7 +859,7 @@ deleteProfile (CCSBackend *backend, GSettings *settings; gchar *pathName = makeCompizPluginPath (currentProfile, plugin); - settings = getSettingsObjectForPluginWithPath (backend, plugin, pathName, context); + settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); g_free (pathName); /* The GSettings documentation says not to use this API diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 9c1c366be..33b6f636f 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -49,7 +49,6 @@ class CCSGSettingsBackendEnv : //g_setenv ("GSETTINGS_BACKEND", "memory", true); g_setenv ("LIBCOMPIZCONFIG_BACKEND_PATH", BACKEND_BINARY_PATH, true); - mSettings = g_settings_new_with_path (MOCK_SCHEMA.c_str (), makeCompizPluginPath ("mock", "mock")); mContext = context; std::string path ("gsettings"); @@ -73,6 +72,8 @@ class CCSGSettingsBackendEnv : ccsObjectRemoveInterface (backend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); ccsObjectAddInterface (backend, (CCSInterface *) &overloadedInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + mSettings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, "mock", makeCompizPluginPath ("mock", "mock"), mContext); + return (CCSBackend *) mBackend; } @@ -82,8 +83,6 @@ class CCSGSettingsBackendEnv : //g_unsetenv ("GSETTINGS_BACKEND"); ccsFreeBackendWithCapabilities (mBackend); - - g_object_unref (mSettings); } void PreWrite (CCSContextGMock *gmockContext, diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index a50262218..6aa88e015 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -80,6 +80,13 @@ operator== (const CCSSettingColorValue &lhs, return false; } +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingColorValue &v) +{ + return os << "Red: " << std::hex << v.color.red << "Blue: " << std::hex << v.color.blue << "Green: " << v.color.green << "Alpha: " << v.color.alpha + << std::dec << std::endl; +} + bool operator== (const CCSSettingKeyValue &lhs, const CCSSettingKeyValue &rhs) @@ -352,7 +359,16 @@ void SetColorWriteExpectation (const std::string &plugin, boost::get (value)), Return (TRUE))); write (); - EXPECT_EQ (env->ReadColorAtKey (plugin, key), boost::get (value)); + + /* Storage on most backends is lossy, so simulate this */ + CCSSettingColorValue v = boost::get (value); + char *str = ccsColorToString (&v); + + ccsStringToColor (str, &v); + + free (str); + + EXPECT_EQ (env->ReadColorAtKey (plugin, key), v); } void SetKeyWriteExpectation (const std::string &plugin, @@ -504,7 +520,14 @@ void SetMatchReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) void SetColorReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setColor (boost::get (value), _)); + CCSSettingColorValue v = boost::get (value); + char *str = ccsColorToString (&v); + + ccsStringToColor (str, &v); + + free (str); + + EXPECT_CALL (*gmock, setColor (v, _)); } void SetKeyReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) @@ -735,9 +758,14 @@ int intValues[] = { 1, 2, 3 }; float floatValues[] = { 1.0, 2.0, 3.0 }; const char * stringValues[] = { "foo", "grill", "bar" }; -CCSSettingColorValue colorValues[3] = { { .color = { 100, 200, 300, 100 } }, - { .color = { 50, 100, 200, 300 } }, - { .color = { 10, 20, 30, 40 } } +unsigned short max = std::numeric_limits ::max (); +unsigned short maxD2 = max / 2; +unsigned short maxD4 = max / 4; +unsigned short maxD8 = max / 8; + +CCSSettingColorValue colorValues[3] = { { .color = { maxD2 , maxD4, maxD8, max } }, + { .color = { maxD8, maxD4, maxD2, max } }, + { .color = { max, maxD4, maxD2, maxD8 } } }; CCSSettingKeyValue keyValue = { (1 << 0) | (1 << 1), -- GitLab From eaefa40e3fcb18f174dbac17bd054e101b68407a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 18 Jul 2012 09:12:09 +0800 Subject: [PATCH 084/562] Fix key and button tests + printers --- .../tests/compizconfig_backend_concept_test.h | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 6aa88e015..067867993 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -13,6 +13,8 @@ #include #include +#include + #include #include @@ -96,6 +98,12 @@ operator== (const CCSSettingKeyValue &lhs, return false; } +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingKeyValue &v) +{ + return os << "Keysym: " << v.keysym << " KeyModMask " << std::hex << v.keyModMask << std::dec << std::endl; +} + bool operator== (const CCSSettingButtonValue &lhs, const CCSSettingButtonValue &rhs) @@ -105,6 +113,12 @@ operator== (const CCSSettingButtonValue &lhs, return false; } +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingButtonValue &v) +{ + return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl; +} + class CharacterWrapper : boost::noncopyable { @@ -768,11 +782,11 @@ CCSSettingColorValue colorValues[3] = { { .color = { maxD2 , maxD4, maxD8, max } { .color = { max, maxD4, maxD2, maxD8 } } }; -CCSSettingKeyValue keyValue = { (1 << 0) | (1 << 1), - 1 }; +CCSSettingKeyValue keyValue = { XK_A, + (1 << 0)}; -CCSSettingButtonValue buttonValue = { (1 << 0) | (1 << 1), - 1, +CCSSettingButtonValue buttonValue = { 1, + (1 << 0), (1 << 1) }; } -- GitLab From 20613987388cbe56d1b1704bd9111f33b9af28c5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 18 Jul 2012 09:17:03 +0800 Subject: [PATCH 085/562] Fix missing break causing a test to fail --- compizconfig/gsettings/src/gsettings.c | 1 + 1 file changed, 1 insertion(+) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index f7aea2c92..a314360fc 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -459,6 +459,7 @@ writeOption (CCSBackend *backend, CCSSetting * setting) success = writeStringToVariant (value, &gsettingsValue); } } + break; case TypeFloat: { float value; -- GitLab From 153aa6080c321ead098b8027d54438aad3cc1206 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 18 Jul 2012 09:23:09 +0800 Subject: [PATCH 086/562] Fix broken ReadBellAtKey --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 33b6f636f..dc0f9ee4e 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -352,7 +352,7 @@ class CCSGSettingsBackendEnv : GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), - TypeInt); + TypeBell); return readBoolFromVariant (variant); } -- GitLab From 7b91238c01e8a9534dc32bde4da88f6ec58ab74d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 18 Jul 2012 17:21:57 +0800 Subject: [PATCH 087/562] Fix failing mock color test, we should simulate the toString behaviour there too --- .../compizconfig_test_ccs_mock_backend_conformance.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index cf2b62aaf..1c47b37d6 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -134,7 +134,13 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - mValues[keynameFromPluginKey (plugin, key)] = value; + CCSSettingColorValue v = boost::get (value); + + /* Convert it to simulate key storage lossyness */ + CharacterWrapper str (ccsColorToString (&v)); + ccsStringToColor (str, &v); + + mValues[keynameFromPluginKey (plugin, key)] = VariantTypes (v); } void WriteKeyAtKey (const std::string &plugin, -- GitLab From 17851602c19610e993803889ea8e8cc0e6475997 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 18 Jul 2012 17:32:30 +0800 Subject: [PATCH 088/562] Whitespace --- .../tests/compizconfig_test_ccs_mock_backend_conformance.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 1c47b37d6..c1cf1587f 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -72,7 +72,6 @@ class MockCCSBackendConceptTestEnvironment : void TearDown (CCSBackend *backend) { ccsFreeMockBackend (backend); - } void PreWrite (CCSContextGMock *gmockContext, -- GitLab From eb972ab5549924a72092dbd1c1e0ed445756de90 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 19 Jul 2012 13:56:27 +0800 Subject: [PATCH 089/562] We need to copy the lists and instantiate the lists a bit later so that we don't get segfault due to a double free --- compizconfig/libcompizconfig/include/ccs.h | 4 + compizconfig/libcompizconfig/src/main.c | 6 +- ...nfig_test_ccs_mock_backend_conformance.cpp | 20 +- .../tests/compizconfig_backend_concept_test.h | 184 ++++++++++++------ 4 files changed, 143 insertions(+), 71 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 0376c4220..1cc13e959 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -808,6 +808,10 @@ Bool * ccsGetBoolArrayFromValueList (CCSSettingValueList list, CCSSettingColorValue* ccsGetColorArrayFromValueList (CCSSettingValueList list, int *num); +/* Copies lists */ +CCSSettingValueList +ccsCopyList (CCSSettingValueList l1, CCSSetting * setting); + /* Converts an array of data items to a setting value list. Behaves similar to ccsGetListFromStringArray */ CCSSettingValueList ccsGetValueListFromStringArray (const char **array, diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 3240500c8..b5db4ed01 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -2300,13 +2300,11 @@ ccsSettingSetBellDefault (CCSSetting * setting, Bool data, Bool processChanged) return TRUE; } -static CCSSettingValueList +CCSSettingValueList ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) { CCSSettingValueList l2 = NULL; - SETTING_PRIV (setting) - while (l1) { CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue)); @@ -2317,7 +2315,7 @@ ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) value->parent = setting; value->isListChild = TRUE; - switch (sPrivate->info.forList.listType) + switch (ccsSettingGetInfo (setting)->forList.listType) { case TypeInt: value->value.asInt = l1->data->value.asInt; diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index c1cf1587f..a182100f5 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -15,6 +15,7 @@ using ::testing::WithArgs; using ::testing::Combine; using ::testing::ValuesIn; using ::testing::Values; +using ::testing::AtLeast; namespace { @@ -82,8 +83,17 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); EXPECT_CALL (*gmockPlugin, getName ()); EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getType ()); EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } } void PostWrite (CCSContextGMock *gmockContext, @@ -410,11 +420,15 @@ class MockCCSBackendConceptTestEnvironment : break; case TypeList: + { + CCSSettingValueList listCopy = NULL; ccsGetList (setting, &vList); - WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (vList, false, ccsSettingGetInfo (setting)->forList.listType))); - break; + listCopy = ccsCopyList (vList, setting); + WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, ccsSettingGetInfo (setting)->forList.listType))); + break; + } default: throw std::exception (); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 067867993..43030401e 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -200,6 +200,8 @@ class CCSBackendConceptTestEnvironmentInterface { public: + typedef boost::shared_ptr Ptr; + virtual ~CCSBackendConceptTestEnvironmentInterface () {}; virtual CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) = 0; @@ -281,6 +283,28 @@ class CCSBackendConceptTestEnvironmentInterface const std::string &key) = 0; }; +class CCSBackendConceptTestEnvironmentFactoryInterface +{ + public: + + virtual ~CCSBackendConceptTestEnvironmentFactoryInterface () {} + + virtual CCSBackendConceptTestEnvironmentInterface::Ptr ConstructTestEnv () = 0; +}; + +template +class CCSBackendConceptTestEnvironmentFactory : + public CCSBackendConceptTestEnvironmentFactoryInterface +{ + public: + + CCSBackendConceptTestEnvironmentInterface::Ptr + ConstructTestEnv () + { + return boost::shared_static_cast (boost::make_shared ()); + } +}; + namespace { @@ -295,7 +319,7 @@ void SetIntWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getInt (_)).WillRepeatedly (DoAll ( @@ -311,7 +335,7 @@ void SetBoolWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getBool (_)).WillRepeatedly (DoAll ( @@ -333,7 +357,7 @@ void SetFloatWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getFloat (_)).WillRepeatedly (DoAll ( @@ -349,7 +373,7 @@ void SetStringWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getString (_)).WillRepeatedly (DoAll ( @@ -365,7 +389,7 @@ void SetColorWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getColor (_)).WillRepeatedly (DoAll ( @@ -390,7 +414,7 @@ void SetKeyWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getKey (_)).WillRepeatedly (DoAll ( @@ -406,7 +430,7 @@ void SetButtonWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getButton (_)).WillRepeatedly (DoAll ( @@ -422,7 +446,7 @@ void SetEdgeWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getEdge (_)).WillRepeatedly (DoAll ( @@ -438,7 +462,7 @@ void SetBellWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getBell (_)).WillRepeatedly (DoAll ( @@ -459,7 +483,7 @@ void SetMatchWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getMatch (_)).WillRepeatedly (DoAll ( @@ -475,7 +499,7 @@ void SetListWriteExpectation (const std::string &plugin, const VariantTypes &value, CCSSetting *setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); CCSSettingValueList list = *(boost::get > (value)); @@ -578,9 +602,10 @@ class CCSBackendConceptTestParamInterface typedef boost::shared_ptr Ptr; - typedef boost::function NativeWriteMethod; + typedef void (CCSBackendConceptTestEnvironmentInterface::*NativeWriteMethod) (const std::string &plugin, + const std::string &keyname, + const VariantTypes &value); + typedef boost::function SetReadExpectation; typedef boost::function SetWriteExpectation; + const CCSBackendConceptTestEnvironmentInterface::Ptr & )> SetWriteExpectation; + + virtual void TearDown (CCSBackend *) = 0; - virtual CCSBackendConceptTestEnvironmentInterface * testEnv () = 0; + virtual CCSBackendConceptTestEnvironmentInterface::Ptr testEnv () = 0; virtual VariantTypes & value () = 0; - virtual NativeWriteMethod & nativeWrite () = 0; + virtual void nativeWrite (const CCSBackendConceptTestEnvironmentInterface::Ptr & iface, + const std::string &plugin, + const std::string &keyname, + const VariantTypes &value) = 0; virtual CCSSettingType & type () = 0; virtual std::string & keyname () = 0; virtual SetWriteExpectation & setWriteExpectationAndWrite () = 0; @@ -608,7 +638,7 @@ class CCSBackendConceptTestParam : typedef boost::shared_ptr > Ptr; - CCSBackendConceptTestParam (CCSBackendConceptTestEnvironmentInterface *testEnv, + CCSBackendConceptTestParam (CCSBackendConceptTestEnvironmentFactoryInterface *testEnvFactory, const VariantTypes &value, const NativeWriteMethod &write, const CCSSettingType &type, @@ -616,7 +646,8 @@ class CCSBackendConceptTestParam : const SetReadExpectation &setReadExpectation, const SetWriteExpectation &setWriteExpectation, const std::string &what) : - mTestEnv (testEnv), + mTestEnvFactory (testEnvFactory), + mTestEnv (), mValue (value), mNativeWrite (write), mType (type), @@ -627,9 +658,30 @@ class CCSBackendConceptTestParam : { } - CCSBackendConceptTestEnvironmentInterface * testEnv () { return mTestEnv; } + void TearDown (CCSBackend *b) + { + if (mTestEnv) + mTestEnv->TearDown (b); + + mTestEnv.reset (); + } + + CCSBackendConceptTestEnvironmentInterface::Ptr testEnv () + { + if (!mTestEnv) + mTestEnv = mTestEnvFactory->ConstructTestEnv (); + + return mTestEnv; + } + VariantTypes & value () { return mValue; } - CCSBackendConceptTestParamInterface::NativeWriteMethod & nativeWrite () { return mNativeWrite; } + void nativeWrite (const CCSBackendConceptTestEnvironmentInterface::Ptr & iface, + const std::string &plugin, + const std::string &keyname, + const VariantTypes &value) + { + return ((iface.get ())->*mNativeWrite) (plugin, keyname, value); + } CCSSettingType & type () { return mType; } std::string & keyname () { return mKeyname; } CCSBackendConceptTestParamInterface::SetReadExpectation & setReadExpectation () { return mSetReadExpectation; } @@ -638,7 +690,8 @@ class CCSBackendConceptTestParam : private: - CCSBackendConceptTestEnvironmentInterface *mTestEnv; + CCSBackendConceptTestEnvironmentFactoryInterface *mTestEnvFactory; + CCSBackendConceptTestEnvironmentInterface::Ptr mTestEnv; VariantTypes mValue; NativeWriteMethod mNativeWrite; CCSSettingType mType; @@ -678,7 +731,7 @@ class CCSBackendConformanceTest : virtual void TearDown () { - CCSBackendConformanceTest::GetParam ()->testEnv ()->TearDown (mBackend); + CCSBackendConformanceTest::GetParam ()->TearDown (mBackend); for (std::list ::iterator it = mSpawnedContexts.begin (); it != mSpawnedContexts.end (); @@ -794,138 +847,140 @@ template ::testing::internal::ParamGenerator GenerateTestingParametersForBackendInterface () { - static I interface; - static CCSBackendConceptTestEnvironmentInterface *backendEnv = &interface; + static CCSBackendConceptTestEnvironmentFactory interfaceFactory; + static CCSBackendConceptTestEnvironmentFactoryInterface *backendEnvFactory = &interfaceFactory; typedef CCSBackendConceptTestParam ConceptParam; + /* Make these all method pointers and do the bind in the tests themselves */ + static typename CCSBackendConceptTestParamInterface::Ptr testParam[] = { - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (1), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, TypeInt, "integer_setting", boost::bind (SetIntReadExpectation, _1, _2), boost::bind (SetIntWriteExpectation, _1, _2, _3, _4, _5, _6), "TestInt"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (true), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, TypeBool, "boolean_setting", boost::bind (SetBoolReadExpectation, _1, _2), boost::bind (SetBoolWriteExpectation, _1, _2, _3, _4, _5, _6), "TestBool"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast (3.0)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, TypeFloat, "float_setting", boost::bind (SetFloatReadExpectation, _1, _2), boost::bind (SetFloatWriteExpectation, _1, _2, _3, _4, _5, _6), "TestFloat"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast ("foo")), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, TypeString, "string_setting", boost::bind (SetStringReadExpectation, _1, _2), boost::bind (SetStringWriteExpectation, _1, _2, _3, _4, _5, _6), "TestString"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast ("foo=bar")), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, TypeMatch, "match_setting", boost::bind (SetMatchReadExpectation, _1, _2), boost::bind (SetMatchWriteExpectation, _1, _2, _3, _4, _5, _6), "TestMatch"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (true), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, TypeBell, "bell_setting", boost::bind (SetBellReadExpectation, _1, _2), boost::bind (SetBellWriteExpectation, _1, _2, _3, _4, _5, _6), "TestBell"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (impl::colorValues[0]), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, TypeColor, "color_setting", boost::bind (SetColorReadExpectation, _1, _2), boost::bind (SetColorWriteExpectation, _1, _2, _3, _4, _5, _6), "TestColor"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (impl::keyValue), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, TypeKey, "key_setting", boost::bind (SetKeyReadExpectation, _1, _2), boost::bind (SetKeyWriteExpectation, _1, _2, _3, _4, _5, _6), "TestKey"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (impl::buttonValue), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, TypeButton, "button_setting", boost::bind (SetButtonReadExpectation, _1, _2), boost::bind (SetButtonWriteExpectation, _1, _2, _3, _4, _5, _6), "TestButton"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast (1)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, TypeEdge, "edge_setting", boost::bind (SetEdgeReadExpectation, _1, _2), boost::bind (SetEdgeWriteExpectation, _1, _2, _3, _4, _5, _6), "TestEdge"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, sizeof (impl::intValues) / sizeof (impl::intValues[0]), NULL), false, TypeInt)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "int_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListInt"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), NULL), false, TypeFloat)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "float_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListInt"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), NULL), false, TypeBool)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "bool_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListBool"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), NULL), false, TypeString)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "string_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListString"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), NULL), false, TypeColor)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "color_list_setting", boost::bind (SetListReadExpectation, _1, _2), @@ -982,7 +1037,8 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->nativeWrite () (pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + pluginName, settingName, VALUE); CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); @@ -995,14 +1051,14 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, - settingName, - VALUE, - setting, - boost::bind (ccsBackendWriteSetting, - CCSBackendConformanceTest::GetBackend (), - context, - setting), - GetParam ()->testEnv ()); + settingName, + VALUE, + setting, + boost::bind (ccsBackendWriteSetting, + CCSBackendConformanceTest::GetBackend (), + context, + setting), + GetParam ()->testEnv ()); CCSBackendConformanceTest::GetParam ()->testEnv ()->PostWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); } -- GitLab From e5cadda61a2d9ec82b0f4f2a9aea0a66aacc41d3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 19 Jul 2012 16:25:18 +0800 Subject: [PATCH 090/562] Fix uninitialized read --- .../tests/compizconfig_backend_concept_test.h | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 43030401e..c8cdf17ca 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -30,6 +30,7 @@ using ::testing::MakeMatcher; using ::testing::Matcher; using ::testing::MatcherInterface; using ::testing::MatchResultListener; +using ::testing::AtLeast; MATCHER(IsTrue, "Is True") { if (arg) return true; else return false; } MATCHER(IsFalse, "Is False") { if (!arg) return true; else return false; } @@ -503,11 +504,14 @@ void SetListWriteExpectation (const std::string &plugin, { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); CCSSettingValueList list = *(boost::get > (value)); - boost::shared_ptr info (boost::make_shared ()); + + EXPECT_CALL (*gmock, getInfo ()); + + CCSSettingInfo *info = ccsSettingGetInfo (setting); info->forList.listType = (boost::get > (value))->type (); - EXPECT_CALL (*gmock, getInfo ()).WillRepeatedly (Return (info.get ())); + EXPECT_CALL (*gmock, getInfo ()).Times (AtLeast (1)); EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( list), @@ -785,6 +789,7 @@ class CCSBackendConformanceTest : { *setting = ccsMockSettingNew (); mSpawnedSettings.push_back (*setting); + mSpawnedSettingInfo.push_back (CCSSettingInfo ()); CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (*setting); @@ -795,6 +800,7 @@ class CCSBackendConformanceTest : ON_CALL (*gmockSetting, getName ()).WillByDefault (Return ((char *) name.c_str ())); ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (type)); ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin)); + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&(mSpawnedSettingInfo.back ()))); } protected: @@ -807,6 +813,7 @@ class CCSBackendConformanceTest : std::list mSpawnedContexts; std::list mSpawnedPlugins; std::list mSpawnedSettings; + std::vector mSpawnedSettingInfo; CCSBackend *mBackend; @@ -939,7 +946,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, sizeof (impl::intValues) / sizeof (impl::intValues[0]), - NULL), false, TypeInt)), + NULL), true, TypeInt)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "int_list_setting", @@ -949,7 +956,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), - NULL), false, TypeFloat)), + NULL), true, TypeFloat)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "float_list_setting", @@ -959,7 +966,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), - NULL), false, TypeBool)), + NULL), true, TypeBool)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "bool_list_setting", @@ -969,7 +976,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), - NULL), false, TypeString)), + NULL), true, TypeString)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "string_list_setting", @@ -979,7 +986,7 @@ GenerateTestingParametersForBackendInterface () boost::make_shared (backendEnvFactory, VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), - NULL), false, TypeColor)), + NULL), true, TypeColor)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "color_list_setting", -- GitLab From a4ed6b91676080b96c1aa207afd6e99348d353f3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 19 Jul 2012 16:28:26 +0800 Subject: [PATCH 091/562] Remove useless comment --- compizconfig/tests/compizconfig_backend_concept_test.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index c8cdf17ca..de1a4be8b 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -859,8 +859,6 @@ GenerateTestingParametersForBackendInterface () typedef CCSBackendConceptTestParam ConceptParam; - /* Make these all method pointers and do the bind in the tests themselves */ - static typename CCSBackendConceptTestParamInterface::Ptr testParam[] = { boost::make_shared (backendEnvFactory, -- GitLab From 92c4149247e29d83588134b6bde09c16a594c188 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 20 Jul 2012 11:04:59 +0800 Subject: [PATCH 092/562] Keep the setting object around for every instance of the value object. --- ...nfig_test_ccs_mock_backend_conformance.cpp | 5 +- .../tests/compizconfig_backend_concept_test.h | 72 ++++++++++++++----- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index a182100f5..b99b0969f 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -426,7 +426,10 @@ class MockCCSBackendConceptTestEnvironment : ccsGetList (setting, &vList); listCopy = ccsCopyList (vList, setting); - WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, ccsSettingGetInfo (setting)->forList.listType))); + WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, + ccsSettingGetInfo (setting)->forList.listType, + boost::shared_ptr (), + boost::shared_ptr ()))); break; } default: diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index de1a4be8b..f0e911abe 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -26,6 +26,7 @@ using ::testing::Eq; using ::testing::SetArgPointee; using ::testing::DoAll; using ::testing::Return; +using ::testing::ReturnNull; using ::testing::MakeMatcher; using ::testing::Matcher; using ::testing::MatcherInterface; @@ -157,10 +158,16 @@ class CCSListWrapper : typedef boost::shared_ptr Ptr; - CCSListWrapper (CCSSettingValueList list, bool freeItems, CCSSettingType type) : + CCSListWrapper (CCSSettingValueList list, + bool freeItems, + CCSSettingType type, + const boost::shared_ptr &listInfo, + const boost::shared_ptr &settingReference) : mList (list), mFreeItems (freeItems), - mType (type) + mType (type), + mListInfo (listInfo), + mSettingReference (settingReference) { } @@ -185,6 +192,8 @@ class CCSListWrapper : CCSSettingValueList mList; bool mFreeItems; CCSSettingType mType; + boost::shared_ptr mListInfo; + boost::shared_ptr mSettingReference; }; typedef boost::variant ConstructorFunc; + +CCSListWrapper::Ptr +CCSListConstructionExpectationsSetter (const ConstructorFunc &c, + CCSSettingType type, + bool freeItems) +{ + boost::function f (boost::bind (ccsFreeMockSetting, _1)); + boost::shared_ptr mockSetting (ccsMockSettingNew (), f); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting.get ())); + + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeList)); + + boost::shared_ptr listInfo (new CCSSettingInfo); + + listInfo->forList.listType = type; + + EXPECT_CALL (*gmockSetting, getInfo ()).WillRepeatedly (Return (listInfo.get ())); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); + return boost::make_shared (c (mockSetting.get ()), freeItems, type, listInfo, mockSetting); } template @@ -942,9 +974,10 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetEdgeWriteExpectation, _1, _2, _3, _4, _5, _6), "TestEdge"), boost::make_shared (backendEnvFactory, - VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, - sizeof (impl::intValues) / sizeof (impl::intValues[0]), - NULL), true, TypeInt)), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromIntArray, + impl::intValues, + sizeof (impl::intValues) / sizeof (impl::intValues[0]), _1), + TypeInt, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "int_list_setting", @@ -952,9 +985,10 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListInt"), boost::make_shared (backendEnvFactory, - VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, - sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), - NULL), true, TypeFloat)), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromFloatArray, + impl::floatValues, + sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), _1), + TypeFloat, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "float_list_setting", @@ -962,9 +996,10 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListInt"), boost::make_shared (backendEnvFactory, - VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, - sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), - NULL), true, TypeBool)), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromBoolArray, + impl::boolValues, + sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), _1), + TypeBool, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "bool_list_setting", @@ -972,9 +1007,10 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListBool"), boost::make_shared (backendEnvFactory, - VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, - sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), - NULL), true, TypeString)), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromStringArray, + impl::stringValues, + sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), _1), + TypeString, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "string_list_setting", @@ -982,9 +1018,10 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListString"), boost::make_shared (backendEnvFactory, - VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, - sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), - NULL), true, TypeColor)), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromColorArray, + impl::colorValues, + sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), _1), + TypeColor, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "color_list_setting", @@ -1069,5 +1106,6 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) } + #endif -- GitLab From 3f2cb6089d0467fcacff72643f93414fb4e2c6d6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 20 Jul 2012 14:39:45 +0800 Subject: [PATCH 093/562] Fix some spurious gmock warnings --- .../gsettings/tests/test_gsettings_conformance.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index dc0f9ee4e..5a14fcdbc 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -14,6 +14,7 @@ using ::testing::AtLeast; using ::testing::Pointee; +using ::testing::ReturnNull; namespace { @@ -240,6 +241,12 @@ class CCSGSettingsBackendEnv : EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, isReadOnly ()).WillRepeatedly (Return (FALSE)); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); + } } void PostRead (CCSContextGMock *gmockContext, -- GitLab From 21c6022b43d412099ba9cf056720c3ad3725130a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 20 Jul 2012 14:39:57 +0800 Subject: [PATCH 094/562] Fix typo in test annotation --- compizconfig/tests/compizconfig_backend_concept_test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index f0e911abe..d043c4224 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -994,7 +994,7 @@ GenerateTestingParametersForBackendInterface () "float_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), - "TestListInt"), + "TestListFloat"), boost::make_shared (backendEnvFactory, VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromBoolArray, impl::boolValues, -- GitLab From 7c860ddb83b06ea43b3b7c2a738e91477a3a6c6a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 20 Jul 2012 14:46:51 +0800 Subject: [PATCH 095/562] Fix unsafe array code fixing test CCSGSettingsBackendConcept/CCSBackendConformanceTestReadWrite --- .../gsettings/gsettings_backend_shared/gsettings_util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 9aefc981b..e993698b0 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -442,8 +442,8 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) break; case TypeFloat: { - double *array = malloc (nItems * sizeof (double)); - double *arrayCounter = array; + float *array = malloc (nItems * sizeof (float)); + float *arrayCounter = array; gdouble value; if (!array) @@ -453,7 +453,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_loop (&iter, "d", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromFloatArray ((float *) array, nItems, NULL); + list = ccsGetValueListFromFloatArray (array, nItems, NULL); free (array); } break; -- GitLab From 0d64993c0deb4b96db19994aef3436b637ec8669 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 20 Jul 2012 14:57:19 +0800 Subject: [PATCH 096/562] Fix bool comparison in ccsCompareLists when using multiple definitions of TRUE and FALSE (it happens ...) --- .../gsettings_backend_shared/gsettings_util.c | 2 +- compizconfig/libcompizconfig/src/main.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index e993698b0..3910804a9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -417,7 +417,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) /* Reads each item from the variant into arrayCounter */ while (g_variant_iter_loop (&iter, "b", &value)) - *arrayCounter++ = value; + *arrayCounter++ = value ? TRUE : FALSE; list = ccsGetValueListFromBoolArray (array, nItems, NULL); free (array); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index b5db4ed01..fac548100 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1614,8 +1614,14 @@ ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, return FALSE; break; case TypeBool: - if (l1->data->value.asBool != l2->data->value.asBool) - return FALSE; + { + Bool bothTrue = (l1->data->value.asBool && l2->data->value.asBool); + Bool bothFalse = (!l1->data->value.asBool && !l2->data->value.asBool); + + /* Use the boolean operators as TRUE/FALSE can be redefined */ + if (!bothTrue && !bothFalse) + return FALSE; + } break; case TypeFloat: if (l1->data->value.asFloat != l2->data->value.asFloat) -- GitLab From fa889755f24fec5ce1f85e57e79512bdc4b251e6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 20 Jul 2012 15:02:52 +0800 Subject: [PATCH 097/562] Added some notes as to remaining work --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 2 +- compizconfig/tests/compizconfig_backend_concept_test.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 5a14fcdbc..adc537c8b 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -370,7 +370,7 @@ class CCSGSettingsBackendEnv : CharacterWrapper (translateKeyForGSettings (key.c_str ())), CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), TypeList); - return readListValue (variant, TypeNum); + return readListValue (variant, TypeNum); /* XXX: We need a way to inject the list type into here */ } private: diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index d043c4224..b28eed881 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1017,6 +1017,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListString"), + /* Needs lossy comparison */ boost::make_shared (backendEnvFactory, VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromColorArray, impl::colorValues, -- GitLab From 31d590ac4a4718eac5c3f6f79540d8d5bb7a8b59 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 21 Jul 2012 02:35:53 +0800 Subject: [PATCH 098/562] Store the initial color value list as lossy --- .../tests/compizconfig_backend_concept_test.h | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index b28eed881..5943bcadb 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -841,15 +841,36 @@ int intValues[] = { 1, 2, 3 }; float floatValues[] = { 1.0, 2.0, 3.0 }; const char * stringValues[] = { "foo", "grill", "bar" }; -unsigned short max = std::numeric_limits ::max (); -unsigned short maxD2 = max / 2; -unsigned short maxD4 = max / 4; -unsigned short maxD8 = max / 8; +const unsigned int NUM_COLOR_VALUES = 3; -CCSSettingColorValue colorValues[3] = { { .color = { maxD2 , maxD4, maxD8, max } }, - { .color = { maxD8, maxD4, maxD2, max } }, - { .color = { max, maxD4, maxD2, maxD8 } } - }; +CCSSettingColorValue * +getColorValueList () +{ + static const unsigned short max = std::numeric_limits ::max (); + static const unsigned short maxD2 = max / 2; + static const unsigned short maxD4 = max / 4; + static const unsigned short maxD8 = max / 8; + + static CCSSettingColorValue colorValues[NUM_COLOR_VALUES] = { { .color = { maxD2, maxD4, maxD8, max } }, + { .color = { maxD8, maxD4, maxD2, max } }, + { .color = { max, maxD4, maxD2, maxD8 } } + }; + static bool colorValueListInitialized = false; + + if (!colorValueListInitialized) + { + for (unsigned int i = 0; i < NUM_COLOR_VALUES; i++) + { + CharacterWrapper s (ccsColorToString (&colorValues[i])); + + ccsStringToColor (s, &colorValues[i]); + } + + colorValueListInitialized = true; + } + + return colorValues; +} CCSSettingKeyValue keyValue = { XK_A, (1 << 0)}; @@ -942,7 +963,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetBellWriteExpectation, _1, _2, _3, _4, _5, _6), "TestBell"), boost::make_shared (backendEnvFactory, - VariantTypes (impl::colorValues[0]), + VariantTypes (impl::getColorValueList ()[0]), &CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, TypeColor, "color_setting", @@ -1020,8 +1041,8 @@ GenerateTestingParametersForBackendInterface () /* Needs lossy comparison */ boost::make_shared (backendEnvFactory, VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromColorArray, - impl::colorValues, - sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), _1), + impl::getColorValueList (), + impl::NUM_COLOR_VALUES, _1), TypeColor, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, -- GitLab From e8ec36c6be57a4d80906fd76c0a540782f5c6194 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 21 Jul 2012 02:58:58 +0800 Subject: [PATCH 099/562] Just calloc the array instead of memsetting every element and fix color read in lists only reading into the first color --- .../gsettings_backend_shared/gsettings_util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 3910804a9..34856b8f3 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -392,7 +392,7 @@ CCSSettingValueList readListValue (GVariant *gsettingsValue, CCSSettingType listType) { gboolean hasVariantType; - unsigned int nItems, i = 0; + unsigned int nItems; CCSSettingValueList list = NULL; GVariantIter iter; @@ -479,18 +479,20 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) break; case TypeColor: { - CCSSettingColorValue *array; char *colorValue; - array = malloc (nItems * sizeof (CCSSettingColorValue)); + CCSSettingColorValue *array = calloc (1, nItems * sizeof (CCSSettingColorValue)); + unsigned int i = 0; + if (!array) break; while (g_variant_iter_loop (&iter, "s", &colorValue)) { - memset (&array[i], 0, sizeof (CCSSettingColorValue)); ccsStringToColor (colorValue, &array[i]); + i++; } + list = ccsGetValueListFromColorArray (array, nItems, NULL); free (array); } -- GitLab From cee7308367fd32f48e0ee7713ec9f163d6b80e4d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 21 Jul 2012 03:01:42 +0800 Subject: [PATCH 100/562] Remove lossy emulation, its no longer necessary now that we store the initial values in a lossy format --- ...nfig_test_ccs_mock_backend_conformance.cpp | 8 +------- .../tests/compizconfig_backend_concept_test.h | 19 ++----------------- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index b99b0969f..0641163d6 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -143,13 +143,7 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, const VariantTypes &value) { - CCSSettingColorValue v = boost::get (value); - - /* Convert it to simulate key storage lossyness */ - CharacterWrapper str (ccsColorToString (&v)); - ccsStringToColor (str, &v); - - mValues[keynameFromPluginKey (plugin, key)] = VariantTypes (v); + mValues[keynameFromPluginKey (plugin, key)] = value; } void WriteKeyAtKey (const std::string &plugin, diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 5943bcadb..e17edebcb 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -408,15 +408,7 @@ void SetColorWriteExpectation (const std::string &plugin, Return (TRUE))); write (); - /* Storage on most backends is lossy, so simulate this */ - CCSSettingColorValue v = boost::get (value); - char *str = ccsColorToString (&v); - - ccsStringToColor (str, &v); - - free (str); - - EXPECT_EQ (env->ReadColorAtKey (plugin, key), v); + EXPECT_EQ (env->ReadColorAtKey (plugin, key), boost::get (value)); } void SetKeyWriteExpectation (const std::string &plugin, @@ -571,14 +563,7 @@ void SetMatchReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) void SetColorReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - CCSSettingColorValue v = boost::get (value); - char *str = ccsColorToString (&v); - - ccsStringToColor (str, &v); - - free (str); - - EXPECT_CALL (*gmock, setColor (v, _)); + EXPECT_CALL (*gmock, setColor (boost::get (value), _)); } void SetKeyReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) -- GitLab From 75394e62e533faa033e630a65f1ada15a1f11de1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 21 Jul 2012 10:21:24 +0800 Subject: [PATCH 101/562] Remove redundant comment --- compizconfig/tests/compizconfig_backend_concept_test.h | 1 - 1 file changed, 1 deletion(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index e17edebcb..38da7c079 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1023,7 +1023,6 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListString"), - /* Needs lossy comparison */ boost::make_shared (backendEnvFactory, VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromColorArray, impl::getColorValueList (), -- GitLab From 88febd6d94249f13323ca006b4e4c0106d1fe89b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 21 Jul 2012 10:27:09 +0800 Subject: [PATCH 102/562] Provide the setting list type in ReadListAtKey. Make the list read tests pass --- .../gsettings/tests/test_gsettings_conformance.cpp | 5 +++-- .../compizconfig_test_ccs_mock_backend_conformance.cpp | 10 +++++++--- compizconfig/tests/compizconfig_backend_concept_test.h | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index adc537c8b..8efeba02f 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -364,13 +364,14 @@ class CCSGSettingsBackendEnv : } CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key) + const std::string &key, + CCSSettingInfo *info) { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), TypeList); - return readListValue (variant, TypeNum); /* XXX: We need a way to inject the list type into here */ + return readListValue (variant, info->forList.listType); } private: diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 0641163d6..f08eac908 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -261,7 +261,8 @@ class MockCCSBackendConceptTestEnvironment : } virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key) + const std::string &key, + CCSSettingInfo *info) { return *(ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); } @@ -326,9 +327,12 @@ class MockCCSBackendConceptTestEnvironment : break; case TypeList: + { + CCSSettingInfo *info = ccsSettingGetInfo (setting); - ccsSetList (setting, ReadListAtKey (plugin, key), FALSE); - break; + ccsSetList (setting, ReadListAtKey (plugin, key, info), FALSE); + } + break; default: diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 38da7c079..123f5bec8 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -290,7 +290,8 @@ class CCSBackendConceptTestEnvironmentInterface virtual Bool ReadBellAtKey (const std::string &plugin, const std::string &key) = 0; virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key) = 0; + const std::string &key, + CCSSettingInfo *info) = 0; }; class CCSBackendConceptTestEnvironmentFactoryInterface @@ -518,7 +519,7 @@ void SetListWriteExpectation (const std::string &plugin, list), Return (TRUE))); write (); - EXPECT_THAT (env->ReadListAtKey (plugin, key), ListEqual (ccsSettingGetInfo (setting)->forList, list)); + EXPECT_THAT (env->ReadListAtKey (plugin, key, info), ListEqual (ccsSettingGetInfo (setting)->forList, list)); } void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) -- GitLab From 87652d33a56c5d1e4508f25e016382eec9e6acb5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 21 Jul 2012 11:33:40 +0800 Subject: [PATCH 103/562] Fix typo in CCSGSettingsTestIndependent.TestReadVariantIsValidTypeGood --- compizconfig/gsettings/tests/test_gsettings_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 7c9858ea0..27c309c2e 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -909,7 +909,7 @@ TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeGood) { GVariant *v = g_variant_new ("i", 1); - EXPECT_FALSE (checkReadVariantIsValid (v, TypeInt, "foo/bar")); + EXPECT_TRUE (checkReadVariantIsValid (v, TypeInt, "foo/bar")); g_variant_unref (v); } -- GitLab From d7c9df5f62b9c0f9d4928636a879abc89af94740 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 21 Jul 2012 16:43:05 +0800 Subject: [PATCH 104/562] Ensure that variants are written to keys, now GSETTINGS_BACKEND=memory works correctly --- compizconfig/gsettings/src/gsettings.c | 3 +-- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index a314360fc..289578979 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -538,7 +538,6 @@ writeOption (CCSBackend *backend, CCSSetting * setting) break; case TypeList: { - GVariant *value = NULL; CCSSettingValueList list = NULL; if (!ccsGetList (setting, &list)) @@ -546,7 +545,7 @@ writeOption (CCSBackend *backend, CCSSetting * setting) success = writeListValue (list, ccsSettingGetInfo (setting)->forList.listType, - &value); + &gsettingsValue); } break; default: diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 8efeba02f..87113607d 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -47,7 +47,7 @@ class CCSGSettingsBackendEnv : /* For some reason a number of tests fail when using * this GSettings backend */ - //g_setenv ("GSETTINGS_BACKEND", "memory", true); + g_setenv ("GSETTINGS_BACKEND", "memory", true); g_setenv ("LIBCOMPIZCONFIG_BACKEND_PATH", BACKEND_BINARY_PATH, true); mContext = context; @@ -81,7 +81,7 @@ class CCSGSettingsBackendEnv : void TearDown (CCSBackend *) { g_unsetenv ("GSETTINGS_SCHEMA_DIR"); - //g_unsetenv ("GSETTINGS_BACKEND"); + g_unsetenv ("GSETTINGS_BACKEND"); ccsFreeBackendWithCapabilities (mBackend); } -- GitLab From 77ac90920931087e4b80e4f046e418d55080a020 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 01:23:35 +0800 Subject: [PATCH 105/562] Added an updateSetting method to the backend interface, not actually used anywhere yet --- compizconfig/gconf/src/gconf.c | 1 + compizconfig/gsettings/src/gsettings.c | 1 + .../libcompizconfig/backend/src/ini.c | 1 + .../libcompizconfig/include/ccs-backend.h | 5 +++++ compizconfig/libcompizconfig/src/main.c | 19 +++++++++++++++++++ .../compizconfig_ccs_backend_mock.cpp | 1 + .../compizconfig_ccs_backend_mock.h | 7 +++++++ 7 files changed, 35 insertions(+) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 28d994871..538cab384 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -2167,6 +2167,7 @@ static CCSBackendInterface gconfVTable = { writeInit, writeSetting, 0, + 0, getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 289578979..25c809968 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -954,6 +954,7 @@ static CCSBackendInterface gsettingsVTable = { writeInit, writeSetting, 0, + 0, getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index f00c18cde..8069de6cb 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -763,6 +763,7 @@ static CCSBackendInterface iniVTable = { writeSetting, writeDone, NULL, + NULL, getSettingIsReadOnly, getExistingProfiles, deleteProfile diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index cbf7aecd2..d9f9d2505 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -33,6 +33,7 @@ typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendInterface CCSBackendInterface; typedef struct _CCSContext CCSContext; +typedef struct _CCSPlugin CCSPlugin; typedef struct _CCSSetting CCSSetting; struct _CCSBackend @@ -57,6 +58,8 @@ typedef void (*CCSBackendWriteSettingFunc) (CCSBackend *, CCSContext * context, CCSSetting * setting); typedef void (*CCSBackendWriteDoneFunc) (CCSBackend *, CCSContext * context); +typedef void (*CCSBackendUpdateFunc) (CCSBackend *, CCSContext *, CCSPlugin *, CCSSetting *); + typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSBackend *, CCSSetting * setting); typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSBackend *, CCSSetting * setting); @@ -93,6 +96,7 @@ struct _CCSBackendInterface CCSBackendWriteSettingFunc writeSetting; CCSBackendWriteDoneFunc writeDone; + CCSBackendUpdateFunc updateSetting; CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated; CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly; @@ -118,6 +122,7 @@ void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context); void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); +void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting); Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting); CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index fac548100..fdadec608 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1378,11 +1378,21 @@ static Bool ccsBackendHasWriteDone (CCSBackend *backend) return (GET_INTERFACE (CCSBackendInterface, backend))->writeDone != NULL; } +static Bool ccsBackendHasUpdateSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->updateSetting != NULL; +} + void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) { return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); } +void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->updateSetting) (backend, context, plugin, setting); +} + static Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated != NULL; @@ -1556,6 +1566,14 @@ static void ccsBackendCapabilitiesWriteDoneWrapper (CCSBackend *backend, CCSCont ccsBackendWriteDone (bcPrivate->backend, context); } +static void ccsBackendCapabilitiesUpdateSettingWrapper (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasUpdateSetting (bcPrivate->backend)) + ccsBackendUpdateSetting (bcPrivate->backend, context, plugin, setting); +} + static Bool ccsBackendCapabilitiesGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) { CAPABILITIES_PRIV (backend); @@ -5524,6 +5542,7 @@ const CCSBackendInterface ccsBackendCapabilitiesInterfaceWrapper = ccsBackendCapabilitiesWriteInitWrapper, ccsBackendCapabilitiesWriteSettingWrapper, ccsBackendCapabilitiesWriteDoneWrapper, + ccsBackendCapabilitiesUpdateSettingWrapper, ccsBackendCapabilitiesGetSettingIsIntegratedWrapper, ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper, ccsBackendCapabilitiesGetExistingProfilesWrapper, diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp index deb19ab70..e826f1d02 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp @@ -21,6 +21,7 @@ CCSBackendInterface CCSBackendGMockInterface = CCSBackendGMock::ccsBackendWriteInit, CCSBackendGMock::ccsBackendWriteSetting, CCSBackendGMock::ccsBackendWriteDone, + CCSBackendGMock::ccsBackendUpdateSetting, CCSBackendGMock::ccsBackendGetSettingIsIntegrated, CCSBackendGMock::ccsBackendGetSettingIsReadOnly, CCSBackendGMock::ccsBackendGetExistingProfiles, diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index 8ba01bb09..d1d5aa66b 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -29,6 +29,7 @@ class CCSBackendGMockInterface virtual Bool writeInit (CCSContext *conxtext) = 0; virtual void writeSetting (CCSContext *context, CCSSetting *setting) = 0; virtual void writeDone (CCSContext *context) = 0; + virtual void updateSetting (CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) = 0; virtual Bool getSettingIsIntegrated (CCSSetting *setting) = 0; virtual Bool getSettingIsReadOnly (CCSSetting *setting) = 0; virtual CCSStringList getExistingProfiles (CCSContext *context) = 0; @@ -62,6 +63,7 @@ class CCSBackendGMock : MOCK_METHOD1 (writeInit, Bool (CCSContext *)); MOCK_METHOD2 (writeSetting, void (CCSContext *, CCSSetting *)); MOCK_METHOD1 (writeDone, void (CCSContext *)); + MOCK_METHOD3 (updateSetting, void (CCSContext *, CCSPlugin *, CCSSetting *)); MOCK_METHOD1 (getSettingIsIntegrated, Bool (CCSSetting *)); MOCK_METHOD1 (getSettingIsReadOnly, Bool (CCSSetting *)); MOCK_METHOD1 (getExistingProfiles, CCSStringList (CCSContext *)); @@ -144,6 +146,11 @@ class CCSBackendGMock : ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeDone (context); } + static void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->updateSetting (context, plugin, setting); + } + static Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) { return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getSettingIsIntegrated (setting); -- GitLab From 1f66e0171133b850e2e0c217acf1c5d118dc20ed Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 01:25:30 +0800 Subject: [PATCH 106/562] Added stub updateSetting definitions to the backend --- compizconfig/gconf/src/gconf.c | 7 ++++++- compizconfig/gsettings/src/gsettings.c | 7 ++++++- compizconfig/libcompizconfig/backend/src/ini.c | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 538cab384..0aaaf3c84 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -2035,6 +2035,11 @@ writeSetting (CCSBackend *backend, } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ +} + static Bool getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { @@ -2167,7 +2172,7 @@ static CCSBackendInterface gconfVTable = { writeInit, writeSetting, 0, - 0, + updateSetting, getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 25c809968..6361cb3d4 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -793,6 +793,11 @@ writeSetting (CCSBackend *backend, } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ +} + static Bool getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { @@ -954,7 +959,7 @@ static CCSBackendInterface gsettingsVTable = { writeInit, writeSetting, 0, - 0, + updateSetting, getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 8069de6cb..b8bd269b4 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -605,6 +605,11 @@ writeDone (CCSBackend *backend, CCSContext * context) free (fileName); } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ +} + static Bool getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { @@ -762,7 +767,7 @@ static CCSBackendInterface iniVTable = { writeInit, writeSetting, writeDone, - NULL, + updateSetting, NULL, getSettingIsReadOnly, getExistingProfiles, -- GitLab From 72516bea9586f3252f5137521db5860877f8f6a2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 01:27:47 +0800 Subject: [PATCH 107/562] Ini backend doesn't really have a concept of updating single settings, but add a sensible definition in case someone wants to do it anyways --- compizconfig/libcompizconfig/backend/src/ini.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index b8bd269b4..63b5f3211 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -608,6 +608,11 @@ writeDone (CCSBackend *backend, CCSContext * context) static void updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { + if (readInit (backend, context)) + { + readSetting (backend, context, setting); + readDone (backend, context); + } } static Bool -- GitLab From cbb65479aa760c9714dedd79cf5db0b3e26a7d58 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 01:31:12 +0800 Subject: [PATCH 108/562] Added a sensible definition of updateSetting --- compizconfig/gconf/src/gconf.c | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 0aaaf3c84..ecfe21924 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -435,6 +435,22 @@ isIntegratedOption (CCSSetting *setting, return FALSE; } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + int index; + readInit (backend, context); + if (!readOption (setting)) + ccsResetToDefault (setting, TRUE); + + if (ccsGetIntegrationEnabled (context) && + isIntegratedOption (setting, &index)) + { + writeInit (backend, context); + writeIntegratedOption (context, setting, index); + } +} + static void valueChanged (GConfClient *client, guint cnxn_id, @@ -445,7 +461,6 @@ valueChanged (GConfClient *client, char *keyName = (char*) gconf_entry_get_key (entry); char *pluginName; char *token; - int index; unsigned int screenNum; CCSPlugin *plugin; CCSSetting *setting; @@ -490,16 +505,9 @@ valueChanged (GConfClient *client, if (!setting) return; - readInit (NULL, context); - if (!readOption (setting)) - ccsResetToDefault (setting, TRUE); - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - writeInit (NULL, context); - writeIntegratedOption (context, setting, index); - } + /* Passing null here is not optimal, but we are not + * maintaining gconf actively here */ + updateSetting (NULL, context, plugin, setting); } static void @@ -2035,11 +2043,6 @@ writeSetting (CCSBackend *backend, } -static void -updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) -{ -} - static Bool getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { -- GitLab From 2e97e1620eac38dc4196a69fce796de8463a347a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 01:33:35 +0800 Subject: [PATCH 109/562] Added a sensible definition of updateSetting for gsettings --- compizconfig/gsettings/src/gsettings.c | 38 ++++++++++++++------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 6361cb3d4..ce1c2f710 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -134,6 +134,25 @@ isIntegratedOption (CCSSetting *setting, #endif } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + int index; + + readInit (backend, context); + if (!readOption (backend, setting)) + { + ccsResetToDefault (setting, TRUE); + } + + if (ccsGetIntegrationEnabled (context) && + isIntegratedOption (setting, &index)) + { + writeInit (backend, context); + writeIntegratedOption (backend, context, setting, index); + } +} + static void valueChanged (GSettings *settings, gchar *keyName, @@ -144,7 +163,6 @@ valueChanged (GSettings *settings, char *uncleanKeyName; char *path, *pathOrig; char *pluginName; - int index; unsigned int screenNum; CCSPlugin *plugin; CCSSetting *setting; @@ -206,18 +224,7 @@ valueChanged (GSettings *settings, } } - readInit (NULL, context); - if (!readOption (backend, setting)) - { - ccsResetToDefault (setting, TRUE); - } - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - writeInit (NULL, context); - writeIntegratedOption (backend, context, setting, index); - } + updateSetting (backend, context, plugin, setting); g_free (pluginName); free (uncleanKeyName); @@ -793,11 +800,6 @@ writeSetting (CCSBackend *backend, } -static void -updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) -{ -} - static Bool getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { -- GitLab From 65652c2f761e217b0c8c3638b808e384595efd4c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 01:38:16 +0800 Subject: [PATCH 110/562] Added test TestUpdateMockedValue --- .../tests/compizconfig_backend_concept_test.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 123f5bec8..c2c919562 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1094,6 +1094,19 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context, setting); } +TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) +{ + SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "UpdateMocked"); + + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + + ccsBackendUpdateSetting (CCSBackendConformanceTest::GetBackend (), context, plugin, setting); +} + TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); -- GitLab From 5c1a993c4e61e77c9b368df5c785c869a3a4c08d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 01:44:45 +0800 Subject: [PATCH 111/562] Added PostUpdate and PreUpdate hooks into the test fixture so now MockCCSBackendConcept/CCSBackendConformanceTestReadWrite.TestUpdateMockedValue/* will pass --- .../tests/test_gsettings_conformance.cpp | 26 +++++++++++++++++++ ...nfig_test_ccs_mock_backend_conformance.cpp | 26 +++++++++++++++++++ .../tests/compizconfig_backend_concept_test.h | 13 ++++++++-- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 87113607d..d130d8274 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -373,6 +373,32 @@ class CCSGSettingsBackendEnv : TypeList); return readListValue (variant, info->forList.listType); } + + void PreUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, isReadOnly ()).WillRepeatedly (Return (FALSE)); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); + } + } + + void PostUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} + private: GSettings *mSettings; diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index f08eac908..159693594 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -60,6 +60,13 @@ class MockCCSBackendConceptTestEnvironment : this, &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + ON_CALL (*mBackendGMock, updateSetting (_, _, _)) + .WillByDefault ( + WithArgs<2> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + ON_CALL (*mBackendGMock, writeSetting (_, _)) .WillByDefault ( WithArgs<1> ( @@ -267,6 +274,25 @@ class MockCCSBackendConceptTestEnvironment : return *(ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); } + void PreUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, updateSetting (_, _, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getType ()); + EXPECT_CALL (*gmockSetting, getParent ()); + } + + void PostUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + protected: void ReadValueIntoSetting (CCSSetting *setting) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index c2c919562..e9fe67d37 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -292,6 +292,15 @@ class CCSBackendConceptTestEnvironmentInterface virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, const std::string &key, CCSSettingInfo *info) = 0; + + virtual void PreUpdate (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + virtual void PostUpdate (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; }; class CCSBackendConceptTestEnvironmentFactoryInterface @@ -1098,10 +1107,10 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "UpdateMocked"); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), pluginName, settingName, VALUE); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); ccsBackendUpdateSetting (CCSBackendConformanceTest::GetBackend (), context, plugin, setting); -- GitLab From a956c35b4e9256f46b2a47e7950c3ba676dbf224 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 02:35:58 +0800 Subject: [PATCH 112/562] Store path as a const char --- compizconfig/gsettings/src/gsettings.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index ce1c2f710..fe4975e49 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -161,7 +161,8 @@ valueChanged (GSettings *settings, CCSBackend *backend = (CCSBackend *)user_data; CCSContext *context = ccsGSettingsBackendGetContext (backend); char *uncleanKeyName; - char *path, *pathOrig; + char *pathOrig; + const char *path; char *pluginName; unsigned int screenNum; CCSPlugin *plugin; -- GitLab From 65fdc5adfc48f59c8b94b2f47c6980a94b54567b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 03:11:35 +0800 Subject: [PATCH 113/562] Refactor out findSettingAndPluginToUpdateFromPath --- compizconfig/gsettings/src/gsettings.c | 116 ++++++++++++++----------- 1 file changed, 64 insertions(+), 52 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index fe4975e49..62c020849 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -153,83 +153,95 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS } } -static void -valueChanged (GSettings *settings, - gchar *keyName, - gpointer user_data) +Bool +findSettingAndPluginToUpdateFromPath (GSettings *settings, + const char *path, + const gchar *keyName, + CCSContext *context, + CCSPlugin **plugin, + CCSSetting **setting, + char **uncleanKeyName) { - CCSBackend *backend = (CCSBackend *)user_data; - CCSContext *context = ccsGSettingsBackendGetContext (backend); - char *uncleanKeyName; - char *pathOrig; - const char *path; char *pluginName; unsigned int screenNum; - CCSPlugin *plugin; - CCSSetting *setting; - - g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); - - path = pathOrig; if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) - { - g_free (pathOrig); - return; - } - - plugin = ccsFindPlugin (context, pluginName); + return FALSE; - uncleanKeyName = translateKeyForCCS (keyName); + *plugin = ccsFindPlugin (context, pluginName); - setting = ccsFindSetting (plugin, uncleanKeyName); - if (!setting) + if (*plugin) { - /* Couldn't find setting straight off the bat, - * try and find the best match */ - GVariant *value = g_settings_get_value (settings, keyName); + *uncleanKeyName = translateKeyForCCS (keyName); - if (value) + *setting = ccsFindSetting (*plugin, *uncleanKeyName); + if (!setting) { - GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); - GList *iter = possibleSettingTypes; + /* Couldn't find setting straight off the bat, + * try and find the best match */ + GVariant *value = g_settings_get_value (settings, keyName); - while (iter) + if (value) { - setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (plugin), - keyName, - (CCSSettingType) GPOINTER_TO_INT (iter->data)); + GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); + GList *iter = possibleSettingTypes; + + while (iter) + { + *setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (*plugin), + keyName, + (CCSSettingType) GPOINTER_TO_INT (iter->data)); - if (setting) - break; + if (*setting) + break; - iter = iter->next; - } + iter = iter->next; + } - g_list_free (possibleSettingTypes); - g_variant_unref (value); + g_list_free (possibleSettingTypes); + g_variant_unref (value); + } } + } + g_free (pluginName); + + if (!*plugin || !*setting) + return FALSE; + + return TRUE; +} + +static void +valueChanged (GSettings *settings, + gchar *keyName, + gpointer user_data) +{ + CCSBackend *backend = (CCSBackend *)user_data; + CCSContext *context = ccsGSettingsBackendGetContext (backend); + char *uncleanKeyName = NULL; + char *pathOrig; + CCSPlugin *plugin; + CCSSetting *setting; + + g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); + + if (findSettingAndPluginToUpdateFromPath (settings, pathOrig, keyName, context, &plugin, &setting, &uncleanKeyName)) + updateSetting (backend, context, plugin, setting); + else + { /* We hit a situation where either the key stored in GSettings couldn't be * matched at all to a key in the xml file, or where there were multiple matches. * Unfortunately, there isn't much we can do about this, other than try * and warn the user and bail out. It just means that if the key was updated * externally we won't know about the change until the next reload of settings */ - if (!setting) - { - ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, path); - g_free (pluginName); - free (uncleanKeyName); - g_free (pathOrig); - return; - } + ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, pathOrig); } - updateSetting (backend, context, plugin, setting); - - g_free (pluginName); - free (uncleanKeyName); g_free (pathOrig); + + if (uncleanKeyName) + free (uncleanKeyName); } static Bool -- GitLab From 761be39508503a516184576917576bd0d169ddbe Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 03:13:28 +0800 Subject: [PATCH 114/562] Move it to gsettings_util --- .../gsettings_backend_shared/gsettings_util.c | 59 +++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 9 +++ compizconfig/gsettings/src/gsettings.c | 59 ------------------- 3 files changed, 68 insertions(+), 59 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 34856b8f3..afb32fa9a 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -330,6 +330,65 @@ attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *l return found; } +Bool +findSettingAndPluginToUpdateFromPath (GSettings *settings, + const char *path, + const gchar *keyName, + CCSContext *context, + CCSPlugin **plugin, + CCSSetting **setting, + char **uncleanKeyName) +{ + char *pluginName; + unsigned int screenNum; + + if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) + return FALSE; + + *plugin = ccsFindPlugin (context, pluginName); + + if (*plugin) + { + *uncleanKeyName = translateKeyForCCS (keyName); + + *setting = ccsFindSetting (*plugin, *uncleanKeyName); + if (!setting) + { + /* Couldn't find setting straight off the bat, + * try and find the best match */ + GVariant *value = g_settings_get_value (settings, keyName); + + if (value) + { + GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); + GList *iter = possibleSettingTypes; + + while (iter) + { + *setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (*plugin), + keyName, + (CCSSettingType) GPOINTER_TO_INT (iter->data)); + + if (*setting) + break; + + iter = iter->next; + } + + g_list_free (possibleSettingTypes); + g_variant_unref (value); + } + } + } + + g_free (pluginName); + + if (!*plugin || !*setting) + return FALSE; + + return TRUE; +} + gchar * makeCompizProfilePath (const gchar *profilename) { diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index ae5779195..3b7fa0af5 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -84,6 +84,15 @@ filterAllSettingsMatchingPartOfStringIgnoringDashesUnderscoresAndCase (const gch CCSSetting * attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *lossyName, CCSSettingType type); +Bool +findSettingAndPluginToUpdateFromPath (GSettings *settings, + const char *path, + const gchar *keyName, + CCSContext *context, + CCSPlugin **plugin, + CCSSetting **setting, + char **uncleanKeyName); + GList * variantTypeToPossibleSettingType (const gchar *vt); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 62c020849..de45cad98 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -153,65 +153,6 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS } } -Bool -findSettingAndPluginToUpdateFromPath (GSettings *settings, - const char *path, - const gchar *keyName, - CCSContext *context, - CCSPlugin **plugin, - CCSSetting **setting, - char **uncleanKeyName) -{ - char *pluginName; - unsigned int screenNum; - - if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) - return FALSE; - - *plugin = ccsFindPlugin (context, pluginName); - - if (*plugin) - { - *uncleanKeyName = translateKeyForCCS (keyName); - - *setting = ccsFindSetting (*plugin, *uncleanKeyName); - if (!setting) - { - /* Couldn't find setting straight off the bat, - * try and find the best match */ - GVariant *value = g_settings_get_value (settings, keyName); - - if (value) - { - GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); - GList *iter = possibleSettingTypes; - - while (iter) - { - *setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (*plugin), - keyName, - (CCSSettingType) GPOINTER_TO_INT (iter->data)); - - if (*setting) - break; - - iter = iter->next; - } - - g_list_free (possibleSettingTypes); - g_variant_unref (value); - } - } - } - - g_free (pluginName); - - if (!*plugin || !*setting) - return FALSE; - - return TRUE; -} - static void valueChanged (GSettings *settings, gchar *keyName, -- GitLab From e48185e5fc4fcea644211a8ca841529da1a60afc Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 03:16:46 +0800 Subject: [PATCH 115/562] Refactor updateSettingWithGSettingsKeyName --- compizconfig/gsettings/src/gsettings.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index de45cad98..49e26721a 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -153,12 +153,11 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS } } -static void -valueChanged (GSettings *settings, - gchar *keyName, - gpointer user_data) +void +updateSettingWithGSettingsKeyName (CCSBackend *backend, + GSettings *settings, + gchar *keyName) { - CCSBackend *backend = (CCSBackend *)user_data; CCSContext *context = ccsGSettingsBackendGetContext (backend); char *uncleanKeyName = NULL; char *pathOrig; @@ -185,6 +184,16 @@ valueChanged (GSettings *settings, free (uncleanKeyName); } +static void +valueChanged (GSettings *settings, + gchar *keyName, + gpointer user_data) +{ + CCSBackend *backend = (CCSBackend *)user_data; + + updateSettingWithGSettingsKeyName (backend, settings, keyName); +} + static Bool readIntegratedOption (CCSBackend *backend, CCSContext *context, -- GitLab From 47b5948a205199408050a081f1f5d456b81dac0f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 03:21:57 +0800 Subject: [PATCH 116/562] Move updateSettingWithGSettingsKeyName into the util library --- .../gsettings_backend_shared/gsettings_util.c | 32 ++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 7 ++++ compizconfig/gsettings/src/gsettings.c | 33 +------------------ 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index afb32fa9a..777b36fd7 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -389,6 +389,38 @@ findSettingAndPluginToUpdateFromPath (GSettings *settings, return TRUE; } +void +updateSettingWithGSettingsKeyName (CCSBackend *backend, + GSettings *settings, + gchar *keyName, + CCSBackendUpdateFunc updateSetting) +{ + CCSContext *context = ccsGSettingsBackendGetContext (backend); + char *uncleanKeyName = NULL; + char *pathOrig; + CCSPlugin *plugin; + CCSSetting *setting; + + g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); + + if (findSettingAndPluginToUpdateFromPath (settings, pathOrig, keyName, context, &plugin, &setting, &uncleanKeyName)) + (*updateSetting) (backend, context, plugin, setting); + else + { + /* We hit a situation where either the key stored in GSettings couldn't be + * matched at all to a key in the xml file, or where there were multiple matches. + * Unfortunately, there isn't much we can do about this, other than try + * and warn the user and bail out. It just means that if the key was updated + * externally we won't know about the change until the next reload of settings */ + ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, pathOrig); + } + + g_free (pathOrig); + + if (uncleanKeyName) + free (uncleanKeyName); +} + gchar * makeCompizProfilePath (const gchar *profilename) { diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 3b7fa0af5..7d5784889 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -2,6 +2,7 @@ #define _COMPIZ_GSETTINGS_UTIL_H #include +#include COMPIZCONFIG_BEGIN_DECLS @@ -93,6 +94,12 @@ findSettingAndPluginToUpdateFromPath (GSettings *settings, CCSSetting **setting, char **uncleanKeyName); +void +updateSettingWithGSettingsKeyName (CCSBackend *backend, + GSettings *settings, + gchar *keyName, + CCSBackendUpdateFunc updateSetting); + GList * variantTypeToPossibleSettingType (const gchar *vt); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 49e26721a..bc234df30 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -153,37 +153,6 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS } } -void -updateSettingWithGSettingsKeyName (CCSBackend *backend, - GSettings *settings, - gchar *keyName) -{ - CCSContext *context = ccsGSettingsBackendGetContext (backend); - char *uncleanKeyName = NULL; - char *pathOrig; - CCSPlugin *plugin; - CCSSetting *setting; - - g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); - - if (findSettingAndPluginToUpdateFromPath (settings, pathOrig, keyName, context, &plugin, &setting, &uncleanKeyName)) - updateSetting (backend, context, plugin, setting); - else - { - /* We hit a situation where either the key stored in GSettings couldn't be - * matched at all to a key in the xml file, or where there were multiple matches. - * Unfortunately, there isn't much we can do about this, other than try - * and warn the user and bail out. It just means that if the key was updated - * externally we won't know about the change until the next reload of settings */ - ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, pathOrig); - } - - g_free (pathOrig); - - if (uncleanKeyName) - free (uncleanKeyName); -} - static void valueChanged (GSettings *settings, gchar *keyName, @@ -191,7 +160,7 @@ valueChanged (GSettings *settings, { CCSBackend *backend = (CCSBackend *)user_data; - updateSettingWithGSettingsKeyName (backend, settings, keyName); + updateSettingWithGSettingsKeyName (backend, settings, keyName, updateSetting); } static Bool -- GitLab From 56c2198ebc9851cd926c7bfceb8e6968bbec4f85 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 03:29:08 +0800 Subject: [PATCH 117/562] Added TestUpdateKeyedValue - all failing --- .../tests/test_gsettings_conformance.cpp | 6 ++++++ ...zconfig_test_ccs_mock_backend_conformance.cpp | 6 ++++++ .../tests/compizconfig_backend_concept_test.h | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index d130d8274..1f8ac0659 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -399,6 +399,12 @@ class CCSGSettingsBackendEnv : CCSSettingGMock *gmockSetting, CCSSettingType type) {} + bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) + { + return false; + } + private: GSettings *mSettings; diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 159693594..0e8b4a2d6 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -293,6 +293,12 @@ class MockCCSBackendConceptTestEnvironment : { } + bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) + { + return false; + } + protected: void ReadValueIntoSetting (CCSSetting *setting) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index e9fe67d37..a9cdd7c29 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -301,6 +301,9 @@ class CCSBackendConceptTestEnvironmentInterface CCSPluginGMock *, CCSSettingGMock *, CCSSettingType) = 0; + + virtual bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) = 0; }; class CCSBackendConceptTestEnvironmentFactoryInterface @@ -1116,6 +1119,19 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) ccsBackendUpdateSetting (CCSBackendConformanceTest::GetBackend (), context, plugin, setting); } +TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) +{ + SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "UpdateMocked"); + + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + + EXPECT_TRUE (CCSBackendConformanceTest::GetParam ()->testEnv ()->UpdateSettingAtKey (pluginName, settingName)); +} + TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) { SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); -- GitLab From 7e9a1b2300650966740bdc827ab96461d98f7850 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 04:11:27 +0800 Subject: [PATCH 118/562] Make the mock UpdateSettingAtKey tests pass --- ...nfig_test_ccs_mock_backend_conformance.cpp | 37 +++++++++++++++++-- .../tests/compizconfig_backend_concept_test.h | 3 ++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 0e8b4a2d6..cd51d56c5 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -50,6 +50,7 @@ class MockCCSBackendConceptTestEnvironment : CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { + mContext = context; mBackend = ccsMockBackendNew (); mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); @@ -196,8 +197,17 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, readSetting (_, _)); EXPECT_CALL (*gmockPlugin, getName ()); EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getType ()); EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } } void PostRead (CCSContextGMock *gmockContext, @@ -282,8 +292,17 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, updateSetting (_, _, _)); EXPECT_CALL (*gmockPlugin, getName ()); EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getType ()); EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } } void PostUpdate (CCSContextGMock *gmockContext, @@ -296,7 +315,18 @@ class MockCCSBackendConceptTestEnvironment : bool UpdateSettingAtKey (const std::string &plugin, const std::string &setting) { - return false; + CCSPlugin *cplugin = ccsFindPlugin (mContext, plugin.c_str ()); + + if (!cplugin) + return false; + + CCSSetting *csetting = ccsFindSetting (cplugin, setting.c_str ()); + + if (!csetting) + return false; + + ccsBackendUpdateSetting (mBackend, mContext, cplugin, csetting); + return true; } protected: @@ -472,6 +502,7 @@ class MockCCSBackendConceptTestEnvironment : CCSBackend *mBackend; CCSBackendGMock *mBackendGMock; + CCSContext *mContext; std::map mValues; }; diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index a9cdd7c29..f06d15772 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1129,6 +1129,9 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (plugin)); + EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (setting)); + EXPECT_TRUE (CCSBackendConformanceTest::GetParam ()->testEnv ()->UpdateSettingAtKey (pluginName, settingName)); } -- GitLab From ebf3969f66b58dcac8e007bcddf610403fb46eb7 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 04:40:04 +0800 Subject: [PATCH 119/562] Make TestUpdateKeyedValu* pass on GSettings --- .../gsettings_backend_shared/gsettings_util.c | 6 ++- .../gsettings_backend_shared/gsettings_util.h | 9 ++-- .../tests/test_gsettings_conformance.cpp | 48 ++++++++++++------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 777b36fd7..dac993aa7 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -389,7 +389,7 @@ findSettingAndPluginToUpdateFromPath (GSettings *settings, return TRUE; } -void +Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, GSettings *settings, gchar *keyName, @@ -400,6 +400,7 @@ updateSettingWithGSettingsKeyName (CCSBackend *backend, char *pathOrig; CCSPlugin *plugin; CCSSetting *setting; + Bool ret = TRUE; g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); @@ -413,12 +414,15 @@ updateSettingWithGSettingsKeyName (CCSBackend *backend, * and warn the user and bail out. It just means that if the key was updated * externally we won't know about the change until the next reload of settings */ ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, pathOrig); + ret = FALSE; } g_free (pathOrig); if (uncleanKeyName) free (uncleanKeyName); + + return ret; } gchar * diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 7d5784889..e58ce760f 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -94,11 +94,10 @@ findSettingAndPluginToUpdateFromPath (GSettings *settings, CCSSetting **setting, char **uncleanKeyName); -void -updateSettingWithGSettingsKeyName (CCSBackend *backend, - GSettings *settings, - gchar *keyName, - CCSBackendUpdateFunc updateSetting); +Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, + GSettings *settings, + gchar *keyName, + CCSBackendUpdateFunc updateSetting); GList * variantTypeToPossibleSettingType (const gchar *vt); diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 1f8ac0659..354b9d0c9 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -59,21 +59,23 @@ class CCSGSettingsBackendEnv : EXPECT_FALSE (fallback); EXPECT_TRUE (dlhand); - CCSBackend *backend = ccsBackendNewWithInterface (mContext, interface, dlhand); - mBackend = ccsBackendWithCapabilitiesWrapBackend (&ccsDefaultInterfaceTable, backend); + mGSettingsBackend = ccsBackendNewWithInterface (mContext, interface, dlhand); + mBackend = ccsBackendWithCapabilitiesWrapBackend (&ccsDefaultInterfaceTable, mGSettingsBackend); CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, mBackend))->backendInit; if (backendInit) (*backendInit) ((CCSBackend *) mBackend, mContext); - overloadedInterface = *(GET_INTERFACE (CCSGSettingsBackendInterface, backend)); + overloadedInterface = *(GET_INTERFACE (CCSGSettingsBackendInterface, mGSettingsBackend)); overloadedInterface.gsettingsBackendConnectToChangedSignal = CCSGSettingsBackendEnv::connectToSignalWrapper; - ccsObjectRemoveInterface (backend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); - ccsObjectAddInterface (backend, (CCSInterface *) &overloadedInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + ccsObjectRemoveInterface (mGSettingsBackend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + ccsObjectAddInterface (mGSettingsBackend, (CCSInterface *) &overloadedInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); - mSettings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, "mock", makeCompizPluginPath ("mock", "mock"), mContext); + mSettings = ccsGSettingsGetSettingsObjectForPluginWithPath (mGSettingsBackend, "mock", makeCompizPluginPath (profileName.c_str (), "mock"), mContext); + + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); return (CCSBackend *) mBackend; } @@ -259,7 +261,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeBool); return readBoolFromVariant (variant); } @@ -269,7 +271,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeInt); return readIntFromVariant (variant); } @@ -279,7 +281,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeFloat); return readFloatFromVariant (variant); } @@ -289,7 +291,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeString); return readStringFromVariant (variant); } @@ -300,7 +302,7 @@ class CCSGSettingsBackendEnv : Bool success = FALSE; GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeColor); CCSSettingColorValue value = readColorFromVariant (variant, &success); EXPECT_TRUE (success); @@ -313,7 +315,7 @@ class CCSGSettingsBackendEnv : Bool success = FALSE; GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeKey); CCSSettingKeyValue value = readKeyFromVariant (variant, &success); EXPECT_TRUE (success); @@ -326,7 +328,7 @@ class CCSGSettingsBackendEnv : Bool success = FALSE; GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeButton); CCSSettingButtonValue value = readButtonFromVariant (variant, &success); EXPECT_TRUE (success); @@ -338,7 +340,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeEdge); return readEdgeFromVariant (variant); } @@ -348,7 +350,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeMatch); return readStringFromVariant (variant); } @@ -358,7 +360,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeBell); return readBoolFromVariant (variant); } @@ -369,7 +371,7 @@ class CCSGSettingsBackendEnv : { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath ("mock", plugin.c_str ())), + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeList); return readListValue (variant, info->forList.listType); } @@ -392,6 +394,8 @@ class CCSGSettingsBackendEnv : EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); } + + EXPECT_CALL (*gmockContext, getProfile ()); } void PostUpdate (CCSContextGMock *gmockContext, @@ -402,6 +406,11 @@ class CCSGSettingsBackendEnv : bool UpdateSettingAtKey (const std::string &plugin, const std::string &setting) { + CharacterWrapper keyName (translateKeyForGSettings (setting.c_str ())); + + if (updateSettingWithGSettingsKeyName (reinterpret_cast (mGSettingsBackend), mSettings, keyName, ccsBackendUpdateSetting)) + return true; + return false; } @@ -410,10 +419,15 @@ class CCSGSettingsBackendEnv : GSettings *mSettings; CCSContext *mContext; CCSBackendWithCapabilities *mBackend; + CCSBackend *mGSettingsBackend; std::string pluginToMatch; CCSGSettingsBackendInterface overloadedInterface; + + static const std::string profileName; }; +const std::string CCSGSettingsBackendEnv::profileName = "mock"; + INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestReadWrite, compizconfig::test::GenerateTestingParametersForBackendInterface ()); -- GitLab From f80340b7b753d6e039e4f44811544fb591197f20 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 22 Jul 2012 04:40:42 +0800 Subject: [PATCH 120/562] Remove useless comment and unset evn --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 354b9d0c9..2edca717e 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -44,9 +44,6 @@ class CCSGSettingsBackendEnv : Bool fallback = FALSE; g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); - - /* For some reason a number of tests fail when using - * this GSettings backend */ g_setenv ("GSETTINGS_BACKEND", "memory", true); g_setenv ("LIBCOMPIZCONFIG_BACKEND_PATH", BACKEND_BINARY_PATH, true); @@ -84,6 +81,7 @@ class CCSGSettingsBackendEnv : { g_unsetenv ("GSETTINGS_SCHEMA_DIR"); g_unsetenv ("GSETTINGS_BACKEND"); + g_unsetenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); ccsFreeBackendWithCapabilities (mBackend); } -- GitLab From 0e37828f1dddae54b9e2895911fd2ea6b9493a34 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 02:25:24 +0800 Subject: [PATCH 121/562] Always assume that lists are copied - fix list leak (and use smart pointers more effectively) --- .../gsettings_backend_shared/gsettings_util.c | 1 + compizconfig/gsettings/src/gsettings.c | 8 +- ...nfig_test_ccs_mock_backend_conformance.cpp | 17 ++- .../tests/compizconfig_backend_concept_test.h | 120 ++++++++---------- 4 files changed, 71 insertions(+), 75 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index dac993aa7..2ebc2836c 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -749,6 +749,7 @@ writeListValue (CCSSettingValueList list, { item = ccsColorToString (&list->data->value.asColor); g_variant_builder_add (builder, "s", item); + g_free (item); list = list->next; } value = g_variant_new ("as", builder); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index bc234df30..242869563 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -642,8 +642,6 @@ initBackend (CCSBackend *backend, CCSContext * context) static Bool finiBackend (CCSBackend *backend, CCSContext * context) { - GList *l = settingsList; - processEvents (backend, 0); #ifdef USE_GCONF @@ -657,11 +655,7 @@ finiBackend (CCSBackend *backend, CCSContext * context) currentProfile = NULL; } - while (l) - { - g_object_unref (G_OBJECT (l->data)); - l = g_list_next (l); - } + g_list_free_full (settingsList, g_object_unref); settingsList = NULL; diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index cd51d56c5..2a56c80d3 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -43,6 +43,11 @@ class ValueForKeyRetreival } }; +namespace +{ + void doNothingWithCCSSetting (CCSSetting *) {}; +} + class MockCCSBackendConceptTestEnvironment : public CCSBackendConceptTestEnvironmentInterface { @@ -281,7 +286,9 @@ class MockCCSBackendConceptTestEnvironment : const std::string &key, CCSSettingInfo *info) { - return *(ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + CCSListWrapper::Ptr lw (ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + + return ccsCopyList (*lw, lw->setting ().get ()); } void PreUpdate (CCSContextGMock *gmockContext, @@ -392,7 +399,11 @@ class MockCCSBackendConceptTestEnvironment : { CCSSettingInfo *info = ccsSettingGetInfo (setting); - ccsSetList (setting, ReadListAtKey (plugin, key, info), FALSE); + ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, info), + true, + info->forList.listType, + boost::shared_ptr (), + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))), FALSE); } break; @@ -489,7 +500,7 @@ class MockCCSBackendConceptTestEnvironment : WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, ccsSettingGetInfo (setting)->forList.listType, boost::shared_ptr (), - boost::shared_ptr ()))); + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))))); break; } default: diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index f06d15772..0d293c1e3 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -187,6 +187,13 @@ class CCSListWrapper : { ccsSettingValueListFree (mList, mFreeItems ? TRUE : FALSE); } + + const boost::shared_ptr & + setting () + { + return mSettingReference; + } + private: CCSSettingValueList mList; @@ -335,12 +342,12 @@ typedef boost::function WriteFunc; Bool boolToBool (bool v) { return v ? TRUE : FALSE; } -CCSSettingGMock * getSettingGMockFromSetting (CCSSetting *setting) { return (CCSSettingGMock *) ccsObjectGetPrivate (setting); } +CCSSettingGMock * getSettingGMockFromSetting (const boost::shared_ptr &setting) { return (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); } void SetIntWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -356,7 +363,7 @@ void SetIntWriteExpectation (const std::string &plugin, void SetBoolWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -378,7 +385,7 @@ void SetBoolWriteExpectation (const std::string &plugin, void SetFloatWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -394,7 +401,7 @@ void SetFloatWriteExpectation (const std::string &plugin, void SetStringWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -410,7 +417,7 @@ void SetStringWriteExpectation (const std::string &plugin, void SetColorWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -427,7 +434,7 @@ void SetColorWriteExpectation (const std::string &plugin, void SetKeyWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -443,7 +450,7 @@ void SetKeyWriteExpectation (const std::string &plugin, void SetButtonWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -459,7 +466,7 @@ void SetButtonWriteExpectation (const std::string &plugin, void SetEdgeWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -475,7 +482,7 @@ void SetEdgeWriteExpectation (const std::string &plugin, void SetBellWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -496,7 +503,7 @@ void SetBellWriteExpectation (const std::string &plugin, void SetMatchWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -512,7 +519,7 @@ void SetMatchWriteExpectation (const std::string &plugin, void SetListWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { @@ -521,7 +528,7 @@ void SetListWriteExpectation (const std::string &plugin, EXPECT_CALL (*gmock, getInfo ()); - CCSSettingInfo *info = ccsSettingGetInfo (setting); + CCSSettingInfo *info = ccsSettingGetInfo (setting.get ()); info->forList.listType = (boost::get > (value))->type (); @@ -531,7 +538,13 @@ void SetListWriteExpectation (const std::string &plugin, list), Return (TRUE))); write (); - EXPECT_THAT (env->ReadListAtKey (plugin, key, info), ListEqual (ccsSettingGetInfo (setting)->forList, list)); + + EXPECT_THAT (CCSListWrapper (env->ReadListAtKey (plugin, key, info), + true, + info->forList.listType, + boost::shared_ptr (), + setting), + ListEqual (info->forList, list)); } void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) @@ -622,7 +635,7 @@ class CCSBackendConceptTestParamInterface typedef boost::function &, const WriteFunc &, const CCSBackendConceptTestEnvironmentInterface::Ptr & )> SetWriteExpectation; @@ -732,32 +745,17 @@ class CCSBackendConformanceTest : virtual void SetUp () { - CCSBackendConformanceTest::SpawnContext (&context); + CCSBackendConformanceTest::SpawnContext (context); gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); - mBackend = GetParam ()->testEnv ()->SetUp (context, gmockContext); + mBackend = GetParam ()->testEnv ()->SetUp (context.get (), gmockContext); } virtual void TearDown () { CCSBackendConformanceTest::GetParam ()->TearDown (mBackend); - - for (std::list ::iterator it = mSpawnedContexts.begin (); - it != mSpawnedContexts.end (); - it++) - ccsFreeMockContext (*it); - - for (std::list ::iterator it = mSpawnedPlugins.begin (); - it != mSpawnedPlugins.end (); - it++) - ccsFreeMockPlugin (*it); - - for (std::list ::iterator it = mSpawnedSettings.begin (); - it != mSpawnedSettings.end (); - it++) - ccsFreeMockSetting (*it); } protected: @@ -767,38 +765,35 @@ class CCSBackendConformanceTest : * you use ASSERT_* unless the function returns void */ void - SpawnContext (CCSContext **context) + SpawnContext (boost::shared_ptr &context) { - *context = ccsMockContextNew (); - mSpawnedContexts.push_back (*context); + context.reset (ccsMockContextNew (), boost::bind (ccsFreeMockContext, _1)); } void - SpawnPlugin (const std::string &name, CCSContext *context, CCSPlugin **plugin) + SpawnPlugin (const std::string &name, const boost::shared_ptr &context, boost::shared_ptr &plugin) { - *plugin = ccsMockPluginNew (); - mSpawnedPlugins.push_back (*plugin); + plugin.reset (ccsMockPluginNew (), boost::bind (ccsFreeMockPlugin, _1)); - CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (*plugin); + CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin.get ()); ASSERT_FALSE (name.empty ()); - ASSERT_TRUE (context); + ASSERT_TRUE (context.get ()); ON_CALL (*gmockPlugin, getName ()).WillByDefault (Return ((char *) name.c_str ())); - ON_CALL (*gmockPlugin, getContext ()).WillByDefault (Return (context)); + ON_CALL (*gmockPlugin, getContext ()).WillByDefault (Return (context.get ())); } void SpawnSetting (const std::string &name, CCSSettingType type, - CCSPlugin *plugin, - CCSSetting **setting) + const boost::shared_ptr &plugin, + boost::shared_ptr &setting) { - *setting = ccsMockSettingNew (); - mSpawnedSettings.push_back (*setting); + setting.reset (ccsMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); mSpawnedSettingInfo.push_back (CCSSettingInfo ()); - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (*setting); + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); ASSERT_FALSE (name.empty ()); ASSERT_NE (type, TypeNum); @@ -806,24 +801,19 @@ class CCSBackendConformanceTest : ON_CALL (*gmockSetting, getName ()).WillByDefault (Return ((char *) name.c_str ())); ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (type)); - ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin)); + ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin.get ())); ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&(mSpawnedSettingInfo.back ()))); } protected: - CCSContext *context; + boost::shared_ptr context; CCSContextGMock *gmockContext; private: - std::list mSpawnedContexts; - std::list mSpawnedPlugins; - std::list mSpawnedSettings; std::vector mSpawnedSettingInfo; - CCSBackend *mBackend; - std::string profileName; }; @@ -1069,11 +1059,11 @@ class CCSBackendConformanceTestReadWrite : settingName = GetParam ()->keyname (); VALUE = GetParam ()->value (); - CCSBackendConformanceTest::SpawnPlugin (pluginName, context, &plugin); - CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); + CCSBackendConformanceTest::SpawnPlugin (pluginName, context, plugin); + CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, setting); - gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); - gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin.get ()); + gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); } virtual void TearDown () @@ -1086,8 +1076,8 @@ class CCSBackendConformanceTestReadWrite : std::string pluginName; std::string settingName; VariantTypes VALUE; - CCSPlugin *plugin; - CCSSetting *setting; + boost::shared_ptr plugin; + boost::shared_ptr setting; CCSPluginGMock *gmockPlugin; CCSSettingGMock *gmockSetting; @@ -1103,7 +1093,7 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); - ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context, setting); + ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context.get (), setting.get ()); } TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) @@ -1116,7 +1106,7 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); - ccsBackendUpdateSetting (CCSBackendConformanceTest::GetBackend (), context, plugin, setting); + ccsBackendUpdateSetting (CCSBackendConformanceTest::GetBackend (), context.get (), plugin.get (), setting.get ()); } TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) @@ -1129,8 +1119,8 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); - EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (plugin)); - EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (setting)); + EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (setting.get ())); EXPECT_TRUE (CCSBackendConformanceTest::GetParam ()->testEnv ()->UpdateSettingAtKey (pluginName, settingName)); } @@ -1146,8 +1136,8 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) setting, boost::bind (ccsBackendWriteSetting, CCSBackendConformanceTest::GetBackend (), - context, - setting), + context.get (), + setting.get ()), GetParam ()->testEnv ()); CCSBackendConformanceTest::GetParam ()->testEnv ()->PostWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); -- GitLab From e358daefe4c78134dc20480475ebef218c265481 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 02:27:42 +0800 Subject: [PATCH 122/562] Fix leaked path in CCSGSettingsBackendEnv::SetUp --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 2edca717e..a13294ebe 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -70,7 +70,9 @@ class CCSGSettingsBackendEnv : ccsObjectRemoveInterface (mGSettingsBackend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); ccsObjectAddInterface (mGSettingsBackend, (CCSInterface *) &overloadedInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); - mSettings = ccsGSettingsGetSettingsObjectForPluginWithPath (mGSettingsBackend, "mock", makeCompizPluginPath (profileName.c_str (), "mock"), mContext); + mSettings = ccsGSettingsGetSettingsObjectForPluginWithPath (mGSettingsBackend, "mock", + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), "mock")), + mContext); ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); -- GitLab From d453ec15a17ffa9bc8604588cc9763065f01a647 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 02:59:14 +0800 Subject: [PATCH 123/562] Fix memory leak in readListValue in gsettings.c - we must always provide a valid CCSSetting object otherwise ccsFreeSettingValue will not actually free the setting value --- .../gsettings_backend_shared/gsettings_util.c | 13 +++++++------ .../gsettings_backend_shared/gsettings_util.h | 2 +- compizconfig/gsettings/src/gsettings.c | 2 +- .../gsettings/tests/test_gsettings_conformance.cpp | 6 +++--- ...mpizconfig_test_ccs_mock_backend_conformance.cpp | 10 +++------- .../tests/compizconfig_backend_concept_test.h | 5 +++-- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 2ebc2836c..2bebd6171 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -484,8 +484,9 @@ getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCS } CCSSettingValueList -readListValue (GVariant *gsettingsValue, CCSSettingType listType) +readListValue (GVariant *gsettingsValue, CCSSetting *setting) { + CCSSettingType listType = ccsSettingGetInfo (setting)->forList.listType; gboolean hasVariantType; unsigned int nItems; CCSSettingValueList list = NULL; @@ -514,7 +515,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_loop (&iter, "b", &value)) *arrayCounter++ = value ? TRUE : FALSE; - list = ccsGetValueListFromBoolArray (array, nItems, NULL); + list = ccsGetValueListFromBoolArray (array, nItems, setting); free (array); } break; @@ -531,7 +532,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_loop (&iter, "i", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromIntArray (array, nItems, NULL); + list = ccsGetValueListFromIntArray (array, nItems, setting); free (array); } break; @@ -548,7 +549,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_loop (&iter, "d", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromFloatArray (array, nItems, NULL); + list = ccsGetValueListFromFloatArray (array, nItems, setting); free (array); } break; @@ -568,7 +569,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_next (&iter, "s", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromStringArray (array, nItems, NULL); + list = ccsGetValueListFromStringArray (array, nItems, setting); g_strfreev ((char **) array); } break; @@ -588,7 +589,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) i++; } - list = ccsGetValueListFromColorArray (array, nItems, NULL); + list = ccsGetValueListFromColorArray (array, nItems, setting); free (array); } break; diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index e58ce760f..e99cdc5fd 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -134,7 +134,7 @@ CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *suc unsigned int readEdgeFromVariant (GVariant *gsettingsValue); CCSSettingValueList -readListValue (GVariant *gsettingsValue, CCSSettingType listType); +readListValue (GVariant *gsettingsValue, CCSSetting *setting); Bool writeListValue (CCSSettingValueList list, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 242869563..218162d08 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -317,7 +317,7 @@ readOption (CCSBackend *backend, CCSSetting * setting) break; case TypeList: { - CCSSettingValueList list = readListValue (gsettingsValue, ccsSettingGetInfo (setting)->forList.listType); + CCSSettingValueList list = readListValue (gsettingsValue, setting); if (list) { diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index a13294ebe..bdb3df1e6 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -366,14 +366,14 @@ class CCSGSettingsBackendEnv : } CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key, - CCSSettingInfo *info) + const std::string &key, + CCSSetting *setting) { GVariant *variant = getVariantAtKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeList); - return readListValue (variant, info->forList.listType); + return readListValue (variant, setting); } void PreUpdate (CCSContextGMock *gmockContext, diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 2a56c80d3..04529f292 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -284,7 +284,7 @@ class MockCCSBackendConceptTestEnvironment : virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, const std::string &key, - CCSSettingInfo *info) + CCSSetting *setting) { CCSListWrapper::Ptr lw (ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); @@ -396,15 +396,11 @@ class MockCCSBackendConceptTestEnvironment : break; case TypeList: - { - CCSSettingInfo *info = ccsSettingGetInfo (setting); - - ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, info), + ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, setting), true, - info->forList.listType, + ccsSettingGetInfo (setting)->forList.listType, boost::shared_ptr (), boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))), FALSE); - } break; default: diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 0d293c1e3..2ea34538d 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -298,7 +298,7 @@ class CCSBackendConceptTestEnvironmentInterface const std::string &key) = 0; virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, const std::string &key, - CCSSettingInfo *info) = 0; + CCSSetting *setting) = 0; virtual void PreUpdate (CCSContextGMock *, CCSPluginGMock *, @@ -532,6 +532,7 @@ void SetListWriteExpectation (const std::string &plugin, info->forList.listType = (boost::get > (value))->type (); + EXPECT_CALL (*gmock, getDefaultValue ()).WillRepeatedly (ReturnNull ()); EXPECT_CALL (*gmock, getInfo ()).Times (AtLeast (1)); EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( @@ -539,7 +540,7 @@ void SetListWriteExpectation (const std::string &plugin, Return (TRUE))); write (); - EXPECT_THAT (CCSListWrapper (env->ReadListAtKey (plugin, key, info), + EXPECT_THAT (CCSListWrapper (env->ReadListAtKey (plugin, key, setting.get ()), true, info->forList.listType, boost::shared_ptr (), -- GitLab From c5141706fea34df06a28a4c1ebbb94b3a167e433 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 03:06:04 +0800 Subject: [PATCH 124/562] Fix various memory leaks due to not unreffing some variants --- compizconfig/gsettings/src/gsettings.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 218162d08..a01273ca6 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -95,6 +95,7 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen g_settings_set_strv (currentProfileSettings, "plugins-with-set-keys", (const gchar * const *)newWrittenPlugins); + g_variant_unref (writtenPlugins); g_free (schemaName); g_strfreev (newWrittenPlugins); @@ -536,6 +537,8 @@ updateCurrentProfileName (const char *profile) g_variant_unref (newProfiles); g_variant_builder_unref (newProfilesBuilder); + g_variant_unref (profiles); + /* Change the current profile and current profile settings */ free (currentProfile); @@ -582,6 +585,8 @@ getCurrentProfileName (void) else ret = strdup (DEFAULTPROF); + g_variant_unref (value); + return ret; } -- GitLab From baaabfada33b3de376ea3e361a07826f12bbb346 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 03:20:04 +0800 Subject: [PATCH 125/562] Added debugging message --- cmake/copy_file_install_user_env.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/copy_file_install_user_env.cmake b/cmake/copy_file_install_user_env.cmake index fdf20482e..0f33be99c 100644 --- a/cmake/copy_file_install_user_env.cmake +++ b/cmake/copy_file_install_user_env.cmake @@ -14,6 +14,8 @@ else (${USERNAME} STREQUAL "root") set (INSTALLDIR ${INSTALLDIR_USER}) endif (${USERNAME} STREQUAL "root") +message ("destdir: " ${DESTDIR} " install dir: " ${INSTALLDIR}) + file (INSTALL DESTINATION $ENV{DESTDIR}${INSTALLDIR} TYPE FILE FILES ${FILE}) -- GitLab From 41fd71bbb1eaeb582c3609b0163d962249211603 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 04:05:18 +0800 Subject: [PATCH 126/562] Put the expectation in the right place --- .../tests/test_gsettings_conformance.cpp | 3 ++ .../compizconfig_ccs_setting_mock.cpp | 36 ++++++++++++++++--- .../compizconfig_ccs_setting_mock.h | 1 + .../tests/compizconfig_backend_concept_test.h | 12 +++---- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index bdb3df1e6..f48b38e56 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -100,6 +100,9 @@ class CCSGSettingsBackendEnv : EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); EXPECT_CALL (*gmockSetting, getIsDefault ()).WillRepeatedly (Return (FALSE)); + + if (type == TypeList) + EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); } void PostWrite (CCSContextGMock *gmockContext, diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp index 8b3d5d0c4..effc6dd55 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp @@ -5,6 +5,8 @@ #include "compizconfig_ccs_setting_mock.h" +using ::testing::NiceMock; + CCSSettingInterface CCSSettingGMockInterface = { CCSSettingGMock::ccsSettingGetName, @@ -50,8 +52,8 @@ CCSSettingInterface CCSSettingGMockInterface = CCSSettingGMock::ccsSettingFree }; -CCSSetting * -ccsMockSettingNew () +static CCSSetting * +allocateSettingObjectWithMockInterface () { CCSSetting *setting = (CCSSetting *) calloc (1, sizeof (CCSSetting)); @@ -60,8 +62,6 @@ ccsMockSettingNew () ccsObjectInit (setting, &ccsDefaultObjectAllocator); - CCSSettingGMock *mock = new CCSSettingGMock (setting); - ccsObjectSetPrivate (setting, (CCSPrivate *) mock); ccsObjectAddInterface (setting, (CCSInterface *) &CCSSettingGMockInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); ccsSettingRef (setting); @@ -69,6 +69,34 @@ ccsMockSettingNew () return setting; } +CCSSetting * +ccsMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + CCSSettingGMock *mock = new CCSSettingGMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + +CCSSetting * +ccsNiceMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + NiceMock *mock = new NiceMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + void ccsFreeMockSetting (CCSSetting *setting) { diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h index 14d02de22..70f0c6d5e 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h @@ -7,6 +7,7 @@ using ::testing::_; using ::testing::Return; CCSSetting * ccsMockSettingNew (); +CCSSetting * ccsNiceMockSettingNew (); void ccsFreeMockSetting (CCSSetting *); class CCSSettingGMockInterface diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 2ea34538d..6dce530f0 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -32,6 +32,7 @@ using ::testing::Matcher; using ::testing::MatcherInterface; using ::testing::MatchResultListener; using ::testing::AtLeast; +using ::testing::NiceMock; MATCHER(IsTrue, "Is True") { if (arg) return true; else return false; } MATCHER(IsFalse, "Is False") { if (!arg) return true; else return false; } @@ -532,7 +533,6 @@ void SetListWriteExpectation (const std::string &plugin, info->forList.listType = (boost::get > (value))->type (); - EXPECT_CALL (*gmock, getDefaultValue ()).WillRepeatedly (ReturnNull ()); EXPECT_CALL (*gmock, getInfo ()).Times (AtLeast (1)); EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( @@ -878,17 +878,17 @@ CCSListConstructionExpectationsSetter (const ConstructorFunc &c, bool freeItems) { boost::function f (boost::bind (ccsFreeMockSetting, _1)); - boost::shared_ptr mockSetting (ccsMockSettingNew (), f); - CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting.get ())); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), f); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); - EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeList)); + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); boost::shared_ptr listInfo (new CCSSettingInfo); listInfo->forList.listType = type; - EXPECT_CALL (*gmockSetting, getInfo ()).WillRepeatedly (Return (listInfo.get ())); - EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (listInfo.get ())); + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); return boost::make_shared (c (mockSetting.get ()), freeItems, type, listInfo, mockSetting); } -- GitLab From 0e6c28b1cb50e470eac2fc37fdb9bf36918cab8c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 04:34:16 +0800 Subject: [PATCH 127/562] Indirect the gconf client registration --- .../gsettings_backend_shared/gsettings_util.c | 12 ++++++ .../gsettings_backend_shared/gsettings_util.h | 10 +++++ compizconfig/gsettings/src/gsettings.c | 40 +++++++++++++------ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 2bebd6171..7a7fb01d2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -876,3 +876,15 @@ ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, { return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetSettingsObjectForPluginWithPath) (backend, plugin, path, context); } + +void +ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendRegisterGConfClient) (backend); +} + +void +ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnregisterGConfClient) (backend); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index e99cdc5fd..70bd6c3c9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -19,12 +19,16 @@ typedef GSettings * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CC const char *plugin, const char *path, CCSContext *context); +typedef void (*CCSGSettingsBackendRegisterGConfClient) (CCSBackend *backend); +typedef void (*CCSGSettingsBackendUnregisterGConfClient) (CCSBackend *backend); struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; CCSGSettingsBackendConnectToChangedSignal gsettingsBackendConnectToChangedSignal; CCSGSettingsBackendGetSettingsObjectForPluginWithPath gsettingsBackendGetSettingsObjectForPluginWithPath; + CCSGSettingsBackendRegisterGConfClient gsettingsBackendRegisterGConfClient; + CCSGSettingsBackendUnregisterGConfClient gsettingsBackendUnregisterGConfClient; }; struct _CCSGSettingsBackendPrivate @@ -173,6 +177,12 @@ ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, const char *path, CCSContext *context); +void +ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend); + +void +ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index a01273ca6..47d07ffa4 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -612,10 +612,31 @@ ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, GObj g_signal_connect (object, "changed", (GCallback) valueChanged, (gpointer) backend); } +static void +ccsGSettingsBackendRegisterGConfClientDefault (CCSBackend *backend) +{ +#ifdef USE_GCONF + CCSContext *context = ccsGSettingsBackendGetContext (backend); + + initGConfClient (context); +#endif +} + +static void +ccsGSettingsBackendUnregisterGConfClientDefault (CCSBackend *backend) +{ +#ifdef USE_GCONF + gconf_client_clear_cache (client); + finiGConfClient (); +#endif +} + static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendGetContextDefault, ccsGSettingsBackendConnectToValueChangedSignalDefault, - ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault + ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault, + ccsGSettingsBackendRegisterGConfClientDefault, + ccsGSettingsBackendUnregisterGConfClientDefault }; static Bool @@ -625,11 +646,13 @@ initBackend (CCSBackend *backend, CCSContext * context) g_type_init (); + storedContext = context; + + ccsObjectAddInterface (backend, (CCSInterface *) &gsettingsAdditionalDefaultInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); -#ifdef USE_GCONF - initGConfClient (context); -#endif + ccsGSettingsBackendRegisterGConfClient (backend); currentProfile = getCurrentProfileName (); currentProfilePath = makeCompizProfilePath (currentProfile); @@ -637,10 +660,6 @@ initBackend (CCSBackend *backend, CCSContext * context) g_free (currentProfilePath); - storedContext = context; - - ccsObjectAddInterface (backend, (CCSInterface *) &gsettingsAdditionalDefaultInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); - return TRUE; } @@ -649,10 +668,7 @@ finiBackend (CCSBackend *backend, CCSContext * context) { processEvents (backend, 0); -#ifdef USE_GCONF - gconf_client_clear_cache (client); - finiGConfClient (); -#endif + ccsGSettingsBackendUnregisterGConfClient (backend); if (currentProfile) { -- GitLab From b4e162a068c88944eb640cad1ab8bb99e35f38c9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 04:36:16 +0800 Subject: [PATCH 128/562] Neuter gconf client connection --- .../gsettings/tests/test_gsettings_conformance.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index f48b38e56..c08ec7f0d 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -38,6 +38,14 @@ class CCSGSettingsBackendEnv : { }; + static void registerGConfClientWrapper (CCSBackend *backend) + { + } + + static void unregisterGConfClientWrapper (CCSBackend *backend) + { + } + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { CCSBackendInterface *interface = NULL; @@ -66,6 +74,8 @@ class CCSGSettingsBackendEnv : overloadedInterface = *(GET_INTERFACE (CCSGSettingsBackendInterface, mGSettingsBackend)); overloadedInterface.gsettingsBackendConnectToChangedSignal = CCSGSettingsBackendEnv::connectToSignalWrapper; + overloadedInterface.gsettingsBackendRegisterGConfClient = CCSGSettingsBackendEnv::registerGConfClientWrapper; + overloadedInterface.gsettingsBackendUnregisterGConfClient = CCSGSettingsBackendEnv::unregisterGConfClientWrapper; ccsObjectRemoveInterface (mGSettingsBackend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); ccsObjectAddInterface (mGSettingsBackend, (CCSInterface *) &overloadedInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); -- GitLab From 9858cdb0e2be28d6e2c121b7f3696fcff191a0f8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 05:09:33 +0800 Subject: [PATCH 129/562] Lazy-register the gconf client --- compizconfig/gsettings/src/gconf-integration.c | 6 ++++++ compizconfig/gsettings/src/gsettings.c | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/src/gconf-integration.c b/compizconfig/gsettings/src/gconf-integration.c index 085a75fa0..43a03ba0e 100644 --- a/compizconfig/gsettings/src/gconf-integration.c +++ b/compizconfig/gsettings/src/gconf-integration.c @@ -546,6 +546,9 @@ readGConfIntegratedOption (CCSBackend *backend, GError *err = NULL; Bool ret = FALSE; + if (!client) + ccsGSettingsBackendRegisterGConfClient (backend); + ret = readOption (backend, setting); gconfValue = gconf_client_get (client, @@ -774,6 +777,9 @@ writeGConfIntegratedOption (CCSBackend *backend, GError *err = NULL; const char *optionName = specialOptions[index].gnomeName; + if (!client) + ccsGSettingsBackendRegisterGConfClient (backend); + switch (specialOptions[index].type) { case OptionInt: diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 47d07ffa4..85602a600 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -652,8 +652,6 @@ initBackend (CCSBackend *backend, CCSContext * context) compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); - ccsGSettingsBackendRegisterGConfClient (backend); - currentProfile = getCurrentProfileName (); currentProfilePath = makeCompizProfilePath (currentProfile); currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath); -- GitLab From fd053da8921f5139cd3aed5ad465bf993700aa51 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 09:24:01 +0800 Subject: [PATCH 130/562] file (INSTALL ...) will respect DESTDIR by default, so no need to include it again. --- cmake/copy_file_install_user_env.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/copy_file_install_user_env.cmake b/cmake/copy_file_install_user_env.cmake index 0f33be99c..3a8798267 100644 --- a/cmake/copy_file_install_user_env.cmake +++ b/cmake/copy_file_install_user_env.cmake @@ -14,8 +14,6 @@ else (${USERNAME} STREQUAL "root") set (INSTALLDIR ${INSTALLDIR_USER}) endif (${USERNAME} STREQUAL "root") -message ("destdir: " ${DESTDIR} " install dir: " ${INSTALLDIR}) - -file (INSTALL DESTINATION $ENV{DESTDIR}${INSTALLDIR} +file (INSTALL DESTINATION ${INSTALLDIR} TYPE FILE FILES ${FILE}) -- GitLab From 5745ea041aedcd41b290bea8af531588473aa87e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 12:25:39 +0800 Subject: [PATCH 131/562] Fix some crashes in debian chroots --- .../tests/compiz_config_test.py | 1 + .../gsettings_backend_shared/CMakeLists.txt | 14 +++++++++++++- .../gsettings/tests/test_gsettings_conformance.cpp | 13 +++++-------- compizconfig/libcompizconfig/config/CMakeLists.txt | 3 +++ compizconfig/libcompizconfig/src/CMakeLists.txt | 8 ++++++++ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/compizconfig/compizconfig-python/tests/compiz_config_test.py b/compizconfig/compizconfig-python/tests/compiz_config_test.py index 805975a7d..d6f15a740 100644 --- a/compizconfig/compizconfig-python/tests/compiz_config_test.py +++ b/compizconfig/compizconfig-python/tests/compiz_config_test.py @@ -5,6 +5,7 @@ import subprocess arch = subprocess.Popen (["uname", "-p"], stdout=subprocess.PIPE).communicate ()[0][:-1] os.environ["COMPIZ_METADATA_PATH"] = "generated/" +os.environ["XDG_CONFIG_HOME"] = "compizconfig/libcompizconfig/config" os.environ["LIBCOMPIZCONFIG_BACKEND_PATH"] = "compizconfig/libcompizconfig/backend/" os.environ["XDG_DATA_DIRS"] = "generated/" diff --git a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt index 51a26d3f9..2b402f7f2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt +++ b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt @@ -15,12 +15,24 @@ if (GSETTINGS_UTIL_FOUND) link_directories (${GSETTINGS_UTIL_LIBRARY_DIRS} ${compiz_BINARY_DIR}/compizconfig/libcompizconfig) - add_library (gsettings_backend_shared STATIC + add_library (gsettings_backend_shared SHARED ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_constants.c ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_util.c) + target_link_libraries (gsettings_backend_shared ${GSETTINGS_UTIL_LIBRARIES} compizconfig) + install (TARGETS gsettings_backend_shared + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + + # + # Tell CMake that targets using gsettings_backend_shared should NOT re-import the + # libraries that gsettings_backend_shared depends on (contains). + # + set_target_properties (gsettings_backend_shared PROPERTIES + LINK_INTERFACE_LIBRARIES "" + ) + endif (GSETTINGS_UTIL_FOUND) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index c08ec7f0d..6fe393545 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -49,6 +49,7 @@ class CCSGSettingsBackendEnv : CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { CCSBackendInterface *interface = NULL; + CCSGSettingsBackendInterface *overloadedInterface = NULL; Bool fallback = FALSE; g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); @@ -72,13 +73,10 @@ class CCSGSettingsBackendEnv : if (backendInit) (*backendInit) ((CCSBackend *) mBackend, mContext); - overloadedInterface = *(GET_INTERFACE (CCSGSettingsBackendInterface, mGSettingsBackend)); - overloadedInterface.gsettingsBackendConnectToChangedSignal = CCSGSettingsBackendEnv::connectToSignalWrapper; - overloadedInterface.gsettingsBackendRegisterGConfClient = CCSGSettingsBackendEnv::registerGConfClientWrapper; - overloadedInterface.gsettingsBackendUnregisterGConfClient = CCSGSettingsBackendEnv::unregisterGConfClientWrapper; - - ccsObjectRemoveInterface (mGSettingsBackend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); - ccsObjectAddInterface (mGSettingsBackend, (CCSInterface *) &overloadedInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + overloadedInterface = GET_INTERFACE (CCSGSettingsBackendInterface, mGSettingsBackend); + overloadedInterface->gsettingsBackendConnectToChangedSignal = CCSGSettingsBackendEnv::connectToSignalWrapper; + overloadedInterface->gsettingsBackendRegisterGConfClient = CCSGSettingsBackendEnv::registerGConfClientWrapper; + overloadedInterface->gsettingsBackendUnregisterGConfClient = CCSGSettingsBackendEnv::unregisterGConfClientWrapper; mSettings = ccsGSettingsGetSettingsObjectForPluginWithPath (mGSettingsBackend, "mock", CharacterWrapper (makeCompizPluginPath (profileName.c_str (), "mock")), @@ -434,7 +432,6 @@ class CCSGSettingsBackendEnv : CCSBackendWithCapabilities *mBackend; CCSBackend *mGSettingsBackend; std::string pluginToMatch; - CCSGSettingsBackendInterface overloadedInterface; static const std::string profileName; }; diff --git a/compizconfig/libcompizconfig/config/CMakeLists.txt b/compizconfig/libcompizconfig/config/CMakeLists.txt index f3ff733cf..63938aa89 100644 --- a/compizconfig/libcompizconfig/config/CMakeLists.txt +++ b/compizconfig/libcompizconfig/config/CMakeLists.txt @@ -1,6 +1,9 @@ set (_config_file config) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config + ${CMAKE_CURRENT_BINARY_DIR}/compiz-1/compizconfig/config) + compiz_opt_install_file (${CMAKE_CURRENT_SOURCE_DIR}/${_config_file} ${COMPIZ_SYSCONFDIR}/compizconfig/${_config_file}) add_custom_target ( diff --git a/compizconfig/libcompizconfig/src/CMakeLists.txt b/compizconfig/libcompizconfig/src/CMakeLists.txt index 919668a62..c12edc90c 100644 --- a/compizconfig/libcompizconfig/src/CMakeLists.txt +++ b/compizconfig/libcompizconfig/src/CMakeLists.txt @@ -68,6 +68,14 @@ target_link_libraries ( compizconfig ${LIBCOMPIZCONFIG_LIBRARIES} m ) +# +# Tell CMake that targets using compizconfig should NOT re-import the +# libraries that compizconfig depends on (contains). +# +set_target_properties (compizconfig PROPERTIES + LINK_INTERFACE_LIBRARIES "" +) + set (COMPIZCONFIG_LIBS "") foreach (_val ${LIBCOMPIZCONFIG_LDFLAGS}) set (COMPIZCONFIG_LIBS "${COMPIZCONFIG_LIBS}${_val} ") -- GitLab From f66a9d733d507a7da5c3999dba82b363b7edd546 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 12:29:14 +0800 Subject: [PATCH 132/562] Make the profile general for tests --- compizconfig/compizconfig-python/tests/compiz_config_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/compizconfig/compizconfig-python/tests/compiz_config_test.py b/compizconfig/compizconfig-python/tests/compiz_config_test.py index d6f15a740..c9468cb67 100644 --- a/compizconfig/compizconfig-python/tests/compiz_config_test.py +++ b/compizconfig/compizconfig-python/tests/compiz_config_test.py @@ -5,6 +5,7 @@ import subprocess arch = subprocess.Popen (["uname", "-p"], stdout=subprocess.PIPE).communicate ()[0][:-1] os.environ["COMPIZ_METADATA_PATH"] = "generated/" +os.environ["COMPIZ_CONFIG_PROFILE"] = "" os.environ["XDG_CONFIG_HOME"] = "compizconfig/libcompizconfig/config" os.environ["LIBCOMPIZCONFIG_BACKEND_PATH"] = "compizconfig/libcompizconfig/backend/" os.environ["XDG_DATA_DIRS"] = "generated/" -- GitLab From ee610ce146b7274c15bb023f77e0a1d052037646 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 23 Jul 2012 14:22:04 +0800 Subject: [PATCH 133/562] Added testing config backend --- compizconfig/libcompizconfig/config/CMakeLists.txt | 2 +- compizconfig/libcompizconfig/config/config_test | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 compizconfig/libcompizconfig/config/config_test diff --git a/compizconfig/libcompizconfig/config/CMakeLists.txt b/compizconfig/libcompizconfig/config/CMakeLists.txt index 63938aa89..c4a09fce5 100644 --- a/compizconfig/libcompizconfig/config/CMakeLists.txt +++ b/compizconfig/libcompizconfig/config/CMakeLists.txt @@ -1,7 +1,7 @@ set (_config_file config) -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config_test ${CMAKE_CURRENT_BINARY_DIR}/compiz-1/compizconfig/config) compiz_opt_install_file (${CMAKE_CURRENT_SOURCE_DIR}/${_config_file} ${COMPIZ_SYSCONFDIR}/compizconfig/${_config_file}) diff --git a/compizconfig/libcompizconfig/config/config_test b/compizconfig/libcompizconfig/config/config_test new file mode 100644 index 000000000..fdf477b78 --- /dev/null +++ b/compizconfig/libcompizconfig/config/config_test @@ -0,0 +1,3 @@ +[general] +backend = ini +plugin_list_autosort = true -- GitLab From 5d531a818e66a3efe1cf6915b8d137de0d8af102 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 24 Jul 2012 20:32:02 +0800 Subject: [PATCH 134/562] Fix compile errors when adding the backend update to the backend_interface branch --- compizconfig/gconf/src/gconf.c | 4 ++-- compizconfig/gsettings/src/gsettings.c | 8 ++++---- compizconfig/libcompizconfig/backend/src/ini.c | 6 +++--- compizconfig/libcompizconfig/src/main.c | 7 +------ 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 9dcccc694..fe449bb8a 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -439,14 +439,14 @@ static void updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { int index; - readInit (backend, context); + readInit (context); if (!readOption (setting)) ccsResetToDefault (setting, TRUE); if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (backend, context); + writeInit (context); writeIntegratedOption (context, setting, index); } } diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 29e4ebc40..2c5004d8b 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -133,8 +133,8 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS { int index; - readInit (backend, context); - if (!readOption (backend, setting)) + readInit (context); + if (!readOption (setting)) { ccsResetToDefault (setting, TRUE); } @@ -142,8 +142,8 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (backend, context); - writeIntegratedOption (backend, context, setting, index); + writeInit (context); + writeIntegratedOption (context, setting, index); } } diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 6dfa3bc9c..8badf3dd6 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -601,10 +601,10 @@ writeDone (CCSContext * context) static void updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { - if (readInit (backend, context)) + if (readInit (context)) { - readSetting (backend, context, setting); - readDone (backend, context); + readSetting (context, setting); + readDone (context); } } diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 34d9e8f99..6711d6b9e 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1274,14 +1274,9 @@ Bool ccsBackendHasWriteDone (CCSBackend *backend) return (GET_INTERFACE (CCSBackendInterface, backend))->writeDone != NULL; } -static Bool ccsBackendHasUpdateSetting (CCSBackend *backend) -{ - return (GET_INTERFACE (CCSBackendInterface, backend))->updateSetting != NULL; -} - void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (context); } void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) -- GitLab From f123011e59b288ade8f57d5ad0267ab21cc1f0f9 Mon Sep 17 00:00:00 2001 From: smspillaz Date: Tue, 24 Jul 2012 06:30:46 -0700 Subject: [PATCH 135/562] Initial backend interface code for updateSetting method (doesn't yet compile) --- compizconfig/gconf/src/gconf.c | 31 +++++++++++------ compizconfig/gsettings/src/gsettings.c | 34 ++++++++++++------- .../libcompizconfig/backend/src/ini.c | 11 ++++++ .../libcompizconfig/include/ccs-backend.h | 5 +++ compizconfig/libcompizconfig/src/main.c | 12 ++++++- 5 files changed, 68 insertions(+), 25 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 3861eaa6e..9dcccc694 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -435,6 +435,22 @@ isIntegratedOption (CCSSetting *setting, return FALSE; } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + int index; + readInit (backend, context); + if (!readOption (setting)) + ccsResetToDefault (setting, TRUE); + + if (ccsGetIntegrationEnabled (context) && + isIntegratedOption (setting, &index)) + { + writeInit (backend, context); + writeIntegratedOption (context, setting, index); + } +} + static void valueChanged (GConfClient *client, guint cnxn_id, @@ -445,7 +461,6 @@ valueChanged (GConfClient *client, char *keyName = (char*) gconf_entry_get_key (entry); char *pluginName; char *token; - int index; unsigned int screenNum; CCSPlugin *plugin; CCSSetting *setting; @@ -490,16 +505,9 @@ valueChanged (GConfClient *client, if (!setting) return; - readInit (context); - if (!readOption (setting)) - ccsResetToDefault (setting, TRUE); - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - writeInit (context); - writeIntegratedOption (context, setting, index); - } + /* Passing null here is not optimal, but we are not + * maintaining gconf actively here */ + updateSetting (NULL, context, plugin, setting); } static void @@ -2163,6 +2171,7 @@ static CCSBackendInterface gconfVTable = { writeInit, writeSetting, 0, + updateSetting, getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 1c6da0c82..c810794e8 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -128,6 +128,25 @@ isIntegratedOption (CCSSetting *setting, #endif } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + int index; + + readInit (backend, context); + if (!readOption (backend, setting)) + { + ccsResetToDefault (setting, TRUE); + } + + if (ccsGetIntegrationEnabled (context) && + isIntegratedOption (setting, &index)) + { + writeInit (backend, context); + writeIntegratedOption (backend, context, setting, index); + } +} + static void valueChanged (GSettings *settings, gchar *keyName, @@ -137,7 +156,6 @@ valueChanged (GSettings *settings, char *uncleanKeyName; char *path, *pathOrig; char *pluginName; - int index; unsigned int screenNum; CCSPlugin *plugin; CCSSetting *setting; @@ -199,18 +217,7 @@ valueChanged (GSettings *settings, } } - readInit (context); - if (!readOption (setting)) - { - ccsResetToDefault (setting, TRUE); - } - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - writeInit (context); - writeIntegratedOption (context, setting, index); - } + updateSetting (backend, context, plugin, setting); g_free (pluginName); free (uncleanKeyName); @@ -1163,6 +1170,7 @@ static CCSBackendInterface gsettingsVTable = { writeInit, writeSetting, 0, + updateSetting, getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 7625eb698..6dfa3bc9c 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -598,6 +598,16 @@ writeDone (CCSContext * context) free (fileName); } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + if (readInit (backend, context)) + { + readSetting (backend, context, setting); + readDone (backend, context); + } +} + static Bool getSettingIsReadOnly (CCSSetting * setting) { @@ -755,6 +765,7 @@ static CCSBackendInterface iniVTable = { writeInit, writeSetting, writeDone, + updateSetting, NULL, getSettingIsReadOnly, getExistingProfiles, diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 1165620c2..b77ad6305 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -30,6 +30,7 @@ typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendInterface CCSBackendInterface; typedef struct _CCSContext CCSContext; +typedef struct _CCSPlugin CCSPlugin; typedef struct _CCSSetting CCSSetting; struct _CCSBackend @@ -54,6 +55,8 @@ typedef void (*CCSBackendWriteSettingFunc) (CCSContext * context, CCSSetting * setting); typedef void (*CCSBackendWriteDoneFunc) (CCSContext * context); +typedef void (*CCSBackendUpdateFunc) (CCSBackend *, CCSContext *, CCSPlugin *, CCSSetting *); + typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSSetting * setting); typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSSetting * setting); @@ -90,6 +93,7 @@ struct _CCSBackendInterface CCSBackendWriteSettingFunc writeSetting; CCSBackendWriteDoneFunc writeDone; + CCSBackendUpdateFunc updateSetting; CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated; CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly; @@ -122,6 +126,7 @@ Bool ccsBackendHasWriteSetting (CCSBackend *backend); void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); Bool ccsBackendHasWriteDone (CCSBackend *backend); void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); +void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting); Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend); Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 1676b04f9..34d9e8f99 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1274,9 +1274,19 @@ Bool ccsBackendHasWriteDone (CCSBackend *backend) return (GET_INTERFACE (CCSBackendInterface, backend))->writeDone != NULL; } +static Bool ccsBackendHasUpdateSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->updateSetting != NULL; +} + void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); +} + +void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->updateSetting) (backend, context, plugin, setting); } Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) -- GitLab From 908478cc46fe6864061a2953dffca867d8200056 Mon Sep 17 00:00:00 2001 From: smspillaz Date: Tue, 24 Jul 2012 06:34:29 -0700 Subject: [PATCH 136/562] Added updateSetting wrapper to CCSBackendWithCapabilities --- compizconfig/libcompizconfig/src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index df4cb94d7..e22676dca 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1566,6 +1566,14 @@ static void ccsBackendCapabilitiesWriteDoneWrapper (CCSBackend *backend, CCSCont ccsBackendWriteDone (bcPrivate->backend, context); } +static void ccsBackendCapabilitiesUpdateSettingWrapper (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + CAPABILITIES_PRIV (backend); + + if (ccsBackendHasUpdateSetting (bcPrivate->backend)) + ccsBackendUpdateSetting (bcPrivate->backend, context, plugin, setting); +} + static Bool ccsBackendCapabilitiesGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) { CAPABILITIES_PRIV (backend); @@ -5530,6 +5538,7 @@ const CCSBackendInterface ccsBackendCapabilitiesInterfaceWrapper = ccsBackendCapabilitiesWriteInitWrapper, ccsBackendCapabilitiesWriteSettingWrapper, ccsBackendCapabilitiesWriteDoneWrapper, + ccsBackendCapabilitiesUpdateSettingWrapper, ccsBackendCapabilitiesGetSettingIsIntegratedWrapper, ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper, ccsBackendCapabilitiesGetExistingProfilesWrapper, -- GitLab From 1aed71972f5fae9fbf87619a4036a571579b5ce2 Mon Sep 17 00:00:00 2001 From: smspillaz Date: Tue, 24 Jul 2012 06:35:19 -0700 Subject: [PATCH 137/562] Added updateSetting mock methods --- .../libcompizconfig/compizconfig_ccs_backend_mock.cpp | 1 + .../mocks/libcompizconfig/compizconfig_ccs_backend_mock.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp index a87c120c9..58e70e50e 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp @@ -21,6 +21,7 @@ CCSBackendInterface CCSBackendGMockInterface = CCSBackendGMock::ccsBackendWriteInit, CCSBackendGMock::ccsBackendWriteSetting, CCSBackendGMock::ccsBackendWriteDone, + CCSBackendGMock::ccsBackendUpdateSetting, CCSBackendGMock::ccsBackendGetSettingIsIntegrated, CCSBackendGMock::ccsBackendGetSettingIsReadOnly, CCSBackendGMock::ccsBackendGetExistingProfiles, diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index 9f5be6622..86d8ce178 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -26,6 +26,7 @@ class CCSBackendGMockInterface virtual Bool writeInit (CCSContext *conxtext) = 0; virtual void writeSetting (CCSContext *context, CCSSetting *setting) = 0; virtual void writeDone (CCSContext *context) = 0; + virtual void updateSetting (CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) = 0; virtual Bool getSettingIsIntegrated (CCSSetting *setting) = 0; virtual Bool getSettingIsReadOnly (CCSSetting *setting) = 0; virtual CCSStringList getExistingProfiles (CCSContext *context) = 0; @@ -52,6 +53,7 @@ class CCSBackendGMock : MOCK_METHOD1 (writeInit, Bool (CCSContext *)); MOCK_METHOD2 (writeSetting, void (CCSContext *, CCSSetting *)); MOCK_METHOD1 (writeDone, void (CCSContext *)); + MOCK_METHOD3 (updateSetting, void (CCSContext *, CCSPlugin *, CCSSetting *)); MOCK_METHOD1 (getSettingIsIntegrated, Bool (CCSSetting *)); MOCK_METHOD1 (getSettingIsReadOnly, Bool (CCSSetting *)); MOCK_METHOD1 (getExistingProfiles, CCSStringList (CCSContext *)); @@ -130,6 +132,11 @@ class CCSBackendGMock : ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeDone (context); } + static void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->updateSetting (context, plugin, setting); + } + static Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) { return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getSettingIsIntegrated (setting); -- GitLab From d853cc85e0d31f076f785e2843dfd66c1548a2fe Mon Sep 17 00:00:00 2001 From: smspillaz Date: Tue, 24 Jul 2012 06:37:32 -0700 Subject: [PATCH 138/562] It should be safe to pass NULL in updateSetting right now --- compizconfig/gsettings/src/gsettings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index c810794e8..29e4ebc40 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -217,7 +217,7 @@ valueChanged (GSettings *settings, } } - updateSetting (backend, context, plugin, setting); + updateSetting (NULL, context, plugin, setting); g_free (pluginName); free (uncleanKeyName); -- GitLab From 34a8da43e5edb6aef112f7986e08fa41b0b6ee60 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 24 Jul 2012 20:51:50 +0800 Subject: [PATCH 139/562] Resolve more conflicts - now we need to pass CCSBackend * to the vtable funcs --- compizconfig/gconf/src/gconf.c | 4 ++-- compizconfig/gsettings/src/gsettings.c | 4 ++-- compizconfig/libcompizconfig/backend/src/ini.c | 6 +++--- .../libcompizconfig/include/ccs-backend.h | 16 +++++++--------- compizconfig/libcompizconfig/src/main.c | 11 ++++++++--- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 188d3f28d..75d969726 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -439,14 +439,14 @@ static void updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { int index; - readInit (context); + readInit (backend, context); if (!readOption (setting)) ccsResetToDefault (setting, TRUE); if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (context); + writeInit (backend, context); writeIntegratedOption (context, setting, index); } } diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 03308d4c0..ff9960eb8 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -133,7 +133,7 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS { int index; - readInit (context); + readInit (backend, context); if (!readOption (setting)) { ccsResetToDefault (setting, TRUE); @@ -142,7 +142,7 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (context); + writeInit (backend, context); writeIntegratedOption (context, setting, index); } } diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index f9e2241f6..283201fe5 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -605,10 +605,10 @@ writeDone (CCSBackend *backend, CCSContext * context) static void updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { - if (readInit (context)) + if (readInit (backend, context)) { - readSetting (context, setting); - readDone (context); + readSetting (backend, context, setting); + readDone (backend, context); } } diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 3d9a80432..2394f5689 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -52,16 +52,16 @@ typedef void (*CCSBackendReadDoneFunc) (CCSBackend *backend, CCSContext * contex typedef Bool (*CCSBackendWriteInitFunc) (CCSBackend *backend, CCSContext * context); typedef void (*CCSBackendWriteSettingFunc) -(CCSContext * context, CCSSetting * setting); -typedef void (*CCSBackendWriteDoneFunc) (CCSContext * context); +(CCSBackend *backend, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendWriteDoneFunc) (CCSBackend *backend, CCSContext * context); typedef void (*CCSBackendUpdateFunc) (CCSBackend *, CCSContext *, CCSPlugin *, CCSSetting *); -typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSSetting * setting); -typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSBackend *, CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSBackend *, CCSSetting * setting); -typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSContext * context); -typedef Bool (*CCSBackendDeleteProfileFunc) (CCSContext * context, char * name); +typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendDeleteProfileFunc) (CCSBackend *, CCSContext * context, char * name); typedef char * (*CCSBackendGetNameFunc) (CCSBackend *); typedef char * (*CCSBackendGetShortDescFunc) (CCSBackend *); @@ -119,11 +119,9 @@ void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context); void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); -<<<<<<< TREE -======= +Bool ccsBackendHasUpdateSetting (CCSBackend *backend); void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting); Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend); ->>>>>>> MERGE-SOURCE Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting); CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 10705c571..dd9b9232f 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1380,15 +1380,20 @@ static Bool ccsBackendHasWriteDone (CCSBackend *backend) void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); } - + +Bool ccsBackendHasUpdateSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->updateSetting != NULL; +} + void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { return (*(GET_INTERFACE (CCSBackendInterface, backend))->updateSetting) (backend, context, plugin, setting); } -static Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) +Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated != NULL; } -- GitLab From 9c6d1a00fa15989ce29f3522e73d3ba23dc40564 Mon Sep 17 00:00:00 2001 From: smspillaz Date: Tue, 24 Jul 2012 06:04:53 -0700 Subject: [PATCH 140/562] Merge lp:cmpiz --- gtk/window-decorator/wnck.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gtk/window-decorator/wnck.c b/gtk/window-decorator/wnck.c index dfa4cff95..ad4b50e26 100644 --- a/gtk/window-decorator/wnck.c +++ b/gtk/window-decorator/wnck.c @@ -50,10 +50,13 @@ get_frame_type (WnckWindow *win) if (xid == None) return "bare"; + gdk_error_trap_push (); result = XGetWindowProperty (gdk_x11_get_default_xdisplay (), xid, net_wm_state_atom, 0L, 1024L, FALSE, XA_ATOM, &actual, &format, &n, &left, &data); + gdk_flush (); + gdk_error_trap_pop (); if (result == Success && data) { -- GitLab From b154075e9985115dca7b1a674c56f35a51562d39 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 24 Jul 2012 21:13:52 +0800 Subject: [PATCH 141/562] Added a quick TODO about the usage of sys.path --- compizconfig/compizconfig-python/tests/compiz_config_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/compizconfig/compizconfig-python/tests/compiz_config_test.py b/compizconfig/compizconfig-python/tests/compiz_config_test.py index c9468cb67..c071056e9 100644 --- a/compizconfig/compizconfig-python/tests/compiz_config_test.py +++ b/compizconfig/compizconfig-python/tests/compiz_config_test.py @@ -10,6 +10,7 @@ os.environ["XDG_CONFIG_HOME"] = "compizconfig/libcompizconfig/config" os.environ["LIBCOMPIZCONFIG_BACKEND_PATH"] = "compizconfig/libcompizconfig/backend/" os.environ["XDG_DATA_DIRS"] = "generated/" +# TODO: does this really work ? sys.path.append ("compizconfig/compizconfig-python/build/lib.linux-" + arch + "-" + str (sys.version_info[0]) + "." + str (sys.version_info[1]) + "/") import unittest -- GitLab From d1dc03a7f82e2fb4e4933f59d59459dada3b2f6e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 24 Jul 2012 21:17:38 +0800 Subject: [PATCH 142/562] Just override sys.path[0] for now, need to prepend --- compizconfig/compizconfig-python/tests/compiz_config_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/compizconfig-python/tests/compiz_config_test.py b/compizconfig/compizconfig-python/tests/compiz_config_test.py index c071056e9..e3fd70689 100644 --- a/compizconfig/compizconfig-python/tests/compiz_config_test.py +++ b/compizconfig/compizconfig-python/tests/compiz_config_test.py @@ -11,7 +11,7 @@ os.environ["LIBCOMPIZCONFIG_BACKEND_PATH"] = "compizconfig/libcompizconfig/backe os.environ["XDG_DATA_DIRS"] = "generated/" # TODO: does this really work ? -sys.path.append ("compizconfig/compizconfig-python/build/lib.linux-" + arch + "-" + str (sys.version_info[0]) + "." + str (sys.version_info[1]) + "/") +sys.path[0] = "compizconfig/compizconfig-python/build/lib.linux-" + arch + "-" + str (sys.version_info[0]) + "." + str (sys.version_info[1]) + "/" import unittest import compizconfig -- GitLab From d5dbfd911789f3220eee6a2bdb9b866aa4f65519 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:03:35 +0800 Subject: [PATCH 143/562] Remove global definitions of ccsBackendHas* --- compizconfig/libcompizconfig/include/ccs-backend.h | 2 -- compizconfig/libcompizconfig/src/main.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 2394f5689..c748a6bc2 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -119,9 +119,7 @@ void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context); void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); -Bool ccsBackendHasUpdateSetting (CCSBackend *backend); void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting); -Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend); Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting); CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index dd9b9232f..fadd05144 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1383,7 +1383,7 @@ void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); } -Bool ccsBackendHasUpdateSetting (CCSBackend *backend) +static Bool ccsBackendHasUpdateSetting (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->updateSetting != NULL; } @@ -1393,7 +1393,7 @@ void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugi return (*(GET_INTERFACE (CCSBackendInterface, backend))->updateSetting) (backend, context, plugin, setting); } -Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) +static Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated != NULL; } -- GitLab From f74d9eaa2456392a66e0af71adc5dddb4bd69c2a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:13:14 +0800 Subject: [PATCH 144/562] Provide method to open backend with interface and create backend objects with a particular interface from dlopen () --- compizconfig/libcompizconfig/src/main.c | 87 +++++++++++++++---------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 6711d6b9e..3db8c6b51 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1085,73 +1085,92 @@ ccsFreeBackend (CCSBackend *backend) free (backend); } -Bool -ccsSetBackendDefault (CCSContext * context, char *name) +CCSBackend * +ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand) { - Bool fallbackMode = FALSE; + CCSBackend *backend = calloc (1, sizeof (CCSBackend)); CCSBackendPrivate *bPrivate = NULL; - CONTEXT_PRIV (context); - if (cPrivate->backend) - { - /* no action needed if the backend is the same */ + if (!backend) + return NULL; - if (strcmp (ccsBackendGetName (cPrivate->backend), name) == 0) - return TRUE; + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + ccsBackendRef (backend); - ccsBackendUnref (cPrivate->backend); - cPrivate->backend = NULL; + bPrivate = calloc (1, sizeof (CCSBackendPrivate)); + + if (!bPrivate) + { + ccsBackendUnref (backend); + return NULL; } + bPrivate->dlhand = dlhand; + bPrivate->context = context; + + ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); + ccsObjectAddInterface (backend, (CCSInterface *) interface, GET_INTERFACE_TYPE (CCSBackendInterface)); + + return backend; +} + +void * +ccsOpenBackend (char *name, CCSBackendInterface **vt, Bool *fellback) +{ void *dlhand = openBackend (name); if (!dlhand) { - fallbackMode = TRUE; + *fellback = TRUE; name = "ini"; dlhand = openBackend (name); } if (!dlhand) - return FALSE; + return NULL; BackendGetInfoProc getInfo = dlsym (dlhand, "getBackendInfo"); if (!getInfo) { dlclose (dlhand); - return FALSE; + return NULL; } - CCSBackendInterface *vt = getInfo (); - if (!vt) + *vt = getInfo (); + if (!*vt) { dlclose (dlhand); - return FALSE; + *vt = NULL; + return NULL; } - CCSBackend *backend = calloc (1, sizeof (CCSBackend)); + return dlhand; +} - if (!backend) - { - dlclose (dlhand); - return FALSE; - } +Bool +ccsSetBackendDefault (CCSContext * context, char *name) +{ + Bool fallbackMode = FALSE; + CONTEXT_PRIV (context); - ccsObjectInit (backend, &ccsDefaultObjectAllocator); - ccsBackendRef (backend); + if (cPrivate->backend) + { + /* no action needed if the backend is the same */ - bPrivate = calloc (1, sizeof (CCSBackendPrivate)); + if (strcmp (ccsBackendGetName ((CCSBackend *) cPrivate->backend), name) == 0) + return TRUE; - if (!bPrivate) - { - ccsBackendUnref (backend); - dlclose (dlhand); + ccsBackendUnref (cPrivate->backend); + cPrivate->backend = NULL; } - bPrivate->dlhand = dlhand; - bPrivate->context = context; + CCSBackendInterface *vt = NULL; - ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); - ccsObjectAddInterface (backend, (CCSInterface *) vt, GET_INTERFACE_TYPE (CCSBackendInterface)); + void *dlhand = ccsOpenBackend (name, &vt, &fallbackMode); + + if (!dlhand) + return FALSE; + + CCSBackend *backend = ccsBackendNewWithInterface (context, vt, dlhand); cPrivate->backend = backend; -- GitLab From 935aee8cbbb13c54975941a28b6a064ed252b7d6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:18:44 +0800 Subject: [PATCH 145/562] Make the definition of ccsOpenBackend globally available properly and also make the name field const --- compizconfig/libcompizconfig/include/ccs-backend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index c748a6bc2..2ec238551 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -159,7 +159,7 @@ void ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *); /* Backend opener method */ void * -ccsBackendOpen (char *name, CCSBackendInterface **interface, Bool *fellback); +ccsOpenBackend (const char *name, CCSBackendInterface **interface, Bool *fellback); /* Constructor method */ CCSBackend * -- GitLab From 9eaa58ba0c80ef2ba87d1044adac0b43446e34dc Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:19:59 +0800 Subject: [PATCH 146/562] Make the constructor methods for the backends available and constify *name --- compizconfig/libcompizconfig/include/ccs-backend.h | 9 +++++++++ compizconfig/libcompizconfig/src/main.c | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index b77ad6305..de302b431 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -137,6 +137,15 @@ Bool ccsBackendHasDeleteProfile (CCSBackend *backend); Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name); void ccsFreeBackend (CCSBackend *backend); +/* Backend opener method */ +void * +ccsOpenBackend (const char *name, CCSBackendInterface **interface, Bool *fellback); + +/* Constructor method */ +CCSBackend * +ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); + + CCSBackendInterface* getBackendInfo (void); #endif diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 3db8c6b51..d695f45f3 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1012,7 +1012,7 @@ CCSREF_OBJ (Setting, CCSSetting) CCSREF_OBJ (Backend, CCSBackend) static void * -openBackend (char *backend) +openBackend (const char *backend) { char *home = getenv ("HOME"); char *override_backend = getenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); @@ -1115,7 +1115,7 @@ ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *inte } void * -ccsOpenBackend (char *name, CCSBackendInterface **vt, Bool *fellback) +ccsOpenBackend (const char *name, CCSBackendInterface **vt, Bool *fellback) { void *dlhand = openBackend (name); if (!dlhand) -- GitLab From dac64abb1e231dfea83dcac3f03e273b9c09a0f9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:28:23 +0800 Subject: [PATCH 147/562] Moves a bunch of bugfixes and tidy-ups from test_gsettings_conformance to split_gsettings_rw_funcs 1) gsettings_backend_shared is now a SHARED library for now in order to avoid duplicated symbol issues when dynamically loading the backend and then running it in a test fixture with the same staticaly linked library 2) refactored out findSettingAndPluginToUpdateFromPath, as we need to be able to test it independently 3) refactored out updateSettingWithGSettingsKeyName as a wrapper around findSetitngAndPluingToUpdateFromPath 4) made the key member of getVariantAtKey const 5) fixes a pretty nasty leak in readListValue - we need to provide the parent CCSSetting object rather than the CCSSettingType as ccsGetValueListFrom*Array needs it in order to set the parent member on the variables - if that isn't done it doesn't have any way of quering the actual setting info and freeing any auxilary data we might have allocated, and (stupidly) bails out by not freeing anyting at all. 6) Made a wrapper writeVariantToKey which wraps g_settings_set_value 7) Introduced private CCSGSettingsBackendInterface with the following methods * - getContext -> get the currently used context by the backend * - connectToChangedSignal -> connect to the valueChanged signal for a particular GObject * - getSettingsObjectForPluginWithPath -> retreives the GSettings object that we created for a particular plugin at a path for context * - registerGConfClient -> opens a global GConfClient * - unregisterGConfClient -> closes GConfClient Note that most of these methods are needed to remove particular side effects that are undesirable during testing, as they, for example might need a running dbus server or worse, X Server. Also we don't want GLib callbacks indeterminately messing up our expectations. 8) Provide a CCSBackend * to readGConfIntegratedOption and writeGConfIntegratedOption so that we can dynamically register the client there 9) Fix a nasty case where we would attempt to read a float value right after reading a string value because of a missing break statement 10) Fixes read list variants not actually being unreff'd 11) Fixes a number of other read keys not related to settings also not being unreff'd 12) Use g_list_free_full to free the settingsList --- .../gsettings_backend_shared/CMakeLists.txt | 14 +- .../gsettings_backend_shared/gsettings_util.c | 174 ++++++++++++-- .../gsettings_backend_shared/gsettings_util.h | 78 ++++++- .../gsettings/src/gconf-integration.c | 14 +- compizconfig/gsettings/src/gsettings.c | 221 ++++++++---------- compizconfig/gsettings/src/gsettings.h | 10 +- .../gsettings/tests/test_gsettings_tests.cpp | 2 +- 7 files changed, 367 insertions(+), 146 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt index 51a26d3f9..2b402f7f2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt +++ b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt @@ -15,12 +15,24 @@ if (GSETTINGS_UTIL_FOUND) link_directories (${GSETTINGS_UTIL_LIBRARY_DIRS} ${compiz_BINARY_DIR}/compizconfig/libcompizconfig) - add_library (gsettings_backend_shared STATIC + add_library (gsettings_backend_shared SHARED ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_constants.c ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_util.c) + target_link_libraries (gsettings_backend_shared ${GSETTINGS_UTIL_LIBRARIES} compizconfig) + install (TARGETS gsettings_backend_shared + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + + # + # Tell CMake that targets using gsettings_backend_shared should NOT re-import the + # libraries that gsettings_backend_shared depends on (contains). + # + set_target_properties (gsettings_backend_shared PROPERTIES + LINK_INTERFACE_LIBRARIES "" + ) + endif (GSETTINGS_UTIL_FOUND) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index b271b53ae..7a7fb01d2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -4,6 +4,8 @@ #include #include "gsettings_shared.h" +INTERFACE_TYPE (CCSGSettingsBackendInterface); + GList * variantTypeToPossibleSettingType (const gchar *vt) { @@ -328,6 +330,101 @@ attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *l return found; } +Bool +findSettingAndPluginToUpdateFromPath (GSettings *settings, + const char *path, + const gchar *keyName, + CCSContext *context, + CCSPlugin **plugin, + CCSSetting **setting, + char **uncleanKeyName) +{ + char *pluginName; + unsigned int screenNum; + + if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) + return FALSE; + + *plugin = ccsFindPlugin (context, pluginName); + + if (*plugin) + { + *uncleanKeyName = translateKeyForCCS (keyName); + + *setting = ccsFindSetting (*plugin, *uncleanKeyName); + if (!setting) + { + /* Couldn't find setting straight off the bat, + * try and find the best match */ + GVariant *value = g_settings_get_value (settings, keyName); + + if (value) + { + GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); + GList *iter = possibleSettingTypes; + + while (iter) + { + *setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (*plugin), + keyName, + (CCSSettingType) GPOINTER_TO_INT (iter->data)); + + if (*setting) + break; + + iter = iter->next; + } + + g_list_free (possibleSettingTypes); + g_variant_unref (value); + } + } + } + + g_free (pluginName); + + if (!*plugin || !*setting) + return FALSE; + + return TRUE; +} + +Bool +updateSettingWithGSettingsKeyName (CCSBackend *backend, + GSettings *settings, + gchar *keyName, + CCSBackendUpdateFunc updateSetting) +{ + CCSContext *context = ccsGSettingsBackendGetContext (backend); + char *uncleanKeyName = NULL; + char *pathOrig; + CCSPlugin *plugin; + CCSSetting *setting; + Bool ret = TRUE; + + g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); + + if (findSettingAndPluginToUpdateFromPath (settings, pathOrig, keyName, context, &plugin, &setting, &uncleanKeyName)) + (*updateSetting) (backend, context, plugin, setting); + else + { + /* We hit a situation where either the key stored in GSettings couldn't be + * matched at all to a key in the xml file, or where there were multiple matches. + * Unfortunately, there isn't much we can do about this, other than try + * and warn the user and bail out. It just means that if the key was updated + * externally we won't know about the change until the next reload of settings */ + ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, pathOrig); + ret = FALSE; + } + + g_free (pathOrig); + + if (uncleanKeyName) + free (uncleanKeyName); + + return ret; +} + gchar * makeCompizProfilePath (const gchar *profilename) { @@ -373,7 +470,7 @@ checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gc } GVariant * -getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettingType type) +getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCSSettingType type) { GVariant *gsettingsValue = g_settings_get_value (settings, key); @@ -387,10 +484,11 @@ getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettin } CCSSettingValueList -readListValue (GVariant *gsettingsValue, CCSSettingType listType) +readListValue (GVariant *gsettingsValue, CCSSetting *setting) { + CCSSettingType listType = ccsSettingGetInfo (setting)->forList.listType; gboolean hasVariantType; - unsigned int nItems, i = 0; + unsigned int nItems; CCSSettingValueList list = NULL; GVariantIter iter; @@ -415,9 +513,9 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) /* Reads each item from the variant into arrayCounter */ while (g_variant_iter_loop (&iter, "b", &value)) - *arrayCounter++ = value; + *arrayCounter++ = value ? TRUE : FALSE; - list = ccsGetValueListFromBoolArray (array, nItems, NULL); + list = ccsGetValueListFromBoolArray (array, nItems, setting); free (array); } break; @@ -434,14 +532,14 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_loop (&iter, "i", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromIntArray (array, nItems, NULL); + list = ccsGetValueListFromIntArray (array, nItems, setting); free (array); } break; case TypeFloat: { - double *array = malloc (nItems * sizeof (double)); - double *arrayCounter = array; + float *array = malloc (nItems * sizeof (float)); + float *arrayCounter = array; gdouble value; if (!array) @@ -451,7 +549,7 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_loop (&iter, "d", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromFloatArray ((float *) array, nItems, NULL); + list = ccsGetValueListFromFloatArray (array, nItems, setting); free (array); } break; @@ -471,25 +569,27 @@ readListValue (GVariant *gsettingsValue, CCSSettingType listType) while (g_variant_iter_next (&iter, "s", &value)) *arrayCounter++ = value; - list = ccsGetValueListFromStringArray (array, nItems, NULL); + list = ccsGetValueListFromStringArray (array, nItems, setting); g_strfreev ((char **) array); } break; case TypeColor: { - CCSSettingColorValue *array; char *colorValue; - array = malloc (nItems * sizeof (CCSSettingColorValue)); + CCSSettingColorValue *array = calloc (1, nItems * sizeof (CCSSettingColorValue)); + unsigned int i = 0; + if (!array) break; while (g_variant_iter_loop (&iter, "s", &colorValue)) { - memset (&array[i], 0, sizeof (CCSSettingColorValue)); ccsStringToColor (colorValue, &array[i]); + i++; } - list = ccsGetValueListFromColorArray (array, nItems, NULL); + + list = ccsGetValueListFromColorArray (array, nItems, setting); free (array); } break; @@ -650,6 +750,7 @@ writeListValue (CCSSettingValueList list, { item = ccsColorToString (&list->data->value.asColor); g_variant_builder_add (builder, "s", item); + g_free (item); list = list->next; } value = g_variant_new ("as", builder); @@ -667,7 +768,7 @@ writeListValue (CCSSettingValueList list, return TRUE; } -Bool writeStringToVariant (char *value, GVariant **variant) +Bool writeStringToVariant (const char *value, GVariant **variant) { *variant = g_variant_new_string (value); return TRUE; @@ -744,3 +845,46 @@ Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) free (edgeString); return TRUE; } + +void +writeVariantToKey (GSettings *settings, + const char *key, + GVariant *value) +{ + g_settings_set_value (settings, key, value); +} + +CCSContext * +ccsGSettingsBackendGetContext (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetContext) (backend); +} + + +void +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, + GObject *object) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendConnectToChangedSignal) (backend, object); +} + +GSettings * +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetSettingsObjectForPluginWithPath) (backend, plugin, path, context); +} + +void +ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendRegisterGConfClient) (backend); +} + +void +ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnregisterGConfClient) (backend); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index e8a22366b..70bd6c3c9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -1,10 +1,42 @@ #ifndef _COMPIZ_GSETTINGS_UTIL_H #define _COMPIZ_GSETTINGS_UTIL_H +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + #include #include #include -#include + +typedef struct _CCSGSettingsBackendPrivate CCSGettingsBackendPrivate; +typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; + +typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); +typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, GObject *); +typedef GSettings * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context); +typedef void (*CCSGSettingsBackendRegisterGConfClient) (CCSBackend *backend); +typedef void (*CCSGSettingsBackendUnregisterGConfClient) (CCSBackend *backend); + +struct _CCSGSettingsBackendInterface +{ + CCSGSettingsBackendGetContext gsettingsBackendGetContext; + CCSGSettingsBackendConnectToChangedSignal gsettingsBackendConnectToChangedSignal; + CCSGSettingsBackendGetSettingsObjectForPluginWithPath gsettingsBackendGetSettingsObjectForPluginWithPath; + CCSGSettingsBackendRegisterGConfClient gsettingsBackendRegisterGConfClient; + CCSGSettingsBackendUnregisterGConfClient gsettingsBackendUnregisterGConfClient; +}; + +struct _CCSGSettingsBackendPrivate +{ + CCSContext *context; +}; + +unsigned int ccsCCSGSettingsBackendInterfaceGetType (); gchar * getSchemaNameForPlugin (const char *plugin); @@ -57,6 +89,20 @@ filterAllSettingsMatchingPartOfStringIgnoringDashesUnderscoresAndCase (const gch CCSSetting * attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *lossyName, CCSSettingType type); +Bool +findSettingAndPluginToUpdateFromPath (GSettings *settings, + const char *path, + const gchar *keyName, + CCSContext *context, + CCSPlugin **plugin, + CCSSetting **setting, + char **uncleanKeyName); + +Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, + GSettings *settings, + gchar *keyName, + CCSBackendUpdateFunc updateSetting); + GList * variantTypeToPossibleSettingType (const gchar *vt); @@ -73,7 +119,7 @@ Bool checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName); GVariant * -getVariantAtKey (GSettings *settings, char *key, const char *pathName, CCSSettingType type); +getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCSSettingType type); const char * readStringFromVariant (GVariant *gsettingsValue); @@ -92,14 +138,14 @@ CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *suc unsigned int readEdgeFromVariant (GVariant *gsettingsValue); CCSSettingValueList -readListValue (GVariant *gsettingsValue, CCSSettingType listType); +readListValue (GVariant *gsettingsValue, CCSSetting *setting); Bool writeListValue (CCSSettingValueList list, CCSSettingType listType, GVariant **gsettingsValue); -Bool writeStringToVariant (char *value, GVariant **variant); +Bool writeStringToVariant (const char *value, GVariant **variant); Bool writeFloatToVariant (float value, GVariant **variant); @@ -115,4 +161,28 @@ Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant); Bool writeEdgeToVariant (unsigned int edges, GVariant **variant); +void writeVariantToKey (GSettings *settings, + const char *key, + GVariant *value); + +CCSContext * +ccsGSettingsBackendGetContext (CCSBackend *backend); + +void +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, GObject *object); + +GSettings * +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context); + +void +ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend); + +void +ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend); + +COMPIZCONFIG_END_DECLS + #endif diff --git a/compizconfig/gsettings/src/gconf-integration.c b/compizconfig/gsettings/src/gconf-integration.c index ebc74cd97..43a03ba0e 100644 --- a/compizconfig/gsettings/src/gconf-integration.c +++ b/compizconfig/gsettings/src/gconf-integration.c @@ -537,7 +537,8 @@ getButtonBindingForSetting (CCSContext *context, } Bool -readGConfIntegratedOption (CCSContext *context, +readGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { @@ -545,7 +546,10 @@ readGConfIntegratedOption (CCSContext *context, GError *err = NULL; Bool ret = FALSE; - ret = readOption (setting); + if (!client) + ccsGSettingsBackendRegisterGConfClient (backend); + + ret = readOption (backend, setting); gconfValue = gconf_client_get (client, specialOptions[index].gnomeName, @@ -765,13 +769,17 @@ setButtonBindingForSetting (CCSContext *context, } void -writeGConfIntegratedOption (CCSContext *context, +writeGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { GError *err = NULL; const char *optionName = specialOptions[index].gnomeName; + if (!client) + ccsGSettingsBackendRegisterGConfClient (backend); + switch (specialOptions[index].type) { case OptionInt: diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 6526aa52c..b94eb5e38 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -46,15 +46,20 @@ static GSettings *currentProfileSettings = NULL; char *currentProfile = NULL; +/* This will need to be rempved */ +CCSContext *storedContext = NULL; + /* some forward declarations */ -static void writeIntegratedOption (CCSContext *context, +static void writeIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index); static GSettings * -getSettingsObjectForPluginWithPath (const char *plugin, - const char *path, - CCSContext *context) +ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) { GSettings *settingsObj = NULL; gchar *schemaName = getSchemaNameForPlugin (plugin); @@ -74,7 +79,7 @@ getSettingsObjectForPluginWithPath (const char *plugin, settingsObj = g_settings_new_with_path (schemaName, path); - g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) context); + ccsGSettingsBackendConnectToChangedSignal (backend, G_OBJECT (settingsObj)); settingsList = g_list_append (settingsList, (void *) settingsObj); @@ -90,6 +95,7 @@ getSettingsObjectForPluginWithPath (const char *plugin, g_settings_set_strv (currentProfileSettings, "plugins-with-set-keys", (const gchar * const *)newWrittenPlugins); + g_variant_unref (writtenPlugins); g_free (schemaName); g_strfreev (newWrittenPlugins); @@ -104,14 +110,15 @@ makeSettingPath (CCSSetting *setting) } static GSettings * -getSettingsObjectForCCSSetting (CCSSetting *setting) +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) { GSettings *ret = NULL; gchar *pathName = makeSettingPath (setting); - ret = getSettingsObjectForPluginWithPath (ccsPluginGetName (ccsSettingGetParent (setting)), - pathName, - ccsPluginGetContext (ccsSettingGetParent (setting))); + ret = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, + ccsPluginGetName (ccsSettingGetParent (setting)), + pathName, + ccsPluginGetContext (ccsSettingGetParent (setting))); g_free (pathName); return ret; @@ -134,7 +141,7 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS int index; readInit (backend, context); - if (!readOption (setting)) + if (!readOption (backend, setting)) { ccsResetToDefault (setting, TRUE); } @@ -143,7 +150,7 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS isIntegratedOption (setting, &index)) { writeInit (backend, context); - writeIntegratedOption (context, setting, index); + writeIntegratedOption (backend, context, setting, index); } } @@ -152,97 +159,34 @@ valueChanged (GSettings *settings, gchar *keyName, gpointer user_data) { - CCSContext *context = (CCSContext *)user_data; - char *uncleanKeyName; - char *path, *pathOrig; - char *pluginName; - unsigned int screenNum; - CCSPlugin *plugin; - CCSSetting *setting; - - g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); - - path = pathOrig; - - if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) - { - g_free (pathOrig); - return; - } - - plugin = ccsFindPlugin (context, pluginName); - - uncleanKeyName = translateKeyForCCS (keyName); - - setting = ccsFindSetting (plugin, uncleanKeyName); - if (!setting) - { - /* Couldn't find setting straight off the bat, - * try and find the best match */ - GVariant *value = g_settings_get_value (settings, keyName); - - if (value) - { - GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); - GList *iter = possibleSettingTypes; - - while (iter) - { - setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (plugin), - keyName, - (CCSSettingType) GPOINTER_TO_INT (iter->data)); + CCSBackend *backend = (CCSBackend *)user_data; - if (setting) - break; - - iter = iter->next; - } - - g_list_free (possibleSettingTypes); - g_variant_unref (value); - } - - /* We hit a situation where either the key stored in GSettings couldn't be - * matched at all to a key in the xml file, or where there were multiple matches. - * Unfortunately, there isn't much we can do about this, other than try - * and warn the user and bail out. It just means that if the key was updated - * externally we won't know about the change until the next reload of settings */ - if (!setting) - { - ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, path); - g_free (pluginName); - free (uncleanKeyName); - g_free (pathOrig); - return; - } - } - - updateSetting (NULL, context, plugin, setting); - - g_free (pluginName); - free (uncleanKeyName); - g_free (pathOrig); + updateSettingWithGSettingsKeyName (backend, settings, keyName, updateSetting); } static Bool -readIntegratedOption (CCSContext *context, +readIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { #ifdef USE_GCONF - return readGConfIntegratedOption (context, setting, index); + return readGConfIntegratedOption (backend, context, setting, index); #else return FALSE; #endif } static GVariant * -getVariantForCCSSetting (CCSSetting *setting) +getVariantForCCSSetting (CCSBackend *backend, CCSSetting *setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); + GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = getNameForCCSSetting (setting); gchar *pathName = makeSettingPath (setting); - GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName, pathName, ccsSettingGetType (setting)); + GVariant *gsettingsValue = getVariantAtKey (settings, + cleanSettingName, + pathName, + ccsSettingGetType (setting)); free (cleanSettingName); free (pathName); @@ -250,7 +194,7 @@ getVariantForCCSSetting (CCSSetting *setting) } Bool -readOption (CCSSetting * setting) +readOption (CCSBackend *backend, CCSSetting * setting) { Bool ret = FALSE; GVariant *gsettingsValue = NULL; @@ -266,7 +210,7 @@ readOption (CCSSetting * setting) return FALSE; } - gsettingsValue = getVariantForCCSSetting (setting); + gsettingsValue = getVariantForCCSSetting (backend, setting); switch (ccsSettingGetType (setting)) { @@ -374,7 +318,7 @@ readOption (CCSSetting * setting) break; case TypeList: { - CCSSettingValueList list = readListValue (gsettingsValue, ccsSettingGetInfo (setting)->forList.listType); + CCSSettingValueList list = readListValue (gsettingsValue, setting); if (list) { @@ -404,21 +348,22 @@ readOption (CCSSetting * setting) } static void -writeIntegratedOption (CCSContext *context, +writeIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index) { #ifdef USE_GCONF - writeGConfIntegratedOption (context, setting, index); + writeGConfIntegratedOption (backend, context, setting, index); #endif return; } static void -resetOptionToDefault (CCSSetting * setting) +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); + GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); @@ -428,9 +373,9 @@ resetOptionToDefault (CCSSetting * setting) } void -writeOption (CCSSetting * setting) +writeOption (CCSBackend *backend, CCSSetting * setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); + GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); GVariant *gsettingsValue = NULL; Bool success = FALSE; @@ -454,6 +399,7 @@ writeOption (CCSSetting * setting) success = writeStringToVariant (value, &gsettingsValue); } } + break; case TypeFloat: { float value; @@ -532,7 +478,6 @@ writeOption (CCSSetting * setting) break; case TypeList: { - GVariant *value = NULL; CCSSettingValueList list = NULL; if (!ccsGetList (setting, &list)) @@ -540,7 +485,7 @@ writeOption (CCSSetting * setting) success = writeListValue (list, ccsSettingGetInfo (setting)->forList.listType, - &value); + &gsettingsValue); } break; default: @@ -553,7 +498,7 @@ writeOption (CCSSetting * setting) { /* g_settings_set_value will consume the reference * so there is no need to unref value here */ - g_settings_set_value (settings, cleanSettingName, gsettingsValue); + writeVariantToKey (settings, cleanSettingName, gsettingsValue); } free (cleanSettingName); @@ -592,6 +537,8 @@ updateCurrentProfileName (const char *profile) g_variant_unref (newProfiles); g_variant_builder_unref (newProfilesBuilder); + g_variant_unref (profiles); + /* Change the current profile and current profile settings */ free (currentProfile); @@ -638,6 +585,8 @@ getCurrentProfileName (void) else ret = strdup (DEFAULTPROF); + g_variant_unref (value); + return ret; } @@ -651,6 +600,45 @@ processEvents (CCSBackend *backend, unsigned int flags) } } +static CCSContext * +ccsGSettingsBackendGetContextDefault (CCSBackend *backend) +{ + return storedContext; +} + +static void +ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, GObject *object) +{ + g_signal_connect (object, "changed", (GCallback) valueChanged, (gpointer) backend); +} + +static void +ccsGSettingsBackendRegisterGConfClientDefault (CCSBackend *backend) +{ +#ifdef USE_GCONF + CCSContext *context = ccsGSettingsBackendGetContext (backend); + + initGConfClient (context); +#endif +} + +static void +ccsGSettingsBackendUnregisterGConfClientDefault (CCSBackend *backend) +{ +#ifdef USE_GCONF + gconf_client_clear_cache (client); + finiGConfClient (); +#endif +} + +static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { + ccsGSettingsBackendGetContextDefault, + ccsGSettingsBackendConnectToValueChangedSignalDefault, + ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault, + ccsGSettingsBackendRegisterGConfClientDefault, + ccsGSettingsBackendUnregisterGConfClientDefault +}; + static Bool initBackend (CCSBackend *backend, CCSContext * context) { @@ -658,11 +646,11 @@ initBackend (CCSBackend *backend, CCSContext * context) g_type_init (); - compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); + storedContext = context; -#ifdef USE_GCONF - initGConfClient (context); -#endif + ccsObjectAddInterface (backend, (CCSInterface *) &gsettingsAdditionalDefaultInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + + compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); currentProfile = getCurrentProfileName (); currentProfilePath = makeCompizProfilePath (currentProfile); @@ -676,14 +664,9 @@ initBackend (CCSBackend *backend, CCSContext * context) static Bool finiBackend (CCSBackend *backend, CCSContext * context) { - GList *l = settingsList; - processEvents (backend, 0); -#ifdef USE_GCONF - gconf_client_clear_cache (client); - finiGConfClient (); -#endif + ccsGSettingsBackendUnregisterGConfClient (backend); if (currentProfile) { @@ -691,11 +674,9 @@ finiBackend (CCSBackend *backend, CCSContext * context) currentProfile = NULL; } - while (l) - { - g_object_unref (G_OBJECT (l->data)); - l = g_list_next (l); - } + g_list_free_full (settingsList, g_object_unref); + + settingsList = NULL; if (currentProfileSettings) { @@ -705,6 +686,8 @@ finiBackend (CCSBackend *backend, CCSContext * context) g_object_unref (G_OBJECT (compizconfigSettings)); + compizconfigSettings = NULL; + processEvents (backend, 0); return TRUE; } @@ -726,10 +709,10 @@ readSetting (CCSBackend *backend, if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - status = readIntegratedOption (context, setting, index); + status = readIntegratedOption (backend, context, setting, index); } else - status = readOption (setting); + status = readOption (backend, setting); if (!status) ccsResetToDefault (setting, TRUE); @@ -751,14 +734,14 @@ writeSetting (CCSBackend *backend, if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeIntegratedOption (context, setting, index); + writeIntegratedOption (backend, context, setting, index); } else if (ccsSettingGetIsDefault (setting)) { - resetOptionToDefault (setting); + resetOptionToDefault (backend, setting); } else - writeOption (setting); + writeOption (backend, setting); } @@ -828,7 +811,7 @@ deleteProfile (CCSBackend *backend, GSettings *settings; gchar *pathName = makeCompizPluginPath (currentProfile, plugin); - settings = getSettingsObjectForPluginWithPath (plugin, pathName, context); + settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); g_free (pathName); /* The GSettings documentation says not to use this API @@ -930,6 +913,8 @@ static CCSBackendInterface gsettingsVTable = { deleteProfile }; + + CCSBackendInterface * getBackendInfo (void) { diff --git a/compizconfig/gsettings/src/gsettings.h b/compizconfig/gsettings/src/gsettings.h index 000a4dbca..718504355 100644 --- a/compizconfig/gsettings/src/gsettings.h +++ b/compizconfig/gsettings/src/gsettings.h @@ -68,9 +68,9 @@ char *currentProfile; Bool readInit (CCSBackend *, CCSContext * context); void readSetting (CCSBackend *, CCSContext * context, CCSSetting * setting); -Bool readOption (CCSSetting * setting); +Bool readOption (CCSBackend *backend, CCSSetting * setting); Bool writeInit (CCSBackend *, CCSContext * context); -void writeOption (CCSSetting *setting); +void writeOption (CCSBackend *backend, CCSSetting *setting); #ifdef USE_GCONF @@ -106,12 +106,14 @@ void finiGConfClient (void); Bool -readGConfIntegratedOption (CCSContext *context, +readGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index); void -writeGConfIntegratedOption (CCSContext *context, +writeGConfIntegratedOption (CCSBackend *backend, + CCSContext *context, CCSSetting *setting, int index); diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 7c9858ea0..27c309c2e 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -909,7 +909,7 @@ TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeGood) { GVariant *v = g_variant_new ("i", 1); - EXPECT_FALSE (checkReadVariantIsValid (v, TypeInt, "foo/bar")); + EXPECT_TRUE (checkReadVariantIsValid (v, TypeInt, "foo/bar")); g_variant_unref (v); } -- GitLab From 5ed38d1b62fd1cb0f5010e70e833cd6ff1d57a64 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:41:13 +0800 Subject: [PATCH 148/562] Expose ccsCopyList --- compizconfig/libcompizconfig/include/ccs.h | 4 ++++ compizconfig/libcompizconfig/src/main.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 57324f9ed..36679e74e 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -969,6 +969,10 @@ Bool * ccsGetBoolArrayFromValueList (CCSSettingValueList list, CCSSettingColorValue* ccsGetColorArrayFromValueList (CCSSettingValueList list, int *num); +/* Deep copies value lists */ +CCSSettingValueList +ccsCopyList (CCSSettingValueList l1, CCSSetting * setting); + /* Converts an array of data items to a setting value list. Behaves similar to ccsGetListFromStringArray */ CCSSettingValueList ccsGetValueListFromStringArray (char **array, diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 8bd293b08..fce36dc26 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1833,7 +1833,7 @@ ccsSettingSetBellDefault (CCSSetting * setting, Bool data, Bool processChanged) return TRUE; } -static CCSSettingValueList +CCSSettingValueList ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) { CCSSettingValueList l2 = NULL; -- GitLab From 7c9db9d54f8c3553dc334a67b825ee9e4347b067 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:43:36 +0800 Subject: [PATCH 149/562] Use interface to determine the setting info (we might not be acting on real settings ...) --- compizconfig/libcompizconfig/src/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index fce36dc26..1d19d3e04 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1838,8 +1838,6 @@ ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) { CCSSettingValueList l2 = NULL; - SETTING_PRIV (setting) - while (l1) { CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue)); @@ -1850,7 +1848,7 @@ ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) value->parent = setting; value->isListChild = TRUE; - switch (sPrivate->info.forList.listType) + switch (ccsSettingGetInfo (setting)->forList.listType) { case TypeInt: value->value.asInt = l1->data->value.asInt; -- GitLab From 262643a9c9421de5e8b32181282a7efaefe111c2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 04:44:48 +0800 Subject: [PATCH 150/562] Use the boolean operators as TRUE/FALSE can be redefined and direct comparisons don't work out so well... --- compizconfig/libcompizconfig/src/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 1d19d3e04..524d7744f 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1147,8 +1147,14 @@ ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, return FALSE; break; case TypeBool: - if (l1->data->value.asBool != l2->data->value.asBool) - return FALSE; + { + Bool bothTrue = (l1->data->value.asBool && l2->data->value.asBool); + Bool bothFalse = (!l1->data->value.asBool && !l2->data->value.asBool); + + /* Use the boolean operators as TRUE/FALSE can be redefined */ + if (!bothTrue && !bothFalse) + return FALSE; + } break; case TypeFloat: if (l1->data->value.asFloat != l2->data->value.asFloat) -- GitLab From f70bb8dcd9cb0dbeae02bfc732e982aab9c3c507 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 25 Jul 2012 09:55:53 +0800 Subject: [PATCH 151/562] Added additional tests for updateSetting and updateSettingByKeyName to the setting tests, instatiate the test environments through a factory class and fixed list, color, string and bool comparison. --- ...nfig_test_ccs_mock_backend_conformance.cpp | 110 +++- .../compizconfig_ccs_setting_mock.cpp | 36 +- .../compizconfig_ccs_setting_mock.h | 1 + .../tests/compizconfig_backend_concept_test.h | 563 +++++++++++++----- 4 files changed, 532 insertions(+), 178 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index cf2b62aaf..04529f292 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -15,6 +15,7 @@ using ::testing::WithArgs; using ::testing::Combine; using ::testing::ValuesIn; using ::testing::Values; +using ::testing::AtLeast; namespace { @@ -42,6 +43,11 @@ class ValueForKeyRetreival } }; +namespace +{ + void doNothingWithCCSSetting (CCSSetting *) {}; +} + class MockCCSBackendConceptTestEnvironment : public CCSBackendConceptTestEnvironmentInterface { @@ -49,6 +55,7 @@ class MockCCSBackendConceptTestEnvironment : CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { + mContext = context; mBackend = ccsMockBackendNew (); mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); @@ -59,6 +66,13 @@ class MockCCSBackendConceptTestEnvironment : this, &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + ON_CALL (*mBackendGMock, updateSetting (_, _, _)) + .WillByDefault ( + WithArgs<2> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + ON_CALL (*mBackendGMock, writeSetting (_, _)) .WillByDefault ( WithArgs<1> ( @@ -72,7 +86,6 @@ class MockCCSBackendConceptTestEnvironment : void TearDown (CCSBackend *backend) { ccsFreeMockBackend (backend); - } void PreWrite (CCSContextGMock *gmockContext, @@ -83,8 +96,17 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); EXPECT_CALL (*gmockPlugin, getName ()); EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getType ()); EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } } void PostWrite (CCSContextGMock *gmockContext, @@ -180,8 +202,17 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, readSetting (_, _)); EXPECT_CALL (*gmockPlugin, getName ()); EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getType ()); EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } } void PostRead (CCSContextGMock *gmockContext, @@ -252,9 +283,57 @@ class MockCCSBackendConceptTestEnvironment : } virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key) + const std::string &key, + CCSSetting *setting) { - return *(ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + CCSListWrapper::Ptr lw (ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + + return ccsCopyList (*lw, lw->setting ().get ()); + } + + void PreUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, updateSetting (_, _, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } + } + + void PostUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + + bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) + { + CCSPlugin *cplugin = ccsFindPlugin (mContext, plugin.c_str ()); + + if (!cplugin) + return false; + + CCSSetting *csetting = ccsFindSetting (cplugin, setting.c_str ()); + + if (!csetting) + return false; + + ccsBackendUpdateSetting (mBackend, mContext, cplugin, csetting); + return true; } protected: @@ -317,9 +396,12 @@ class MockCCSBackendConceptTestEnvironment : break; case TypeList: - - ccsSetList (setting, ReadListAtKey (plugin, key), FALSE); - break; + ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, setting), + true, + ccsSettingGetInfo (setting)->forList.listType, + boost::shared_ptr (), + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))), FALSE); + break; default: @@ -405,11 +487,18 @@ class MockCCSBackendConceptTestEnvironment : break; case TypeList: + { + CCSSettingValueList listCopy = NULL; ccsGetList (setting, &vList); - WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (vList, false, ccsSettingGetInfo (setting)->forList.listType))); - break; + listCopy = ccsCopyList (vList, setting); + WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, + ccsSettingGetInfo (setting)->forList.listType, + boost::shared_ptr (), + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))))); + break; + } default: throw std::exception (); @@ -420,6 +509,7 @@ class MockCCSBackendConceptTestEnvironment : CCSBackend *mBackend; CCSBackendGMock *mBackendGMock; + CCSContext *mContext; std::map mValues; }; diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp index 8b3d5d0c4..effc6dd55 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp @@ -5,6 +5,8 @@ #include "compizconfig_ccs_setting_mock.h" +using ::testing::NiceMock; + CCSSettingInterface CCSSettingGMockInterface = { CCSSettingGMock::ccsSettingGetName, @@ -50,8 +52,8 @@ CCSSettingInterface CCSSettingGMockInterface = CCSSettingGMock::ccsSettingFree }; -CCSSetting * -ccsMockSettingNew () +static CCSSetting * +allocateSettingObjectWithMockInterface () { CCSSetting *setting = (CCSSetting *) calloc (1, sizeof (CCSSetting)); @@ -60,8 +62,6 @@ ccsMockSettingNew () ccsObjectInit (setting, &ccsDefaultObjectAllocator); - CCSSettingGMock *mock = new CCSSettingGMock (setting); - ccsObjectSetPrivate (setting, (CCSPrivate *) mock); ccsObjectAddInterface (setting, (CCSInterface *) &CCSSettingGMockInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); ccsSettingRef (setting); @@ -69,6 +69,34 @@ ccsMockSettingNew () return setting; } +CCSSetting * +ccsMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + CCSSettingGMock *mock = new CCSSettingGMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + +CCSSetting * +ccsNiceMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + NiceMock *mock = new NiceMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + void ccsFreeMockSetting (CCSSetting *setting) { diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h index 14d02de22..70f0c6d5e 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h @@ -7,6 +7,7 @@ using ::testing::_; using ::testing::Return; CCSSetting * ccsMockSettingNew (); +CCSSetting * ccsNiceMockSettingNew (); void ccsFreeMockSetting (CCSSetting *); class CCSSettingGMockInterface diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index fd145602d..6dce530f0 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -13,6 +13,8 @@ #include #include +#include + #include #include @@ -24,10 +26,16 @@ using ::testing::Eq; using ::testing::SetArgPointee; using ::testing::DoAll; using ::testing::Return; +using ::testing::ReturnNull; using ::testing::MakeMatcher; using ::testing::Matcher; using ::testing::MatcherInterface; using ::testing::MatchResultListener; +using ::testing::AtLeast; +using ::testing::NiceMock; + +MATCHER(IsTrue, "Is True") { if (arg) return true; else return false; } +MATCHER(IsFalse, "Is False") { if (!arg) return true; else return false; } class ListEqualityMatcher : public MatcherInterface @@ -77,6 +85,13 @@ operator== (const CCSSettingColorValue &lhs, return false; } +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingColorValue &v) +{ + return os << "Red: " << std::hex << v.color.red << "Blue: " << std::hex << v.color.blue << "Green: " << v.color.green << "Alpha: " << v.color.alpha + << std::dec << std::endl; +} + bool operator== (const CCSSettingKeyValue &lhs, const CCSSettingKeyValue &rhs) @@ -86,6 +101,12 @@ operator== (const CCSSettingKeyValue &lhs, return false; } +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingKeyValue &v) +{ + return os << "Keysym: " << v.keysym << " KeyModMask " << std::hex << v.keyModMask << std::dec << std::endl; +} + bool operator== (const CCSSettingButtonValue &lhs, const CCSSettingButtonValue &rhs) @@ -95,6 +116,42 @@ operator== (const CCSSettingButtonValue &lhs, return false; } +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingButtonValue &v) +{ + return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl; +} + +class CharacterWrapper : + boost::noncopyable +{ + public: + + explicit CharacterWrapper (char *c) : + mChar (c) + { + } + + ~CharacterWrapper () + { + free (mChar); + } + + operator char * () + { + return mChar; + } + + operator const char * () const + { + return mChar; + } + + private: + + char *mChar; +}; + class CCSListWrapper : boost::noncopyable { @@ -102,10 +159,16 @@ class CCSListWrapper : typedef boost::shared_ptr Ptr; - CCSListWrapper (CCSSettingValueList list, bool freeItems, CCSSettingType type) : + CCSListWrapper (CCSSettingValueList list, + bool freeItems, + CCSSettingType type, + const boost::shared_ptr &listInfo, + const boost::shared_ptr &settingReference) : mList (list), mFreeItems (freeItems), - mType (type) + mType (type), + mListInfo (listInfo), + mSettingReference (settingReference) { } @@ -125,11 +188,20 @@ class CCSListWrapper : { ccsSettingValueListFree (mList, mFreeItems ? TRUE : FALSE); } + + const boost::shared_ptr & + setting () + { + return mSettingReference; + } + private: CCSSettingValueList mList; bool mFreeItems; CCSSettingType mType; + boost::shared_ptr mListInfo; + boost::shared_ptr mSettingReference; }; typedef boost::variant Ptr; + virtual ~CCSBackendConceptTestEnvironmentInterface () {}; virtual CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) = 0; @@ -224,7 +298,42 @@ class CCSBackendConceptTestEnvironmentInterface virtual Bool ReadBellAtKey (const std::string &plugin, const std::string &key) = 0; virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key) = 0; + const std::string &key, + CCSSetting *setting) = 0; + + virtual void PreUpdate (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + virtual void PostUpdate (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + + virtual bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) = 0; +}; + +class CCSBackendConceptTestEnvironmentFactoryInterface +{ + public: + + virtual ~CCSBackendConceptTestEnvironmentFactoryInterface () {} + + virtual CCSBackendConceptTestEnvironmentInterface::Ptr ConstructTestEnv () = 0; +}; + +template +class CCSBackendConceptTestEnvironmentFactory : + public CCSBackendConceptTestEnvironmentFactoryInterface +{ + public: + + CCSBackendConceptTestEnvironmentInterface::Ptr + ConstructTestEnv () + { + return boost::shared_static_cast (boost::make_shared ()); + } }; namespace @@ -234,14 +343,14 @@ typedef boost::function WriteFunc; Bool boolToBool (bool v) { return v ? TRUE : FALSE; } -CCSSettingGMock * getSettingGMockFromSetting (CCSSetting *setting) { return (CCSSettingGMock *) ccsObjectGetPrivate (setting); } +CCSSettingGMock * getSettingGMockFromSetting (const boost::shared_ptr &setting) { return (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); } void SetIntWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getInt (_)).WillRepeatedly (DoAll ( @@ -255,9 +364,9 @@ void SetIntWriteExpectation (const std::string &plugin, void SetBoolWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getBool (_)).WillRepeatedly (DoAll ( @@ -265,15 +374,21 @@ void SetBoolWriteExpectation (const std::string &plugin, boolToBool (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadBoolAtKey (plugin, key), boolToBool (boost::get (value))); + + bool v (boost::get (value)); + + if (v) + EXPECT_THAT (env->ReadBoolAtKey (plugin, key), IsTrue ()); + else + EXPECT_THAT (env->ReadBoolAtKey (plugin, key), IsFalse ()); } void SetFloatWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getFloat (_)).WillRepeatedly (DoAll ( @@ -287,9 +402,9 @@ void SetFloatWriteExpectation (const std::string &plugin, void SetStringWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getString (_)).WillRepeatedly (DoAll ( @@ -297,15 +412,15 @@ void SetStringWriteExpectation (const std::string &plugin, const_cast (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadStringAtKey (plugin, key), boost::get (value)); + EXPECT_EQ (std::string (env->ReadStringAtKey (plugin, key)), std::string (boost::get (value))); } void SetColorWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getColor (_)).WillRepeatedly (DoAll ( @@ -313,15 +428,16 @@ void SetColorWriteExpectation (const std::string &plugin, boost::get (value)), Return (TRUE))); write (); + EXPECT_EQ (env->ReadColorAtKey (plugin, key), boost::get (value)); } void SetKeyWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getKey (_)).WillRepeatedly (DoAll ( @@ -335,9 +451,9 @@ void SetKeyWriteExpectation (const std::string &plugin, void SetButtonWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getButton (_)).WillRepeatedly (DoAll ( @@ -351,9 +467,9 @@ void SetButtonWriteExpectation (const std::string &plugin, void SetEdgeWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getEdge (_)).WillRepeatedly (DoAll ( @@ -367,9 +483,9 @@ void SetEdgeWriteExpectation (const std::string &plugin, void SetBellWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getBell (_)).WillRepeatedly (DoAll ( @@ -377,15 +493,20 @@ void SetBellWriteExpectation (const std::string &plugin, boolToBool (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadBellAtKey (plugin, key), boolToBool (boost::get (value))); + bool v (boost::get (value)); + + if (v) + EXPECT_THAT (env->ReadBellAtKey (plugin, key), IsTrue ()); + else + EXPECT_THAT (env->ReadBellAtKey (plugin, key), IsFalse ()); } void SetMatchWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); EXPECT_CALL (*gmock, getMatch (_)).WillRepeatedly (DoAll ( @@ -393,29 +514,38 @@ void SetMatchWriteExpectation (const std::string &plugin, const_cast (boost::get (value))), Return (TRUE))); write (); - EXPECT_EQ (env->ReadMatchAtKey (plugin, key), boost::get (value)); + EXPECT_EQ (std::string (env->ReadMatchAtKey (plugin, key)), std::string (boost::get (value))); } void SetListWriteExpectation (const std::string &plugin, const std::string &key, const VariantTypes &value, - CCSSetting *setting, + const boost::shared_ptr &setting, const WriteFunc &write, - CCSBackendConceptTestEnvironmentInterface *env) + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) { CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); CCSSettingValueList list = *(boost::get > (value)); - boost::shared_ptr info (boost::make_shared ()); + + EXPECT_CALL (*gmock, getInfo ()); + + CCSSettingInfo *info = ccsSettingGetInfo (setting.get ()); info->forList.listType = (boost::get > (value))->type (); - EXPECT_CALL (*gmock, getInfo ()).WillRepeatedly (Return (info.get ())); + EXPECT_CALL (*gmock, getInfo ()).Times (AtLeast (1)); EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll ( SetArgPointee <0> ( list), Return (TRUE))); write (); - EXPECT_THAT (env->ReadListAtKey (plugin, key), ListEqual (ccsSettingGetInfo (setting)->forList, list)); + + EXPECT_THAT (CCSListWrapper (env->ReadListAtKey (plugin, key, setting.get ()), + true, + info->forList.listType, + boost::shared_ptr (), + setting), + ListEqual (info->forList, list)); } void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) @@ -425,12 +555,22 @@ void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) void SetBoolReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setBool (boolToBool (boost::get (value)), _)); + bool v (boost::get (value)); + + if (v) + EXPECT_CALL (*gmock, setBool (IsTrue (), _)); + else + EXPECT_CALL (*gmock, setBool (IsFalse (), _)); } void SetBellReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - EXPECT_CALL (*gmock, setBell (boolToBool (boost::get (value)), _)); + bool v (boost::get (value)); + + if (v) + EXPECT_CALL (*gmock, setBell (IsTrue (), _)); + else + EXPECT_CALL (*gmock, setBell (IsFalse (), _)); } void SetFloatReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) @@ -468,14 +608,15 @@ void SetEdgeReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) EXPECT_CALL (*gmock, setEdge (boost::get (value), _)); } +CCSSettingInfo globalListInfo; + void SetListReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) { - CCSSettingInfo info; + globalListInfo.forList.listType = (boost::get > (value))->type (); + globalListInfo.forList.listInfo = NULL; - info.forList.listType = (boost::get > (value))->type (); - info.forList.listInfo = NULL; - - EXPECT_CALL (*gmock, setList (ListEqual (info.forList, *(boost::get > (value))), _)); + ON_CALL (*gmock, getInfo ()).WillByDefault (Return (&globalListInfo)); + EXPECT_CALL (*gmock, setList (ListEqual (globalListInfo.forList, *(boost::get > (value))), _)); } } @@ -486,21 +627,27 @@ class CCSBackendConceptTestParamInterface typedef boost::shared_ptr Ptr; - typedef boost::function NativeWriteMethod; + typedef void (CCSBackendConceptTestEnvironmentInterface::*NativeWriteMethod) (const std::string &plugin, + const std::string &keyname, + const VariantTypes &value); + typedef boost::function SetReadExpectation; typedef boost::function &, const WriteFunc &, - CCSBackendConceptTestEnvironmentInterface *)> SetWriteExpectation; + const CCSBackendConceptTestEnvironmentInterface::Ptr & )> SetWriteExpectation; - virtual CCSBackendConceptTestEnvironmentInterface * testEnv () = 0; + virtual void TearDown (CCSBackend *) = 0; + + virtual CCSBackendConceptTestEnvironmentInterface::Ptr testEnv () = 0; virtual VariantTypes & value () = 0; - virtual NativeWriteMethod & nativeWrite () = 0; + virtual void nativeWrite (const CCSBackendConceptTestEnvironmentInterface::Ptr & iface, + const std::string &plugin, + const std::string &keyname, + const VariantTypes &value) = 0; virtual CCSSettingType & type () = 0; virtual std::string & keyname () = 0; virtual SetWriteExpectation & setWriteExpectationAndWrite () = 0; @@ -516,7 +663,7 @@ class CCSBackendConceptTestParam : typedef boost::shared_ptr > Ptr; - CCSBackendConceptTestParam (CCSBackendConceptTestEnvironmentInterface *testEnv, + CCSBackendConceptTestParam (CCSBackendConceptTestEnvironmentFactoryInterface *testEnvFactory, const VariantTypes &value, const NativeWriteMethod &write, const CCSSettingType &type, @@ -524,7 +671,8 @@ class CCSBackendConceptTestParam : const SetReadExpectation &setReadExpectation, const SetWriteExpectation &setWriteExpectation, const std::string &what) : - mTestEnv (testEnv), + mTestEnvFactory (testEnvFactory), + mTestEnv (), mValue (value), mNativeWrite (write), mType (type), @@ -535,9 +683,30 @@ class CCSBackendConceptTestParam : { } - CCSBackendConceptTestEnvironmentInterface * testEnv () { return mTestEnv; } + void TearDown (CCSBackend *b) + { + if (mTestEnv) + mTestEnv->TearDown (b); + + mTestEnv.reset (); + } + + CCSBackendConceptTestEnvironmentInterface::Ptr testEnv () + { + if (!mTestEnv) + mTestEnv = mTestEnvFactory->ConstructTestEnv (); + + return mTestEnv; + } + VariantTypes & value () { return mValue; } - CCSBackendConceptTestParamInterface::NativeWriteMethod & nativeWrite () { return mNativeWrite; } + void nativeWrite (const CCSBackendConceptTestEnvironmentInterface::Ptr & iface, + const std::string &plugin, + const std::string &keyname, + const VariantTypes &value) + { + return ((iface.get ())->*mNativeWrite) (plugin, keyname, value); + } CCSSettingType & type () { return mType; } std::string & keyname () { return mKeyname; } CCSBackendConceptTestParamInterface::SetReadExpectation & setReadExpectation () { return mSetReadExpectation; } @@ -546,7 +715,8 @@ class CCSBackendConceptTestParam : private: - CCSBackendConceptTestEnvironmentInterface *mTestEnv; + CCSBackendConceptTestEnvironmentFactoryInterface *mTestEnvFactory; + CCSBackendConceptTestEnvironmentInterface::Ptr mTestEnv; VariantTypes mValue; NativeWriteMethod mNativeWrite; CCSSettingType mType; @@ -576,32 +746,17 @@ class CCSBackendConformanceTest : virtual void SetUp () { - CCSBackendConformanceTest::SpawnContext (&context); + CCSBackendConformanceTest::SpawnContext (context); gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); - mBackend = GetParam ()->testEnv ()->SetUp (context, gmockContext); + mBackend = GetParam ()->testEnv ()->SetUp (context.get (), gmockContext); } virtual void TearDown () { - CCSBackendConformanceTest::GetParam ()->testEnv ()->TearDown (mBackend); - - for (std::list ::iterator it = mSpawnedContexts.begin (); - it != mSpawnedContexts.end (); - it++) - ccsFreeMockContext (*it); - - for (std::list ::iterator it = mSpawnedPlugins.begin (); - it != mSpawnedPlugins.end (); - it++) - ccsFreeMockPlugin (*it); - - for (std::list ::iterator it = mSpawnedSettings.begin (); - it != mSpawnedSettings.end (); - it++) - ccsFreeMockSetting (*it); + CCSBackendConformanceTest::GetParam ()->TearDown (mBackend); } protected: @@ -611,37 +766,35 @@ class CCSBackendConformanceTest : * you use ASSERT_* unless the function returns void */ void - SpawnContext (CCSContext **context) + SpawnContext (boost::shared_ptr &context) { - *context = ccsMockContextNew (); - mSpawnedContexts.push_back (*context); + context.reset (ccsMockContextNew (), boost::bind (ccsFreeMockContext, _1)); } void - SpawnPlugin (const std::string &name, CCSContext *context, CCSPlugin **plugin) + SpawnPlugin (const std::string &name, const boost::shared_ptr &context, boost::shared_ptr &plugin) { - *plugin = ccsMockPluginNew (); - mSpawnedPlugins.push_back (*plugin); + plugin.reset (ccsMockPluginNew (), boost::bind (ccsFreeMockPlugin, _1)); - CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (*plugin); + CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin.get ()); ASSERT_FALSE (name.empty ()); - ASSERT_TRUE (context); + ASSERT_TRUE (context.get ()); ON_CALL (*gmockPlugin, getName ()).WillByDefault (Return ((char *) name.c_str ())); - ON_CALL (*gmockPlugin, getContext ()).WillByDefault (Return (context)); + ON_CALL (*gmockPlugin, getContext ()).WillByDefault (Return (context.get ())); } void SpawnSetting (const std::string &name, CCSSettingType type, - CCSPlugin *plugin, - CCSSetting **setting) + const boost::shared_ptr &plugin, + boost::shared_ptr &setting) { - *setting = ccsMockSettingNew (); - mSpawnedSettings.push_back (*setting); + setting.reset (ccsMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + mSpawnedSettingInfo.push_back (CCSSettingInfo ()); - CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (*setting); + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); ASSERT_FALSE (name.empty ()); ASSERT_NE (type, TypeNum); @@ -649,22 +802,19 @@ class CCSBackendConformanceTest : ON_CALL (*gmockSetting, getName ()).WillByDefault (Return ((char *) name.c_str ())); ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (type)); - ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin)); + ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin.get ())); + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&(mSpawnedSettingInfo.back ()))); } protected: - CCSContext *context; + boost::shared_ptr context; CCSContextGMock *gmockContext; private: - std::list mSpawnedContexts; - std::list mSpawnedPlugins; - std::list mSpawnedSettings; - + std::vector mSpawnedSettingInfo; CCSBackend *mBackend; - std::string profileName; }; @@ -680,155 +830,209 @@ int intValues[] = { 1, 2, 3 }; float floatValues[] = { 1.0, 2.0, 3.0 }; const char * stringValues[] = { "foo", "grill", "bar" }; -CCSSettingColorValue colorValues[3] = { { .color = { 100, 200, 300, 100 } }, - { .color = { 50, 100, 200, 300 } }, - { .color = { 10, 20, 30, 40 } } - }; +const unsigned int NUM_COLOR_VALUES = 3; -CCSSettingKeyValue keyValue = { (1 << 0) | (1 << 1), - 1 }; +CCSSettingColorValue * +getColorValueList () +{ + static const unsigned short max = std::numeric_limits ::max (); + static const unsigned short maxD2 = max / 2; + static const unsigned short maxD4 = max / 4; + static const unsigned short maxD8 = max / 8; + + static CCSSettingColorValue colorValues[NUM_COLOR_VALUES] = { { .color = { maxD2, maxD4, maxD8, max } }, + { .color = { maxD8, maxD4, maxD2, max } }, + { .color = { max, maxD4, maxD2, maxD8 } } + }; + static bool colorValueListInitialized = false; + + if (!colorValueListInitialized) + { + for (unsigned int i = 0; i < NUM_COLOR_VALUES; i++) + { + CharacterWrapper s (ccsColorToString (&colorValues[i])); -CCSSettingButtonValue buttonValue = { (1 << 0) | (1 << 1), - 1, + ccsStringToColor (s, &colorValues[i]); + } + + colorValueListInitialized = true; + } + + return colorValues; +} + +CCSSettingKeyValue keyValue = { XK_A, + (1 << 0)}; + +CCSSettingButtonValue buttonValue = { 1, + (1 << 0), (1 << 1) }; + +} + +typedef boost::function ConstructorFunc; + +CCSListWrapper::Ptr +CCSListConstructionExpectationsSetter (const ConstructorFunc &c, + CCSSettingType type, + bool freeItems) +{ + boost::function f (boost::bind (ccsFreeMockSetting, _1)); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), f); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + boost::shared_ptr listInfo (new CCSSettingInfo); + + listInfo->forList.listType = type; + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (listInfo.get ())); + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); + return boost::make_shared (c (mockSetting.get ()), freeItems, type, listInfo, mockSetting); } template ::testing::internal::ParamGenerator GenerateTestingParametersForBackendInterface () { - static I interface; - static CCSBackendConceptTestEnvironmentInterface *backendEnv = &interface; + static CCSBackendConceptTestEnvironmentFactory interfaceFactory; + static CCSBackendConceptTestEnvironmentFactoryInterface *backendEnvFactory = &interfaceFactory; typedef CCSBackendConceptTestParam ConceptParam; static typename CCSBackendConceptTestParamInterface::Ptr testParam[] = { - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (1), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, TypeInt, "integer_setting", boost::bind (SetIntReadExpectation, _1, _2), boost::bind (SetIntWriteExpectation, _1, _2, _3, _4, _5, _6), "TestInt"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (true), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, TypeBool, "boolean_setting", boost::bind (SetBoolReadExpectation, _1, _2), boost::bind (SetBoolWriteExpectation, _1, _2, _3, _4, _5, _6), "TestBool"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast (3.0)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, TypeFloat, "float_setting", boost::bind (SetFloatReadExpectation, _1, _2), boost::bind (SetFloatWriteExpectation, _1, _2, _3, _4, _5, _6), "TestFloat"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast ("foo")), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, TypeString, "string_setting", boost::bind (SetStringReadExpectation, _1, _2), boost::bind (SetStringWriteExpectation, _1, _2, _3, _4, _5, _6), "TestString"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast ("foo=bar")), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, TypeMatch, "match_setting", boost::bind (SetMatchReadExpectation, _1, _2), boost::bind (SetMatchWriteExpectation, _1, _2, _3, _4, _5, _6), "TestMatch"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (true), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, TypeBell, "bell_setting", boost::bind (SetBellReadExpectation, _1, _2), boost::bind (SetBellWriteExpectation, _1, _2, _3, _4, _5, _6), "TestBell"), - boost::make_shared (backendEnv, - VariantTypes (impl::colorValues[0]), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, backendEnv, _1, _2, _3), + boost::make_shared (backendEnvFactory, + VariantTypes (impl::getColorValueList ()[0]), + &CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, TypeColor, "color_setting", boost::bind (SetColorReadExpectation, _1, _2), boost::bind (SetColorWriteExpectation, _1, _2, _3, _4, _5, _6), "TestColor"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (impl::keyValue), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, TypeKey, "key_setting", boost::bind (SetKeyReadExpectation, _1, _2), boost::bind (SetKeyWriteExpectation, _1, _2, _3, _4, _5, _6), "TestKey"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (impl::buttonValue), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, TypeButton, "button_setting", boost::bind (SetButtonReadExpectation, _1, _2), boost::bind (SetButtonWriteExpectation, _1, _2, _3, _4, _5, _6), "TestButton"), - boost::make_shared (backendEnv, + boost::make_shared (backendEnvFactory, VariantTypes (static_cast (1)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, backendEnv, _1, _2, _3), + &CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, TypeEdge, "edge_setting", boost::bind (SetEdgeReadExpectation, _1, _2), boost::bind (SetEdgeWriteExpectation, _1, _2, _3, _4, _5, _6), "TestEdge"), - boost::make_shared (backendEnv, - VariantTypes (boost::make_shared (ccsGetValueListFromIntArray (impl::intValues, - sizeof (impl::intValues) / sizeof (impl::intValues[0]), - NULL), false, TypeInt)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromIntArray, + impl::intValues, + sizeof (impl::intValues) / sizeof (impl::intValues[0]), _1), + TypeInt, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "int_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListInt"), - boost::make_shared (backendEnv, - VariantTypes (boost::make_shared (ccsGetValueListFromFloatArray (impl::floatValues, - sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), - NULL), false, TypeFloat)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromFloatArray, + impl::floatValues, + sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), _1), + TypeFloat, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "float_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), - "TestListInt"), - boost::make_shared (backendEnv, - VariantTypes (boost::make_shared (ccsGetValueListFromBoolArray (impl::boolValues, - sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), - NULL), false, TypeBool)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + "TestListFloat"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromBoolArray, + impl::boolValues, + sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), _1), + TypeBool, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "bool_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListBool"), - boost::make_shared (backendEnv, - VariantTypes (boost::make_shared (ccsGetValueListFromStringArray (impl::stringValues, - sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), - NULL), false, TypeString)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromStringArray, + impl::stringValues, + sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), _1), + TypeString, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "string_list_setting", boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListString"), - boost::make_shared (backendEnv, - VariantTypes (boost::make_shared (ccsGetValueListFromColorArray (impl::colorValues, - sizeof (impl::colorValues) / sizeof (impl::colorValues[0]), - NULL), false, TypeColor)), - boost::bind (&CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, backendEnv, _1, _2, _3), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromColorArray, + impl::getColorValueList (), + impl::NUM_COLOR_VALUES, _1), + TypeColor, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "color_list_setting", boost::bind (SetListReadExpectation, _1, _2), @@ -856,11 +1060,11 @@ class CCSBackendConformanceTestReadWrite : settingName = GetParam ()->keyname (); VALUE = GetParam ()->value (); - CCSBackendConformanceTest::SpawnPlugin (pluginName, context, &plugin); - CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, &setting); + CCSBackendConformanceTest::SpawnPlugin (pluginName, context, plugin); + CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, setting); - gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin); - gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin.get ()); + gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); } virtual void TearDown () @@ -873,8 +1077,8 @@ class CCSBackendConformanceTestReadWrite : std::string pluginName; std::string settingName; VariantTypes VALUE; - CCSPlugin *plugin; - CCSSetting *setting; + boost::shared_ptr plugin; + boost::shared_ptr setting; CCSPluginGMock *gmockPlugin; CCSSettingGMock *gmockSetting; @@ -885,11 +1089,41 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->nativeWrite () (pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + pluginName, settingName, VALUE); CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); - ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context, setting); + ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context.get (), setting.get ()); +} + +TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) +{ + SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "UpdateMocked"); + + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + + ccsBackendUpdateSetting (CCSBackendConformanceTest::GetBackend (), context.get (), plugin.get (), setting.get ()); +} + +TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) +{ + SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "UpdateMocked"); + + CCSBackendConformanceTest::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + pluginName, settingName, VALUE); + CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + + EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (setting.get ())); + + EXPECT_TRUE (CCSBackendConformanceTest::GetParam ()->testEnv ()->UpdateSettingAtKey (pluginName, settingName)); } TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) @@ -898,18 +1132,19 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, - settingName, - VALUE, - setting, - boost::bind (ccsBackendWriteSetting, - CCSBackendConformanceTest::GetBackend (), - context, - setting), - GetParam ()->testEnv ()); + settingName, + VALUE, + setting, + boost::bind (ccsBackendWriteSetting, + CCSBackendConformanceTest::GetBackend (), + context.get (), + setting.get ()), + GetParam ()->testEnv ()); CCSBackendConformanceTest::GetParam ()->testEnv ()->PostWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); } + #endif -- GitLab From 1d9f994adb99fb003920d57d4a558108a1a32042 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 05:39:35 +0800 Subject: [PATCH 152/562] Pass the backend to all of the backend specific functions --- compizconfig/gconf/src/gconf.c | 47 ++++++++++--------- .../gsettings/src/gconf-integration.c | 12 ++--- compizconfig/gsettings/src/gsettings.c | 33 +++++++------ compizconfig/gsettings/src/gsettings.h | 6 +-- .../libcompizconfig/backend/src/ini.c | 32 +++++++------ .../libcompizconfig/include/ccs-backend.h | 26 +++++----- compizconfig/libcompizconfig/src/main.c | 28 +++++------ 7 files changed, 97 insertions(+), 87 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index fe449bb8a..75d969726 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -89,10 +89,10 @@ static guint gnomeNotifyIds[NUM_WATCHED_DIRS]; static char *currentProfile = NULL; /* some forward declarations */ -static Bool readInit (CCSContext * context); -static void readSetting (CCSContext * context, CCSSetting * setting); +static Bool readInit (CCSBackend *backend, CCSContext * context); +static void readSetting (CCSBackend *backend, CCSContext * context, CCSSetting * setting); static Bool readOption (CCSSetting * setting); -static Bool writeInit (CCSContext * context); +static Bool writeInit (CCSBackend *backend, CCSContext * context); static void writeIntegratedOption (CCSContext *context, CCSSetting *setting, int index); @@ -439,14 +439,14 @@ static void updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { int index; - readInit (context); + readInit (backend, context); if (!readOption (setting)) ccsResetToDefault (setting, TRUE); if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (context); + writeInit (backend, context); writeIntegratedOption (context, setting, index); } } @@ -551,24 +551,24 @@ gnomeValueChanged (GConfClient *client, if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } s = findDisplaySettingForPlugin (context, "core", "window_menu_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "move", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "resize", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); } else { @@ -587,10 +587,10 @@ gnomeValueChanged (GConfClient *client, { if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } - readSetting (context, setting); + readSetting (NULL, context, setting); } /* do not read display settings multiple @@ -1949,7 +1949,7 @@ checkProfile (CCSContext *context) } static void -processEvents (unsigned int flags) +processEvents (CCSBackend *backend, unsigned int flags) { if (!(flags & ProcessEventsNoGlibMainLoopMask)) { @@ -1959,7 +1959,7 @@ processEvents (unsigned int flags) } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { g_type_init (); @@ -1972,7 +1972,7 @@ initBackend (CCSContext * context) } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend *backend, CCSContext * context) { gconf_client_clear_cache (client); finiClient (); @@ -1990,13 +1990,14 @@ finiBackend (CCSContext * context) } static Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, CCSContext * context) { return checkProfile (context); } static void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status; @@ -2015,13 +2016,14 @@ readSetting (CCSContext *context, } static Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { return checkProfile (context); } static void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { int index; @@ -2041,7 +2043,7 @@ writeSetting (CCSContext *context, } static Bool -getSettingIsIntegrated (CCSSetting * setting) +getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { if (!ccsGetIntegrationEnabled (ccsPluginGetContext (ccsSettingGetParent (setting)))) return FALSE; @@ -2053,14 +2055,14 @@ getSettingIsIntegrated (CCSSetting * setting) } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; } static CCSStringList -getExistingProfiles (CCSContext *context) +getExistingProfiles (CCSBackend *backend, CCSContext *context) { GSList *data, *tmp; CCSStringList ret = NULL; @@ -2098,7 +2100,8 @@ getExistingProfiles (CCSContext *context) } static Bool -deleteProfile (CCSContext *context, +deleteProfile (CCSBackend *backend, + CCSContext *context, char *profile) { char path[BUFSIZE]; diff --git a/compizconfig/gsettings/src/gconf-integration.c b/compizconfig/gsettings/src/gconf-integration.c index b13ffa6f8..ebc74cd97 100644 --- a/compizconfig/gsettings/src/gconf-integration.c +++ b/compizconfig/gsettings/src/gconf-integration.c @@ -405,24 +405,24 @@ gnomeGConfValueChanged (GConfClient *client, if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } s = findDisplaySettingForPlugin (context, "core", "window_menu_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "move", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); s = findDisplaySettingForPlugin (context, "resize", "initiate_button"); if (s) - readSetting (context, s); + readSetting (NULL, context, s); } else { @@ -441,10 +441,10 @@ gnomeGConfValueChanged (GConfClient *client, { if (needInit) { - readInit (context); + readInit (NULL, context); needInit = FALSE; } - readSetting (context, setting); + readSetting (NULL, context, setting); } /* do not read display settings multiple diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 2c5004d8b..ff9960eb8 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -133,7 +133,7 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS { int index; - readInit (context); + readInit (backend, context); if (!readOption (setting)) { ccsResetToDefault (setting, TRUE); @@ -142,7 +142,7 @@ updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSS if (ccsGetIntegrationEnabled (context) && isIntegratedOption (setting, &index)) { - writeInit (context); + writeInit (backend, context); writeIntegratedOption (context, setting, index); } } @@ -892,7 +892,7 @@ getCurrentProfileName (void) } static void -processEvents (unsigned int flags) +processEvents (CCSBackend *backend, unsigned int flags) { if (!(flags & ProcessEventsNoGlibMainLoopMask)) { @@ -902,7 +902,7 @@ processEvents (unsigned int flags) } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { char *currentProfilePath; @@ -924,11 +924,11 @@ initBackend (CCSContext * context) } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend *backend, CCSContext * context) { GList *l = settingsList; - processEvents (0); + processEvents (backend, 0); #ifdef USE_GCONF gconf_client_clear_cache (client); @@ -955,18 +955,19 @@ finiBackend (CCSContext * context) g_object_unref (G_OBJECT (compizconfigSettings)); - processEvents (0); + processEvents (backend, 0); return TRUE; } Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, CCSContext * context) { return updateProfile (context); } void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status; @@ -985,13 +986,14 @@ readSetting (CCSContext *context, } Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { return updateProfile (context); } void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { int index; @@ -1011,7 +1013,7 @@ writeSetting (CCSContext *context, } static Bool -getSettingIsIntegrated (CCSSetting * setting) +getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { if (!ccsGetIntegrationEnabled (ccsPluginGetContext (ccsSettingGetParent (setting)))) return FALSE; @@ -1023,14 +1025,14 @@ getSettingIsIntegrated (CCSSetting * setting) } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; } static CCSStringList -getExistingProfiles (CCSContext *context) +getExistingProfiles (CCSBackend *backend, CCSContext *context) { GVariant *value; char *profile; @@ -1054,7 +1056,8 @@ getExistingProfiles (CCSContext *context) } static Bool -deleteProfile (CCSContext *context, +deleteProfile (CCSBackend *backend, + CCSContext *context, char *profile) { GVariant *plugins; diff --git a/compizconfig/gsettings/src/gsettings.h b/compizconfig/gsettings/src/gsettings.h index 4ac1c7cc7..000a4dbca 100644 --- a/compizconfig/gsettings/src/gsettings.h +++ b/compizconfig/gsettings/src/gsettings.h @@ -66,10 +66,10 @@ typedef enum { char *currentProfile; -Bool readInit (CCSContext * context); -void readSetting (CCSContext * context, CCSSetting * setting); +Bool readInit (CCSBackend *, CCSContext * context); +void readSetting (CCSBackend *, CCSContext * context, CCSSetting * setting); Bool readOption (CCSSetting * setting); -Bool writeInit (CCSContext * context); +Bool writeInit (CCSBackend *, CCSContext * context); void writeOption (CCSSetting *setting); #ifdef USE_GCONF diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 8badf3dd6..283201fe5 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -180,7 +180,7 @@ setProfile (IniPrivData *data, } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { IniPrivData *newData; @@ -197,7 +197,8 @@ initBackend (CCSContext * context) } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend * backend, + CCSContext * context) { IniPrivData *data; @@ -229,7 +230,8 @@ finiBackend (CCSContext * context) } static Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, + CCSContext * context) { char *currentProfile; IniPrivData *data; @@ -258,7 +260,8 @@ readInit (CCSContext * context) } static void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status = FALSE; @@ -414,12 +417,12 @@ readSetting (CCSContext *context, } static void -readDone (CCSContext * context) +readDone (CCSBackend *backend, CCSContext * context) { } static Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { char *currentProfile; IniPrivData *data; @@ -450,7 +453,8 @@ writeInit (CCSContext * context) } static void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { char *keyName; @@ -569,7 +573,7 @@ writeSetting (CCSContext *context, } static void -writeDone (CCSContext * context) +writeDone (CCSBackend *backend, CCSContext * context) { /* export the data to ensure the changes are on disk */ char *fileName; @@ -601,15 +605,15 @@ writeDone (CCSContext * context) static void updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { - if (readInit (context)) + if (readInit (backend, context)) { - readSetting (context, setting); - readDone (context); + readSetting (backend, context, setting); + readDone (backend, context); } } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; @@ -662,7 +666,7 @@ scanConfigDir (char * filePath) } static CCSStringList -getExistingProfiles (CCSContext * context) +getExistingProfiles (CCSBackend *backend, CCSContext * context) { CCSStringList ret = NULL; char *filePath = NULL; @@ -699,7 +703,7 @@ getExistingProfiles (CCSContext * context) } static Bool -deleteProfile (CCSContext * context, char * profile) +deleteProfile (CCSBackend *backend, CCSContext * context, char * profile) { char *fileName; diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index de302b431..d6948bf88 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -40,28 +40,28 @@ struct _CCSBackend typedef CCSBackendInterface * (*BackendGetInfoProc) (void); -typedef void (*CCSBackendExecuteEventsFunc) (unsigned int flags); +typedef void (*CCSBackendExecuteEventsFunc) (CCSBackend *backend, unsigned int flags); -typedef Bool (*CCSBackendInitFunc) (CCSContext * context); -typedef Bool (*CCSBackendFiniFunc) (CCSContext * context); +typedef Bool (*CCSBackendInitFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendFiniFunc) (CCSBackend *, CCSContext * context); -typedef Bool (*CCSBackendReadInitFunc) (CCSContext * context); +typedef Bool (*CCSBackendReadInitFunc) (CCSBackend *, CCSContext * context); typedef void (*CCSBackendReadSettingFunc) -(CCSContext * context, CCSSetting * setting); -typedef void (*CCSBackendReadDoneFunc) (CCSContext * context); +(CCSBackend *, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendReadDoneFunc) (CCSBackend *backend, CCSContext * context); -typedef Bool (*CCSBackendWriteInitFunc) (CCSContext * context); +typedef Bool (*CCSBackendWriteInitFunc) (CCSBackend *backend, CCSContext * context); typedef void (*CCSBackendWriteSettingFunc) -(CCSContext * context, CCSSetting * setting); -typedef void (*CCSBackendWriteDoneFunc) (CCSContext * context); +(CCSBackend *backend, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendWriteDoneFunc) (CCSBackend *backend, CCSContext * context); typedef void (*CCSBackendUpdateFunc) (CCSBackend *, CCSContext *, CCSPlugin *, CCSSetting *); -typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSSetting * setting); -typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSBackend *, CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSBackend *, CCSSetting * setting); -typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSContext * context); -typedef Bool (*CCSBackendDeleteProfileFunc) (CCSContext * context, char * name); +typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendDeleteProfileFunc) (CCSBackend *, CCSContext * context, char * name); typedef char * (*CCSBackendGetNameFunc) (CCSBackend *); typedef char * (*CCSBackendGetShortDescFunc) (CCSBackend *); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index bb6b172c0..defb60e11 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1177,7 +1177,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; if (backendInit) - (*backendInit) (context); + (*backendInit) (backend, context); ccsDisableFileWatch (cPrivate->configWatchId); if (!fallbackMode) @@ -1225,17 +1225,17 @@ Bool ccsBackendHasExecuteEvents (CCSBackend *backend) void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags) { - (*(GET_INTERFACE (CCSBackendInterface, backend))->executeEvents) (flags); + (*(GET_INTERFACE (CCSBackendInterface, backend))->executeEvents) (backend, flags); } Bool ccsBackendInit (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendInit) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendInit) (backend, context); } Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (backend, context); } Bool ccsBackendHasReadInit (CCSBackend *backend) @@ -1245,7 +1245,7 @@ Bool ccsBackendHasReadInit (CCSBackend *backend) Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->readInit) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readInit) (backend, context); } Bool ccsBackendHasReadSetting (CCSBackend *backend) @@ -1255,7 +1255,7 @@ Bool ccsBackendHasReadSetting (CCSBackend *backend) void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - (*(GET_INTERFACE (CCSBackendInterface, backend))->readSetting) (context, setting); + (*(GET_INTERFACE (CCSBackendInterface, backend))->readSetting) (backend, context, setting); } Bool ccsBackendHasReadDone (CCSBackend *backend) @@ -1265,7 +1265,7 @@ Bool ccsBackendHasReadDone (CCSBackend *backend) void ccsBackendReadDone (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->readDone) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readDone) (backend, context); } Bool ccsBackendHasWriteInit (CCSBackend *backend) @@ -1275,7 +1275,7 @@ Bool ccsBackendHasWriteInit (CCSBackend *backend) Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeInit) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeInit) (backend, context); } Bool ccsBackendHasWriteSetting (CCSBackend *backend) @@ -1285,7 +1285,7 @@ Bool ccsBackendHasWriteSetting (CCSBackend *backend) void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - (*(GET_INTERFACE (CCSBackendInterface, backend))->writeSetting) (context, setting); + (*(GET_INTERFACE (CCSBackendInterface, backend))->writeSetting) (backend, context, setting); } Bool ccsBackendHasWriteDone (CCSBackend *backend) @@ -1295,7 +1295,7 @@ Bool ccsBackendHasWriteDone (CCSBackend *backend) void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); } void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) @@ -1310,7 +1310,7 @@ Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated) (setting); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated) (backend, setting); } Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) @@ -1320,7 +1320,7 @@ Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly) (setting); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly) (backend, setting); } Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) @@ -1330,7 +1330,7 @@ Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles) (context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles) (backend, context); } Bool ccsBackendHasDeleteProfile (CCSBackend *backend) @@ -1340,7 +1340,7 @@ Bool ccsBackendHasDeleteProfile (CCSBackend *backend) Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (context, name); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (backend, context, name); } static Bool -- GitLab From ab89bc2425977c83f8273760b6d774d966d0b81e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 08:40:43 +0800 Subject: [PATCH 153/562] Remove fellback arg from ccsOpenBackend, make falling back the caller's problem --- .../libcompizconfig/include/ccs-backend.h | 2 +- compizconfig/libcompizconfig/src/main.c | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index d6948bf88..846322ec1 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -139,7 +139,7 @@ void ccsFreeBackend (CCSBackend *backend); /* Backend opener method */ void * -ccsOpenBackend (const char *name, CCSBackendInterface **interface, Bool *fellback); +ccsOpenBackend (const char *name, CCSBackendInterface **interface); /* Constructor method */ CCSBackend * diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index defb60e11..af4fe6d90 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1115,15 +1115,9 @@ ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *inte } void * -ccsOpenBackend (const char *name, CCSBackendInterface **vt, Bool *fellback) +ccsOpenBackend (const char *name, CCSBackendInterface **vt) { void *dlhand = openBackend (name); - if (!dlhand) - { - *fellback = TRUE; - name = "ini"; - dlhand = openBackend (name); - } if (!dlhand) return NULL; @@ -1165,10 +1159,21 @@ ccsSetBackendDefault (CCSContext * context, char *name) CCSBackendInterface *vt = NULL; - void *dlhand = ccsOpenBackend (name, &vt, &fallbackMode); + void *dlhand = ccsOpenBackend (name, &vt); if (!dlhand) - return FALSE; + { + ccsWarning ("unable to open backend %s, falling back to ini", name); + + dlhand = ccsOpenBackend ("ini", &vt); + if (!dlhand) + { + ccsError ("failed to open any backends, aborting"); + abort (); + } + + fallbackMode = TRUE; + } CCSBackend *backend = ccsBackendNewWithInterface (context, vt, dlhand); -- GitLab From 3110a92f6d23a57766a2e0d79258d1e4eb3d946b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 08:43:34 +0800 Subject: [PATCH 154/562] Rename ccsBackendNewWithInterface to ccsBackendNewWithDynamicInterface --- compizconfig/libcompizconfig/include/ccs-backend.h | 2 +- compizconfig/libcompizconfig/src/main.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 846322ec1..0835c1de2 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -143,7 +143,7 @@ ccsOpenBackend (const char *name, CCSBackendInterface **interface); /* Constructor method */ CCSBackend * -ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); +ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); CCSBackendInterface* getBackendInfo (void); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index af4fe6d90..ddb2e0d6c 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1086,7 +1086,7 @@ ccsFreeBackend (CCSBackend *backend) } CCSBackend * -ccsBackendNewWithInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand) +ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand) { CCSBackend *backend = calloc (1, sizeof (CCSBackend)); CCSBackendPrivate *bPrivate = NULL; @@ -1175,7 +1175,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) fallbackMode = TRUE; } - CCSBackend *backend = ccsBackendNewWithInterface (context, vt, dlhand); + CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt, dlhand); cPrivate->backend = backend; -- GitLab From de0993538898257aea63bdaeeff7f973adcd7b3a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 08:55:51 +0800 Subject: [PATCH 155/562] Make loading and unloading the backend library the responsibility of CCSBackendWithCapabilities --- .../libcompizconfig/include/ccs-backend.h | 2 +- .../libcompizconfig/src/ccs-private.h | 2 +- compizconfig/libcompizconfig/src/main.c | 22 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 71863a6ba..ffb9241af 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -163,7 +163,7 @@ ccsOpenBackend (const char *name, CCSBackendInterface **interface); /* Constructor method */ CCSBackend * -ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); +ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface); CCSBackendInterface* getBackendInfo (void); diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 7a93dcb83..72ec343a1 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -126,13 +126,13 @@ typedef struct _CCSSettingPrivate struct _CCSBackendPrivate { - void *dlhand; CCSContext *context; CCSBackendInterface *vTable; }; typedef struct _CCSBackendWithCapabilitiesPrivate { + void *dlhand; CCSBackend *backend; } CCSBackendWithCapabilitiesPrivate; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 2c7424e23..f1ff9e821 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1067,11 +1067,11 @@ openBackend (const char *backend) } void * -ccsBackendGetDlHand (CCSBackend *backend) +ccsBackendWithCapabilitiesGetDlHand (CCSBackend *backend) { - BACKEND_PRIV (backend); + CAPABILITIES_PRIV (backend); - return bPrivate->dlhand; + return bcPrivate->dlhand; } void @@ -1081,9 +1081,6 @@ ccsFreeBackend (CCSBackend *backend) ccsBackendFini (backend, bPrivate->context); - if (bPrivate->dlhand) - dlclose (bPrivate->dlhand); - ccsObjectFinalize (backend); free (backend); } @@ -1095,12 +1092,15 @@ ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *backendCapabilities) ccsBackendUnref (bcPrivate->backend); + if (bcPrivate->dlhand) + dlclose (bcPrivate->dlhand); + ccsObjectFinalize (backendCapabilities); free (backendCapabilities); } CCSBackend * -ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand) +ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface) { CCSBackend *backend = calloc (1, sizeof (CCSBackend)); @@ -1120,7 +1120,6 @@ ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterfac return NULL; } - bPrivate->dlhand = dlhand; bPrivate->context = context; ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); @@ -1130,7 +1129,7 @@ ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterfac } CCSBackendWithCapabilities * -ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend) +ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand) { CCSBackendWithCapabilities *backendCapabilities = calloc (1, sizeof (CCSBackendWithCapabilities)); CCSBackendWithCapabilitiesPrivate *bcPrivate = NULL; @@ -1149,6 +1148,7 @@ ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSB return NULL; } + bcPrivate->dlhand = dlhand; bcPrivate->backend = backend; ccsObjectSetPrivate (backendCapabilities, (CCSPrivate *) bcPrivate); @@ -1219,7 +1219,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) fallbackMode = TRUE; } - CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt, dlhand); + CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt); if (!backend) { @@ -1227,7 +1227,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) return FALSE; } - CCSBackendWithCapabilities *backendWrapper = ccsBackendWithCapabilitiesWrapBackend (cPrivate->object_interfaces, backend); + CCSBackendWithCapabilities *backendWrapper = ccsBackendWithCapabilitiesWrapBackend (cPrivate->object_interfaces, backend, dlhand); if (!backendWrapper) { -- GitLab From dbece4823c179cd2f9e10c432285bfdf9af88139 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 09:00:07 +0800 Subject: [PATCH 156/562] Rename ccsBackendWithCapabilities to ccsDynamicBackend --- .../libcompizconfig/include/ccs-backend.h | 24 +++++------ .../libcompizconfig/src/ccs-private.h | 8 ++-- compizconfig/libcompizconfig/src/main.c | 42 +++++++++---------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index ffb9241af..5aa85da10 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -126,19 +126,19 @@ CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *co Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name); void ccsFreeBackend (CCSBackend *backend); -typedef struct _CCSBackendWithCapabilities CCSBackendWithCapabilities; -typedef struct _CCSBackendWithCapabilitiesPrivate CCSBackendWithCapabilitiesPrivate; +typedef struct _CCSDynamicBackend CCSDynamicBackend; +typedef struct _CCSDynamicBackendPrivate CCSDynamicBackendPrivate; typedef struct _CCSBackendCapabilitiesInterface CCSBackendCapabilitiesInterface; -struct _CCSBackendWithCapabilities +struct _CCSDynamicBackend { CCSObject object; }; -typedef Bool (*CCSBackendCapabilitiesSupportsRead) (CCSBackendWithCapabilities *); -typedef Bool (*CCSBackendCapabilitiesSupportsWrite) (CCSBackendWithCapabilities *); -typedef Bool (*CCSBackendCapabilitiesSupportsProfiles) (CCSBackendWithCapabilities *); -typedef Bool (*CCSBackendCapabilitiesSupportsIntegration) (CCSBackendWithCapabilities *); +typedef Bool (*CCSBackendCapabilitiesSupportsRead) (CCSDynamicBackend *); +typedef Bool (*CCSBackendCapabilitiesSupportsWrite) (CCSDynamicBackend *); +typedef Bool (*CCSBackendCapabilitiesSupportsProfiles) (CCSDynamicBackend *); +typedef Bool (*CCSBackendCapabilitiesSupportsIntegration) (CCSDynamicBackend *); struct _CCSBackendCapabilitiesInterface { @@ -148,14 +148,14 @@ struct _CCSBackendCapabilitiesInterface CCSBackendCapabilitiesSupportsIntegration supportsIntegration; }; -Bool ccsBackendCapabilitiesSupportsRead (CCSBackendWithCapabilities *); -Bool ccsBackendCapabilitiesSupportsWrite (CCSBackendWithCapabilities *); -Bool ccsBackendCapabilitiesSupportsProfiles (CCSBackendWithCapabilities *); -Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *); +Bool ccsBackendCapabilitiesSupportsRead (CCSDynamicBackend *); +Bool ccsBackendCapabilitiesSupportsWrite (CCSDynamicBackend *); +Bool ccsBackendCapabilitiesSupportsProfiles (CCSDynamicBackend *); +Bool ccsBackendCapabilitiesSupportsIntegration (CCSDynamicBackend *); unsigned int ccsCCSBackendCapabilitiesInterfaceGetType (); -void ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *); +void ccsFreeDynamicBackend (CCSDynamicBackend *); /* Backend opener method */ void * diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 72ec343a1..3e934f1ab 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -34,13 +34,13 @@ #define BACKEND_PRIV(b) \ CCSBackendPrivate *bPrivate = (CCSBackendPrivate *) ccsObjectGetPrivate (b); #define CAPABILITIES_PRIV(bc) \ - CCSBackendWithCapabilitiesPrivate *bcPrivate = (CCSBackendWithCapabilitiesPrivate *) ccsObjectGetPrivate (bc); + CCSDynamicBackendPrivate *bcPrivate = (CCSDynamicBackendPrivate *) ccsObjectGetPrivate (bc); extern Bool basicMetadata; typedef struct _CCSContextPrivate { - CCSBackendWithCapabilities *backend; + CCSDynamicBackend *backend; CCSPluginList plugins; /* list of plugins settings were loaded for */ CCSPluginCategory *categories; /* list of plugin categories */ @@ -130,11 +130,11 @@ struct _CCSBackendPrivate CCSBackendInterface *vTable; }; -typedef struct _CCSBackendWithCapabilitiesPrivate +typedef struct _CCSDynamicBackendPrivate { void *dlhand; CCSBackend *backend; -} CCSBackendWithCapabilitiesPrivate; +} CCSDynamicBackendPrivate; typedef struct _CCSSettingsUpgrade { diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index f1ff9e821..1a7ebc850 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1011,7 +1011,7 @@ CCSREF (StrExtension, CCSStrExtension) CCSREF_OBJ (Plugin, CCSPlugin) CCSREF_OBJ (Setting, CCSSetting) CCSREF_OBJ (Backend, CCSBackend) -CCSREF_OBJ (BackendWithCapabilities, CCSBackendWithCapabilities) +CCSREF_OBJ (DynamicBackend, CCSDynamicBackend) static void * openBackend (const char *backend) @@ -1067,7 +1067,7 @@ openBackend (const char *backend) } void * -ccsBackendWithCapabilitiesGetDlHand (CCSBackend *backend) +ccsDynamicBackendGetDlHand (CCSBackend *backend) { CAPABILITIES_PRIV (backend); @@ -1086,7 +1086,7 @@ ccsFreeBackend (CCSBackend *backend) } void -ccsFreeBackendWithCapabilities (CCSBackendWithCapabilities *backendCapabilities) +ccsFreeDynamicBackend (CCSDynamicBackend *backendCapabilities) { CAPABILITIES_PRIV (backendCapabilities); @@ -1128,23 +1128,23 @@ ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterfac return backend; } -CCSBackendWithCapabilities * -ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand) +CCSDynamicBackend * +ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand) { - CCSBackendWithCapabilities *backendCapabilities = calloc (1, sizeof (CCSBackendWithCapabilities)); - CCSBackendWithCapabilitiesPrivate *bcPrivate = NULL; + CCSDynamicBackend *backendCapabilities = calloc (1, sizeof (CCSDynamicBackend)); + CCSDynamicBackendPrivate *bcPrivate = NULL; if (!backendCapabilities) return NULL; ccsObjectInit (backendCapabilities, &ccsDefaultObjectAllocator); - ccsBackendWithCapabilitiesRef (backendCapabilities); + ccsDynamicBackendRef (backendCapabilities); - bcPrivate = calloc (1, sizeof (CCSBackendWithCapabilitiesPrivate)); + bcPrivate = calloc (1, sizeof (CCSDynamicBackendPrivate)); if (!bcPrivate) { - ccsBackendWithCapabilitiesUnref (backendCapabilities); + ccsDynamicBackendUnref (backendCapabilities); return NULL; } @@ -1197,7 +1197,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) if (strcmp (ccsBackendGetName ((CCSBackend *) cPrivate->backend), name) == 0) return TRUE; - ccsBackendWithCapabilitiesUnref (cPrivate->backend); + ccsDynamicBackendUnref (cPrivate->backend); cPrivate->backend = NULL; } @@ -1227,7 +1227,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) return FALSE; } - CCSBackendWithCapabilities *backendWrapper = ccsBackendWithCapabilitiesWrapBackend (cPrivate->object_interfaces, backend, dlhand); + CCSDynamicBackend *backendWrapper = ccsDynamicBackendWrapLoadedBackend (cPrivate->object_interfaces, backend, dlhand); if (!backendWrapper) { @@ -1282,29 +1282,29 @@ Bool ccsBackendHasProfileSupport (CCSBackend *backend) } static Bool -ccsBackendCapabilitiesSupportsIntegrationDefault (CCSBackendWithCapabilities *capabilities) +ccsBackendCapabilitiesSupportsIntegrationDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); return ccsBackendHasIntegrationSupport (bcPrivate->backend); } -Bool ccsBackendCapabilitiesSupportsRead (CCSBackendWithCapabilities *capabilities) +Bool ccsBackendCapabilitiesSupportsRead (CCSDynamicBackend *capabilities) { return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsRead) (capabilities); } -Bool ccsBackendCapabilitiesSupportsWrite (CCSBackendWithCapabilities *capabilities) +Bool ccsBackendCapabilitiesSupportsWrite (CCSDynamicBackend *capabilities) { return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsWrite) (capabilities); } -Bool ccsBackendCapabilitiesSupportsProfiles (CCSBackendWithCapabilities *capabilities) +Bool ccsBackendCapabilitiesSupportsProfiles (CCSDynamicBackend *capabilities) { return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsProfiles) (capabilities); } -Bool ccsBackendCapabilitiesSupportsIntegration (CCSBackendWithCapabilities *capabilities) +Bool ccsBackendCapabilitiesSupportsIntegration (CCSDynamicBackend *capabilities) { return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsIntegration) (capabilities); } @@ -1440,7 +1440,7 @@ Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *na } static Bool -ccsBackendCapabilitiesSupportsReadDefault (CCSBackendWithCapabilities *capabilities) +ccsBackendCapabilitiesSupportsReadDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); @@ -1448,7 +1448,7 @@ ccsBackendCapabilitiesSupportsReadDefault (CCSBackendWithCapabilities *capabilit } static Bool -ccsBackendCapabilitiesSupportsWriteDefault (CCSBackendWithCapabilities *capabilities) +ccsBackendCapabilitiesSupportsWriteDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); @@ -1456,7 +1456,7 @@ ccsBackendCapabilitiesSupportsWriteDefault (CCSBackendWithCapabilities *capabili } static Bool -ccsBackendCapabilitiesSupportsProfilesDefault (CCSBackendWithCapabilities *capabilities) +ccsBackendCapabilitiesSupportsProfilesDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); @@ -2805,7 +2805,7 @@ ccsContextDestroy (CCSContext * context) if (cPrivate->backend) { - ccsBackendWithCapabilitiesUnref (cPrivate->backend); + ccsDynamicBackendUnref (cPrivate->backend); cPrivate->backend = NULL; } -- GitLab From adc2172c45bc618e63d2a6ad088b7a53969f201d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 09:09:40 +0800 Subject: [PATCH 157/562] Eliminate CCSBackendPrivate - private data is the responsibility of the backend itself --- compizconfig/gconf/src/gconf.c | 2 +- compizconfig/gsettings/src/gsettings.c | 2 +- .../libcompizconfig/backend/src/ini.c | 52 ++++--------------- .../libcompizconfig/include/ccs-backend.h | 5 +- .../libcompizconfig/src/ccs-private.h | 6 --- compizconfig/libcompizconfig/src/main.c | 28 ++-------- 6 files changed, 20 insertions(+), 75 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index 75d969726..c4828b2f2 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -1972,7 +1972,7 @@ initBackend (CCSBackend *backend, CCSContext * context) } static Bool -finiBackend (CCSBackend *backend, CCSContext * context) +finiBackend (CCSBackend *backend) { gconf_client_clear_cache (client); finiClient (); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index ff9960eb8..c51d72dcc 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -924,7 +924,7 @@ initBackend (CCSBackend *backend, CCSContext * context) } static Bool -finiBackend (CCSBackend *backend, CCSContext * context) +finiBackend (CCSBackend *backend) { GList *l = settingsList; diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 283201fe5..c459be91a 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -50,29 +50,9 @@ typedef struct _IniPrivData IniPrivData; -static IniPrivData *privData = NULL; - -static int privDataSize = 0; - /* forward declaration */ static void setProfile (IniPrivData *data, char *profile); -static IniPrivData* -findPrivFromContext (CCSContext *context) -{ - int i; - IniPrivData *data; - - for (i = 0, data = privData; i < privDataSize; i++, data++) - if (data->context == context) - break; - - if (i == privDataSize) - return NULL; - - return data; -} - static char* getIniFileName (char *profile) { @@ -184,25 +164,22 @@ initBackend (CCSBackend *backend, CCSContext * context) { IniPrivData *newData; - privData = realloc (privData, (privDataSize + 1) * sizeof (IniPrivData)); - newData = privData + privDataSize; + newData = calloc (1, sizeof (IniPrivData)); /* initialize the newly allocated part */ - memset (newData, 0, sizeof (IniPrivData)); newData->context = context; - privDataSize++; + ccsObjectSetPrivate (backend, (CCSPrivate *) newData); return TRUE; } static Bool -finiBackend (CCSBackend * backend, - CCSContext * context) +finiBackend (CCSBackend * backend) { IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return FALSE; @@ -216,15 +193,8 @@ finiBackend (CCSBackend * backend, if (data->lastProfile) free (data->lastProfile); - privDataSize--; - - if (privDataSize) - privData = realloc (privData, privDataSize * sizeof (IniPrivData)); - else - { - free (privData); - privData = NULL; - } + free (data); + ccsObjectSetPrivate (backend, NULL); return TRUE; } @@ -236,7 +206,7 @@ readInit (CCSBackend *backend, char *currentProfile; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return FALSE; @@ -268,7 +238,7 @@ readSetting (CCSBackend *backend, char *keyName; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return; @@ -427,7 +397,7 @@ writeInit (CCSBackend *backend, CCSContext * context) char *currentProfile; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return FALSE; @@ -460,7 +430,7 @@ writeSetting (CCSBackend *backend, char *keyName; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return; @@ -580,7 +550,7 @@ writeDone (CCSBackend *backend, CCSContext * context) char *currentProfile; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return; diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 5aa85da10..0adca38ea 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -26,7 +26,6 @@ #include typedef struct _CCSBackend CCSBackend; -typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendInterface CCSBackendInterface; typedef struct _CCSContext CCSContext; @@ -43,7 +42,7 @@ typedef CCSBackendInterface * (*BackendGetInfoProc) (void); typedef void (*CCSBackendExecuteEventsFunc) (CCSBackend *backend, unsigned int flags); typedef Bool (*CCSBackendInitFunc) (CCSBackend *, CCSContext * context); -typedef Bool (*CCSBackendFiniFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendFiniFunc) (CCSBackend *); typedef Bool (*CCSBackendReadInitFunc) (CCSBackend *, CCSContext * context); typedef void (*CCSBackendReadSettingFunc) @@ -112,7 +111,7 @@ Bool ccsBackendHasProfileSupport (CCSBackend *backend); void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags); Bool ccsBackendInit (CCSBackend *backend, CCSContext *context); -Bool ccsBackendFini (CCSBackend *backend, CCSContext *context); +Bool ccsBackendFini (CCSBackend *backend); Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context); void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 3e934f1ab..5e7dac9f3 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -124,12 +124,6 @@ typedef struct _CCSSettingPrivate void *privatePtr; /* private pointer for usage by the caller */ } CCSSettingPrivate; -struct _CCSBackendPrivate -{ - CCSContext *context; - CCSBackendInterface *vTable; -}; - typedef struct _CCSDynamicBackendPrivate { void *dlhand; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 1a7ebc850..d9b245ef1 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1077,9 +1077,7 @@ ccsDynamicBackendGetDlHand (CCSBackend *backend) void ccsFreeBackend (CCSBackend *backend) { - BACKEND_PRIV (backend); - - ccsBackendFini (backend, bPrivate->context); + ccsBackendFini (backend); ccsObjectFinalize (backend); free (backend); @@ -1104,25 +1102,9 @@ ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterfac { CCSBackend *backend = calloc (1, sizeof (CCSBackend)); - CCSBackendPrivate *bPrivate = NULL; - - if (!backend) - return NULL; - ccsObjectInit (backend, &ccsDefaultObjectAllocator); ccsBackendRef (backend); - bPrivate = calloc (1, sizeof (CCSBackendPrivate)); - - if (!bPrivate) - { - ccsBackendUnref (backend); - return NULL; - } - - bPrivate->context = context; - - ccsObjectSetPrivate (backend, (CCSPrivate *) bPrivate); ccsObjectAddInterface (backend, (CCSInterface *) interface, GET_INTERFACE_TYPE (CCSBackendInterface)); return backend; @@ -1324,9 +1306,9 @@ Bool ccsBackendInit (CCSBackend *backend, CCSContext *context) return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendInit) (backend, context); } -Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) +Bool ccsBackendFini (CCSBackend *backend) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (backend, context); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (backend); } static Bool ccsBackendHasReadInit (CCSBackend *backend) @@ -1505,11 +1487,11 @@ static Bool ccsBackendCapabilitiesHasProfileSupportWrapper (CCSBackend *backend) return ccsBackendHasProfileSupport (bcPrivate->backend); } -static Bool ccsBackendCapabilitiesFiniWrapper (CCSBackend *backend, CCSContext *context) +static Bool ccsBackendCapabilitiesFiniWrapper (CCSBackend *backend) { CAPABILITIES_PRIV (backend); - return ccsBackendFini (bcPrivate->backend, context); + return ccsBackendFini (bcPrivate->backend); } static void ccsBackendCapabilitiesExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) -- GitLab From aa2211c9aca44fbdc2042dfd79a7584d04b75007 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 09:15:02 +0800 Subject: [PATCH 158/562] BackendCapabilities -> DynamicBackend --- .../libcompizconfig/include/ccs-backend.h | 30 ++-- compizconfig/libcompizconfig/include/ccs.h | 6 +- compizconfig/libcompizconfig/src/main.c | 160 +++++++++--------- 3 files changed, 98 insertions(+), 98 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 0adca38ea..d21f7848d 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -127,32 +127,32 @@ void ccsFreeBackend (CCSBackend *backend); typedef struct _CCSDynamicBackend CCSDynamicBackend; typedef struct _CCSDynamicBackendPrivate CCSDynamicBackendPrivate; -typedef struct _CCSBackendCapabilitiesInterface CCSBackendCapabilitiesInterface; +typedef struct _CCSDynamicBackendInterface CCSDynamicBackendInterface; struct _CCSDynamicBackend { CCSObject object; }; -typedef Bool (*CCSBackendCapabilitiesSupportsRead) (CCSDynamicBackend *); -typedef Bool (*CCSBackendCapabilitiesSupportsWrite) (CCSDynamicBackend *); -typedef Bool (*CCSBackendCapabilitiesSupportsProfiles) (CCSDynamicBackend *); -typedef Bool (*CCSBackendCapabilitiesSupportsIntegration) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsRead) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsWrite) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsProfiles) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsIntegration) (CCSDynamicBackend *); -struct _CCSBackendCapabilitiesInterface +struct _CCSDynamicBackendInterface { - CCSBackendCapabilitiesSupportsRead supportsRead; - CCSBackendCapabilitiesSupportsWrite supportsWrite; - CCSBackendCapabilitiesSupportsProfiles supportsProfiles; - CCSBackendCapabilitiesSupportsIntegration supportsIntegration; + CCSDynamicBackendSupportsRead supportsRead; + CCSDynamicBackendSupportsWrite supportsWrite; + CCSDynamicBackendSupportsProfiles supportsProfiles; + CCSDynamicBackendSupportsIntegration supportsIntegration; }; -Bool ccsBackendCapabilitiesSupportsRead (CCSDynamicBackend *); -Bool ccsBackendCapabilitiesSupportsWrite (CCSDynamicBackend *); -Bool ccsBackendCapabilitiesSupportsProfiles (CCSDynamicBackend *); -Bool ccsBackendCapabilitiesSupportsIntegration (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *); -unsigned int ccsCCSBackendCapabilitiesInterfaceGetType (); +unsigned int ccsCCSDynamicBackendInterfaceGetType (); void ccsFreeDynamicBackend (CCSDynamicBackend *); diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 176c9874a..dcd84ea75 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -128,15 +128,15 @@ typedef struct _CCSInterfaceTable CCSInterfaceTable; typedef struct _CCSContextInterface CCSContextInterface; typedef struct _CCSPluginInterface CCSPluginInterface; typedef struct _CCSSettingInterface CCSSettingInterface; -typedef struct _CCSBackendCapabilitiesInterface CCSBackendCapabilitiesInterface; +typedef struct _CCSDynamicBackendInterface CCSDynamicBackendInterface; struct _CCSInterfaceTable { const CCSContextInterface *contextInterface; const CCSPluginInterface *pluginInterface; const CCSSettingInterface *settingInterface; - const CCSBackendInterface *backendCapabilitiesWrapperInterface; - const CCSBackendCapabilitiesInterface *backendCapabilitiesInterface; + const CCSBackendInterface *dynamicBackendWrapperInterface; + const CCSDynamicBackendInterface *dynamicBackendInterface; }; extern const CCSInterfaceTable ccsDefaultInterfaceTable; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index d9b245ef1..a46afc523 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -232,7 +232,7 @@ INTERFACE_TYPE (CCSContextInterface) INTERFACE_TYPE (CCSPluginInterface) INTERFACE_TYPE (CCSSettingInterface) INTERFACE_TYPE (CCSBackendInterface); -INTERFACE_TYPE (CCSBackendCapabilitiesInterface); +INTERFACE_TYPE (CCSDynamicBackendInterface); Bool basicMetadata = FALSE; @@ -1084,17 +1084,17 @@ ccsFreeBackend (CCSBackend *backend) } void -ccsFreeDynamicBackend (CCSDynamicBackend *backendCapabilities) +ccsFreeDynamicBackend (CCSDynamicBackend *DynamicBackend) { - CAPABILITIES_PRIV (backendCapabilities); + CAPABILITIES_PRIV (DynamicBackend); ccsBackendUnref (bcPrivate->backend); if (bcPrivate->dlhand) dlclose (bcPrivate->dlhand); - ccsObjectFinalize (backendCapabilities); - free (backendCapabilities); + ccsObjectFinalize (DynamicBackend); + free (DynamicBackend); } CCSBackend * @@ -1113,31 +1113,31 @@ ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterfac CCSDynamicBackend * ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand) { - CCSDynamicBackend *backendCapabilities = calloc (1, sizeof (CCSDynamicBackend)); + CCSDynamicBackend *dynamicBackend = calloc (1, sizeof (CCSDynamicBackend)); CCSDynamicBackendPrivate *bcPrivate = NULL; - if (!backendCapabilities) + if (!dynamicBackend) return NULL; - ccsObjectInit (backendCapabilities, &ccsDefaultObjectAllocator); - ccsDynamicBackendRef (backendCapabilities); + ccsObjectInit (dynamicBackend, &ccsDefaultObjectAllocator); + ccsDynamicBackendRef (dynamicBackend); bcPrivate = calloc (1, sizeof (CCSDynamicBackendPrivate)); if (!bcPrivate) { - ccsDynamicBackendUnref (backendCapabilities); + ccsDynamicBackendUnref (dynamicBackend); return NULL; } bcPrivate->dlhand = dlhand; bcPrivate->backend = backend; - ccsObjectSetPrivate (backendCapabilities, (CCSPrivate *) bcPrivate); - ccsObjectAddInterface (backendCapabilities, (CCSInterface *) interfaces->backendCapabilitiesWrapperInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); - ccsObjectAddInterface (backendCapabilities, (CCSInterface *) interfaces->backendCapabilitiesInterface, GET_INTERFACE_TYPE (CCSBackendCapabilitiesInterface)); + ccsObjectSetPrivate (dynamicBackend, (CCSPrivate *) bcPrivate); + ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); + ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendWrapperInterface, GET_INTERFACE_TYPE (CCSDynamicBackendInterface)); - return backendCapabilities; + return dynamicBackend; } void * @@ -1264,31 +1264,31 @@ Bool ccsBackendHasProfileSupport (CCSBackend *backend) } static Bool -ccsBackendCapabilitiesSupportsIntegrationDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); return ccsBackendHasIntegrationSupport (bcPrivate->backend); } -Bool ccsBackendCapabilitiesSupportsRead (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *capabilities) { - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsRead) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsRead) (capabilities); } -Bool ccsBackendCapabilitiesSupportsWrite (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *capabilities) { - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsWrite) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsWrite) (capabilities); } -Bool ccsBackendCapabilitiesSupportsProfiles (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *capabilities) { - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsProfiles) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsProfiles) (capabilities); } -Bool ccsBackendCapabilitiesSupportsIntegration (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *capabilities) { - return (*(GET_INTERFACE (CCSBackendCapabilitiesInterface, capabilities))->supportsIntegration) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsIntegration) (capabilities); } Bool ccsBackendHasExecuteEvents (CCSBackend *backend) @@ -1422,7 +1422,7 @@ Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *na } static Bool -ccsBackendCapabilitiesSupportsReadDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); @@ -1430,7 +1430,7 @@ ccsBackendCapabilitiesSupportsReadDefault (CCSDynamicBackend *capabilities) } static Bool -ccsBackendCapabilitiesSupportsWriteDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsWriteDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); @@ -1438,63 +1438,63 @@ ccsBackendCapabilitiesSupportsWriteDefault (CCSDynamicBackend *capabilities) } static Bool -ccsBackendCapabilitiesSupportsProfilesDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *capabilities) { CAPABILITIES_PRIV (capabilities); return ccsBackendHasProfileSupport (bcPrivate->backend); } -static Bool ccsBackendCapabilitiesInitWrapper (CCSBackend *backend, CCSContext *context) +static Bool ccsDynamicBackendInitWrapper (CCSBackend *backend, CCSContext *context) { CAPABILITIES_PRIV (backend); return ccsBackendInit (bcPrivate->backend, context); } -static char * ccsBackendCapabilitiesGetNameWrapper (CCSBackend *backend) +static char * ccsDynamicBackendGetNameWrapper (CCSBackend *backend) { CAPABILITIES_PRIV (backend); return ccsBackendGetName (bcPrivate->backend); } -static char * ccsBackendCapabilitiesGetShortDescWrapper (CCSBackend *backend) +static char * ccsDynamicBackendGetShortDescWrapper (CCSBackend *backend) { CAPABILITIES_PRIV (backend); return ccsBackendGetShortDesc (bcPrivate->backend); } -static char * ccsBackendCapabilitiesGetLongDescWrapper (CCSBackend *backend) +static char * ccsDynamicBackendGetLongDescWrapper (CCSBackend *backend) { CAPABILITIES_PRIV (backend); return ccsBackendGetName (bcPrivate->backend); } -static Bool ccsBackendCapabilitiesHasIntegrationSupportWrapper (CCSBackend *backend) +static Bool ccsDynamicBackendHasIntegrationSupportWrapper (CCSBackend *backend) { CAPABILITIES_PRIV (backend); return ccsBackendHasIntegrationSupport (bcPrivate->backend); } -static Bool ccsBackendCapabilitiesHasProfileSupportWrapper (CCSBackend *backend) +static Bool ccsDynamicBackendHasProfileSupportWrapper (CCSBackend *backend) { CAPABILITIES_PRIV (backend); return ccsBackendHasProfileSupport (bcPrivate->backend); } -static Bool ccsBackendCapabilitiesFiniWrapper (CCSBackend *backend) +static Bool ccsDynamicBackendFiniWrapper (CCSBackend *backend) { CAPABILITIES_PRIV (backend); return ccsBackendFini (bcPrivate->backend); } -static void ccsBackendCapabilitiesExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) +static void ccsDynamicBackendExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) { CAPABILITIES_PRIV (backend); @@ -1502,7 +1502,7 @@ static void ccsBackendCapabilitiesExecuteEventsWrapper (CCSBackend *backend, uns ccsBackendExecuteEvents (bcPrivate->backend, flags); } -static Bool ccsBackendCapabilitiesReadInitWrapper (CCSBackend *backend, CCSContext *context) +static Bool ccsDynamicBackendReadInitWrapper (CCSBackend *backend, CCSContext *context) { CAPABILITIES_PRIV (backend); @@ -1512,7 +1512,7 @@ static Bool ccsBackendCapabilitiesReadInitWrapper (CCSBackend *backend, CCSConte return TRUE; } -static void ccsBackendCapabilitiesReadSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +static void ccsDynamicBackendReadSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { CAPABILITIES_PRIV (backend); @@ -1520,7 +1520,7 @@ static void ccsBackendCapabilitiesReadSettingWrapper (CCSBackend *backend, CCSCo ccsBackendReadSetting (bcPrivate->backend, context, setting); } -static void ccsBackendCapabilitiesReadDoneWrapper (CCSBackend *backend, CCSContext *context) +static void ccsDynamicBackendReadDoneWrapper (CCSBackend *backend, CCSContext *context) { CAPABILITIES_PRIV (backend); @@ -1528,7 +1528,7 @@ static void ccsBackendCapabilitiesReadDoneWrapper (CCSBackend *backend, CCSConte ccsBackendReadDone (bcPrivate->backend, context); } -static Bool ccsBackendCapabilitiesWriteInitWrapper (CCSBackend *backend, CCSContext *context) +static Bool ccsDynamicBackendWriteInitWrapper (CCSBackend *backend, CCSContext *context) { CAPABILITIES_PRIV (backend); @@ -1538,7 +1538,7 @@ static Bool ccsBackendCapabilitiesWriteInitWrapper (CCSBackend *backend, CCSCont return TRUE; } -static void ccsBackendCapabilitiesWriteSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +static void ccsDynamicBackendWriteSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { CAPABILITIES_PRIV (backend); @@ -1546,7 +1546,7 @@ static void ccsBackendCapabilitiesWriteSettingWrapper (CCSBackend *backend, CCSC ccsBackendWriteSetting (bcPrivate->backend, context, setting); } -static void ccsBackendCapabilitiesWriteDoneWrapper (CCSBackend *backend, CCSContext *context) +static void ccsDynamicBackendWriteDoneWrapper (CCSBackend *backend, CCSContext *context) { CAPABILITIES_PRIV (backend); @@ -1554,7 +1554,7 @@ static void ccsBackendCapabilitiesWriteDoneWrapper (CCSBackend *backend, CCSCont ccsBackendWriteDone (bcPrivate->backend, context); } -static void ccsBackendCapabilitiesUpdateSettingWrapper (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +static void ccsDynamicBackendUpdateSettingWrapper (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { CAPABILITIES_PRIV (backend); @@ -1562,7 +1562,7 @@ static void ccsBackendCapabilitiesUpdateSettingWrapper (CCSBackend *backend, CCS ccsBackendUpdateSetting (bcPrivate->backend, context, plugin, setting); } -static Bool ccsBackendCapabilitiesGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) +static Bool ccsDynamicBackendGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) { CAPABILITIES_PRIV (backend); @@ -1573,7 +1573,7 @@ static Bool ccsBackendCapabilitiesGetSettingIsIntegratedWrapper (CCSBackend *bac return FALSE; } -static Bool ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper (CCSBackend *backend, CCSSetting *setting) +static Bool ccsDynamicBackendGetSettingIsReadOnlyWrapper (CCSBackend *backend, CCSSetting *setting) { CAPABILITIES_PRIV (backend); @@ -1583,7 +1583,7 @@ static Bool ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper (CCSBackend *backe return FALSE; } -static CCSStringList ccsBackendCapabilitiesGetExistingProfilesWrapper (CCSBackend *backend, CCSContext *context) +static CCSStringList ccsDynamicBackendGetExistingProfilesWrapper (CCSBackend *backend, CCSContext *context) { CAPABILITIES_PRIV (backend); @@ -1596,7 +1596,7 @@ static CCSStringList ccsBackendCapabilitiesGetExistingProfilesWrapper (CCSBacken return sl; } -static Bool ccsBackendCapabilitiesDeleteProfileWrapper (CCSBackend *backend, CCSContext *context, char *profile) +static Bool ccsDynamicBackendDeleteProfileWrapper (CCSBackend *backend, CCSContext *context, char *profile) { CAPABILITIES_PRIV (backend); @@ -3228,7 +3228,7 @@ ccsReadSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!ccsBackendCapabilitiesSupportsRead (cPrivate->backend)) + if (!ccsDynamicBackendSupportsRead (cPrivate->backend)) return; if (!ccsBackendReadInit ((CCSBackend *) cPrivate->backend, context)) @@ -3272,7 +3272,7 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) if (!cPrivate->backend) return; - if (!ccsBackendCapabilitiesSupportsRead (cPrivate->backend)) + if (!ccsDynamicBackendSupportsRead (cPrivate->backend)) return; if (!ccsBackendReadInit ((CCSBackend *) cPrivate->backend, ccsPluginGetContext (plugin))) @@ -3307,7 +3307,7 @@ ccsWriteSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!ccsBackendCapabilitiesSupportsWrite (cPrivate->backend)) + if (!ccsDynamicBackendSupportsWrite (cPrivate->backend)) return; if (!ccsBackendWriteInit ((CCSBackend *) cPrivate->backend, context)) @@ -3354,7 +3354,7 @@ ccsWriteChangedSettingsDefault (CCSContext * context) if (!cPrivate->backend) return; - if (!ccsBackendCapabilitiesSupportsWrite (cPrivate->backend)) + if (!ccsDynamicBackendSupportsWrite (cPrivate->backend)) return; if (!ccsBackendWriteInit ((CCSBackend *) cPrivate->backend, context)) @@ -3782,7 +3782,7 @@ ccsGetExistingProfilesDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - if (ccsBackendCapabilitiesSupportsProfiles (cPrivate->backend)) + if (ccsDynamicBackendSupportsProfiles (cPrivate->backend)) return ccsBackendGetExistingProfiles ((CCSBackend *) cPrivate->backend, context); return NULL; @@ -3808,7 +3808,7 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (!cPrivate->backend) return; - if (!ccsBackendCapabilitiesSupportsProfiles (cPrivate->backend)) + if (!ccsDynamicBackendSupportsProfiles (cPrivate->backend)) return; /* never ever delete default profile */ @@ -5270,7 +5270,7 @@ Bool ccsSettingGetIsIntegratedDefault (CCSSetting *setting) if (!cPrivate->backend) return FALSE; - if (ccsBackendCapabilitiesSupportsIntegration (cPrivate->backend)) + if (ccsDynamicBackendSupportsIntegration (cPrivate->backend)) return ccsBackendGetSettingIsIntegrated ((CCSBackend *) cPrivate->backend, setting); return FALSE; @@ -5514,35 +5514,35 @@ static const CCSSettingInterface ccsDefaultSettingInterface = ccsFreeSettingDefault }; -const CCSBackendInterface ccsBackendCapabilitiesInterfaceWrapper = -{ - ccsBackendCapabilitiesGetNameWrapper, - ccsBackendCapabilitiesGetShortDescWrapper, - ccsBackendCapabilitiesGetLongDescWrapper, - ccsBackendCapabilitiesHasIntegrationSupportWrapper, - ccsBackendCapabilitiesHasProfileSupportWrapper, - ccsBackendCapabilitiesExecuteEventsWrapper, - ccsBackendCapabilitiesInitWrapper, - ccsBackendCapabilitiesFiniWrapper, - ccsBackendCapabilitiesReadInitWrapper, - ccsBackendCapabilitiesReadSettingWrapper, - ccsBackendCapabilitiesReadDoneWrapper, - ccsBackendCapabilitiesWriteInitWrapper, - ccsBackendCapabilitiesWriteSettingWrapper, - ccsBackendCapabilitiesWriteDoneWrapper, - ccsBackendCapabilitiesUpdateSettingWrapper, - ccsBackendCapabilitiesGetSettingIsIntegratedWrapper, - ccsBackendCapabilitiesGetSettingIsReadOnlyWrapper, - ccsBackendCapabilitiesGetExistingProfilesWrapper, - ccsBackendCapabilitiesDeleteProfileWrapper +const CCSBackendInterface ccsDynamicBackendInterfaceWrapper = +{ + ccsDynamicBackendGetNameWrapper, + ccsDynamicBackendGetShortDescWrapper, + ccsDynamicBackendGetLongDescWrapper, + ccsDynamicBackendHasIntegrationSupportWrapper, + ccsDynamicBackendHasProfileSupportWrapper, + ccsDynamicBackendExecuteEventsWrapper, + ccsDynamicBackendInitWrapper, + ccsDynamicBackendFiniWrapper, + ccsDynamicBackendReadInitWrapper, + ccsDynamicBackendReadSettingWrapper, + ccsDynamicBackendReadDoneWrapper, + ccsDynamicBackendWriteInitWrapper, + ccsDynamicBackendWriteSettingWrapper, + ccsDynamicBackendWriteDoneWrapper, + ccsDynamicBackendUpdateSettingWrapper, + ccsDynamicBackendGetSettingIsIntegratedWrapper, + ccsDynamicBackendGetSettingIsReadOnlyWrapper, + ccsDynamicBackendGetExistingProfilesWrapper, + ccsDynamicBackendDeleteProfileWrapper }; -const CCSBackendCapabilitiesInterface ccsDefaultBackendCapabilitiesInterface = +const CCSDynamicBackendInterface ccsDefaultDynamicBackendInterface = { - ccsBackendCapabilitiesSupportsReadDefault, - ccsBackendCapabilitiesSupportsWriteDefault, - ccsBackendCapabilitiesSupportsIntegrationDefault, - ccsBackendCapabilitiesSupportsProfilesDefault + ccsDynamicBackendSupportsReadDefault, + ccsDynamicBackendSupportsWriteDefault, + ccsDynamicBackendSupportsIntegrationDefault, + ccsDynamicBackendSupportsProfilesDefault }; const CCSInterfaceTable ccsDefaultInterfaceTable = @@ -5550,6 +5550,6 @@ const CCSInterfaceTable ccsDefaultInterfaceTable = &ccsDefaultContextInterface, &ccsDefaultPluginInterface, &ccsDefaultSettingInterface, - &ccsBackendCapabilitiesInterfaceWrapper, - &ccsDefaultBackendCapabilitiesInterface + &ccsDynamicBackendInterfaceWrapper, + &ccsDefaultDynamicBackendInterface }; -- GitLab From 8756f6be091311e2e1daa6b14d523bd82cbf3c2b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 09:35:16 +0800 Subject: [PATCH 159/562] Merge --- .../libcompizconfig/include/ccs-backend.h | 3 +- compizconfig/libcompizconfig/src/main.c | 58 ++++++++++--------- .../tests/compizconfig_test_ccs_backend.cpp | 4 +- .../compizconfig_ccs_backend_mock.h | 8 +-- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index cdc3cea71..a464d2f04 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -160,8 +160,7 @@ unsigned int ccsCCSDynamicBackendInterfaceGetType (); void ccsFreeDynamicBackend (CCSDynamicBackend *); /* Backend opener method */ -void * -ccsOpenBackend (const char *name, CCSBackendInterface **interface); +CCSBackend * ccsOpenBackend (CCSContext *context, const char *name); /* Constructor method */ CCSBackend * diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 4f7897826..31812f016 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1140,11 +1140,14 @@ ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBack return dynamicBackend; } -void * -ccsOpenBackend (const char *name, CCSBackendInterface **vt) +CCSBackend * +ccsOpenBackend (CCSContext *context, const char *name) { + CCSBackendInterface *vt; void *dlhand = openBackend (name); + CONTEXT_PRIV (context); + if (!dlhand) return NULL; @@ -1155,11 +1158,28 @@ ccsOpenBackend (const char *name, CCSBackendInterface **vt) return NULL; } - *vt = getInfo (); - if (!*vt) + vt = getInfo (); + if (!vt) { dlclose (dlhand); - *vt = NULL; + vt = NULL; + return NULL; + } + + CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt); + + if (!backend) + { + dlclose (dlhand); + return NULL; + } + + CCSDynamicBackend *backendWrapper = ccsDynamicBackendWrapLoadedBackend (cPrivate->object_interfaces, backend, dlhand); + + if (!backendWrapper) + { + dlclose (dlhand); + ccsBackendUnref (backend); return NULL; } @@ -1183,16 +1203,14 @@ ccsSetBackendDefault (CCSContext * context, char *name) cPrivate->backend = NULL; } - CCSBackendInterface *vt = NULL; - - void *dlhand = ccsOpenBackend (name, &vt); + CCSBackend *backend = ccsOpenBackend (context, name); - if (!dlhand) + if (!backend) { ccsWarning ("unable to open backend %s, falling back to ini", name); - dlhand = ccsOpenBackend ("ini", &vt); - if (!dlhand) + backend = ccsOpenBackend (context, "ini"); + if (!backend) { ccsError ("failed to open any backends, aborting"); abort (); @@ -1201,23 +1219,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) fallbackMode = TRUE; } - CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt); - - if (!backend) - { - dlclose (dlhand); - return FALSE; - } - - CCSDynamicBackend *backendWrapper = ccsDynamicBackendWrapLoadedBackend (cPrivate->object_interfaces, backend, dlhand); - - if (!backendWrapper) - { - ccsBackendUnref (backend); - return FALSE; - } - - cPrivate->backend = backendWrapper; + cPrivate->backend = (CCSDynamicBackend *) backend; CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp index 9a31f7f3e..a534c3ef5 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp @@ -27,7 +27,7 @@ TEST(CCSBackendTest, TestMock) EXPECT_CALL (*mock, hasIntegrationSupport ()); EXPECT_CALL (*mock, executeEvents (_)); EXPECT_CALL (*mock, init (_)); - EXPECT_CALL (*mock, fini (_)); + EXPECT_CALL (*mock, fini ()); EXPECT_CALL (*mock, readInit (_)); EXPECT_CALL (*mock, readSetting (_,_)); EXPECT_CALL (*mock, readDone (_)); @@ -46,7 +46,7 @@ TEST(CCSBackendTest, TestMock) ccsBackendHasIntegrationSupport (backend); ccsBackendExecuteEvents (backend, 0); ccsBackendInit (backend, NULL); - ccsBackendFini (backend, NULL); + ccsBackendFini (backend); ccsBackendReadInit (backend, NULL); ccsBackendReadSetting (backend, NULL, NULL); ccsBackendReadDone (backend, NULL); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index d1d5aa66b..96407d795 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -22,7 +22,7 @@ class CCSBackendGMockInterface virtual Bool hasIntegrationSupport () = 0; virtual void executeEvents (unsigned int) = 0; virtual Bool init (CCSContext *context) = 0; - virtual Bool fini (CCSContext *context) = 0; + virtual Bool fini () = 0; virtual Bool readInit (CCSContext *context) = 0; virtual void readSetting (CCSContext *context, CCSSetting *setting) = 0; virtual void readDone (CCSContext *context) = 0; @@ -56,7 +56,7 @@ class CCSBackendGMock : MOCK_METHOD0 (hasIntegrationSupport, Bool ()); MOCK_METHOD1 (executeEvents, void (unsigned int)); MOCK_METHOD1 (init, Bool (CCSContext *)); - MOCK_METHOD1 (fini, Bool (CCSContext *)); + MOCK_METHOD0 (fini, Bool ()); MOCK_METHOD1 (readInit, Bool (CCSContext *)); MOCK_METHOD2 (readSetting, void (CCSContext *, CCSSetting *)); MOCK_METHOD1 (readDone, void (CCSContext *)); @@ -111,9 +111,9 @@ class CCSBackendGMock : return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->init (context); } - static Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) + static Bool ccsBackendFini (CCSBackend *backend) { - return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->fini (context); + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->fini (); } static Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) -- GitLab From f553a4976ebef136e1b336829aed45987823e1dc Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 09:46:27 +0800 Subject: [PATCH 160/562] Merge from previous. All the GSettings backend tests fail but that's fine --- .../tests/test_gsettings_conformance.cpp | 15 ++++++--------- .../libcompizconfig/include/ccs-backend.h | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 6fe393545..fbee9b812 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -48,9 +48,7 @@ class CCSGSettingsBackendEnv : CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { - CCSBackendInterface *interface = NULL; CCSGSettingsBackendInterface *overloadedInterface = NULL; - Bool fallback = FALSE; g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); g_setenv ("GSETTINGS_BACKEND", "memory", true); @@ -60,13 +58,12 @@ class CCSGSettingsBackendEnv : std::string path ("gsettings"); - void *dlhand = ccsOpenBackend (path.c_str (), &interface, &fallback); + mBackend = reinterpret_cast (ccsOpenBackend (mContext, path.c_str ())); - EXPECT_FALSE (fallback); - EXPECT_TRUE (dlhand); + EXPECT_TRUE (mBackend); - mGSettingsBackend = ccsBackendNewWithInterface (mContext, interface, dlhand); - mBackend = ccsBackendWithCapabilitiesWrapBackend (&ccsDefaultInterfaceTable, mGSettingsBackend); + //mGSettingsBackend = ccsBackendNewWithInterface (mContext, interface, dlhand); + mGSettingsBackend = NULL; CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, mBackend))->backendInit; @@ -93,7 +90,7 @@ class CCSGSettingsBackendEnv : g_unsetenv ("GSETTINGS_BACKEND"); g_unsetenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); - ccsFreeBackendWithCapabilities (mBackend); + ccsFreeDynamicBackend (mBackend); } void PreWrite (CCSContextGMock *gmockContext, @@ -429,7 +426,7 @@ class CCSGSettingsBackendEnv : GSettings *mSettings; CCSContext *mContext; - CCSBackendWithCapabilities *mBackend; + CCSDynamicBackend *mBackend; CCSBackend *mGSettingsBackend; std::string pluginToMatch; diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index eb869541e..283fb3a88 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -169,8 +169,8 @@ ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterfac typedef struct _CCSInterfaceTable CCSInterfaceTable; /* Constructor method */ -CCSBackendWithCapabilities * -ccsBackendWithCapabilitiesWrapBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend); +CCSDynamicBackend * +ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand); CCSBackendInterface* getBackendInfo (void); -- GitLab From 9864ae33c7487ca62b10f6662acd19d74d7c3bf8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 09:51:30 +0800 Subject: [PATCH 161/562] Added a getter for the raw backend wrapped by CCSDynamicBackend --- .../libcompizconfig/include/ccs-backend.h | 3 +++ compizconfig/libcompizconfig/src/main.c | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index d21f7848d..43e6d54a0 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -138,6 +138,7 @@ typedef Bool (*CCSDynamicBackendSupportsRead) (CCSDynamicBackend *); typedef Bool (*CCSDynamicBackendSupportsWrite) (CCSDynamicBackend *); typedef Bool (*CCSDynamicBackendSupportsProfiles) (CCSDynamicBackend *); typedef Bool (*CCSDynamicBackendSupportsIntegration) (CCSDynamicBackend *); +typedef CCSBackend * (*CCSDynamicBackendGetRawBackend) (CCSDynamicBackend *); struct _CCSDynamicBackendInterface { @@ -145,12 +146,14 @@ struct _CCSDynamicBackendInterface CCSDynamicBackendSupportsWrite supportsWrite; CCSDynamicBackendSupportsProfiles supportsProfiles; CCSDynamicBackendSupportsIntegration supportsIntegration; + CCSDynamicBackendGetRawBackend getRawBackend; }; Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *); Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *); Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *); Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *); +CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *); unsigned int ccsCCSDynamicBackendInterfaceGetType (); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index a46afc523..a25a52e0a 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1291,6 +1291,11 @@ Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *capabilities) return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsIntegration) (capabilities); } +CCSBackend * ccsDynamicBackendGetRawBacend (CCSDynamicBackend *capabilities) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->getRawBackend) (capabilities); +} + Bool ccsBackendHasExecuteEvents (CCSBackend *backend) { return (GET_INTERFACE (CCSBackendInterface, backend))->executeEvents != NULL; @@ -1445,6 +1450,13 @@ ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *capabilities) return ccsBackendHasProfileSupport (bcPrivate->backend); } +static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *capabilities) +{ + CAPABILITIES_PRIV (capabilities); + + return bcPrivate->backend; +} + static Bool ccsDynamicBackendInitWrapper (CCSBackend *backend, CCSContext *context) { CAPABILITIES_PRIV (backend); @@ -5542,7 +5554,8 @@ const CCSDynamicBackendInterface ccsDefaultDynamicBackendInterface = ccsDynamicBackendSupportsReadDefault, ccsDynamicBackendSupportsWriteDefault, ccsDynamicBackendSupportsIntegrationDefault, - ccsDynamicBackendSupportsProfilesDefault + ccsDynamicBackendSupportsProfilesDefault, + ccsDynamicBackendGetRawBackendDefault }; const CCSInterfaceTable ccsDefaultInterfaceTable = -- GitLab From 83126a2875ba47c12aeb8ce63f77114a40f0d696 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 10:51:55 +0800 Subject: [PATCH 162/562] Move code into the right place and fix some crashers --- .../libcompizconfig/include/ccs-backend.h | 4 +- compizconfig/libcompizconfig/src/main.c | 64 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 43e6d54a0..fa94c398a 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -128,6 +128,7 @@ void ccsFreeBackend (CCSBackend *backend); typedef struct _CCSDynamicBackend CCSDynamicBackend; typedef struct _CCSDynamicBackendPrivate CCSDynamicBackendPrivate; typedef struct _CCSDynamicBackendInterface CCSDynamicBackendInterface; +typedef struct _CCSInterfaceTable CCSInterfaceTable; struct _CCSDynamicBackend { @@ -160,8 +161,7 @@ unsigned int ccsCCSDynamicBackendInterfaceGetType (); void ccsFreeDynamicBackend (CCSDynamicBackend *); /* Backend opener method */ -void * -ccsOpenBackend (const char *name, CCSBackendInterface **interface); +CCSBackend * ccsOpenBackend (const CCSInterfaceTable *, CCSContext *context, const char *name); /* Constructor method */ CCSBackend * diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index a25a52e0a..171b010b3 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1134,15 +1134,16 @@ ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBack bcPrivate->backend = backend; ccsObjectSetPrivate (dynamicBackend, (CCSPrivate *) bcPrivate); - ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); - ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendWrapperInterface, GET_INTERFACE_TYPE (CCSDynamicBackendInterface)); + ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendWrapperInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); + ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendInterface, GET_INTERFACE_TYPE (CCSDynamicBackendInterface)); return dynamicBackend; } -void * -ccsOpenBackend (const char *name, CCSBackendInterface **vt) +CCSBackend * +ccsOpenBackend (const CCSInterfaceTable *interfaces, CCSContext *context, const char *name) { + CCSBackendInterface *vt; void *dlhand = openBackend (name); if (!dlhand) @@ -1155,15 +1156,32 @@ ccsOpenBackend (const char *name, CCSBackendInterface **vt) return NULL; } - *vt = getInfo (); - if (!*vt) + vt = getInfo (); + if (!vt) { dlclose (dlhand); - *vt = NULL; + vt = NULL; return NULL; } - return dlhand; + CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt); + + if (!backend) + { + dlclose (dlhand); + return NULL; + } + + CCSDynamicBackend *backendWrapper = ccsDynamicBackendWrapLoadedBackend (interfaces, backend, dlhand); + + if (!backendWrapper) + { + dlclose (dlhand); + ccsBackendUnref (backend); + return NULL; + } + + return (CCSBackend *) backendWrapper; } Bool @@ -1183,16 +1201,14 @@ ccsSetBackendDefault (CCSContext * context, char *name) cPrivate->backend = NULL; } - CCSBackendInterface *vt = NULL; - - void *dlhand = ccsOpenBackend (name, &vt); + CCSBackend *backend = ccsOpenBackend (cPrivate->object_interfaces, context, name); - if (!dlhand) + if (!backend) { ccsWarning ("unable to open backend %s, falling back to ini", name); - dlhand = ccsOpenBackend ("ini", &vt); - if (!dlhand) + backend = ccsOpenBackend (cPrivate->object_interfaces, context, "ini"); + if (!backend) { ccsError ("failed to open any backends, aborting"); abort (); @@ -1201,23 +1217,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) fallbackMode = TRUE; } - CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt); - - if (!backend) - { - dlclose (dlhand); - return FALSE; - } - - CCSDynamicBackend *backendWrapper = ccsDynamicBackendWrapLoadedBackend (cPrivate->object_interfaces, backend, dlhand); - - if (!backendWrapper) - { - ccsBackendUnref (backend); - return FALSE; - } - - cPrivate->backend = backendWrapper; + cPrivate->backend = (CCSDynamicBackend *) backend; CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; @@ -1291,7 +1291,7 @@ Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *capabilities) return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsIntegration) (capabilities); } -CCSBackend * ccsDynamicBackendGetRawBacend (CCSDynamicBackend *capabilities) +CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *capabilities) { return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->getRawBackend) (capabilities); } -- GitLab From 580f61b8dd000073c791fbe280cda1c4533023ba Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 11:04:02 +0800 Subject: [PATCH 163/562] Fix crashing GSettings tests --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index fbee9b812..9a0b9b098 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -58,12 +58,11 @@ class CCSGSettingsBackendEnv : std::string path ("gsettings"); - mBackend = reinterpret_cast (ccsOpenBackend (mContext, path.c_str ())); + mBackend = reinterpret_cast (ccsOpenBackend (&ccsDefaultInterfaceTable, mContext, path.c_str ())); EXPECT_TRUE (mBackend); - //mGSettingsBackend = ccsBackendNewWithInterface (mContext, interface, dlhand); - mGSettingsBackend = NULL; + mGSettingsBackend = ccsDynamicBackendGetRawBackend (mBackend); CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, mBackend))->backendInit; -- GitLab From e4498c3df616f9617e36c046386ef39b2191ebcf Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 11:41:26 +0800 Subject: [PATCH 164/562] Move global data to a private struct --- .../gsettings_backend_shared/gsettings_util.h | 7 +- .../gsettings/src/gconf-integration.c | 85 ++++++------ compizconfig/gsettings/src/gsettings.c | 127 ++++++++++-------- compizconfig/gsettings/src/gsettings.h | 32 +++-- 4 files changed, 139 insertions(+), 112 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 70bd6c3c9..4c7914d98 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -10,7 +10,7 @@ COMPIZCONFIG_BEGIN_DECLS #include #include -typedef struct _CCSGSettingsBackendPrivate CCSGettingsBackendPrivate; +typedef struct _CCSGSettingsBackendPrivate CCSGSettingsBackendPrivate; typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); @@ -31,11 +31,6 @@ struct _CCSGSettingsBackendInterface CCSGSettingsBackendUnregisterGConfClient gsettingsBackendUnregisterGConfClient; }; -struct _CCSGSettingsBackendPrivate -{ - CCSContext *context; -}; - unsigned int ccsCCSGSettingsBackendInterfaceGetType (); gchar * diff --git a/compizconfig/gsettings/src/gconf-integration.c b/compizconfig/gsettings/src/gconf-integration.c index 43a03ba0e..1e3390637 100644 --- a/compizconfig/gsettings/src/gconf-integration.c +++ b/compizconfig/gsettings/src/gconf-integration.c @@ -33,8 +33,6 @@ #include "gsettings.h" #ifdef USE_GCONF -GConfClient *client = NULL; -guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS]; const SpecialOptionGConf specialOptions[] = { {"run_key", "gnomecompat", FALSE, @@ -456,45 +454,48 @@ gnomeGConfValueChanged (GConfClient *client, } void -initGConfClient (CCSContext *context) +initGConfClient (CCSBackend *backend) { int i; - client = gconf_client_get_default (); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + priv->client = gconf_client_get_default (); for (i = 0; i < NUM_WATCHED_DIRS; i++) { - gnomeGConfNotifyIds[i] = gconf_client_notify_add (client, - watchedGConfGnomeDirectories[i], - gnomeGConfValueChanged, context, - NULL, NULL); - gconf_client_add_dir (client, watchedGConfGnomeDirectories[i], + priv->gnomeGConfNotifyIds[i] = gconf_client_notify_add (priv->client, + watchedGConfGnomeDirectories[i], + gnomeGConfValueChanged, priv->context, + NULL, NULL); + gconf_client_add_dir (priv->client, watchedGConfGnomeDirectories[i], GCONF_CLIENT_PRELOAD_NONE, NULL); } } void -finiGConfClient (void) +finiGConfClient (CCSBackend *backend) { int i; + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + for (i = 0; i < NUM_WATCHED_DIRS; i++) { - if (gnomeGConfNotifyIds[i]) + if (priv->gnomeGConfNotifyIds[i]) { - gconf_client_notify_remove (client, gnomeGConfNotifyIds[0]); - gnomeGConfNotifyIds[i] = 0; + gconf_client_notify_remove (priv->client, priv->gnomeGConfNotifyIds[0]); + priv->gnomeGConfNotifyIds[i] = 0; } - gconf_client_remove_dir (client, watchedGConfGnomeDirectories[i], NULL); + gconf_client_remove_dir (priv->client, watchedGConfGnomeDirectories[i], NULL); } - gconf_client_suggest_sync (client, NULL); + gconf_client_suggest_sync (priv->client, NULL); - g_object_unref (client); - client = NULL; + g_object_unref (priv->client); + priv->client = NULL; } static unsigned int -getGnomeMouseButtonModifier(void) +getGnomeMouseButtonModifier(GConfClient *client) { unsigned int modMask = 0; GError *err = NULL; @@ -545,13 +546,15 @@ readGConfIntegratedOption (CCSBackend *backend, GConfValue *gconfValue; GError *err = NULL; Bool ret = FALSE; + + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - if (!client) + if (!priv->client) ccsGSettingsBackendRegisterGConfClient (backend); ret = readOption (backend, setting); - gconfValue = gconf_client_get (client, + gconfValue = gconf_client_get (priv->client, specialOptions[index].gnomeName, &err); @@ -679,10 +682,10 @@ readGConfIntegratedOption (CCSBackend *backend, memset (&button, 0, sizeof (CCSSettingButtonValue)); ccsGetButton (setting, &button); - button.buttonModMask = getGnomeMouseButtonModifier (); + button.buttonModMask = getGnomeMouseButtonModifier (priv->client); resizeWithRightButton = - gconf_client_get_bool (client, METACITY + gconf_client_get_bool (priv->client, METACITY "/general/resize_with_right_button", &err); @@ -708,7 +711,7 @@ readGConfIntegratedOption (CCSBackend *backend, } static Bool -setGnomeMouseButtonModifier (unsigned int modMask) +setGnomeMouseButtonModifier (GConfClient *client, unsigned int modMask) { char *modifiers, *currentValue; GError *err = NULL; @@ -777,7 +780,9 @@ writeGConfIntegratedOption (CCSBackend *backend, GError *err = NULL; const char *optionName = specialOptions[index].gnomeName; - if (!client) + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + if (!priv->client) ccsGSettingsBackendRegisterGConfClient (backend); switch (specialOptions[index].type) @@ -787,10 +792,10 @@ writeGConfIntegratedOption (CCSBackend *backend, int newValue, currentValue; if (!ccsGetInt (setting, &newValue)) break; - currentValue = gconf_client_get_int (client, optionName, &err); + currentValue = gconf_client_get_int (priv->client, optionName, &err); if (!err && (currentValue != newValue)) - gconf_client_set_int(client, specialOptions[index].gnomeName, + gconf_client_set_int(priv->client, specialOptions[index].gnomeName, newValue, NULL); } break; @@ -800,11 +805,11 @@ writeGConfIntegratedOption (CCSBackend *backend, gboolean currentValue; if (!ccsGetBool (setting, &newValue)) break; - currentValue = gconf_client_get_bool (client, optionName, &err); + currentValue = gconf_client_get_bool (priv->client, optionName, &err); if (!err && ((currentValue && !newValue) || (!currentValue && newValue))) - gconf_client_set_bool (client, specialOptions[index].gnomeName, + gconf_client_set_bool (priv->client, specialOptions[index].gnomeName, newValue, NULL); } break; @@ -814,12 +819,12 @@ writeGConfIntegratedOption (CCSBackend *backend, gchar *currentValue; if (!ccsGetString (setting, &newValue)) break; - currentValue = gconf_client_get_string (client, optionName, &err); + currentValue = gconf_client_get_string (priv->client, optionName, &err); if (!err && currentValue) { if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, + gconf_client_set_string (priv->client, optionName, newValue, NULL); g_free (currentValue); } @@ -839,13 +844,13 @@ writeGConfIntegratedOption (CCSBackend *backend, newValue[0] = 'd'; } - currentValue = gconf_client_get_string (client, + currentValue = gconf_client_get_string (priv->client, optionName, &err); if (!err && currentValue) { if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, + gconf_client_set_string (priv->client, optionName, newValue, NULL); g_free (currentValue); } @@ -865,7 +870,7 @@ writeGConfIntegratedOption (CCSBackend *backend, if (!ccsGetBool (setting, ¤tViewport)) break; - gconf_client_set_bool (client, optionName, + gconf_client_set_bool (priv->client, optionName, !currentViewport, NULL); } else if (strcmp (settingName, "fullscreen_visual_bell") == 0) @@ -876,12 +881,12 @@ writeGConfIntegratedOption (CCSBackend *backend, break; newValue = fullscreen ? "fullscreen" : "frame_flash"; - currentValue = gconf_client_get_string (client, + currentValue = gconf_client_get_string (priv->client, optionName, &err); if (!err && currentValue) { if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, + gconf_client_set_string (priv->client, optionName, newValue, NULL); g_free (currentValue); } @@ -894,13 +899,13 @@ writeGConfIntegratedOption (CCSBackend *backend, break; newValue = clickToFocus ? "click" : "sloppy"; - currentValue = gconf_client_get_string (client, + currentValue = gconf_client_get_string (priv->client, optionName, &err); if (!err && currentValue) { if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, + gconf_client_set_string (priv->client, optionName, newValue, NULL); g_free (currentValue); } @@ -924,21 +929,21 @@ writeGConfIntegratedOption (CCSBackend *backend, } currentValue = - gconf_client_get_bool (client, METACITY + gconf_client_get_bool (priv->client, METACITY "/general/resize_with_right_button", &err); if (!err && ((currentValue && !resizeWithRightButton) || (!currentValue && resizeWithRightButton))) { - gconf_client_set_bool (client, + gconf_client_set_bool (priv->client, METACITY "/general/resize_with_right_button", resizeWithRightButton, NULL); } modMask = ccsSettingGetValue (setting)->value.asButton.buttonModMask; - if (setGnomeMouseButtonModifier (modMask)) + if (setGnomeMouseButtonModifier (priv->client, modMask)) { setButtonBindingForSetting (context, "move", "initiate_button", 1, modMask); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 4b92ccaba..4836b512c 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -40,15 +40,6 @@ valueChanged (GSettings *settings, gchar *keyname, gpointer user_data); -static GList *settingsList = NULL; -static GSettings *compizconfigSettings = NULL; -static GSettings *currentProfileSettings = NULL; - -char *currentProfile = NULL; - -/* This will need to be rempved */ -CCSContext *storedContext = NULL; - /* some forward declarations */ static void writeIntegratedOption (CCSBackend *backend, CCSContext *context, @@ -67,7 +58,9 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen gsize newWrittenPluginsSize; gchar **newWrittenPlugins; - settingsObj = (GSettings *) findObjectInListWithPropertySchemaName (schemaName, settingsList); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + settingsObj = (GSettings *) findObjectInListWithPropertySchemaName (schemaName, priv->settingsList); if (settingsObj) { @@ -81,7 +74,7 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen ccsGSettingsBackendConnectToChangedSignal (backend, G_OBJECT (settingsObj)); - settingsList = g_list_append (settingsList, (void *) settingsObj); + priv->settingsList = g_list_append (priv->settingsList, (void *) settingsObj); /* Also write the plugin name to the list of modified plugins so * that when we delete the profile the keys for that profile are also @@ -89,11 +82,11 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen * store keys that have changed from their defaults ... though * gsettings doesn't seem to give you a way to get all of the schemas */ - writtenPlugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys"); + writtenPlugins = g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); appendToPluginsWithSetKeysList (plugin, writtenPlugins, &newWrittenPlugins, &newWrittenPluginsSize); - g_settings_set_strv (currentProfileSettings, "plugins-with-set-keys", (const gchar * const *)newWrittenPlugins); + g_settings_set_strv (priv->currentProfileSettings, "plugins-with-set-keys", (const gchar * const *)newWrittenPlugins); g_variant_unref (writtenPlugins); g_free (schemaName); @@ -103,7 +96,7 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen } static gchar * -makeSettingPath (CCSSetting *setting) +makeSettingPath (const char *currentProfile, CCSSetting *setting) { return makeCompizPluginPath (currentProfile, ccsPluginGetName (ccsSettingGetParent (setting))); @@ -113,7 +106,8 @@ static GSettings * getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) { GSettings *ret = NULL; - gchar *pathName = makeSettingPath (setting); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + gchar *pathName = makeSettingPath (priv->currentProfile, setting); ret = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, ccsPluginGetName (ccsSettingGetParent (setting)), @@ -180,9 +174,10 @@ readIntegratedOption (CCSBackend *backend, static GVariant * getVariantForCCSSetting (CCSBackend *backend, CCSSetting *setting) { + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = getNameForCCSSetting (setting); - gchar *pathName = makeSettingPath (setting); + gchar *pathName = makeSettingPath (priv->currentProfile, setting); GVariant *gsettingsValue = getVariantAtKey (settings, cleanSettingName, pathName, @@ -505,7 +500,7 @@ writeOption (CCSBackend *backend, CCSSetting * setting) } static void -updateCurrentProfileName (const char *profile) +updateCurrentProfileName (CCSBackend *backend, const char *profile) { GVariant *profiles; char *prof; @@ -515,7 +510,9 @@ updateCurrentProfileName (const char *profile) GVariantIter iter; gboolean found = FALSE; - profiles = g_settings_get_value (compizconfigSettings, "existing-profiles"); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + profiles = g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); @@ -532,7 +529,7 @@ updateCurrentProfileName (const char *profile) g_variant_builder_add (newProfilesBuilder, "s", profile); newProfiles = g_variant_new ("as", newProfilesBuilder); - g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles); + g_settings_set_value (priv->compizconfigSettings, "existing-profiles", newProfiles); g_variant_unref (newProfiles); g_variant_builder_unref (newProfilesBuilder); @@ -540,19 +537,21 @@ updateCurrentProfileName (const char *profile) g_variant_unref (profiles); /* Change the current profile and current profile settings */ - free (currentProfile); + free (priv->currentProfile); - currentProfile = strdup (profile); - currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); + priv->currentProfile = strdup (profile); + priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); - g_settings_set (compizconfigSettings, "current-profile", "s", profile, NULL); + g_settings_set (priv->compizconfigSettings, "current-profile", "s", profile, NULL); g_free (profilePath); } static gboolean -updateProfile (CCSContext *context) +updateProfile (CCSBackend *backend, CCSContext *context) { + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + char *profile = strdup (ccsGetProfile (context)); if (!profile) @@ -564,8 +563,8 @@ updateProfile (CCSContext *context) profile = strdup (DEFAULTPROF); } - if (g_strcmp0 (profile, currentProfile)) - updateCurrentProfileName (profile); + if (g_strcmp0 (profile, priv->currentProfile)) + updateCurrentProfileName (backend, profile); free (profile); @@ -573,12 +572,14 @@ updateProfile (CCSContext *context) } static char* -getCurrentProfileName (void) +getCurrentProfileName (CCSBackend *backend) { GVariant *value; char *ret = NULL; - value = g_settings_get_value (compizconfigSettings, "current-profile"); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + value = g_settings_get_value (priv->compizconfigSettings, "current-profile"); if (value) ret = strdup (g_variant_get_string (value, NULL)); @@ -603,7 +604,9 @@ processEvents (CCSBackend *backend, unsigned int flags) static CCSContext * ccsGSettingsBackendGetContextDefault (CCSBackend *backend) { - return storedContext; + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return priv->context; } static void @@ -616,9 +619,7 @@ static void ccsGSettingsBackendRegisterGConfClientDefault (CCSBackend *backend) { #ifdef USE_GCONF - CCSContext *context = ccsGSettingsBackendGetContext (backend); - - initGConfClient (context); + initGConfClient (backend); #endif } @@ -626,8 +627,10 @@ static void ccsGSettingsBackendUnregisterGConfClientDefault (CCSBackend *backend) { #ifdef USE_GCONF - gconf_client_clear_cache (client); - finiGConfClient (); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + gconf_client_clear_cache (priv->client); + finiGConfClient (backend); #endif } @@ -646,47 +649,52 @@ initBackend (CCSBackend *backend, CCSContext * context) g_type_init (); - storedContext = context; - ccsObjectAddInterface (backend, (CCSInterface *) &gsettingsAdditionalDefaultInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); - compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); + CCSGSettingsBackendPrivate *priv = calloc (1, sizeof (CCSGSettingsBackendPrivate)); + + priv->compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); - currentProfile = getCurrentProfileName (); - currentProfilePath = makeCompizProfilePath (currentProfile); - currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath); + priv->currentProfile = getCurrentProfileName (backend); + currentProfilePath = makeCompizProfilePath (priv->currentProfile); + priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath); + priv->context = context; g_free (currentProfilePath); + ccsObjectSetPrivate (backend, (CCSPrivate *) priv); + return TRUE; } static Bool finiBackend (CCSBackend *backend) { + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + processEvents (backend, 0); ccsGSettingsBackendUnregisterGConfClient (backend); - if (currentProfile) + if (priv->currentProfile) { - free (currentProfile); - currentProfile = NULL; + free (priv->currentProfile); + priv->currentProfile = NULL; } - g_list_free_full (settingsList, g_object_unref); + g_list_free_full (priv->settingsList, g_object_unref); - settingsList = NULL; + priv->settingsList = NULL; - if (currentProfileSettings) + if (priv->currentProfileSettings) { - g_object_unref (currentProfileSettings); - currentProfileSettings = NULL; + g_object_unref (priv->currentProfileSettings); + priv->currentProfileSettings = NULL; } - g_object_unref (G_OBJECT (compizconfigSettings)); + g_object_unref (G_OBJECT (priv->compizconfigSettings)); - compizconfigSettings = NULL; + priv->compizconfigSettings = NULL; processEvents (backend, 0); return TRUE; @@ -695,7 +703,7 @@ finiBackend (CCSBackend *backend) Bool readInit (CCSBackend *backend, CCSContext * context) { - return updateProfile (context); + return updateProfile (backend, context); } void @@ -721,7 +729,7 @@ readSetting (CCSBackend *backend, Bool writeInit (CCSBackend *backend, CCSContext * context) { - return updateProfile (context); + return updateProfile (backend, context); } void @@ -772,7 +780,9 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) GVariantIter iter; CCSStringList ret = NULL; - value = g_settings_get_value (compizconfigSettings, "existing-profiles"); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + value = g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); g_variant_iter_init (&iter, value); while (g_variant_iter_loop (&iter, "s", &profile)) { @@ -801,15 +811,16 @@ deleteProfile (CCSBackend *backend, GVariantIter iter; char *profileSettingsPath = makeCompizProfilePath (profile); GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - plugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys"); - profiles = g_settings_get_value (compizconfigSettings, "existing-profiles"); + plugins = g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); + profiles = g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); g_variant_iter_init (&iter, plugins); while (g_variant_iter_loop (&iter, "s", &plugin)) { GSettings *settings; - gchar *pathName = makeCompizPluginPath (currentProfile, plugin); + gchar *pathName = makeCompizPluginPath (priv->currentProfile, plugin); settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); g_free (pathName); @@ -843,14 +854,14 @@ deleteProfile (CCSBackend *backend, } newProfiles = g_variant_new ("as", newProfilesBuilder); - g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles); + g_settings_set_value (priv->compizconfigSettings, "existing-profiles", newProfiles); g_variant_unref (newProfiles); g_variant_builder_unref (newProfilesBuilder); g_free (profileSettingsPath); - updateProfile (context); + updateProfile (backend, context); return TRUE; } diff --git a/compizconfig/gsettings/src/gsettings.h b/compizconfig/gsettings/src/gsettings.h index 718504355..b29b6f024 100644 --- a/compizconfig/gsettings/src/gsettings.h +++ b/compizconfig/gsettings/src/gsettings.h @@ -56,6 +56,13 @@ #define _GNU_SOURCE #endif +#ifdef USE_GCONF +#include +#include +#include +#endif + + typedef enum { OptionInt, OptionBool, @@ -64,7 +71,21 @@ typedef enum { OptionSpecial, } SpecialOptionType; -char *currentProfile; +struct _CCSGSettingsBackendPrivate +{ + GList *settingsList; + GSettings *compizconfigSettings; + GSettings *currentProfileSettings; + + char *currentProfile; + CCSContext *context; + +#ifdef USE_GCONF + GConfClient *client; + guint *gnomeGConfNotifyIds; +#endif + +}; Bool readInit (CCSBackend *, CCSContext * context); void readSetting (CCSBackend *, CCSContext * context, CCSSetting * setting); @@ -74,12 +95,7 @@ void writeOption (CCSBackend *backend, CCSSetting *setting); #ifdef USE_GCONF -#include -#include -#include -GConfClient *client; -guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS]; typedef struct _SpecialOptionGConf { const char* settingName; @@ -100,10 +116,10 @@ gnomeGConfValueChanged (GConfClient *client, gpointer user_data); void -initGConfClient (CCSContext *context); +initGConfClient (CCSBackend *backend); void -finiGConfClient (void); +finiGConfClient (CCSBackend *backend); Bool readGConfIntegratedOption (CCSBackend *backend, -- GitLab From ae27cff1aa6b1ab60d49a37aa9baa340e3b8b287 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 11:42:57 +0800 Subject: [PATCH 165/562] Also free it --- compizconfig/gsettings/src/gsettings.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 4836b512c..e15199b6d 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -697,6 +697,10 @@ finiBackend (CCSBackend *backend) priv->compizconfigSettings = NULL; processEvents (backend, 0); + + free (priv); + ccsObjectSetPrivate (backend, NULL); + return TRUE; } -- GitLab From b13919907e7033b14ca4496c5d7c4200d1bb47e7 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 13:59:43 +0800 Subject: [PATCH 166/562] Set private in the right place --- compizconfig/gsettings/src/gsettings.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index e15199b6d..bf335b0d4 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -653,6 +653,11 @@ initBackend (CCSBackend *backend, CCSContext * context) CCSGSettingsBackendPrivate *priv = calloc (1, sizeof (CCSGSettingsBackendPrivate)); + if (!priv) + return FALSE; + + ccsObjectSetPrivate (backend, (CCSPrivate *) priv); + priv->compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); priv->currentProfile = getCurrentProfileName (backend); @@ -662,8 +667,6 @@ initBackend (CCSBackend *backend, CCSContext * context) g_free (currentProfilePath); - ccsObjectSetPrivate (backend, (CCSPrivate *) priv); - return TRUE; } -- GitLab From 312e0aece18f3b9cb303a5d951de1d1bf658a896 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 14:06:14 +0800 Subject: [PATCH 167/562] CAPABILITIES_PRIV -> DYNAMIC_BACKEND_PRIV --- .../libcompizconfig/src/ccs-private.h | 4 +- compizconfig/libcompizconfig/src/main.c | 82 +++++++++---------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index 5e7dac9f3..d3c4f12db 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -31,9 +31,7 @@ CCSPluginPrivate *pPrivate = (CCSPluginPrivate *) ccsObjectGetPrivate (p); #define SETTING_PRIV(s) \ CCSSettingPrivate *sPrivate = (CCSSettingPrivate *) ccsObjectGetPrivate (s); -#define BACKEND_PRIV(b) \ - CCSBackendPrivate *bPrivate = (CCSBackendPrivate *) ccsObjectGetPrivate (b); -#define CAPABILITIES_PRIV(bc) \ +#define DYNAMIC_BACKEND_PRIV(bc) \ CCSDynamicBackendPrivate *bcPrivate = (CCSDynamicBackendPrivate *) ccsObjectGetPrivate (bc); extern Bool basicMetadata; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 171b010b3..a01749442 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1069,7 +1069,7 @@ openBackend (const char *backend) void * ccsDynamicBackendGetDlHand (CCSBackend *backend) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return bcPrivate->dlhand; } @@ -1086,7 +1086,7 @@ ccsFreeBackend (CCSBackend *backend) void ccsFreeDynamicBackend (CCSDynamicBackend *DynamicBackend) { - CAPABILITIES_PRIV (DynamicBackend); + DYNAMIC_BACKEND_PRIV (DynamicBackend); ccsBackendUnref (bcPrivate->backend); @@ -1264,36 +1264,36 @@ Bool ccsBackendHasProfileSupport (CCSBackend *backend) } static Bool -ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - CAPABILITIES_PRIV (capabilities); + DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); return ccsBackendHasIntegrationSupport (bcPrivate->backend); } -Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsRead) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsRead) (DYNAMIC_BACKEND_PRIVities); } -Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsWrite) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsWrite) (DYNAMIC_BACKEND_PRIVities); } -Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsProfiles) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsProfiles) (DYNAMIC_BACKEND_PRIVities); } -Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *capabilities) +Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->supportsIntegration) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsIntegration) (DYNAMIC_BACKEND_PRIVities); } -CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *capabilities) +CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, capabilities))->getRawBackend) (capabilities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->getRawBackend) (DYNAMIC_BACKEND_PRIVities); } Bool ccsBackendHasExecuteEvents (CCSBackend *backend) @@ -1427,88 +1427,88 @@ Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *na } static Bool -ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - CAPABILITIES_PRIV (capabilities); + DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); return ccsBackendHasReadSetting (bcPrivate->backend); } static Bool -ccsDynamicBackendSupportsWriteDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsWriteDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - CAPABILITIES_PRIV (capabilities); + DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); return ccsBackendHasWriteSetting (bcPrivate->backend); } static Bool -ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *capabilities) +ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - CAPABILITIES_PRIV (capabilities); + DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); return ccsBackendHasProfileSupport (bcPrivate->backend); } -static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *capabilities) +static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { - CAPABILITIES_PRIV (capabilities); + DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); return bcPrivate->backend; } static Bool ccsDynamicBackendInitWrapper (CCSBackend *backend, CCSContext *context) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendInit (bcPrivate->backend, context); } static char * ccsDynamicBackendGetNameWrapper (CCSBackend *backend) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendGetName (bcPrivate->backend); } static char * ccsDynamicBackendGetShortDescWrapper (CCSBackend *backend) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendGetShortDesc (bcPrivate->backend); } static char * ccsDynamicBackendGetLongDescWrapper (CCSBackend *backend) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendGetName (bcPrivate->backend); } static Bool ccsDynamicBackendHasIntegrationSupportWrapper (CCSBackend *backend) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendHasIntegrationSupport (bcPrivate->backend); } static Bool ccsDynamicBackendHasProfileSupportWrapper (CCSBackend *backend) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendHasProfileSupport (bcPrivate->backend); } static Bool ccsDynamicBackendFiniWrapper (CCSBackend *backend) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendFini (bcPrivate->backend); } static void ccsDynamicBackendExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasExecuteEvents (bcPrivate->backend)) ccsBackendExecuteEvents (bcPrivate->backend, flags); @@ -1516,7 +1516,7 @@ static void ccsDynamicBackendExecuteEventsWrapper (CCSBackend *backend, unsigned static Bool ccsDynamicBackendReadInitWrapper (CCSBackend *backend, CCSContext *context) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasReadInit (bcPrivate->backend)) return ccsBackendReadInit (bcPrivate->backend, context); @@ -1526,7 +1526,7 @@ static Bool ccsDynamicBackendReadInitWrapper (CCSBackend *backend, CCSContext *c static void ccsDynamicBackendReadSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasReadSetting (bcPrivate->backend)) ccsBackendReadSetting (bcPrivate->backend, context, setting); @@ -1534,7 +1534,7 @@ static void ccsDynamicBackendReadSettingWrapper (CCSBackend *backend, CCSContext static void ccsDynamicBackendReadDoneWrapper (CCSBackend *backend, CCSContext *context) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasReadDone (bcPrivate->backend)) ccsBackendReadDone (bcPrivate->backend, context); @@ -1542,7 +1542,7 @@ static void ccsDynamicBackendReadDoneWrapper (CCSBackend *backend, CCSContext *c static Bool ccsDynamicBackendWriteInitWrapper (CCSBackend *backend, CCSContext *context) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasWriteInit (bcPrivate->backend)) return ccsBackendWriteInit (bcPrivate->backend, context); @@ -1552,7 +1552,7 @@ static Bool ccsDynamicBackendWriteInitWrapper (CCSBackend *backend, CCSContext * static void ccsDynamicBackendWriteSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasWriteSetting (bcPrivate->backend)) ccsBackendWriteSetting (bcPrivate->backend, context, setting); @@ -1560,7 +1560,7 @@ static void ccsDynamicBackendWriteSettingWrapper (CCSBackend *backend, CCSContex static void ccsDynamicBackendWriteDoneWrapper (CCSBackend *backend, CCSContext *context) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasWriteDone (bcPrivate->backend)) ccsBackendWriteDone (bcPrivate->backend, context); @@ -1568,7 +1568,7 @@ static void ccsDynamicBackendWriteDoneWrapper (CCSBackend *backend, CCSContext * static void ccsDynamicBackendUpdateSettingWrapper (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasUpdateSetting (bcPrivate->backend)) ccsBackendUpdateSetting (bcPrivate->backend, context, plugin, setting); @@ -1576,7 +1576,7 @@ static void ccsDynamicBackendUpdateSettingWrapper (CCSBackend *backend, CCSConte static Bool ccsDynamicBackendGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasGetSettingIsIntegrated (bcPrivate->backend) && ccsBackendHasIntegrationSupport (bcPrivate->backend)) @@ -1587,7 +1587,7 @@ static Bool ccsDynamicBackendGetSettingIsIntegratedWrapper (CCSBackend *backend, static Bool ccsDynamicBackendGetSettingIsReadOnlyWrapper (CCSBackend *backend, CCSSetting *setting) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasGetSettingIsReadOnly (bcPrivate->backend)) return ccsBackendGetSettingIsReadOnly (bcPrivate->backend, setting); @@ -1597,7 +1597,7 @@ static Bool ccsDynamicBackendGetSettingIsReadOnlyWrapper (CCSBackend *backend, C static CCSStringList ccsDynamicBackendGetExistingProfilesWrapper (CCSBackend *backend, CCSContext *context) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasGetExistingProfiles (bcPrivate->backend) && ccsBackendHasProfileSupport (bcPrivate->backend)) @@ -1610,7 +1610,7 @@ static CCSStringList ccsDynamicBackendGetExistingProfilesWrapper (CCSBackend *ba static Bool ccsDynamicBackendDeleteProfileWrapper (CCSBackend *backend, CCSContext *context, char *profile) { - CAPABILITIES_PRIV (backend); + DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasDeleteProfile (bcPrivate->backend) && ccsBackendHasProfileSupport (bcPrivate->backend)) -- GitLab From 0c69232012c50776d757f60c788b5d77da8c7263 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 14:06:55 +0800 Subject: [PATCH 168/562] Remove ccsDynamicBackendGetDlHand as it was unused --- compizconfig/libcompizconfig/src/main.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index a01749442..020e527ce 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1066,14 +1066,6 @@ openBackend (const char *backend) return dlhand; } -void * -ccsDynamicBackendGetDlHand (CCSBackend *backend) -{ - DYNAMIC_BACKEND_PRIV (backend); - - return bcPrivate->dlhand; -} - void ccsFreeBackend (CCSBackend *backend) { -- GitLab From b38d13927a2f28cbde40685a19dd5e8c37e9fa2f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 14:12:44 +0800 Subject: [PATCH 169/562] Use COMPIZCONFIG_BEGIN_DECLS / COMPIZCONFIG_END_DECLS in ccs-backend.h --- compizconfig/libcompizconfig/include/ccs-backend.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 0835c1de2..37d2e159b 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -25,6 +25,8 @@ #include #include +COMPIZCONFIG_BEGIN_DECLS + typedef struct _CCSBackend CCSBackend; typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendInterface CCSBackendInterface; @@ -148,4 +150,6 @@ ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterfac CCSBackendInterface* getBackendInfo (void); +COMPIZCONFIG_END_DECLS + #endif -- GitLab From c221e204e74b368b7636bd1a11bdf1f30b131e14 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 14:25:12 +0800 Subject: [PATCH 170/562] Make functions that should take const char ** take const char ** --- compizconfig/gconf/src/gconf.c | 13 +++++----- compizconfig/gsettings/src/gsettings.c | 6 ++--- .../libcompizconfig/backend/src/ini.c | 25 +++++++++++-------- compizconfig/libcompizconfig/include/ccs.h | 4 +-- compizconfig/libcompizconfig/src/ini.c | 2 +- compizconfig/libcompizconfig/src/lists.c | 4 +-- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index e730231f9..fd90074de 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -868,7 +868,7 @@ readListValue (CCSSetting *setting, case TypeString: case TypeMatch: { - char **array = malloc (nItems * sizeof (char*)); + const char **array = malloc (nItems * sizeof (char*)); if (!array) break; @@ -877,7 +877,7 @@ readListValue (CCSSetting *setting, list = ccsGetValueListFromStringArray (array, nItems, setting); for (i = 0; i < nItems; i++) if (array[i]) - free (array[i]); + free ((char *) array[i]); free (array); } break; @@ -1885,15 +1885,16 @@ getCurrentProfileName (void) static Bool checkProfile (CCSContext *context) { - char *profile, *lastProfile; + const char *profileCCS; + char *lastProfile; lastProfile = currentProfile; - profile = ccsGetProfile (context); - if (!profile || !strlen (profile)) + profileCCS = ccsGetProfile (context); + if (!profileCCS || !strlen (profileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (profile); + currentProfile = strdup (profileCCS); if (!lastProfile || strcmp (lastProfile, currentProfile) != 0) { diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index f06b8dc03..073b2d061 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -300,8 +300,8 @@ readListValue (CCSSetting *setting) case TypeString: case TypeMatch: { - gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); - gchar **arrayCounter = array; + const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); + const gchar **arrayCounter = array; gchar *value; if (!array) @@ -314,7 +314,7 @@ readListValue (CCSSetting *setting) *arrayCounter++ = value; list = ccsGetValueListFromStringArray (array, nItems, setting); - g_strfreev (array); + g_strfreev ((char **) array); } break; case TypeColor: diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 1fb83a642..62d166f52 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -231,7 +231,8 @@ finiBackend (CCSContext * context) static Bool readInit (CCSContext * context) { - char *currentProfile; + const char *currentProfileCCS; + char *currentProfile; IniPrivData *data; data = findPrivFromContext (context); @@ -239,12 +240,12 @@ readInit (CCSContext * context) if (!data) return FALSE; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); if (!data->lastProfile || (strcmp (data->lastProfile, currentProfile) != 0)) setProfile (data, currentProfile); @@ -421,6 +422,7 @@ readDone (CCSContext * context) static Bool writeInit (CCSContext * context) { + const char *currentProfileCCS; char *currentProfile; IniPrivData *data; @@ -429,12 +431,12 @@ writeInit (CCSContext * context) if (!data) return FALSE; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); if (!data->lastProfile || (strcmp (data->lastProfile, currentProfile) != 0)) setProfile (data, currentProfile); @@ -573,19 +575,20 @@ writeDone (CCSContext * context) { /* export the data to ensure the changes are on disk */ char *fileName; - char *currentProfile; + const char *currentProfileCCS; + char *currentProfile; IniPrivData *data; data = findPrivFromContext (context); if (!data) return; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); fileName = getIniFileName (currentProfile); diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 36679e74e..be5c31c20 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -975,10 +975,10 @@ ccsCopyList (CCSSettingValueList l1, CCSSetting * setting); /* Converts an array of data items to a setting value list. Behaves similar to ccsGetListFromStringArray */ -CCSSettingValueList ccsGetValueListFromStringArray (char **array, +CCSSettingValueList ccsGetValueListFromStringArray (const char **array, int num, CCSSetting *parent); -CCSSettingValueList ccsGetValueListFromMatchArray (char **array, +CCSSettingValueList ccsGetValueListFromMatchArray (const char **array, int num, CCSSetting *parent); CCSSettingValueList ccsGetValueListFromIntArray (int *array, diff --git a/compizconfig/libcompizconfig/src/ini.c b/compizconfig/libcompizconfig/src/ini.c index 6e44619bb..1284e836b 100644 --- a/compizconfig/libcompizconfig/src/ini.c +++ b/compizconfig/libcompizconfig/src/ini.c @@ -397,7 +397,7 @@ ccsIniParseList (const char *str, token = strsep (&valueString, ";"); } - list = ccsGetValueListFromStringArray (array, nItems, parent); + list = ccsGetValueListFromStringArray ((const char **) array, nItems, parent); for (i = 0; i < nItems; i++) free (array[i]); diff --git a/compizconfig/libcompizconfig/src/lists.c b/compizconfig/libcompizconfig/src/lists.c index 1c8081782..ec82a8140 100644 --- a/compizconfig/libcompizconfig/src/lists.c +++ b/compizconfig/libcompizconfig/src/lists.c @@ -392,7 +392,7 @@ CCSSettingColorValue * ccsGetColorArrayFromValueList (CCSSettingValueList list, return rv; } -CCSSettingValueList ccsGetValueListFromStringArray (char ** array, int num, +CCSSettingValueList ccsGetValueListFromStringArray (const char ** array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; @@ -414,7 +414,7 @@ CCSSettingValueList ccsGetValueListFromStringArray (char ** array, int num, return l; } -CCSSettingValueList ccsGetValueListFromMatchArray (char ** array, int num, +CCSSettingValueList ccsGetValueListFromMatchArray (const char ** array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; -- GitLab From 0316463d1cf81b04a2a471f402a0948260087d87 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 22:03:05 +0800 Subject: [PATCH 171/562] #include the right stuff --- compizconfig/libcompizconfig/include/ccs-backend.h | 1 + compizconfig/libcompizconfig/include/ccs-object.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 37d2e159b..82c5a4179 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -23,6 +23,7 @@ #define CCS_BACKEND_H #include +#include #include COMPIZCONFIG_BEGIN_DECLS diff --git a/compizconfig/libcompizconfig/include/ccs-object.h b/compizconfig/libcompizconfig/include/ccs-object.h index a2505de1b..c01f0fc2e 100644 --- a/compizconfig/libcompizconfig/include/ccs-object.h +++ b/compizconfig/libcompizconfig/include/ccs-object.h @@ -23,6 +23,8 @@ #ifndef _CCS_OBJECT_H #define _CCS_OBJECT_H +#include + COMPIZCONFIG_BEGIN_DECLS typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ -- GitLab From a7deebbe5a96698df38a98dff1720ccfcd042c40 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 22:03:25 +0800 Subject: [PATCH 172/562] constify --- compizconfig/libcompizconfig/include/ccs.h | 8 ++++++-- compizconfig/libcompizconfig/src/main.c | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 7f91f06d0..5cac502f2 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -158,7 +158,7 @@ typedef char * (*CCSContextGetBackend) (CCSContext *context); typedef void (*CCSContextSetIntegrationEnabled) (CCSContext *context, Bool value); typedef void (*CCSContextSetProfile) (CCSContext *context, char *name); typedef void (*CCSContextSetPluginListAutoSort) (CCSContext *context, Bool value); -typedef char * (*CCSContextGetProfile) (CCSContext *context); +typedef const char * (*CCSContextGetProfile) (CCSContext *context); typedef Bool (*CCSContextGetIntegrationEnabled) (CCSContext *context); typedef Bool (*CCSContextGetPluginListAutoSort) (CCSContext *context); typedef void (*CCSContextProcessEvents) (CCSContext *context, unsigned int flags); @@ -761,6 +761,10 @@ Bool ccsIsEqualKey (CCSSettingKeyValue c1, Bool ccsIsEqualButton (CCSSettingButtonValue c1, CCSSettingButtonValue c2); +/* Compares lists */ +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, + CCSSettingListInfo info); + /* Retrieves a list of settings in a plugin */ CCSSettingList ccsGetPluginSettings (CCSPlugin *plugin); @@ -853,7 +857,7 @@ void ccsSetPluginListAutoSort (CCSContext *context, Bool value); /* Retrieve current profile of the context. */ -char * ccsGetProfile (CCSContext *context); +const char *ccsGetProfile (CCSContext *context); /* Retrieves current DE integration status for a context */ Bool ccsGetIntegrationEnabled (CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index ddb2e0d6c..f748f8217 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1348,7 +1348,7 @@ Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *na return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (backend, context, name); } -static Bool +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, CCSSettingListInfo info) { @@ -2792,7 +2792,7 @@ ccsGetIntegrationEnabled (CCSContext *context) return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetIntegrationEnabled) (context); } -char * +const char * ccsGetProfileDefault (CCSContext * context) { if (!context) @@ -2803,7 +2803,7 @@ ccsGetProfileDefault (CCSContext * context) return cPrivate->profile; } -char * +const char * ccsGetProfile (CCSContext *context) { if (!context) -- GitLab From 59467a12be8235e8e0591f653cff97a8fbd75095 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 22:06:32 +0800 Subject: [PATCH 173/562] Make ccsCompareLists public --- compizconfig/libcompizconfig/include/ccs.h | 4 ++++ compizconfig/libcompizconfig/src/main.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index be5c31c20..8fe054dad 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -929,6 +929,10 @@ Bool ccsIsEqualKey (CCSSettingKeyValue c1, Bool ccsIsEqualButton (CCSSettingButtonValue c1, CCSSettingButtonValue c2); +/* Compares lists */ +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, + CCSSettingListInfo info); + /* Retrieves a list of settings in a plugin */ CCSSettingList ccsGetPluginSettings (CCSPlugin *plugin); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 524d7744f..0a0bca61d 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1134,7 +1134,7 @@ ccsSetBackend (CCSContext *context, char *name) return (*(GET_INTERFACE (CCSContextInterface, context))->contextSetBackend) (context, name); } -static Bool +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, CCSSettingListInfo info) { -- GitLab From 4deb8461088a627750262622ca5cde5dadfc9772 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 26 Jul 2012 22:32:54 +0800 Subject: [PATCH 174/562] Constify --- .../mocks/libcompizconfig/compizconfig_ccs_context_mock.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h index 1000d0d90..72f276bd4 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h @@ -31,7 +31,7 @@ class CCSContextGMockInterface virtual void setIntegrationEnabled (Bool value) = 0; virtual void setProfile (char *name) = 0; virtual void setPluginListAutoSort (Bool value) = 0; - virtual char * getProfile () = 0; + virtual const char * getProfile () = 0; virtual Bool getIntegrationEnabled () = 0; virtual Bool getPluginListAutoSort () = 0; virtual void processEvents (unsigned int flags) = 0; @@ -72,7 +72,7 @@ class CCSContextGMock : MOCK_METHOD1 (setIntegrationEnabled, void (Bool)); MOCK_METHOD1 (setProfile, void (char *)); MOCK_METHOD1 (setPluginListAutoSort, void (Bool)); - MOCK_METHOD0 (getProfile, char * ()); + MOCK_METHOD0 (getProfile, const char * ()); MOCK_METHOD0 (getIntegrationEnabled, Bool ()); MOCK_METHOD0 (getPluginListAutoSort, Bool ()); MOCK_METHOD1 (processEvents, void (unsigned int)); @@ -190,7 +190,7 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getIntegrationEnabled (); } - static char * + static const char * ccsGetProfile (CCSContext *context) { if (!context) -- GitLab From 239f5d4ce082231d25ccdb8f3c27d5f0507cba5e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 07:08:50 +0800 Subject: [PATCH 175/562] Cleanup --- compizconfig/libcompizconfig/include/ccs-backend.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 41e978da3..08d0361c2 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -54,8 +54,8 @@ typedef void (*CCSBackendReadDoneFunc) (CCSBackend *backend, CCSContext * contex typedef Bool (*CCSBackendWriteInitFunc) (CCSBackend *backend, CCSContext * context); typedef void (*CCSBackendWriteSettingFunc) -(CCSBackend *backend, CCSContext * context, CCSSetting * setting); -typedef void (*CCSBackendWriteDoneFunc) (CCSBackend *backend, CCSContext * context); +(CCSBackend *, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendWriteDoneFunc) (CCSBackend *, CCSContext * context); typedef void (*CCSBackendUpdateFunc) (CCSBackend *, CCSContext *, CCSPlugin *, CCSSetting *); -- GitLab From cbf1179ac35f3a4f781758aeae64626bdd93b20a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 07:10:28 +0800 Subject: [PATCH 176/562] set LINK_INTERFACE_LIBRARIES correctly --- compizconfig/libcompizconfig/src/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compizconfig/libcompizconfig/src/CMakeLists.txt b/compizconfig/libcompizconfig/src/CMakeLists.txt index 919668a62..4f308ac77 100644 --- a/compizconfig/libcompizconfig/src/CMakeLists.txt +++ b/compizconfig/libcompizconfig/src/CMakeLists.txt @@ -68,6 +68,14 @@ target_link_libraries ( compizconfig ${LIBCOMPIZCONFIG_LIBRARIES} m ) +# +# Tell CMake that targets using compizconfig should NOT re-import the +# libraries that compizconfig depends on (contains). +# +set_target_properties (compizconfig PROPERTIES + LINK_INTERFACE_LIBRARIES "" +) + set (COMPIZCONFIG_LIBS "") foreach (_val ${LIBCOMPIZCONFIG_LDFLAGS}) set (COMPIZCONFIG_LIBS "${COMPIZCONFIG_LIBS}${_val} ") -- GitLab From e3bc51587cfbd64a4857d4f4deda584e9e9e4bdc Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 07:16:47 +0800 Subject: [PATCH 177/562] Nuke unused function in header file --- compizconfig/libcompizconfig/include/ccs-backend.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 03446c933..08d0361c2 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -170,12 +170,6 @@ CCSBackend * ccsOpenBackend (const CCSInterfaceTable *, CCSContext *context, con CCSBackend * ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface); -typedef struct _CCSInterfaceTable CCSInterfaceTable; - -/* Constructor method */ -CCSDynamicBackend * -ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand); - CCSBackendInterface* getBackendInfo (void); COMPIZCONFIG_END_DECLS -- GitLab From b2566af8f91cb9b4f75529fb411f615e46d94666 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 07:24:45 +0800 Subject: [PATCH 178/562] Refactor out readBoolListValue --- .../gsettings_backend_shared/gsettings_util.c | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 7a7fb01d2..eee771a74 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -483,6 +483,27 @@ getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCS return gsettingsValue; } +CCSSettingValueList +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +{ + CCSSettingValueList list = NULL; + Bool *array = malloc (nItems * sizeof (Bool)); + Bool *arrayCounter = array; + gboolean value; + + if (!array) + return NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (iter, "b", &value)) + *arrayCounter++ = value ? TRUE : FALSE; + + list = ccsGetValueListFromBoolArray (array, nItems, setting); + free (array); + + return list; +} + CCSSettingValueList readListValue (GVariant *gsettingsValue, CCSSetting *setting) { @@ -503,21 +524,7 @@ readListValue (GVariant *gsettingsValue, CCSSetting *setting) switch (listType) { case TypeBool: - { - Bool *array = malloc (nItems * sizeof (Bool)); - Bool *arrayCounter = array; - gboolean value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "b", &value)) - *arrayCounter++ = value ? TRUE : FALSE; - - list = ccsGetValueListFromBoolArray (array, nItems, setting); - free (array); - } + list = readBoolListValue (&iter, nItems, setting); break; case TypeInt: { -- GitLab From be1306249d72ef852eb7b15a31d6124f7472835d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 07:31:36 +0800 Subject: [PATCH 179/562] Refactor out readIntListValue --- .../gsettings_backend_shared/gsettings_util.c | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index eee771a74..3879df123 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -504,6 +504,27 @@ readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) return list; } +CCSSettingValueList +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +{ + CCSSettingValueList list = NULL; + int *array = malloc (nItems * sizeof (int)); + int *arrayCounter = array; + gint value; + + if (!array) + return NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (iter, "i", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromIntArray (array, nItems, setting); + free (array); + + return list; +} + CCSSettingValueList readListValue (GVariant *gsettingsValue, CCSSetting *setting) { @@ -527,21 +548,7 @@ readListValue (GVariant *gsettingsValue, CCSSetting *setting) list = readBoolListValue (&iter, nItems, setting); break; case TypeInt: - { - int *array = malloc (nItems * sizeof (int)); - int *arrayCounter = array; - gint value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "i", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromIntArray (array, nItems, setting); - free (array); - } + list = readIntListValue (&iter, nItems, setting); break; case TypeFloat: { -- GitLab From 609d1fe4b650576cb6ad6935c35d65b2bd6c8ed5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 07:46:30 +0800 Subject: [PATCH 180/562] Refactor out the other read*ListValue funcs --- .../gsettings_backend_shared/gsettings_util.c | 122 ++++++++++-------- 1 file changed, 71 insertions(+), 51 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 3879df123..daa9a7e97 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -525,6 +525,74 @@ readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) return list; } +CCSSettingValueList +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +{ + CCSSettingValueList list = NULL; + float *array = malloc (nItems * sizeof (float)); + float *arrayCounter = array; + gdouble value; + + if (!array) + return NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (iter, "d", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromFloatArray (array, nItems, setting); + free (array); + + return list; +} + +CCSSettingValueList +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +{ + CCSSettingValueList list = NULL; + const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); + const gchar **arrayCounter = array; + gchar *value; + + if (!array) + return NULL; + + array[nItems] = NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_next (iter, "s", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromStringArray (array, nItems, setting); + g_strfreev ((char **) array); + + return list; +} + +CCSSettingValueList +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +{ + CCSSettingValueList list = NULL; + char *colorValue; + CCSSettingColorValue *array = calloc (1, nItems * sizeof (CCSSettingColorValue)); + unsigned int i = 0; + + if (!array) + return NULL; + + while (g_variant_iter_loop (iter, "s", &colorValue)) + { + ccsStringToColor (colorValue, + &array[i]); + i++; + } + + list = ccsGetValueListFromColorArray (array, nItems, setting); + free (array); + + return list; +} + CCSSettingValueList readListValue (GVariant *gsettingsValue, CCSSetting *setting) { @@ -551,61 +619,13 @@ readListValue (GVariant *gsettingsValue, CCSSetting *setting) list = readIntListValue (&iter, nItems, setting); break; case TypeFloat: - { - float *array = malloc (nItems * sizeof (float)); - float *arrayCounter = array; - gdouble value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "d", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromFloatArray (array, nItems, setting); - free (array); - } - break; + list = readFloatListValue (&iter, nItems, setting); case TypeString: case TypeMatch: - { - const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); - const gchar **arrayCounter = array; - gchar *value; - - if (!array) - break; - - array[nItems] = NULL; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_next (&iter, "s", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromStringArray (array, nItems, setting); - g_strfreev ((char **) array); - } + list = readStringListValue (&iter, nItems, setting); break; case TypeColor: - { - char *colorValue; - CCSSettingColorValue *array = calloc (1, nItems * sizeof (CCSSettingColorValue)); - unsigned int i = 0; - - if (!array) - break; - - while (g_variant_iter_loop (&iter, "s", &colorValue)) - { - ccsStringToColor (colorValue, - &array[i]); - i++; - } - - list = ccsGetValueListFromColorArray (array, nItems, setting); - free (array); - } + list = readColorListValue (&iter, nItems, setting); break; default: break; -- GitLab From 17ce8fb4a57cd2c23bfc84335b161e38f7e6b399 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 07:48:14 +0800 Subject: [PATCH 181/562] Added missing break statement --- compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index daa9a7e97..ad1cb55ad 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -620,6 +620,7 @@ readListValue (GVariant *gsettingsValue, CCSSetting *setting) break; case TypeFloat: list = readFloatListValue (&iter, nItems, setting); + break; case TypeString: case TypeMatch: list = readStringListValue (&iter, nItems, setting); -- GitLab From 139e1913cc5246611360465cd42c301e451b3cfd Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 08:00:43 +0800 Subject: [PATCH 182/562] Refactor out list writing functions too --- .../gsettings_backend_shared/gsettings_util.c | 168 +++++++++++------- 1 file changed, 105 insertions(+), 63 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index ad1cb55ad..7bc9178df 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -708,6 +708,105 @@ unsigned int readEdgeFromVariant (GVariant *gsettingsValue) return 0; } +GVariant * +writeBoolListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); + while (list) + { + g_variant_builder_add (builder, "b", list->data->value.asBool); + list = list->next; + } + value = g_variant_new ("ab", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeIntListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); + while (list) + { + g_variant_builder_add (builder, "i", list->data->value.asInt); + list = list->next; + } + value = g_variant_new ("ai", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeFloatListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); + while (list) + { + g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); + list = list->next; + } + value = g_variant_new ("ad", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeStringListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + while (list) + { + g_variant_builder_add (builder, "s", list->data->value.asString); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeMatchListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + while (list) + { + g_variant_builder_add (builder, "s", list->data->value.asMatch); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeColorListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + char *item; + while (list) + { + item = ccsColorToString (&list->data->value.asColor); + g_variant_builder_add (builder, "s", item); + g_free (item); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + + return value; +} + Bool writeListValue (CCSSettingValueList list, CCSSettingType listType, @@ -718,79 +817,22 @@ writeListValue (CCSSettingValueList list, switch (listType) { case TypeBool: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); - while (list) - { - g_variant_builder_add (builder, "b", list->data->value.asBool); - list = list->next; - } - value = g_variant_new ("ab", builder); - g_variant_builder_unref (builder); - } + value = writeBoolListValue (list); break; case TypeInt: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); - while (list) - { - g_variant_builder_add (builder, "i", list->data->value.asInt); - list = list->next; - } - value = g_variant_new ("ai", builder); - g_variant_builder_unref (builder); - } + value = writeIntListValue (list); break; case TypeFloat: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); - while (list) - { - g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); - list = list->next; - } - value = g_variant_new ("ad", builder); - g_variant_builder_unref (builder); - } + value = writeFloatListValue (list); break; case TypeString: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - while (list) - { - g_variant_builder_add (builder, "s", list->data->value.asString); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } + value = writeStringListValue (list); break; case TypeMatch: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - while (list) - { - g_variant_builder_add (builder, "s", list->data->value.asMatch); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } + value = writeMatchListValue (list); break; case TypeColor: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - char *item; - while (list) - { - item = ccsColorToString (&list->data->value.asColor); - g_variant_builder_add (builder, "s", item); - g_free (item); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } + value = writeColorListValue (list); break; default: ccsWarning ("Attempt to write unsupported list type %d!", -- GitLab From 74c4d8ce851705695f7f07a0c3a23339f60eb1b6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 22:29:06 +0800 Subject: [PATCH 183/562] Interface seams for : + ccsGSettingsBackendUnregisterGConfClientDefault, + ccsGSettingsBackendGetExistingProfilesDefault, + ccsGSettingsBackendSetExistingProfilesDefault, + ccsGSettingsBackendSetCurrentProfileDefault --- .../gsettings_backend_shared/gsettings_util.c | 18 ++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 16 ++++++++++ compizconfig/gsettings/src/gsettings.c | 29 ++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 7bc9178df..b33d1fac6 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -965,3 +965,21 @@ ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend) { (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnregisterGConfClient) (backend); } + +GVariant * +ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetExistingProfiles) (backend); +} + +void +ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendSetExistingProfiles) (backend, value); +} + +void +ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendSetCurrentProfile) (backend, value); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 4c7914d98..eed8a2fce 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -22,6 +22,10 @@ typedef GSettings * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CC typedef void (*CCSGSettingsBackendRegisterGConfClient) (CCSBackend *backend); typedef void (*CCSGSettingsBackendUnregisterGConfClient) (CCSBackend *backend); +typedef GVariant * (*CCSGSettingsBackendGetExistingProfiles) (CCSBackend *backend); +typedef void (*CCSGSettingsBackendSetExistingProfiles) (CCSBackend *backend, GVariant *value); +typedef void (*CCSGSettingsBackendSetCurrentProfile) (CCSBackend *backend, const gchar *value); + struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; @@ -29,6 +33,9 @@ struct _CCSGSettingsBackendInterface CCSGSettingsBackendGetSettingsObjectForPluginWithPath gsettingsBackendGetSettingsObjectForPluginWithPath; CCSGSettingsBackendRegisterGConfClient gsettingsBackendRegisterGConfClient; CCSGSettingsBackendUnregisterGConfClient gsettingsBackendUnregisterGConfClient; + CCSGSettingsBackendGetExistingProfiles gsettingsBackendGetExistingProfiles; + CCSGSettingsBackendSetExistingProfiles gsettingsBackendSetExistingProfiles; + CCSGSettingsBackendSetCurrentProfile gsettingsBackendSetCurrentProfile; }; unsigned int ccsCCSGSettingsBackendInterfaceGetType (); @@ -178,6 +185,15 @@ ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend); void ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend); +GVariant * +ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend); + +void +ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value); + +void +ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index bf335b0d4..c9a88bb51 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -634,12 +634,39 @@ ccsGSettingsBackendUnregisterGConfClientDefault (CCSBackend *backend) #endif } +static GVariant * +ccsGSettingsBackendGetExistingProfilesDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); +} + +static void +ccsGSettingsBackendSetExistingProfilesDefault (CCSBackend *backend, GVariant *value) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + g_settings_set_value (priv->compizconfigSettings, "existing-profiles", value); +} + +static void +ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *value) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + g_settings_set (priv->compizconfigSettings, "current-profile", "s", value, NULL); +} + static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendGetContextDefault, ccsGSettingsBackendConnectToValueChangedSignalDefault, ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault, ccsGSettingsBackendRegisterGConfClientDefault, - ccsGSettingsBackendUnregisterGConfClientDefault + ccsGSettingsBackendUnregisterGConfClientDefault, + ccsGSettingsBackendGetExistingProfilesDefault, + ccsGSettingsBackendSetExistingProfilesDefault, + ccsGSettingsBackendSetCurrentProfileDefault }; static Bool -- GitLab From 207cadc753d73ef533bb8b8da92d53c327377d95 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 22:41:39 +0800 Subject: [PATCH 184/562] Use those seams --- compizconfig/gsettings/src/gsettings.c | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index c9a88bb51..312fdc3bf 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -504,15 +504,12 @@ updateCurrentProfileName (CCSBackend *backend, const char *profile) { GVariant *profiles; char *prof; - gchar *profilePath = makeCompizProfilePath (profile); GVariant *newProfiles; GVariantBuilder *newProfilesBuilder; GVariantIter iter; gboolean found = FALSE; - CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - - profiles = g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); + profiles = ccsGSettingsBackendGetExistingProfiles (backend); newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); @@ -529,22 +526,14 @@ updateCurrentProfileName (CCSBackend *backend, const char *profile) g_variant_builder_add (newProfilesBuilder, "s", profile); newProfiles = g_variant_new ("as", newProfilesBuilder); - g_settings_set_value (priv->compizconfigSettings, "existing-profiles", newProfiles); + ccsGSettingsBackendSetExistingProfiles (backend, newProfiles); g_variant_unref (newProfiles); g_variant_builder_unref (newProfilesBuilder); g_variant_unref (profiles); - /* Change the current profile and current profile settings */ - free (priv->currentProfile); - - priv->currentProfile = strdup (profile); - priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); - - g_settings_set (priv->compizconfigSettings, "current-profile", "s", profile, NULL); - - g_free (profilePath); + ccsGSettingsBackendSetCurrentProfile (backend, profile); } static gboolean @@ -655,7 +644,17 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + /* Change the current profile and current profile settings */ + free (priv->currentProfile); + + gchar *profilePath = makeCompizProfilePath (value); + + priv->currentProfile = strdup (value); + priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); + g_settings_set (priv->compizconfigSettings, "current-profile", "s", value, NULL); + + g_free (profilePath); } static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { -- GitLab From 822f05cb9f1410c9c178336896285778d968bc18 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 27 Jul 2012 22:47:21 +0800 Subject: [PATCH 185/562] Put updateCurrentProfileName in gsettings_util.c --- .../gsettings_backend_shared/gsettings_util.c | 37 +++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 3 ++ compizconfig/gsettings/src/gsettings.c | 37 ------------------- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index b33d1fac6..1e8922ff2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -931,6 +931,43 @@ writeVariantToKey (GSettings *settings, g_settings_set_value (settings, key, value); } +void +updateCurrentProfileName (CCSBackend *backend, const char *profile) +{ + GVariant *profiles; + char *prof; + GVariant *newProfiles; + GVariantBuilder *newProfilesBuilder; + GVariantIter iter; + gboolean found = FALSE; + + profiles = ccsGSettingsBackendGetExistingProfiles (backend); + + newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + + g_variant_iter_init (&iter, profiles); + while (g_variant_iter_loop (&iter, "s", &prof)) + { + g_variant_builder_add (newProfilesBuilder, "s", prof); + + if (!found) + found = (g_strcmp0 (prof, profile) == 0); + } + + if (!found) + g_variant_builder_add (newProfilesBuilder, "s", profile); + + newProfiles = g_variant_new ("as", newProfilesBuilder); + ccsGSettingsBackendSetExistingProfiles (backend, newProfiles); + + g_variant_unref (newProfiles); + g_variant_builder_unref (newProfilesBuilder); + + g_variant_unref (profiles); + + ccsGSettingsBackendSetCurrentProfile (backend, profile); +} + CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend) { diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index eed8a2fce..95cd3f71b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -179,6 +179,9 @@ ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, const char *path, CCSContext *context); +void +updateCurrentProfileName (CCSBackend *backend, const char *profile); + void ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 312fdc3bf..5529d74fc 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -499,43 +499,6 @@ writeOption (CCSBackend *backend, CCSSetting * setting) free (cleanSettingName); } -static void -updateCurrentProfileName (CCSBackend *backend, const char *profile) -{ - GVariant *profiles; - char *prof; - GVariant *newProfiles; - GVariantBuilder *newProfilesBuilder; - GVariantIter iter; - gboolean found = FALSE; - - profiles = ccsGSettingsBackendGetExistingProfiles (backend); - - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - - g_variant_iter_init (&iter, profiles); - while (g_variant_iter_loop (&iter, "s", &prof)) - { - g_variant_builder_add (newProfilesBuilder, "s", prof); - - if (!found) - found = (g_strcmp0 (prof, profile) == 0); - } - - if (!found) - g_variant_builder_add (newProfilesBuilder, "s", profile); - - newProfiles = g_variant_new ("as", newProfilesBuilder); - ccsGSettingsBackendSetExistingProfiles (backend, newProfiles); - - g_variant_unref (newProfiles); - g_variant_builder_unref (newProfilesBuilder); - - g_variant_unref (profiles); - - ccsGSettingsBackendSetCurrentProfile (backend, profile); -} - static gboolean updateProfile (CCSBackend *backend, CCSContext *context) { -- GitLab From 5e7a202107f32bfd690d515a070c3f06f9d55f51 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 07:31:10 +0800 Subject: [PATCH 186/562] Added a GMock stub file and move mock_gsettings to wrap_gsettigns --- compizconfig/gsettings/tests/CMakeLists.txt | 9 +++++++-- .../gsettings/tests/ccs_gsettings_backend_mock.cpp | 0 .../gsettings/tests/ccs_gsettings_backend_mock.h | 0 compizconfig/gsettings/tests/test_gsettings_tests.cpp | 2 +- .../tests/{gsettings_mocks.cpp => wrap_gsettings.cpp} | 2 +- .../tests/{gsettings_mocks.h => wrap_gsettings.h} | 4 ++-- 6 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp create mode 100644 compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h rename compizconfig/gsettings/tests/{gsettings_mocks.cpp => wrap_gsettings.cpp} (99%) rename compizconfig/gsettings/tests/{gsettings_mocks.h => wrap_gsettings.h} (93%) diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 57f6ceb30..53886ae69 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -5,11 +5,15 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) +add_library (compizconfig_ccs_gsettings_backend_mock STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.h) + add_executable (compizconfig_test_gsettings - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wrap_gsettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.h + ${CMAKE_CURRENT_SOURCE_DIR}/wrap_gsettings.h ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.h) link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) @@ -17,6 +21,7 @@ link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) target_link_libraries (compizconfig_test_gsettings gsettings_backend_shared compizconfig_ccs_setting_mock + compizconfig_ccs_gsettings_backend_mock ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h new file mode 100644 index 000000000..e69de29bb diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 27c309c2e..74bdaef7a 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -3,7 +3,7 @@ #include "test_gsettings_tests.h" #include "gsettings.h" -#include "gsettings_mocks.h" +#include "wrap_gsettings.h" using ::testing::Values; using ::testing::ValuesIn; diff --git a/compizconfig/gsettings/tests/gsettings_mocks.cpp b/compizconfig/gsettings/tests/wrap_gsettings.cpp similarity index 99% rename from compizconfig/gsettings/tests/gsettings_mocks.cpp rename to compizconfig/gsettings/tests/wrap_gsettings.cpp index ec2e600ea..6063da7f3 100644 --- a/compizconfig/gsettings/tests/gsettings_mocks.cpp +++ b/compizconfig/gsettings/tests/wrap_gsettings.cpp @@ -1,4 +1,4 @@ -#include +#include static void compizconfig_gsettings_wrap_gsettings_default_init (CCSGSettingsWrapGSettingsInterface *interface); diff --git a/compizconfig/gsettings/tests/gsettings_mocks.h b/compizconfig/gsettings/tests/wrap_gsettings.h similarity index 93% rename from compizconfig/gsettings/tests/gsettings_mocks.h rename to compizconfig/gsettings/tests/wrap_gsettings.h index 5cbcaea60..79b4b86f4 100644 --- a/compizconfig/gsettings/tests/gsettings_mocks.h +++ b/compizconfig/gsettings/tests/wrap_gsettings.h @@ -1,5 +1,5 @@ -#ifndef _COMPIZ_COMPIZCONFIG_GSETTINGS_MOCKS -#define _COMPIZ_COMPIZCONFIG_GSETTINGS_MOCKS +#ifndef _COMPIZ_COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS +#define _COMPIZ_COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS #include #include -- GitLab From 3485516a46e05abe7599e3a0f87f04e0ab1d9107 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 07:40:12 +0800 Subject: [PATCH 187/562] Added stub mock --- .../tests/ccs_gsettings_backend_mock.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h index e69de29bb..e5b3d182b 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -0,0 +1,21 @@ +#ifndef _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_MOCK +#define _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_MOCK + +#include +#include + +#include +#include + +using ::testing::_; +using ::testing::Return; + +CCSBackend * ccsGSettingsBackendGMockNew (); +void ccsGSettingsBackendGMockFree (CCSBackend *backend); + +class CCSGSettingsBackendGMockInterface +{ + public: + + virtual ~CCSGSettingsBackendGMockInterface () {} +}; -- GitLab From 473b014e06c774b842eed3f56539d1d6d960e186 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 08:03:05 +0800 Subject: [PATCH 188/562] Mock implementation of CCSGSettingsBackend * --- .../gsettings_backend_shared/gsettings_util.h | 8 +- .../tests/ccs_gsettings_backend_mock.cpp | 54 +++++++++++ .../tests/ccs_gsettings_backend_mock.h | 96 +++++++++++++++++++ 3 files changed, 154 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 95cd3f71b..d6e3767c2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -1,4 +1,4 @@ -#ifndef _COMPIZ_GSETTINGS_UTIL_H + #ifndef _COMPIZ_GSETTINGS_UTIL_H #define _COMPIZ_GSETTINGS_UTIL_H #include @@ -167,6 +167,9 @@ void writeVariantToKey (GSettings *settings, const char *key, GVariant *value); +void +updateCurrentProfileName (CCSBackend *backend, const char *profile); + CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend); @@ -179,9 +182,6 @@ ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, const char *path, CCSContext *context); -void -updateCurrentProfileName (CCSBackend *backend, const char *profile); - void ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend); diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp index e69de29bb..5a9fa3fcf 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp @@ -0,0 +1,54 @@ +#include +#include + +#include + +#include "ccs_gsettings_backend_mock.h" + +CCSGSettingsBackendInterface ccsGSettingsBackendGMockInterface = +{ + CCSGSettingsBackendGMock::ccsGSettingsBackendGetContext, + CCSGSettingsBackendGMock::ccsGSettingsBackendConnectToValueChangedSignal, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetSettingsObjectForPluginWithPath, + CCSGSettingsBackendGMock::ccsGSettingsBackendRegisterGConfClient, + CCSGSettingsBackendGMock::ccsGSettingsBackendUnregisterGConfClient, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetExistingProfiles, + CCSGSettingsBackendGMock::ccsGSettingsBackendSetExistingProfiles, + CCSGSettingsBackendGMock::ccsGSettingsBackendSetCurrentProfile +}; + +CCSBackend * +ccsGSettingsBackendGMockNew () +{ + CCSBackend *backend = (CCSBackend *) calloc (1, sizeof (CCSBackend *)); + + if (!backend) + return NULL; + + CCSGSettingsBackendGMock *gmock = new CCSGSettingsBackendGMock (backend); + + if (!gmock) + { + free (backend); + return NULL; + } + + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + ccsObjectAddInterface (backend, (const CCSInterface *) &ccsGSettingsBackendGMockInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + ccsObjectSetPrivate (backend, reinterpret_cast (backend)); + + return backend; +} + +void +ccsGSettingsBackendGMockFree (CCSBackend *backend) +{ + CCSGSettingsBackendGMock *mock = reinterpret_cast (ccsObjectGetPrivate (backend)); + + delete mock; + + ccsObjectSetPrivate (backend, NULL); + ccsObjectFinalize (backend); + + free (backend); +} diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h index e5b3d182b..a235165a2 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -18,4 +18,100 @@ class CCSGSettingsBackendGMockInterface public: virtual ~CCSGSettingsBackendGMockInterface () {} + + virtual CCSContext * getContext () = 0; + virtual void connectToChangedSignal (GObject *) = 0; + virtual GSettings * getSettingsObjectForPluginWithPath (const char * plugin, + const char * path, + CCSContext * context) = 0; + virtual void registerGConfClient () = 0; + virtual void unregisterGConfClient () = 0; + virtual GVariant * getExistingProfiles () = 0; + virtual void setExistingProfiles (GVariant *) = 0; + virtual void setCurrentProfile (const gchar *) = 0; }; + +class CCSGSettingsBackendGMock : + public CCSGSettingsBackendGMockInterface +{ + public: + + CCSGSettingsBackendGMock (CCSBackend *backend) : + mBackend (backend) + { + } + + MOCK_METHOD0 (getContext, CCSContext * ()); + MOCK_METHOD1 (connectToChangedSignal, void (GObject *)); + MOCK_METHOD3 (getSettingsObjectForPluginWithPath, GSettings * (const char * plugin, + const char * path, + CCSContext * context)); + MOCK_METHOD0 (registerGConfClient, void ()); + MOCK_METHOD0 (unregisterGConfClient, void ()); + MOCK_METHOD0 (getExistingProfiles, GVariant * ()); + MOCK_METHOD1 (setExistingProfiles, void (GVariant *)); + MOCK_METHOD1 (setCurrentProfile, void (const gchar *)); + + CCSBackend * getBackend () { return mBackend; } + + private: + + CCSBackend *mBackend; + + public: + + static CCSContext * + ccsGSettingsBackendGetContext (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getContext (); + } + + static void + ccsGSettingsBackendConnectToValueChangedSignal (CCSBackend *backend, GObject *object) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->connectToChangedSignal(object); + } + + static GSettings * + ccsGSettingsBackendGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getSettingsObjectForPluginWithPath (plugin, + path, + context); + } + + static void + ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->registerGConfClient (); + } + + static void + ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->unregisterGConfClient (); + } + + static GVariant * + ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getExistingProfiles (); + } + + static void + ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->setExistingProfiles (value); + } + + static void + ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->setCurrentProfile (value); + } +}; + +#endif -- GitLab From aad4295eef3becaf99d04f13ae956e4a1ab9d34a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 08:37:11 +0800 Subject: [PATCH 189/562] Added a simple (but incomplete test for updateCurrentProfileName --- .../tests/ccs_gsettings_backend_mock.cpp | 4 +- .../gsettings/tests/test_gsettings_tests.cpp | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp index 5a9fa3fcf..c1d9bf04e 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp @@ -20,7 +20,7 @@ CCSGSettingsBackendInterface ccsGSettingsBackendGMockInterface = CCSBackend * ccsGSettingsBackendGMockNew () { - CCSBackend *backend = (CCSBackend *) calloc (1, sizeof (CCSBackend *)); + CCSBackend *backend = (CCSBackend *) calloc (1, sizeof (CCSBackend)); if (!backend) return NULL; @@ -35,7 +35,7 @@ ccsGSettingsBackendGMockNew () ccsObjectInit (backend, &ccsDefaultObjectAllocator); ccsObjectAddInterface (backend, (const CCSInterface *) &ccsGSettingsBackendGMockInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); - ccsObjectSetPrivate (backend, reinterpret_cast (backend)); + ccsObjectSetPrivate (backend, reinterpret_cast (gmock)); return backend; } diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 74bdaef7a..e2b12d760 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1,13 +1,49 @@ #include #include +#include + #include "test_gsettings_tests.h" #include "gsettings.h" #include "wrap_gsettings.h" +#include "ccs_gsettings_backend_mock.h" using ::testing::Values; using ::testing::ValuesIn; using ::testing::Return; +using ::testing::MatcherInterface; +using ::testing::MatchResultListener; +using ::testing::AllOf; +using ::testing::Matcher; + +class GVariantSubtypeMatcher : + public ::testing::MatcherInterface +{ + public: + GVariantSubtypeMatcher (const std::string &type) : + mType (type) + { + } + + virtual ~GVariantSubtypeMatcher () {} + virtual bool MatchAndExplain (GVariant *x, MatchResultListener *listener) const + { + return g_variant_type_is_subtype_of (G_VARIANT_TYPE (mType.c_str ()), g_variant_get_type (x)); + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "is subtype of " << mType; + } + private: + + std::string mType; +}; + +inline Matcher IsVariantSubtypeOf (const std::string &type) +{ + return MakeMatcher (new GVariantSubtypeMatcher (type)); +} TEST_P(CCSGSettingsTest, TestTestFixtures) { @@ -17,6 +53,32 @@ TEST_F(CCSGSettingsTestIndependent, TestTest) { } +TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) +{ + g_type_init (); + + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&builder, "s", "foo"); + g_variant_builder_add (&builder, "s", "bar"); + g_variant_builder_add (&builder, "s", "baz"); + + GVariant *existingProfiles = g_variant_builder_end (&builder); + + EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); + EXPECT_CALL (*gmock, setExistingProfiles (IsVariantSubtypeOf ("as"))); + EXPECT_CALL (*gmock, setCurrentProfile (_)); + + updateCurrentProfileName (backend.get (), "narr"); + + g_variant_unref (existingProfiles); +} + TEST_F(CCSGSettingsTestIndependent, TestGetSchemaNameForPlugin) { const gchar *plugin = "foo"; -- GitLab From e094c5905a2de9091718129dd58c40f5eaf96428 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 09:04:57 +0800 Subject: [PATCH 190/562] Also match the value --- .../gsettings/tests/test_gsettings_tests.cpp | 67 ++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index e2b12d760..663c116a3 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -11,6 +11,7 @@ using ::testing::Values; using ::testing::ValuesIn; using ::testing::Return; +using ::testing::Invoke; using ::testing::MatcherInterface; using ::testing::MatchResultListener; using ::testing::AllOf; @@ -40,6 +41,56 @@ class GVariantSubtypeMatcher : std::string mType; }; +template +class GVariantHasValueInArrayMatcher : + public ::testing::MatcherInterface +{ + public: + GVariantHasValueInArrayMatcher (const std::string &type, + const T &t, + const boost::function &eq) : + mType (type), + mT (t), + mEq (eq) + { + } + + virtual ~GVariantHasValueInArrayMatcher () {} + virtual bool MatchAndExplain (GVariant *x, MatchResultListener *listener) const + { + GVariantIter iter; + T match; + bool found = false; + + g_variant_iter_init (&iter, x); + while (g_variant_iter_loop (&iter, mType.c_str (), &match)) + { + if (mEq (match, mT)) + found = true; + } + + return found; + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "contains " << mT; + } + private: + + std::string mType; + T mT; + boost::function mEq; +}; + +template +inline Matcher GVariantHasValueInArray (const std::string &type, + const T &t, + const boost::function &eq) +{ + return MakeMatcher (new GVariantHasValueInArrayMatcher (type, t, eq)); +} + inline Matcher IsVariantSubtypeOf (const std::string &type) { return MakeMatcher (new GVariantSubtypeMatcher (type)); @@ -53,6 +104,15 @@ TEST_F(CCSGSettingsTestIndependent, TestTest) { } +namespace +{ +bool streq (const char * const &s1, const char * const &s2) +{ + return g_str_equal (s1, s2); +} + +} + TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) { g_type_init (); @@ -71,12 +131,13 @@ TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) GVariant *existingProfiles = g_variant_builder_end (&builder); EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); - EXPECT_CALL (*gmock, setExistingProfiles (IsVariantSubtypeOf ("as"))); + EXPECT_CALL (*gmock, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), + GVariantHasValueInArray ("s", + "narr", + boost::bind (streq, _1, _2))))); EXPECT_CALL (*gmock, setCurrentProfile (_)); updateCurrentProfileName (backend.get (), "narr"); - - g_variant_unref (existingProfiles); } TEST_F(CCSGSettingsTestIndependent, TestGetSchemaNameForPlugin) -- GitLab From 1229c4e70f42e55ade97d210c1fd503f3c93a886 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 09:55:26 +0800 Subject: [PATCH 191/562] Added a test for handling of calling updateCurrentProfile with a known profile --- .../gsettings_backend_shared/gsettings_util.c | 10 ++++---- .../gsettings/tests/test_gsettings_tests.cpp | 23 +++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 1e8922ff2..a5580d0db 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -955,14 +955,16 @@ updateCurrentProfileName (CCSBackend *backend, const char *profile) } if (!found) + { g_variant_builder_add (newProfilesBuilder, "s", profile); - newProfiles = g_variant_new ("as", newProfilesBuilder); - ccsGSettingsBackendSetExistingProfiles (backend, newProfiles); + newProfiles = g_variant_new ("as", newProfilesBuilder); + ccsGSettingsBackendSetExistingProfiles (backend, newProfiles); - g_variant_unref (newProfiles); - g_variant_builder_unref (newProfilesBuilder); + g_variant_unref (newProfiles); + } + g_variant_builder_unref (newProfilesBuilder); g_variant_unref (profiles); ccsGSettingsBackendSetCurrentProfile (backend, profile); diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 663c116a3..2a45e61e1 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -125,8 +125,6 @@ TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); g_variant_builder_add (&builder, "s", "foo"); - g_variant_builder_add (&builder, "s", "bar"); - g_variant_builder_add (&builder, "s", "baz"); GVariant *existingProfiles = g_variant_builder_end (&builder); @@ -140,6 +138,27 @@ TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) updateCurrentProfileName (backend.get (), "narr"); } +TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameExisting) +{ + g_type_init (); + + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&builder, "s", "foo"); + + GVariant *existingProfiles = g_variant_builder_end (&builder); + + EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); + EXPECT_CALL (*gmock, setCurrentProfile (_)); + + updateCurrentProfileName (backend.get (), "foo"); +} + TEST_F(CCSGSettingsTestIndependent, TestGetSchemaNameForPlugin) { const gchar *plugin = "foo"; -- GitLab From ed100db68bd56507015b0fa9ad77e67de22d92af Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 10:08:53 +0800 Subject: [PATCH 192/562] Refactor out insertStringIntoVariantIfNew --- .../gsettings_backend_shared/gsettings_util.c | 29 ++++++++++++------- compizconfig/gsettings/src/gsettings.c | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index a5580d0db..a2f6f9f52 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -931,21 +931,17 @@ writeVariantToKey (GSettings *settings, g_settings_set_value (settings, key, value); } -void -updateCurrentProfileName (CCSBackend *backend, const char *profile) +gboolean +insertStringIntoVariantIfNew (GVariant **profiles, const char *profile) { - GVariant *profiles; char *prof; - GVariant *newProfiles; GVariantBuilder *newProfilesBuilder; GVariantIter iter; gboolean found = FALSE; - profiles = ccsGSettingsBackendGetExistingProfiles (backend); - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - g_variant_iter_init (&iter, profiles); + g_variant_iter_init (&iter, *profiles); while (g_variant_iter_loop (&iter, "s", &prof)) { g_variant_builder_add (newProfilesBuilder, "s", prof); @@ -958,13 +954,24 @@ updateCurrentProfileName (CCSBackend *backend, const char *profile) { g_variant_builder_add (newProfilesBuilder, "s", profile); - newProfiles = g_variant_new ("as", newProfilesBuilder); - ccsGSettingsBackendSetExistingProfiles (backend, newProfiles); - - g_variant_unref (newProfiles); + g_variant_unref (*profiles); + *profiles = g_variant_new ("as", newProfilesBuilder); } g_variant_builder_unref (newProfilesBuilder); + + return !found; +} + +void +updateCurrentProfileName (CCSBackend *backend, const char *profile) +{ + GVariant *profiles; + + profiles = ccsGSettingsBackendGetExistingProfiles (backend); + if (insertStringIntoVariantIfNew (&profiles, profile)) + ccsGSettingsBackendSetExistingProfiles (backend, profiles); + g_variant_unref (profiles); ccsGSettingsBackendSetCurrentProfile (backend, profile); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 5529d74fc..1c96249fc 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -810,7 +810,7 @@ deleteProfile (CCSBackend *backend, CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); plugins = g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); - profiles = g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); + profiles = ccsGSettingsBackendGetExistingProfiles (backend); g_variant_iter_init (&iter, plugins); while (g_variant_iter_loop (&iter, "s", &plugin)) -- GitLab From 4a6a88e1589fab159008f45ee1f95a35a1cace63 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 28 Jul 2012 10:10:33 +0800 Subject: [PATCH 193/562] Rename variables in insertStringIntoVariantIfNew --- .../gsettings_backend_shared/gsettings_util.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index a2f6f9f52..0962412d9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -932,33 +932,33 @@ writeVariantToKey (GSettings *settings, } gboolean -insertStringIntoVariantIfNew (GVariant **profiles, const char *profile) +insertStringIntoVariantIfNew (GVariant **variant, const char *string) { - char *prof; - GVariantBuilder *newProfilesBuilder; + char *str; + GVariantBuilder *newVariantBuilder; GVariantIter iter; gboolean found = FALSE; - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + newVariantBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - g_variant_iter_init (&iter, *profiles); - while (g_variant_iter_loop (&iter, "s", &prof)) + g_variant_iter_init (&iter, *variant); + while (g_variant_iter_loop (&iter, "s", &str)) { - g_variant_builder_add (newProfilesBuilder, "s", prof); + g_variant_builder_add (newVariantBuilder, "s", str); if (!found) - found = (g_strcmp0 (prof, profile) == 0); + found = (g_strcmp0 (str, string) == 0); } if (!found) { - g_variant_builder_add (newProfilesBuilder, "s", profile); + g_variant_builder_add (newVariantBuilder, "s", string); - g_variant_unref (*profiles); - *profiles = g_variant_new ("as", newProfilesBuilder); + g_variant_unref (*variant); + *variant = g_variant_new ("as", newVariantBuilder); } - g_variant_builder_unref (newProfilesBuilder); + g_variant_builder_unref (newVariantBuilder); return !found; } -- GitLab From 0c0f9ae0f6826c34e57738dde17a0d5687d0b121 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 29 Jul 2012 07:32:20 +0800 Subject: [PATCH 194/562] refactor out unsetAllChangedPluginKeysInProfile --- .../gsettings_backend_shared/gsettings_util.c | 26 +++++++---- compizconfig/gsettings/src/gsettings.c | 46 ++++++++++++------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 0962412d9..afe6c828d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -931,26 +931,36 @@ writeVariantToKey (GSettings *settings, g_settings_set_value (settings, key, value); } +typedef int (*ComparisonPredicate) (const void *s1, const void *s2); + gboolean -insertStringIntoVariantIfNew (GVariant **variant, const char *string) +insertStringIntoVariantIfMatchesPredicate (GVariant **variant, + const char *string, + ComparisonPredicate insert, + ComparisonPredicate append) { char *str; GVariantBuilder *newVariantBuilder; GVariantIter iter; - gboolean found = FALSE; + gboolean doAppend = FALSE; newVariantBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); g_variant_iter_init (&iter, *variant); while (g_variant_iter_loop (&iter, "s", &str)) { - g_variant_builder_add (newVariantBuilder, "s", str); + gboolean doInsert = TRUE; + if (insert) + doInsert = (*insert) (str, string); - if (!found) - found = (g_strcmp0 (str, string) == 0); + if (doInsert) + g_variant_builder_add (newVariantBuilder, "s", str); + + if (!doAppend && append) + doAppend = (*append) (str, string); } - if (!found) + if (!doAppend) { g_variant_builder_add (newVariantBuilder, "s", string); @@ -960,7 +970,7 @@ insertStringIntoVariantIfNew (GVariant **variant, const char *string) g_variant_builder_unref (newVariantBuilder); - return !found; + return !doAppend; } void @@ -969,7 +979,7 @@ updateCurrentProfileName (CCSBackend *backend, const char *profile) GVariant *profiles; profiles = ccsGSettingsBackendGetExistingProfiles (backend); - if (insertStringIntoVariantIfNew (&profiles, profile)) + if (insertStringIntoVariantIfMatchesPredicate (&profiles, profile, NULL, g_str_equal)) ccsGSettingsBackendSetExistingProfiles (backend, profiles); g_variant_unref (profiles); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 1c96249fc..7bbaaffe2 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -794,29 +794,20 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) return ret; } -static Bool -deleteProfile (CCSBackend *backend, - CCSContext *context, - char *profile) +static void +unsetAllChangedPluginKeysInProfile (CCSBackend *backend, + CCSContext *context, + GVariant *pluginsWithChangedKeys, + const char * profile) { - GVariant *plugins; - GVariant *profiles; - GVariant *newProfiles; - GVariantBuilder *newProfilesBuilder; - char *plugin, *prof; GVariantIter iter; - char *profileSettingsPath = makeCompizProfilePath (profile); - GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); - CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - - plugins = g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); - profiles = ccsGSettingsBackendGetExistingProfiles (backend); + char *plugin; - g_variant_iter_init (&iter, plugins); + g_variant_iter_init (&iter, pluginsWithChangedKeys); while (g_variant_iter_loop (&iter, "s", &plugin)) { GSettings *settings; - gchar *pathName = makeCompizPluginPath (priv->currentProfile, plugin); + gchar *pathName = makeCompizPluginPath (profile, plugin); settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); g_free (pathName); @@ -836,6 +827,27 @@ deleteProfile (CCSBackend *backend, g_strfreev (keys); } } +} + +static Bool +deleteProfile (CCSBackend *backend, + CCSContext *context, + char *profile) +{ + GVariant *plugins; + GVariant *profiles; + GVariant *newProfiles; + GVariantBuilder *newProfilesBuilder; + char *prof; + GVariantIter iter; + char *profileSettingsPath = makeCompizProfilePath (profile); + GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + plugins = g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); + profiles = ccsGSettingsBackendGetExistingProfiles (backend); + + unsetAllChangedPluginKeysInProfile (backend, context, plugins, priv->currentProfile); /* Remove the profile from existing-profiles */ g_settings_reset (profileSettings, "plugins-with-set-values"); -- GitLab From 175f3ccb11b4745a4c40248247bc8de64fedb69c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 29 Jul 2012 07:33:20 +0800 Subject: [PATCH 195/562] Fix weird indent --- .../gsettings/gsettings_backend_shared/gsettings_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index d6e3767c2..f0aaeba3b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -1,4 +1,4 @@ - #ifndef _COMPIZ_GSETTINGS_UTIL_H +#ifndef _COMPIZ_GSETTINGS_UTIL_H #define _COMPIZ_GSETTINGS_UTIL_H #include -- GitLab From c8748de0d1ce59a8803b31a36b481a239cbe3de6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 29 Jul 2012 11:21:51 +0800 Subject: [PATCH 196/562] Use the interface seams and make: +gboolean +insertStringIntoVariantIfMatchesPredicate (GVariant **variant, + const char *string, + ComparisonPredicate insert, + ComparisonPredicate append); public --- .../gsettings_backend_shared/gsettings_util.c | 14 ++++++-- .../gsettings_backend_shared/gsettings_util.h | 19 +++++++++++ compizconfig/gsettings/src/gsettings.c | 33 +++++++++++++++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index afe6c828d..69bc1fc0a 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -931,8 +931,6 @@ writeVariantToKey (GSettings *settings, g_settings_set_value (settings, key, value); } -typedef int (*ComparisonPredicate) (const void *s1, const void *s2); - gboolean insertStringIntoVariantIfMatchesPredicate (GVariant **variant, const char *string, @@ -1039,3 +1037,15 @@ ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value) { (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendSetCurrentProfile) (backend, value); } + +GVariant * +ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetPluginsWithSetKeys) (backend); +} + +void +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *profile) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendClearPluginsWithSetKeys) (backend, profile); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index f0aaeba3b..72f5d2a3c 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -26,6 +26,9 @@ typedef GVariant * (*CCSGSettingsBackendGetExistingProfiles) (CCSBackend *backen typedef void (*CCSGSettingsBackendSetExistingProfiles) (CCSBackend *backend, GVariant *value); typedef void (*CCSGSettingsBackendSetCurrentProfile) (CCSBackend *backend, const gchar *value); +typedef GVariant * (*CCSGSettingsBackendGetPluginsWithSetKeys) (CCSBackend *backend); +typedef void (*CCSGSettingsBackendClearPluginsWithSetKeys) (CCSBackend *backend, const char *profile); + struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; @@ -36,6 +39,8 @@ struct _CCSGSettingsBackendInterface CCSGSettingsBackendGetExistingProfiles gsettingsBackendGetExistingProfiles; CCSGSettingsBackendSetExistingProfiles gsettingsBackendSetExistingProfiles; CCSGSettingsBackendSetCurrentProfile gsettingsBackendSetCurrentProfile; + CCSGSettingsBackendGetPluginsWithSetKeys gsettingsBackendGetPluginsWithSetKeys; + CCSGSettingsBackendClearPluginsWithSetKeys gsettingsBackendClearPluginsWithSetKeys; }; unsigned int ccsCCSGSettingsBackendInterfaceGetType (); @@ -167,6 +172,14 @@ void writeVariantToKey (GSettings *settings, const char *key, GVariant *value); +typedef int (*ComparisonPredicate) (const void *s1, const void *s2); + +gboolean +insertStringIntoVariantIfMatchesPredicate (GVariant **variant, + const char *string, + ComparisonPredicate insert, + ComparisonPredicate append); + void updateCurrentProfileName (CCSBackend *backend, const char *profile); @@ -197,6 +210,12 @@ ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value); void ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value); +GVariant * +ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend); + +void +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *profile); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 7bbaaffe2..8b90f0a83 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -620,6 +620,27 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v g_free (profilePath); } +GVariant * +ccsGSettingsBackendGetPluginsWithSetKeysDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); +} + +void +ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend, const char *profile) +{ + char *profileSettingsPath = makeCompizProfilePath (profile); + + /* This looks weird, we are leaking this ... */ + GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); + + g_settings_reset (profileSettings, "plugins-with-set-values"); + + g_free (profileSettingsPath); +} + static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendGetContextDefault, ccsGSettingsBackendConnectToValueChangedSignalDefault, @@ -628,7 +649,9 @@ static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendUnregisterGConfClientDefault, ccsGSettingsBackendGetExistingProfilesDefault, ccsGSettingsBackendSetExistingProfilesDefault, - ccsGSettingsBackendSetCurrentProfileDefault + ccsGSettingsBackendSetCurrentProfileDefault, + ccsGSettingsBackendGetPluginsWithSetKeysDefault, + ccsGSettingsBackendClearPluginsWithSetKeysDefault }; static Bool @@ -840,17 +863,15 @@ deleteProfile (CCSBackend *backend, GVariantBuilder *newProfilesBuilder; char *prof; GVariantIter iter; - char *profileSettingsPath = makeCompizProfilePath (profile); - GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - plugins = g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); + plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); profiles = ccsGSettingsBackendGetExistingProfiles (backend); unsetAllChangedPluginKeysInProfile (backend, context, plugins, priv->currentProfile); /* Remove the profile from existing-profiles */ - g_settings_reset (profileSettings, "plugins-with-set-values"); + ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); g_variant_iter_init (&iter, profiles); newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); @@ -867,8 +888,6 @@ deleteProfile (CCSBackend *backend, g_variant_unref (newProfiles); g_variant_builder_unref (newProfilesBuilder); - g_free (profileSettingsPath); - updateProfile (backend, context); return TRUE; -- GitLab From d36395a123e5421c1db8c45acbf12fb78f64e9c2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 29 Jul 2012 17:02:02 +0800 Subject: [PATCH 197/562] Make deleteProfile use the link seams --- .../gsettings_backend_shared/gsettings_util.c | 5 +++++ .../gsettings_backend_shared/gsettings_util.h | 2 ++ compizconfig/gsettings/src/gsettings.c | 20 +++---------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 69bc1fc0a..884bfd39e 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -6,6 +6,11 @@ INTERFACE_TYPE (CCSGSettingsBackendInterface); +int voidcmp0 (const void *v1, const void *v2) +{ + return g_strcmp0 ((const char *) v1, (const char *) v2); +} + GList * variantTypeToPossibleSettingType (const gchar *vt) { diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 72f5d2a3c..be88100f4 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -174,6 +174,8 @@ void writeVariantToKey (GSettings *settings, typedef int (*ComparisonPredicate) (const void *s1, const void *s2); +int voidcmp0 (const void *v1, const void *v2); + gboolean insertStringIntoVariantIfMatchesPredicate (GVariant **variant, const char *string, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 8b90f0a83..6bf084839 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -859,10 +859,6 @@ deleteProfile (CCSBackend *backend, { GVariant *plugins; GVariant *profiles; - GVariant *newProfiles; - GVariantBuilder *newProfilesBuilder; - char *prof; - GVariantIter iter; CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); @@ -873,20 +869,10 @@ deleteProfile (CCSBackend *backend, /* Remove the profile from existing-profiles */ ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); - g_variant_iter_init (&iter, profiles); - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - - while (g_variant_iter_loop (&iter, "s", &prof)) - { - if (g_strcmp0 (prof, profile)) - g_variant_builder_add (newProfilesBuilder, "s", prof); - } - - newProfiles = g_variant_new ("as", newProfilesBuilder); - g_settings_set_value (priv->compizconfigSettings, "existing-profiles", newProfiles); + insertStringIntoVariantIfMatchesPredicate (&profiles, profile, voidcmp0, NULL); - g_variant_unref (newProfiles); - g_variant_builder_unref (newProfilesBuilder); + ccsGSettingsBackendSetExistingProfiles (backend, profiles); + g_variant_unref (profiles); updateProfile (backend, context); -- GitLab From d51f0cca09ddc2366dbfa38d506b5d12197e8978 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 29 Jul 2012 17:26:24 +0800 Subject: [PATCH 198/562] Kill the dependency on priv in deleteProfile. Also add the other interface functions to the mock as they were missing --- .../gsettings_backend_shared/gsettings_util.c | 15 ++++ .../gsettings_backend_shared/gsettings_util.h | 15 ++++ compizconfig/gsettings/src/gsettings.c | 88 +++++++++++-------- .../tests/ccs_gsettings_backend_mock.cpp | 6 +- .../tests/ccs_gsettings_backend_mock.h | 35 ++++++++ 5 files changed, 119 insertions(+), 40 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 884bfd39e..8de1b080d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1025,6 +1025,12 @@ ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend) (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnregisterGConfClient) (backend); } +const char * +ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetCurrentProfile) (backend); +} + GVariant * ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) { @@ -1054,3 +1060,12 @@ ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *pro { (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendClearPluginsWithSetKeys) (backend, profile); } + +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, + CCSContext *context, + GVariant *pluginKeys, + const char *profile) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnsetAllChangedPluginKeysInProfile) (backend, context, pluginKeys, profile); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index be88100f4..8db2cafec 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -22,6 +22,8 @@ typedef GSettings * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CC typedef void (*CCSGSettingsBackendRegisterGConfClient) (CCSBackend *backend); typedef void (*CCSGSettingsBackendUnregisterGConfClient) (CCSBackend *backend); +typedef const char * (*CCSGSettingsBackendGetCurrentProfile) (CCSBackend *backend); + typedef GVariant * (*CCSGSettingsBackendGetExistingProfiles) (CCSBackend *backend); typedef void (*CCSGSettingsBackendSetExistingProfiles) (CCSBackend *backend, GVariant *value); typedef void (*CCSGSettingsBackendSetCurrentProfile) (CCSBackend *backend, const gchar *value); @@ -29,6 +31,8 @@ typedef void (*CCSGSettingsBackendSetCurrentProfile) (CCSBackend *backend, const typedef GVariant * (*CCSGSettingsBackendGetPluginsWithSetKeys) (CCSBackend *backend); typedef void (*CCSGSettingsBackendClearPluginsWithSetKeys) (CCSBackend *backend, const char *profile); +typedef void (*CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile) (CCSBackend *backend, CCSContext *, GVariant *, const char *); + struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; @@ -36,11 +40,13 @@ struct _CCSGSettingsBackendInterface CCSGSettingsBackendGetSettingsObjectForPluginWithPath gsettingsBackendGetSettingsObjectForPluginWithPath; CCSGSettingsBackendRegisterGConfClient gsettingsBackendRegisterGConfClient; CCSGSettingsBackendUnregisterGConfClient gsettingsBackendUnregisterGConfClient; + CCSGSettingsBackendGetCurrentProfile gsettingsBackendGetCurrentProfile; CCSGSettingsBackendGetExistingProfiles gsettingsBackendGetExistingProfiles; CCSGSettingsBackendSetExistingProfiles gsettingsBackendSetExistingProfiles; CCSGSettingsBackendSetCurrentProfile gsettingsBackendSetCurrentProfile; CCSGSettingsBackendGetPluginsWithSetKeys gsettingsBackendGetPluginsWithSetKeys; CCSGSettingsBackendClearPluginsWithSetKeys gsettingsBackendClearPluginsWithSetKeys; + CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile gsettingsBackendUnsetAllChangedPluginKeysInProfile; }; unsigned int ccsCCSGSettingsBackendInterfaceGetType (); @@ -203,6 +209,9 @@ ccsGSettingsBackendRegisterGConfClient (CCSBackend *backend); void ccsGSettingsBackendUnregisterGConfClient (CCSBackend *backend); +const char * +ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend); + GVariant * ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend); @@ -218,6 +227,12 @@ ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend); void ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *profile); +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, + CCSContext *context, + GVariant *pluginKeys, + const char *profile); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 6bf084839..855abfdb3 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -586,6 +586,14 @@ ccsGSettingsBackendUnregisterGConfClientDefault (CCSBackend *backend) #endif } +static const char * +ccsGSettingsBackendGetCurrentProfileDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return priv->currentProfile; +} + static GVariant * ccsGSettingsBackendGetExistingProfilesDefault (CCSBackend *backend) { @@ -641,17 +649,54 @@ ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend, const ch g_free (profileSettingsPath); } +static void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, + CCSContext *context, + GVariant *pluginsWithChangedKeys, + const char * profile) +{ + GVariantIter iter; + char *plugin; + + g_variant_iter_init (&iter, pluginsWithChangedKeys); + while (g_variant_iter_loop (&iter, "s", &plugin)) + { + GSettings *settings; + gchar *pathName = makeCompizPluginPath (profile, plugin); + + settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); + g_free (pathName); + + /* The GSettings documentation says not to use this API + * because we should know our own schema ... though really + * we don't because we autogenerate schemas ... */ + if (settings) + { + char **keys = g_settings_list_keys (settings); + char **key_ptr; + + /* Unset all the keys */ + for (key_ptr = keys; *key_ptr; key_ptr++) + g_settings_reset (settings, *key_ptr); + + g_strfreev (keys); + } + } +} + static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendGetContextDefault, ccsGSettingsBackendConnectToValueChangedSignalDefault, ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault, ccsGSettingsBackendRegisterGConfClientDefault, ccsGSettingsBackendUnregisterGConfClientDefault, + ccsGSettingsBackendGetCurrentProfileDefault, ccsGSettingsBackendGetExistingProfilesDefault, ccsGSettingsBackendSetExistingProfilesDefault, ccsGSettingsBackendSetCurrentProfileDefault, ccsGSettingsBackendGetPluginsWithSetKeysDefault, - ccsGSettingsBackendClearPluginsWithSetKeysDefault + ccsGSettingsBackendClearPluginsWithSetKeysDefault, + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault }; static Bool @@ -817,54 +862,19 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) return ret; } -static void -unsetAllChangedPluginKeysInProfile (CCSBackend *backend, - CCSContext *context, - GVariant *pluginsWithChangedKeys, - const char * profile) -{ - GVariantIter iter; - char *plugin; - - g_variant_iter_init (&iter, pluginsWithChangedKeys); - while (g_variant_iter_loop (&iter, "s", &plugin)) - { - GSettings *settings; - gchar *pathName = makeCompizPluginPath (profile, plugin); - - settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); - g_free (pathName); - - /* The GSettings documentation says not to use this API - * because we should know our own schema ... though really - * we don't because we autogenerate schemas ... */ - if (settings) - { - char **keys = g_settings_list_keys (settings); - char **key_ptr; - - /* Unset all the keys */ - for (key_ptr = keys; *key_ptr; key_ptr++) - g_settings_reset (settings, *key_ptr); - - g_strfreev (keys); - } - } -} - -static Bool +gboolean deleteProfile (CCSBackend *backend, CCSContext *context, char *profile) { GVariant *plugins; GVariant *profiles; - CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); profiles = ccsGSettingsBackendGetExistingProfiles (backend); - unsetAllChangedPluginKeysInProfile (backend, context, plugins, priv->currentProfile); + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); /* Remove the profile from existing-profiles */ ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp index c1d9bf04e..a6ba58614 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp @@ -12,9 +12,13 @@ CCSGSettingsBackendInterface ccsGSettingsBackendGMockInterface = CCSGSettingsBackendGMock::ccsGSettingsBackendGetSettingsObjectForPluginWithPath, CCSGSettingsBackendGMock::ccsGSettingsBackendRegisterGConfClient, CCSGSettingsBackendGMock::ccsGSettingsBackendUnregisterGConfClient, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetCurrentProfile, CCSGSettingsBackendGMock::ccsGSettingsBackendGetExistingProfiles, CCSGSettingsBackendGMock::ccsGSettingsBackendSetExistingProfiles, - CCSGSettingsBackendGMock::ccsGSettingsBackendSetCurrentProfile + CCSGSettingsBackendGMock::ccsGSettingsBackendSetCurrentProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetPluginsWithSetKeys, + CCSGSettingsBackendGMock::ccsGSettingsBackendClearPluginsWithSetKeys, + CCSGSettingsBackendGMock::ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile }; CCSBackend * diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h index a235165a2..8d0361452 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -26,9 +26,13 @@ class CCSGSettingsBackendGMockInterface CCSContext * context) = 0; virtual void registerGConfClient () = 0; virtual void unregisterGConfClient () = 0; + virtual const char * getCurrentProfile () = 0; virtual GVariant * getExistingProfiles () = 0; virtual void setExistingProfiles (GVariant *) = 0; virtual void setCurrentProfile (const gchar *) = 0; + virtual GVariant * getPluginsWithSetKeys () = 0; + virtual void clearPluginsWithSetKeys (const char *) = 0; + virtual void unsetAllChangedPluginKeysInProfile (CCSContext *, GVariant *, const char *) = 0; }; class CCSGSettingsBackendGMock : @@ -48,9 +52,13 @@ class CCSGSettingsBackendGMock : CCSContext * context)); MOCK_METHOD0 (registerGConfClient, void ()); MOCK_METHOD0 (unregisterGConfClient, void ()); + MOCK_METHOD0 (getCurrentProfile, const char * ()); MOCK_METHOD0 (getExistingProfiles, GVariant * ()); MOCK_METHOD1 (setExistingProfiles, void (GVariant *)); MOCK_METHOD1 (setCurrentProfile, void (const gchar *)); + MOCK_METHOD0 (getPluginsWithSetKeys, GVariant * ()); + MOCK_METHOD1 (clearPluginsWithSetKeys, void (const char *)); + MOCK_METHOD3 (unsetAllChangedPluginKeysInProfile, void (CCSContext *, GVariant *, const char *)); CCSBackend * getBackend () { return mBackend; } @@ -95,6 +103,12 @@ class CCSGSettingsBackendGMock : (reinterpret_cast (ccsObjectGetPrivate (backend)))->unregisterGConfClient (); } + static const char * + ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getCurrentProfile (); + } + static GVariant * ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) { @@ -112,6 +126,27 @@ class CCSGSettingsBackendGMock : { (reinterpret_cast (ccsObjectGetPrivate (backend)))->setCurrentProfile (value); } + + static GVariant * + ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getPluginsWithSetKeys (); + } + + static void + ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *profile) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->clearPluginsWithSetKeys (profile); + } + + static void + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, + CCSContext *context, + GVariant *pluginKeys, + const char *profile) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->unsetAllChangedPluginKeysInProfile (context, pluginKeys, profile); + } }; #endif -- GitLab From 73a77eea1a0676fc23724adaa77350cec189d6f9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 29 Jul 2012 17:32:03 +0800 Subject: [PATCH 199/562] Split out updateProfile and deleteProfile --- .../gsettings_backend_shared/gsettings_util.c | 50 ++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 8 +++ compizconfig/gsettings/src/gsettings.c | 51 ------------------- 3 files changed, 58 insertions(+), 51 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 8de1b080d..06e54d3f9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -990,6 +990,56 @@ updateCurrentProfileName (CCSBackend *backend, const char *profile) ccsGSettingsBackendSetCurrentProfile (backend, profile); } +gboolean +updateProfile (CCSBackend *backend, CCSContext *context) +{ + const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); + char *profile = strdup (ccsGetProfile (context)); + + if (!profile) + profile = strdup (DEFAULTPROF); + + if (!strlen (profile)) + { + free (profile); + profile = strdup (DEFAULTPROF); + } + + if (g_strcmp0 (profile, currentProfile)) + updateCurrentProfileName (backend, profile); + + free (profile); + + return TRUE; +} + +gboolean +deleteProfile (CCSBackend *backend, + CCSContext *context, + char *profile) +{ + GVariant *plugins; + GVariant *profiles; + const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); + + plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); + profiles = ccsGSettingsBackendGetExistingProfiles (backend); + + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); + + /* Remove the profile from existing-profiles */ + ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); + + insertStringIntoVariantIfMatchesPredicate (&profiles, profile, voidcmp0, NULL); + + ccsGSettingsBackendSetExistingProfiles (backend, profiles); + g_variant_unref (profiles); + + updateProfile (backend, context); + + return TRUE; +} + CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend) { diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 8db2cafec..1b75879ba 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -182,6 +182,14 @@ typedef int (*ComparisonPredicate) (const void *s1, const void *s2); int voidcmp0 (const void *v1, const void *v2); +gboolean +updateProfile (CCSBackend *backend, CCSContext *context); + +gboolean +deleteProfile (CCSBackend *backend, + CCSContext *context, + char *profile); + gboolean insertStringIntoVariantIfMatchesPredicate (GVariant **variant, const char *string, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 855abfdb3..da3ad69fd 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -499,30 +499,6 @@ writeOption (CCSBackend *backend, CCSSetting * setting) free (cleanSettingName); } -static gboolean -updateProfile (CCSBackend *backend, CCSContext *context) -{ - CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - - char *profile = strdup (ccsGetProfile (context)); - - if (!profile) - profile = strdup (DEFAULTPROF); - - if (!strlen (profile)) - { - free (profile); - profile = strdup (DEFAULTPROF); - } - - if (g_strcmp0 (profile, priv->currentProfile)) - updateCurrentProfileName (backend, profile); - - free (profile); - - return TRUE; -} - static char* getCurrentProfileName (CCSBackend *backend) { @@ -862,33 +838,6 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) return ret; } -gboolean -deleteProfile (CCSBackend *backend, - CCSContext *context, - char *profile) -{ - GVariant *plugins; - GVariant *profiles; - const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); - - plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); - profiles = ccsGSettingsBackendGetExistingProfiles (backend); - - ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); - - /* Remove the profile from existing-profiles */ - ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); - - insertStringIntoVariantIfMatchesPredicate (&profiles, profile, voidcmp0, NULL); - - ccsGSettingsBackendSetExistingProfiles (backend, profiles); - g_variant_unref (profiles); - - updateProfile (backend, context); - - return TRUE; -} - static char * getName (CCSBackend *backend) { -- GitLab From d207c38598a2a43d3d42400d9b75ca90b0b87ce8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 30 Jul 2012 08:58:07 +0800 Subject: [PATCH 200/562] Introduce enough seams such that CCSGSettingsTestIndependent.TestDeleteProfileExistingProfile fails without segfaulting --- compizconfig/gconf/src/gconf.c | 4 +- .../gsettings_backend_shared/gsettings_util.c | 29 ++++++++++---- .../gsettings_backend_shared/gsettings_util.h | 23 ++++++++--- compizconfig/gsettings/src/gsettings.c | 18 +++++++-- compizconfig/gsettings/tests/CMakeLists.txt | 1 + .../tests/ccs_gsettings_backend_mock.cpp | 4 +- .../tests/ccs_gsettings_backend_mock.h | 16 ++++++++ .../gsettings/tests/test_gsettings_tests.cpp | 39 ++++++++++++++++++- compizconfig/gsettings/tests/wrap_gsettings.h | 1 - .../compizconfig_ccs_setting_mock.h | 5 +++ 10 files changed, 118 insertions(+), 22 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index e479bfbf5..59f30b92d 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -1835,7 +1835,7 @@ writeOption (CCSSetting * setting) } static void -updateCurrentProfileName (char *profile) +ccsGSettingsBackendUpdateCurrentProfileName (char *profile) { GConfSchema *schema; GConfValue *value; @@ -1940,7 +1940,7 @@ checkProfile (CCSContext *context) } /* update current profile name */ - updateCurrentProfileName (currentProfile); + ccsGSettingsBackendUpdateCurrentProfileName (currentProfile); } if (lastProfile) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 06e54d3f9..83420b9bb 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -977,7 +977,7 @@ insertStringIntoVariantIfMatchesPredicate (GVariant **variant, } void -updateCurrentProfileName (CCSBackend *backend, const char *profile) +ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile) { GVariant *profiles; @@ -991,7 +991,7 @@ updateCurrentProfileName (CCSBackend *backend, const char *profile) } gboolean -updateProfile (CCSBackend *backend, CCSContext *context) +ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context) { const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); char *profile = strdup (ccsGetProfile (context)); @@ -1006,7 +1006,7 @@ updateProfile (CCSBackend *backend, CCSContext *context) } if (g_strcmp0 (profile, currentProfile)) - updateCurrentProfileName (backend, profile); + ccsGSettingsBackendUpdateCurrentProfileName (backend, profile); free (profile); @@ -1016,7 +1016,7 @@ updateProfile (CCSBackend *backend, CCSContext *context) gboolean deleteProfile (CCSBackend *backend, CCSContext *context, - char *profile) + const char *profile) { GVariant *plugins; GVariant *profiles; @@ -1027,15 +1027,15 @@ deleteProfile (CCSBackend *backend, ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); - /* Remove the profile from existing-profiles */ ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); insertStringIntoVariantIfMatchesPredicate (&profiles, profile, voidcmp0, NULL); - + /* Remove the profile from existing-profiles */ ccsGSettingsBackendSetExistingProfiles (backend, profiles); + g_variant_unref (profiles); - updateProfile (backend, context); + ccsGSettingsBackendUpdateProfile (backend, context); return TRUE; } @@ -1119,3 +1119,18 @@ ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, { (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnsetAllChangedPluginKeysInProfile) (backend, context, pluginKeys, profile); } + +gboolean +ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUpdateProfile) (backend, context); +} + +void +ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUpdateCurrentProfileName) (backend, profile); +} + +CCSContext * +ccsGSettingsBackendGetContext (CCSBackend *backend); diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 1b75879ba..cd059aed7 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -33,6 +33,9 @@ typedef void (*CCSGSettingsBackendClearPluginsWithSetKeys) (CCSBackend *backend, typedef void (*CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile) (CCSBackend *backend, CCSContext *, GVariant *, const char *); +typedef gboolean (*CCSGSettingsBackendUpdateProfile) (CCSBackend *, CCSContext *); +typedef void (*CCSGSettingsBackendUpdateCurrentProfileName) (CCSBackend *backend, const char *profile); + struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; @@ -47,6 +50,8 @@ struct _CCSGSettingsBackendInterface CCSGSettingsBackendGetPluginsWithSetKeys gsettingsBackendGetPluginsWithSetKeys; CCSGSettingsBackendClearPluginsWithSetKeys gsettingsBackendClearPluginsWithSetKeys; CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile gsettingsBackendUnsetAllChangedPluginKeysInProfile; + CCSGSettingsBackendUpdateProfile gsettingsBackendUpdateProfile; + CCSGSettingsBackendUpdateCurrentProfileName gsettingsBackendUpdateCurrentProfileName; }; unsigned int ccsCCSGSettingsBackendInterfaceGetType (); @@ -182,13 +187,10 @@ typedef int (*ComparisonPredicate) (const void *s1, const void *s2); int voidcmp0 (const void *v1, const void *v2); -gboolean -updateProfile (CCSBackend *backend, CCSContext *context); - gboolean deleteProfile (CCSBackend *backend, CCSContext *context, - char *profile); + const char *profile); gboolean insertStringIntoVariantIfMatchesPredicate (GVariant **variant, @@ -196,8 +198,11 @@ insertStringIntoVariantIfMatchesPredicate (GVariant **variant, ComparisonPredicate insert, ComparisonPredicate append); +gboolean +ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context); + void -updateCurrentProfileName (CCSBackend *backend, const char *profile); +ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile); CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend); @@ -241,6 +246,14 @@ ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, GVariant *pluginKeys, const char *profile); +/* Default implementations, should be moved */ + +void +ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile); + +gboolean +ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index da3ad69fd..0f84356e9 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -672,7 +672,9 @@ static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendSetCurrentProfileDefault, ccsGSettingsBackendGetPluginsWithSetKeysDefault, ccsGSettingsBackendClearPluginsWithSetKeysDefault, - ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault, + ccsGSettingsBackendUpdateProfileDefault, + ccsGSettingsBackendUpdateCurrentProfileNameDefault }; static Bool @@ -743,7 +745,7 @@ finiBackend (CCSBackend *backend) Bool readInit (CCSBackend *backend, CCSContext * context) { - return updateProfile (backend, context); + return ccsGSettingsBackendUpdateProfile (backend, context); } void @@ -769,7 +771,7 @@ readSetting (CCSBackend *backend, Bool writeInit (CCSBackend *backend, CCSContext * context) { - return updateProfile (backend, context); + return ccsGSettingsBackendUpdateProfile (backend, context); } void @@ -874,6 +876,14 @@ hasProfileSupport (CCSBackend *backend) return TRUE; } +static Bool +ccsGSettingsDeleteProfileWrapper (CCSBackend *backend, + CCSContext *context, + char *profile) +{ + return deleteProfile (backend, context, profile); +} + static CCSBackendInterface gsettingsVTable = { getName, getShortDesc, @@ -893,7 +903,7 @@ static CCSBackendInterface gsettingsVTable = { getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, - deleteProfile + ccsGSettingsDeleteProfileWrapper }; diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 53886ae69..9925f6ce9 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -21,6 +21,7 @@ link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) target_link_libraries (compizconfig_test_gsettings gsettings_backend_shared compizconfig_ccs_setting_mock + compizconfig_ccs_context_mock compizconfig_ccs_gsettings_backend_mock ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} ${GTEST_BOTH_LIBRARIES} diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp index a6ba58614..632c7f765 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp @@ -18,7 +18,9 @@ CCSGSettingsBackendInterface ccsGSettingsBackendGMockInterface = CCSGSettingsBackendGMock::ccsGSettingsBackendSetCurrentProfile, CCSGSettingsBackendGMock::ccsGSettingsBackendGetPluginsWithSetKeys, CCSGSettingsBackendGMock::ccsGSettingsBackendClearPluginsWithSetKeys, - CCSGSettingsBackendGMock::ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile + CCSGSettingsBackendGMock::ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateCurrentProfileName, }; CCSBackend * diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h index 8d0361452..df8a3c3e7 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -33,6 +33,8 @@ class CCSGSettingsBackendGMockInterface virtual GVariant * getPluginsWithSetKeys () = 0; virtual void clearPluginsWithSetKeys (const char *) = 0; virtual void unsetAllChangedPluginKeysInProfile (CCSContext *, GVariant *, const char *) = 0; + virtual gboolean updateProfile (CCSContext *) = 0; + virtual void updateCurrentProfileName (const char *) = 0; }; class CCSGSettingsBackendGMock : @@ -59,6 +61,8 @@ class CCSGSettingsBackendGMock : MOCK_METHOD0 (getPluginsWithSetKeys, GVariant * ()); MOCK_METHOD1 (clearPluginsWithSetKeys, void (const char *)); MOCK_METHOD3 (unsetAllChangedPluginKeysInProfile, void (CCSContext *, GVariant *, const char *)); + MOCK_METHOD1 (updateProfile, gboolean (CCSContext *)); + MOCK_METHOD1 (updateCurrentProfileName, void (const char *)); CCSBackend * getBackend () { return mBackend; } @@ -147,6 +151,18 @@ class CCSGSettingsBackendGMock : { return (reinterpret_cast (ccsObjectGetPrivate (backend)))->unsetAllChangedPluginKeysInProfile (context, pluginKeys, profile); } + + static gboolean + ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->updateProfile (context); + } + + static void + ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->updateCurrentProfileName (profile); + } }; #endif diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 2a45e61e1..305185448 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -7,6 +7,8 @@ #include "gsettings.h" #include "wrap_gsettings.h" #include "ccs_gsettings_backend_mock.h" +#include "compizconfig_ccs_context_mock.h" +#include "compizconfig_ccs_setting_mock.h" using ::testing::Values; using ::testing::ValuesIn; @@ -135,7 +137,7 @@ TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) boost::bind (streq, _1, _2))))); EXPECT_CALL (*gmock, setCurrentProfile (_)); - updateCurrentProfileName (backend.get (), "narr"); + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), "narr"); } TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameExisting) @@ -156,7 +158,40 @@ TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameExisting) EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); EXPECT_CALL (*gmock, setCurrentProfile (_)); - updateCurrentProfileName (backend.get (), "foo"); + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), "foo"); +} + +TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) +{ + g_type_init (); + + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (ccsFreeMockContext, _1)); + + CCSGSettingsBackendGMock *mockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + CCSContextGMock *mockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("foo"); + + GVariant *existingProfiles = NULL; + GVariantBuilder existingProfilesBuilder; + + g_variant_builder_init (&existingProfilesBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&existingProfilesBuilder, "s", "foo"); + + existingProfiles = g_variant_builder_end (&existingProfilesBuilder); + + EXPECT_CALL (*mockBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*mockContext, getProfile ()).WillOnce (Return (currentProfile.c_str ())); + + EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillRepeatedly (Return (existingProfiles)); + EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillRepeatedly (Return (existingProfiles)); + + deleteProfile (backend.get (), context.get (), "foo"); + + //g_variant_unref (existingProfiles); } TEST_F(CCSGSettingsTestIndependent, TestGetSchemaNameForPlugin) diff --git a/compizconfig/gsettings/tests/wrap_gsettings.h b/compizconfig/gsettings/tests/wrap_gsettings.h index 79b4b86f4..97e4f2414 100644 --- a/compizconfig/gsettings/tests/wrap_gsettings.h +++ b/compizconfig/gsettings/tests/wrap_gsettings.h @@ -2,7 +2,6 @@ #define _COMPIZ_COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS #include -#include G_BEGIN_DECLS diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h index 70f0c6d5e..59123b4fd 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h @@ -1,3 +1,6 @@ +#ifndef _COMPIZCONFIG_CCS_SETTING_MOCK +#define _COMPIZCONFIG_CCS_SETTING_MOCK + #include #include @@ -364,3 +367,5 @@ class CCSSettingGMock : }; extern CCSSettingInterface CCSSettingGMockInterface; + +#endif -- GitLab From 07ee4aed13e6c938a524c58aaa4ee715a5a0c9ee Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 30 Jul 2012 09:29:06 +0800 Subject: [PATCH 201/562] Make the profile deletion test pass --- .../gsettings_backend_shared/gsettings_util.c | 25 +++++++++---------- .../gsettings/tests/test_gsettings_tests.cpp | 16 +++++++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 83420b9bb..74533749b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -936,16 +936,17 @@ writeVariantToKey (GSettings *settings, g_settings_set_value (settings, key, value); } +/* This shouldn't be one function */ gboolean insertStringIntoVariantIfMatchesPredicate (GVariant **variant, const char *string, - ComparisonPredicate insert, - ComparisonPredicate append) + ComparisonPredicate shouldInsertIntoListFunc, + ComparisonPredicate checkIfItemAlreadyInListFunc) { char *str; GVariantBuilder *newVariantBuilder; GVariantIter iter; - gboolean doAppend = FALSE; + gboolean foundItemInListAlready = FALSE; newVariantBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); @@ -953,27 +954,25 @@ insertStringIntoVariantIfMatchesPredicate (GVariant **variant, while (g_variant_iter_loop (&iter, "s", &str)) { gboolean doInsert = TRUE; - if (insert) - doInsert = (*insert) (str, string); + if (shouldInsertIntoListFunc) + doInsert = (*shouldInsertIntoListFunc) (str, string); if (doInsert) g_variant_builder_add (newVariantBuilder, "s", str); - if (!doAppend && append) - doAppend = (*append) (str, string); + if (!foundItemInListAlready && checkIfItemAlreadyInListFunc) + foundItemInListAlready = (*checkIfItemAlreadyInListFunc) (str, string); } - if (!doAppend) - { + if (!foundItemInListAlready && checkIfItemAlreadyInListFunc) g_variant_builder_add (newVariantBuilder, "s", string); - g_variant_unref (*variant); - *variant = g_variant_new ("as", newVariantBuilder); - } + g_variant_unref (*variant); + *variant = g_variant_new ("as", newVariantBuilder); g_variant_builder_unref (newVariantBuilder); - return !doAppend; + return !foundItemInListAlready; } void diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 305185448..cce341aa3 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -13,10 +13,12 @@ using ::testing::Values; using ::testing::ValuesIn; using ::testing::Return; +using ::testing::ReturnNull; using ::testing::Invoke; using ::testing::MatcherInterface; using ::testing::MatchResultListener; using ::testing::AllOf; +using ::testing::Not; using ::testing::Matcher; class GVariantSubtypeMatcher : @@ -171,7 +173,6 @@ TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) boost::bind (ccsFreeMockContext, _1)); CCSGSettingsBackendGMock *mockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); - CCSContextGMock *mockContext = reinterpret_cast (ccsObjectGetPrivate (context)); std::string currentProfile ("foo"); @@ -183,11 +184,18 @@ TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) existingProfiles = g_variant_builder_end (&existingProfilesBuilder); + EXPECT_CALL (*mockBackend, getPluginsWithSetKeys ()).WillOnce (ReturnNull ()); + EXPECT_CALL (*mockBackend, unsetAllChangedPluginKeysInProfile (context.get (), NULL, _)); + EXPECT_CALL (*mockBackend, clearPluginsWithSetKeys (_)); + EXPECT_CALL (*mockBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); - EXPECT_CALL (*mockContext, getProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillOnce (Return (existingProfiles)); + EXPECT_CALL (*mockBackend, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), + Not (GVariantHasValueInArray ("s", + "foo", + boost::bind (streq, _1, _2)))))); - EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillRepeatedly (Return (existingProfiles)); - EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillRepeatedly (Return (existingProfiles)); + EXPECT_CALL (*mockBackend, updateProfile (context.get ())); deleteProfile (backend.get (), context.get (), "foo"); -- GitLab From 193f21ae10ebdaa6534bff4bdbc51c42c2594ba7 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 31 Jul 2012 11:23:01 +0800 Subject: [PATCH 202/562] Refactor to remove gboolean -insertStringIntoVariantIfMatchesPredicate (GVariant **variant, - const char *string, - ComparisonPredicate insert, - ComparisonPredicate append); --- .../gsettings_backend_shared/gsettings_util.c | 98 +++++++++++++------ .../gsettings_backend_shared/gsettings_util.h | 10 +- 2 files changed, 76 insertions(+), 32 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 74533749b..b4f3fd550 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -936,43 +936,85 @@ writeVariantToKey (GSettings *settings, g_settings_set_value (settings, key, value); } -/* This shouldn't be one function */ -gboolean -insertStringIntoVariantIfMatchesPredicate (GVariant **variant, - const char *string, - ComparisonPredicate shouldInsertIntoListFunc, - ComparisonPredicate checkIfItemAlreadyInListFunc) +typedef void (*VariantItemCheckAndInsertFunc) (GVariantBuilder *, const char *item, void *userData); + +typedef struct _FindItemInVariantData { - char *str; - GVariantBuilder *newVariantBuilder; - GVariantIter iter; - gboolean foundItemInListAlready = FALSE; + gboolean found; + const char *item; +} FindItemInVariantData; + +static void +insertIfNotEqual (GVariantBuilder *builder, const char *item, void *userData) +{ + const char *cmp = (const char *) userData; + + if (g_strcmp0 (item, cmp)) + g_variant_builder_add (builder, "s", item); +} - newVariantBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); +static void +findItemForVariantData (GVariantBuilder *builder, const char *item, void *userData) +{ + FindItemInVariantData *data = (FindItemInVariantData *) userData; + + if (!data->found) + data->found = g_str_equal (data->item, item); + + g_variant_builder_add (builder, "s", item); +} + +static void +rebuildVariant (GVariantBuilder *builder, + GVariant *originalVariant, + VariantItemCheckAndInsertFunc checkAndInsert, + void *userData) +{ + GVariantIter iter; + char *str; - g_variant_iter_init (&iter, *variant); + g_variant_iter_init (&iter, originalVariant); while (g_variant_iter_loop (&iter, "s", &str)) { - gboolean doInsert = TRUE; - if (shouldInsertIntoListFunc) - doInsert = (*shouldInsertIntoListFunc) (str, string); + (*checkAndInsert) (builder, str, userData); + } +} + +gboolean +appendStringToVariantIfUnique (GVariant **variant, + const char *string) +{ + GVariantBuilder newVariantBuilder; + FindItemInVariantData findItemData; - if (doInsert) - g_variant_builder_add (newVariantBuilder, "s", str); + memset (&findItemData, 0, sizeof (FindItemInVariantData)); + g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as")); - if (!foundItemInListAlready && checkIfItemAlreadyInListFunc) - foundItemInListAlready = (*checkIfItemAlreadyInListFunc) (str, string); - } + findItemData.item = string; - if (!foundItemInListAlready && checkIfItemAlreadyInListFunc) - g_variant_builder_add (newVariantBuilder, "s", string); + rebuildVariant (&newVariantBuilder, *variant, findItemForVariantData, &findItemData); + + if (!findItemData.found) + g_variant_builder_add (&newVariantBuilder, "s", string); g_variant_unref (*variant); - *variant = g_variant_new ("as", newVariantBuilder); + *variant = g_variant_builder_end (&newVariantBuilder); + + return !findItemData.found; +} + +void +removeItemFromVariant (GVariant **variant, + const char *string) +{ + GVariantBuilder newVariantBuilder; - g_variant_builder_unref (newVariantBuilder); + g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as")); - return !foundItemInListAlready; + rebuildVariant (&newVariantBuilder, *variant, insertIfNotEqual, (void *) string); + + g_variant_unref (*variant); + *variant = g_variant_builder_end (&newVariantBuilder); } void @@ -981,7 +1023,7 @@ ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const c GVariant *profiles; profiles = ccsGSettingsBackendGetExistingProfiles (backend); - if (insertStringIntoVariantIfMatchesPredicate (&profiles, profile, NULL, g_str_equal)) + if (appendStringToVariantIfUnique (&profiles, profile)) ccsGSettingsBackendSetExistingProfiles (backend, profiles); g_variant_unref (profiles); @@ -1025,10 +1067,10 @@ deleteProfile (CCSBackend *backend, profiles = ccsGSettingsBackendGetExistingProfiles (backend); ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); - ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); - insertStringIntoVariantIfMatchesPredicate (&profiles, profile, voidcmp0, NULL); + removeItemFromVariant (&profiles, profile); + /* Remove the profile from existing-profiles */ ccsGSettingsBackendSetExistingProfiles (backend, profiles); diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index cd059aed7..4581599f0 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -193,10 +193,12 @@ deleteProfile (CCSBackend *backend, const char *profile); gboolean -insertStringIntoVariantIfMatchesPredicate (GVariant **variant, - const char *string, - ComparisonPredicate insert, - ComparisonPredicate append); +appendStringToVariantIfUnique (GVariant **variant, + const char *string); + +void +removeItemFromVariant (GVariant **variant, + const char *string); gboolean ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context); -- GitLab From b4d26ee10383d58be806b576d1f91a4b5a8f8948 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 31 Jul 2012 20:37:35 +0800 Subject: [PATCH 203/562] Moved CharacterWrapper definition into tests/shared/gtest_shared_characterwrapper.h --- compizconfig/gsettings/tests/CMakeLists.txt | 3 +- .../libcompizconfig/tests/CMakeLists.txt | 1 + tests/shared/gtest_shared_characterwrapper.h | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/shared/gtest_shared_characterwrapper.h diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 738b9dd5a..5302bbd18 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -5,7 +5,8 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig - ${CMAKE_CURRENT_SOURCE_DIR}/../../tests) + ${CMAKE_CURRENT_SOURCE_DIR}/../../tests + ${CMAKE_SOURCE_DIR}/tests/shared) pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 9e7a43eb7..ad4e0f724 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_SOURCE_DIR}/tests/shared) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) diff --git a/tests/shared/gtest_shared_characterwrapper.h b/tests/shared/gtest_shared_characterwrapper.h new file mode 100644 index 000000000..617c0d2ea --- /dev/null +++ b/tests/shared/gtest_shared_characterwrapper.h @@ -0,0 +1,34 @@ +#ifndef _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER +#define _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER + +class CharacterWrapper : + boost::noncopyable +{ + public: + + explicit CharacterWrapper (char *c) : + mChar (c) + { + } + + ~CharacterWrapper () + { + free (mChar); + } + + operator char * () + { + return mChar; + } + + operator const char * () const + { + return mChar; + } + + private: + + char *mChar; +}; + +#endif -- GitLab From 4f1751b559b6d928795c2486d072b36294f1ab16 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 31 Jul 2012 20:41:45 +0800 Subject: [PATCH 204/562] Split out CharacterWrapper for testing --- compizconfig/gsettings/tests/CMakeLists.txt | 2 ++ .../libcompizconfig/tests/CMakeLists.txt | 1 + tests/shared/gtest_shared_characterwrapper.h | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tests/shared/gtest_shared_characterwrapper.h diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 57f6ceb30..a3e8844a4 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -2,6 +2,8 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) + ${CMAKE_CURRENT_SOURCE_DIR}/../../tests + ${CMAKE_SOURCE_DIR}/tests/shared) pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 9e7a43eb7..ad4e0f724 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_SOURCE_DIR}/tests/shared) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) diff --git a/tests/shared/gtest_shared_characterwrapper.h b/tests/shared/gtest_shared_characterwrapper.h new file mode 100644 index 000000000..617c0d2ea --- /dev/null +++ b/tests/shared/gtest_shared_characterwrapper.h @@ -0,0 +1,34 @@ +#ifndef _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER +#define _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER + +class CharacterWrapper : + boost::noncopyable +{ + public: + + explicit CharacterWrapper (char *c) : + mChar (c) + { + } + + ~CharacterWrapper () + { + free (mChar); + } + + operator char * () + { + return mChar; + } + + operator const char * () const + { + return mChar; + } + + private: + + char *mChar; +}; + +#endif -- GitLab From 5a63276e59029105d4d1d1eb4d3b3b6c43610128 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 31 Jul 2012 20:43:53 +0800 Subject: [PATCH 205/562] Fix typo --- compizconfig/gsettings/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index a3e8844a4..afe659211 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,7 +1,7 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests - ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) + ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig ${CMAKE_CURRENT_SOURCE_DIR}/../../tests ${CMAKE_SOURCE_DIR}/tests/shared) -- GitLab From 061ef0636339c4e67ab444cc6337f1f0dea6290b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 31 Jul 2012 21:03:47 +0800 Subject: [PATCH 206/562] Match some of the passed profile names too --- .../gsettings/tests/test_gsettings_tests.cpp | 20 +++++++----- .../tests/compizconfig_backend_concept_test.h | 32 ++----------------- tests/shared/gtest_shared_characterwrapper.h | 2 ++ 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index cce341aa3..980a2d374 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -9,6 +9,7 @@ #include "ccs_gsettings_backend_mock.h" #include "compizconfig_ccs_context_mock.h" #include "compizconfig_ccs_setting_mock.h" +#include "gtest_shared_characterwrapper.h" using ::testing::Values; using ::testing::ValuesIn; @@ -20,6 +21,7 @@ using ::testing::MatchResultListener; using ::testing::AllOf; using ::testing::Not; using ::testing::Matcher; +using ::testing::Eq; class GVariantSubtypeMatcher : public ::testing::MatcherInterface @@ -132,14 +134,16 @@ TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) GVariant *existingProfiles = g_variant_builder_end (&builder); + std::string newProfileName ("narr"); + EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); EXPECT_CALL (*gmock, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), GVariantHasValueInArray ("s", - "narr", + newProfileName.c_str (), boost::bind (streq, _1, _2))))); - EXPECT_CALL (*gmock, setCurrentProfile (_)); + EXPECT_CALL (*gmock, setCurrentProfile (Eq (newProfileName))); - ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), "narr"); + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), newProfileName.c_str ()); } TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameExisting) @@ -180,24 +184,24 @@ TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) GVariantBuilder existingProfilesBuilder; g_variant_builder_init (&existingProfilesBuilder, G_VARIANT_TYPE ("as")); - g_variant_builder_add (&existingProfilesBuilder, "s", "foo"); + g_variant_builder_add (&existingProfilesBuilder, "s", currentProfile.c_str ()); existingProfiles = g_variant_builder_end (&existingProfilesBuilder); EXPECT_CALL (*mockBackend, getPluginsWithSetKeys ()).WillOnce (ReturnNull ()); - EXPECT_CALL (*mockBackend, unsetAllChangedPluginKeysInProfile (context.get (), NULL, _)); - EXPECT_CALL (*mockBackend, clearPluginsWithSetKeys (_)); + EXPECT_CALL (*mockBackend, unsetAllChangedPluginKeysInProfile (context.get (), NULL, Eq (currentProfile))); + EXPECT_CALL (*mockBackend, clearPluginsWithSetKeys (Eq (currentProfile))); EXPECT_CALL (*mockBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillOnce (Return (existingProfiles)); EXPECT_CALL (*mockBackend, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), Not (GVariantHasValueInArray ("s", - "foo", + currentProfile.c_str (), boost::bind (streq, _1, _2)))))); EXPECT_CALL (*mockBackend, updateProfile (context.get ())); - deleteProfile (backend.get (), context.get (), "foo"); + deleteProfile (backend.get (), context.get (), currentProfile.c_str ()); //g_variant_unref (existingProfiles); } diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 6dce530f0..266929fad 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -22,6 +22,8 @@ #include #include +#include "gtest_shared_characterwrapper.h" + using ::testing::Eq; using ::testing::SetArgPointee; using ::testing::DoAll; @@ -122,36 +124,6 @@ operator<< (::std::ostream &os, const CCSSettingButtonValue &v) return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl; } -class CharacterWrapper : - boost::noncopyable -{ - public: - - explicit CharacterWrapper (char *c) : - mChar (c) - { - } - - ~CharacterWrapper () - { - free (mChar); - } - - operator char * () - { - return mChar; - } - - operator const char * () const - { - return mChar; - } - - private: - - char *mChar; -}; - class CCSListWrapper : boost::noncopyable { diff --git a/tests/shared/gtest_shared_characterwrapper.h b/tests/shared/gtest_shared_characterwrapper.h index 617c0d2ea..1b79e1c9a 100644 --- a/tests/shared/gtest_shared_characterwrapper.h +++ b/tests/shared/gtest_shared_characterwrapper.h @@ -1,6 +1,8 @@ #ifndef _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER #define _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER +#include + class CharacterWrapper : boost::noncopyable { -- GitLab From e8ffd4d54c7e58daa757038824ec8548aae5fe37 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 31 Jul 2012 21:04:53 +0800 Subject: [PATCH 207/562] Fix some build issues --- .../tests/compizconfig_backend_concept_test.h | 32 ++----------------- tests/shared/gtest_shared_characterwrapper.h | 2 ++ 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 6dce530f0..266929fad 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -22,6 +22,8 @@ #include #include +#include "gtest_shared_characterwrapper.h" + using ::testing::Eq; using ::testing::SetArgPointee; using ::testing::DoAll; @@ -122,36 +124,6 @@ operator<< (::std::ostream &os, const CCSSettingButtonValue &v) return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl; } -class CharacterWrapper : - boost::noncopyable -{ - public: - - explicit CharacterWrapper (char *c) : - mChar (c) - { - } - - ~CharacterWrapper () - { - free (mChar); - } - - operator char * () - { - return mChar; - } - - operator const char * () const - { - return mChar; - } - - private: - - char *mChar; -}; - class CCSListWrapper : boost::noncopyable { diff --git a/tests/shared/gtest_shared_characterwrapper.h b/tests/shared/gtest_shared_characterwrapper.h index 617c0d2ea..1b79e1c9a 100644 --- a/tests/shared/gtest_shared_characterwrapper.h +++ b/tests/shared/gtest_shared_characterwrapper.h @@ -1,6 +1,8 @@ #ifndef _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER #define _COMPIZ_GTEST_SHARED_CHARACTERWRAPPER +#include + class CharacterWrapper : boost::noncopyable { -- GitLab From 3d62f1538cb212af4965a919300ddf7448f1a41c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 13:19:08 +0800 Subject: [PATCH 208/562] Update test discovery --- compizconfig/libcompizconfig/tests/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 288fd1d7d..e2fb612ad 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -63,7 +63,7 @@ target_link_libraries (compizconfig_test_ccs_setting compizconfig_ccs_plugin_mock compizconfig_ccs_setting_mock) -compiz_discover_tests (test-ccs-object COVERAGE compizconfig) -compiz_discover_tests (test-context COVERAGE context-mock) -compiz_discover_tests (test-plugin COVERAGE plugin-mock) -compiz_discover_tests (test-setting COVERAGE setting-mock) +compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig) +compiz_discover_tests (test-context COVERAGE compizconfig_ccs_context_mock) +compiz_discover_tests (test-plugin COVERAGE compizconfig_ccs_plugin_mock) +compiz_discover_tests (test-setting COVERAGE compizconfig_ccs_setting_mock) -- GitLab From 1f057e3038d261806cc3ba81523d3c3a64323671 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 13:21:07 +0800 Subject: [PATCH 209/562] Update properly --- compizconfig/libcompizconfig/tests/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index e2fb612ad..2ad92645b 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -64,6 +64,6 @@ target_link_libraries (compizconfig_test_ccs_setting compizconfig_ccs_setting_mock) compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig) -compiz_discover_tests (test-context COVERAGE compizconfig_ccs_context_mock) -compiz_discover_tests (test-plugin COVERAGE compizconfig_ccs_plugin_mock) -compiz_discover_tests (test-setting COVERAGE compizconfig_ccs_setting_mock) +compiz_discover_tests (compizconfig_test_ccs_context COVERAGE compizconfig_ccs_context_mock) +compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock) +compiz_discover_tests (compizconfig_test_ccs_setting COVERAGE compizconfig_ccs_setting_mock) -- GitLab From 8e51ab7456f30da0a1cdced2d701ab8838e9aff5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 14:57:57 +0800 Subject: [PATCH 210/562] Fix build fail in mock --- .../tests/compizconfig_test_ccs_backend.cpp | 4 ++-- .../mocks/libcompizconfig/compizconfig_ccs_backend_mock.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp index 9a31f7f3e..a534c3ef5 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp @@ -27,7 +27,7 @@ TEST(CCSBackendTest, TestMock) EXPECT_CALL (*mock, hasIntegrationSupport ()); EXPECT_CALL (*mock, executeEvents (_)); EXPECT_CALL (*mock, init (_)); - EXPECT_CALL (*mock, fini (_)); + EXPECT_CALL (*mock, fini ()); EXPECT_CALL (*mock, readInit (_)); EXPECT_CALL (*mock, readSetting (_,_)); EXPECT_CALL (*mock, readDone (_)); @@ -46,7 +46,7 @@ TEST(CCSBackendTest, TestMock) ccsBackendHasIntegrationSupport (backend); ccsBackendExecuteEvents (backend, 0); ccsBackendInit (backend, NULL); - ccsBackendFini (backend, NULL); + ccsBackendFini (backend); ccsBackendReadInit (backend, NULL); ccsBackendReadSetting (backend, NULL, NULL); ccsBackendReadDone (backend, NULL); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index 86d8ce178..e0824c213 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -19,7 +19,7 @@ class CCSBackendGMockInterface virtual Bool hasIntegrationSupport () = 0; virtual void executeEvents (unsigned int) = 0; virtual Bool init (CCSContext *context) = 0; - virtual Bool fini (CCSContext *context) = 0; + virtual Bool fini () = 0; virtual Bool readInit (CCSContext *context) = 0; virtual void readSetting (CCSContext *context, CCSSetting *setting) = 0; virtual void readDone (CCSContext *context) = 0; @@ -46,7 +46,7 @@ class CCSBackendGMock : MOCK_METHOD0 (hasIntegrationSupport, Bool ()); MOCK_METHOD1 (executeEvents, void (unsigned int)); MOCK_METHOD1 (init, Bool (CCSContext *)); - MOCK_METHOD1 (fini, Bool (CCSContext *)); + MOCK_METHOD0 (fini, Bool ()); MOCK_METHOD1 (readInit, Bool (CCSContext *)); MOCK_METHOD2 (readSetting, void (CCSContext *, CCSSetting *)); MOCK_METHOD1 (readDone, void (CCSContext *)); @@ -97,9 +97,9 @@ class CCSBackendGMock : return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->init (context); } - static Bool ccsBackendFini (CCSBackend *backend, CCSContext *context) + static Bool ccsBackendFini (CCSBackend *backend) { - return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->fini (context); + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->fini (); } static Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) -- GitLab From 1bc139d31f6d1e8da3e46727a73f09ecbda4f575 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 15:15:11 +0800 Subject: [PATCH 211/562] Fix merge marker --- compizconfig/gsettings/tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 22be20f63..250f992c6 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -35,7 +35,6 @@ target_link_libraries (compizconfig_test_gsettings ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) -<<<<<<< TREE configure_file (${CMAKE_CURRENT_SOURCE_DIR}/backend-conformance-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/backend-conformance-config.h) -- GitLab From a7b019dcb18c5b5b16fa2f140629a80d60d41f3a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 17:02:53 +0800 Subject: [PATCH 212/562] Test match lists too --- .../tests/compizconfig_backend_concept_test.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 266929fad..3389820b8 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -801,6 +801,7 @@ Bool boolValues[] = { TRUE, FALSE, TRUE }; int intValues[] = { 1, 2, 3 }; float floatValues[] = { 1.0, 2.0, 3.0 }; const char * stringValues[] = { "foo", "grill", "bar" }; +const char * matchValues[] = { "type=foo", "class=bar", "xid=42" }; const unsigned int NUM_COLOR_VALUES = 3; @@ -999,6 +1000,17 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListReadExpectation, _1, _2), boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListString"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromMatchArray, + impl::matchValues, + sizeof (impl::matchValues) / sizeof (impl::matchValues[0]), _1), + TypeMatch, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, + TypeList, + "match_list_setting", + boost::bind (SetListReadExpectation, _1, _2), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListMatch"), boost::make_shared (backendEnvFactory, VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromColorArray, impl::getColorValueList (), -- GitLab From 418942ac9d347082dd4f83c17285b153fed20d7c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 17:04:01 +0800 Subject: [PATCH 213/562] Add match-list-setting to the mock schema --- compizconfig/gsettings/tests/org.compiz.mock.gschema.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml index d6c0187ad..1d3d8491b 100644 --- a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml +++ b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml @@ -43,6 +43,9 @@ [""] + + [""] + [""] -- GitLab From fcb70726389f6bcb0093002ac0cc665d6905c2bb Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 17:51:19 +0800 Subject: [PATCH 214/562] Move all of the getName, getShortDesc etc functions in CCSBackendInterface to CCSBackendInfo and return it directly (never freed) --- .../compizconfig-python/src/compizconfig.pyx | 6 +- compizconfig/gconf/src/gconf.c | 47 ++++---------- compizconfig/gsettings/src/gsettings.c | 47 ++++---------- .../libcompizconfig/backend/src/ini.c | 48 ++++---------- .../libcompizconfig/include/ccs-backend.h | 31 ++++----- compizconfig/libcompizconfig/include/ccs.h | 14 +--- compizconfig/libcompizconfig/src/main.c | 64 ++++--------------- .../compizconfig_ccs_context_mock.h | 6 +- 8 files changed, 70 insertions(+), 193 deletions(-) diff --git a/compizconfig/compizconfig-python/src/compizconfig.pyx b/compizconfig/compizconfig-python/src/compizconfig.pyx index 59bf3600d..fef0bc5ed 100644 --- a/compizconfig/compizconfig-python/src/compizconfig.pyx +++ b/compizconfig/compizconfig-python/src/compizconfig.pyx @@ -99,9 +99,9 @@ ctypedef CCSList CCSStrRestrictionList ctypedef CCSList CCSStrExtensionList cdef struct CCSBackendInfo: - char * name - char * shortDesc - char * longDesc + const char * name + const char * shortDesc + const char * longDesc Bool integrationSupport Bool profileSupport unsigned int refCount diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index ecfe21924..f8dfe93e6 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -2124,48 +2124,23 @@ deleteProfile (CCSBackend *backend, return status; } -static char * -getName (CCSBackend *backend) +const CCSBackendInfo gconfBackendInfo = { - static char name[] = "gconf"; - - return name; -} - -static char * -getShortDesc (CCSBackend *backend) -{ - static char shortDesc[] = "GConf Configuration Backend"; - - return shortDesc; -} - -static char * -getLongDesc (CCSBackend *backend) -{ - static char longDesc[] = "GConf Configuration Backend for libccs"; - - return longDesc; -} - -static Bool -hasIntegrationSupport (CCSBackend *backend) -{ - return TRUE; -} + "gconf", + "GConf Configuration Backend", + "GConf Configuration Backend for libccs", + TRUE, + TRUE +}; -static Bool -hasProfileSupport (CCSBackend *backend) +static const CCSBackendInfo * +getInfo (CCSBackend *backend) { - return TRUE; + return &gconfBackendInfo; } static CCSBackendInterface gconfVTable = { - getName, - getShortDesc, - getLongDesc, - hasIntegrationSupport, - hasProfileSupport, + getInfo, processEvents, initBackend, finiBackend, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 094779bb1..da85eafe1 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -1122,48 +1122,23 @@ deleteProfile (CCSBackend *backend, return TRUE; } -static char * -getName (CCSBackend *backend) +const CCSBackendInfo gconfBackendInfo = { - static char name[] = "gsettings"; - - return name; -} - -static char * -getShortDesc (CCSBackend *backend) -{ - static char shortDesc[] = "GSettings Configuration Backend"; - - return shortDesc; -} - -static char * -getLongDesc (CCSBackend *backend) -{ - static char longDesc[] = "GSettings Configuration Backend for libccs"; - - return longDesc; -} - -static Bool -hasIntegrationSupport (CCSBackend *backend) -{ - return TRUE; -} + "gsettings", + "GSettings Configuration Backend", + "GSettings Configuration Backend for libccs", + TRUE, + TRUE +}; -static Bool -hasProfileSupport (CCSBackend *backend) +static const CCSBackendInfo * +getInfo (CCSBackend *backend) { - return TRUE; + return &gconfBackendInfo; } static CCSBackendInterface gsettingsVTable = { - getName, - getShortDesc, - getLongDesc, - hasIntegrationSupport, - hasProfileSupport, + getInfo, processEvents, initBackend, finiBackend, diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 63b5f3211..1e425ed3c 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -721,48 +721,24 @@ deleteProfile (CCSBackend *backend, CCSContext * context, char * profile) return TRUE; } -static char * -getName (CCSBackend *backend) +const CCSBackendInfo iniBackendInfo = { - static char name[] = "ini"; - - return name; -} - -static char * -getShortDesc (CCSBackend *backend) -{ - static char shortDesc[] = "Flat-file Configuration Backend"; - - return shortDesc; -} - -static char * -getLongDesc (CCSBackend *backend) -{ - static char longDesc[] = "Flat file Configuration Backend for libccs"; - - return longDesc; -} - -static Bool -hasIntegrationSupport (CCSBackend *backend) -{ - return FALSE; -} + "ini", + "Flat-file Configuration Backend", + "Flat file Configuration Backend for libccs", + FALSE, + TRUE, + 1 +}; -static Bool -hasProfileSupport (CCSBackend *backend) +static const CCSBackendInfo * +getInfo (CCSBackend *backend) { - return TRUE; + return &iniBackendInfo; } static CCSBackendInterface iniVTable = { - getName, - getShortDesc, - getLongDesc, - hasIntegrationSupport, - hasProfileSupport, + getInfo, NULL, initBackend, finiBackend, diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 82c5a4179..fa2176c93 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -29,6 +29,7 @@ COMPIZCONFIG_BEGIN_DECLS typedef struct _CCSBackend CCSBackend; +typedef struct _CCSBackendInfo CCSBackendInfo; typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendInterface CCSBackendInterface; @@ -41,6 +42,16 @@ struct _CCSBackend CCSObject object; }; +struct _CCSBackendInfo +{ + const char *name; /* name of the backend */ + const char *shortDesc; /* backend's short description */ + const char *longDesc; /* backend's long description */ + Bool integrationSupport; /* does the backend support DE integration? */ + Bool profileSupport; /* does the backend support profiles? */ + unsigned int refCount; /* reference count */ +}; + typedef CCSBackendInterface * (*BackendGetInfoProc) (void); typedef void (*CCSBackendExecuteEventsFunc) (CCSBackend *backend, unsigned int flags); @@ -66,19 +77,11 @@ typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSBackend *, CCSSetting * s typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSBackend *, CCSContext * context); typedef Bool (*CCSBackendDeleteProfileFunc) (CCSBackend *, CCSContext * context, char * name); -typedef char * (*CCSBackendGetNameFunc) (CCSBackend *); -typedef char * (*CCSBackendGetShortDescFunc) (CCSBackend *); -typedef char * (*CCSBackendGetLongDescFunc) (CCSBackend *); -typedef Bool (*CCSBackendHasIntegrationSupportFunc) (CCSBackend *); -typedef Bool (*CCSBackendHasProfileSupportFunc) (CCSBackend *); +typedef const CCSBackendInfo * (*CCSBackendGetInfoFunc) (CCSBackend *); struct _CCSBackendInterface { - CCSBackendGetNameFunc getName; - CCSBackendGetShortDescFunc getShortDesc; - CCSBackendGetLongDescFunc getLongDesc; - CCSBackendHasIntegrationSupportFunc hasIntegrationSupport; - CCSBackendHasProfileSupportFunc hasProfileSupport; + CCSBackendGetInfoFunc backendGetInfo; /* something like a event loop call for the backend, so it can check for file changes (gconf changes in the gconf backend) @@ -107,12 +110,7 @@ struct _CCSBackendInterface unsigned int ccsCCSBackendInterfaceGetType (); -char * ccsBackendGetName (CCSBackend *backend); -char * ccsBackendGetShortDesc (CCSBackend *backend); -char * ccsBackendGetLongDesc (CCSBackend *backend); -Bool ccsBackendHasIntegrationSupport (CCSBackend *backend); -Bool ccsBackendHasProfileSupport (CCSBackend *backend); - +const CCSBackendInfo * ccsBackendGetInfo (CCSBackend *backend); Bool ccsBackendHasExecuteEvents (CCSBackend *backend); void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags); Bool ccsBackendInit (CCSBackend *backend, CCSContext *context); @@ -148,7 +146,6 @@ ccsOpenBackend (const char *name, CCSBackendInterface **interface); CCSBackend * ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface, void *dlhand); - CCSBackendInterface* getBackendInfo (void); COMPIZCONFIG_END_DECLS diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 5cac502f2..da4aee6c1 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -154,7 +154,7 @@ typedef Bool (*CCSContextPluginIsActive) (CCSContext *context, char *name); typedef CCSPluginList (*CCSContextGetActivePluginList) (CCSContext *context); typedef CCSStringList (*CCSContextGetSortedPluginStringList) (CCSContext *context); typedef Bool (*CCSContextSetBackend) (CCSContext *context, char *name); -typedef char * (*CCSContextGetBackend) (CCSContext *context); +typedef const char * (*CCSContextGetBackend) (CCSContext *context); typedef void (*CCSContextSetIntegrationEnabled) (CCSContext *context, Bool value); typedef void (*CCSContextSetProfile) (CCSContext *context, char *name); typedef void (*CCSContextSetPluginListAutoSort) (CCSContext *context, Bool value); @@ -237,16 +237,6 @@ struct _CCSContext CCSObject object; }; -struct _CCSBackendInfo -{ - char *name; /* name of the backend */ - char *shortDesc; /* backend's short description */ - char *longDesc; /* backend's long description */ - Bool integrationSupport; /* does the backend support DE integration? */ - Bool profileSupport; /* does the backend support profiles? */ - unsigned int refCount; /* reference count */ -}; - /* CCSPluginInterface */ typedef char * (*CCSPluginGetName) (CCSPlugin *plugin); typedef char * (*CCSPluginGetShortDesc) (CCSPlugin *plugin); @@ -842,7 +832,7 @@ CCSStringList ccsGetSortedPluginStringList (CCSContext *context); Bool ccsSetBackend (CCSContext *context, char *name); /* Retrieves the name of the backend active for the context. */ -char * ccsGetBackend (CCSContext *context); +const char * ccsGetBackend (CCSContext *context); /* Enable/disable DE integration for a context. */ void ccsSetIntegrationEnabled (CCSContext *context, diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index f748f8217..2adc6dd8a 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -320,7 +320,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", ccsBackendGetName (cPrivate->backend)); + ccsInfo ("Backend : %s", ccsBackendGetInfo (cPrivate->backend)->name); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -907,19 +907,9 @@ ccsFreePluginConflict (CCSPluginConflict * c) void ccsFreeBackendInfo (CCSBackendInfo * b) { - if (!b) - return; - - if (b->name) - free (b->name); - - if (b->shortDesc) - free (b->shortDesc); - - if (b->longDesc) - free (b->longDesc); - - free (b); + /* Does nothing, as backend info is + * the owned by the backend library + * itself */ } void @@ -1150,7 +1140,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) { /* no action needed if the backend is the same */ - if (strcmp (ccsBackendGetName ((CCSBackend *) cPrivate->backend), name) == 0) + if (strcmp (ccsBackendGetInfo ((CCSBackend *) cPrivate->backend)->name, name) == 0) return TRUE; ccsBackendUnref (cPrivate->backend); @@ -1198,29 +1188,9 @@ ccsSetBackend (CCSContext *context, char *name) return (*(GET_INTERFACE (CCSContextInterface, context))->contextSetBackend) (context, name); } -char * ccsBackendGetName (CCSBackend *backend) -{ - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getName) (backend); -} - -char * ccsBackendGetShortDesc (CCSBackend *backend) -{ - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getShortDesc) (backend); -} - -char * ccsBackendGetLongDesc (CCSBackend *backend) +const CCSBackendInfo * ccsBackendGetInfo (CCSBackend *backend) { - return (*(GET_INTERFACE (CCSBackendInterface, backend))->getLongDesc) (backend); -} - -Bool ccsBackendHasIntegrationSupport (CCSBackend *backend) -{ - return (*(GET_INTERFACE (CCSBackendInterface, backend))->hasIntegrationSupport) (backend); -} - -Bool ccsBackendHasProfileSupport (CCSBackend *backend) -{ - return (*(GET_INTERFACE (CCSBackendInterface, backend))->hasProfileSupport) (backend); + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendGetInfo) (backend); } Bool ccsBackendHasExecuteEvents (CCSBackend *backend) @@ -2752,7 +2722,7 @@ ccsGetSortedPluginStringList (CCSContext *context) return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetSortedPluginStringList) (context); } -char * +const char * ccsGetBackendDefault (CCSContext * context) { if (!context) @@ -2763,10 +2733,10 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return (*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) (cPrivate->backend); + return ccsBackendGetInfo (cPrivate->backend)->name; } -char * +const char * ccsGetBackend (CCSContext *context) { return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetBackend) (context); @@ -3585,7 +3555,6 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) void *dlhand = NULL; char *err = NULL; Bool found = FALSE; - CCSBackendInfo *info; dlerror (); @@ -3608,10 +3577,12 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) return; } + const CCSBackendInfo *info = (*vt->backendGetInfo) (NULL); + CCSBackendInfoList l = *bl; while (l) { - if (!strcmp (l->data->name, (*vt->getName) (NULL))) + if (!strcmp (l->data->name, info->name)) { found = TRUE; break; @@ -3633,14 +3604,7 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) return; } - info->refCount = 1; - info->name = strdup ((*vt->getName) (NULL)); - info->shortDesc = (vt->getShortDesc) ? strdup ((*vt->getShortDesc) (NULL)) : strdup (""); - info->longDesc = (vt->getLongDesc) ? strdup ((*vt->getLongDesc) (NULL)) : strdup (""); - info->integrationSupport = (*vt->hasIntegrationSupport) (NULL); - info->profileSupport = (*vt->hasProfileSupport) (NULL); - - *bl = ccsBackendInfoListAppend (*bl, info); + *bl = ccsBackendInfoListAppend (*bl, (CCSBackendInfo *) info); dlclose (dlhand); } diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h index 72f276bd4..7e9b38110 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h @@ -26,7 +26,7 @@ class CCSContextGMockInterface virtual Bool pluginIsActive (char *name) = 0; virtual CCSPluginList getActivePluginList () = 0; virtual CCSStringList getSortedPluginStringList () = 0; - virtual char * getBackend () = 0; + virtual const char * getBackend () = 0; virtual Bool setBackend (char *name) = 0; virtual void setIntegrationEnabled (Bool value) = 0; virtual void setProfile (char *name) = 0; @@ -67,7 +67,7 @@ class CCSContextGMock : MOCK_METHOD1 (pluginIsActive, Bool (char *)); MOCK_METHOD0 (getActivePluginList, CCSPluginList ()); MOCK_METHOD0 (getSortedPluginStringList, CCSStringList ()); - MOCK_METHOD0 (getBackend, char * ()); + MOCK_METHOD0 (getBackend, const char * ()); MOCK_METHOD1 (setBackend, Bool (char *)); MOCK_METHOD1 (setIntegrationEnabled, void (Bool)); MOCK_METHOD1 (setProfile, void (char *)); @@ -175,7 +175,7 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getSortedPluginStringList (); } - static char * + static const char * ccsGetBackend (CCSContext *context) { return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getBackend (); -- GitLab From 6b5148891ee7e55bcef530b01fee336de9de1003 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 17:52:22 +0800 Subject: [PATCH 215/562] Initialize refcount of gconfBackendInfo and gsettingsBackendInfo --- compizconfig/gconf/src/gconf.c | 3 ++- compizconfig/gsettings/src/gsettings.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index f8dfe93e6..eb9c6835b 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -2130,7 +2130,8 @@ const CCSBackendInfo gconfBackendInfo = "GConf Configuration Backend", "GConf Configuration Backend for libccs", TRUE, - TRUE + TRUE, + 1 }; static const CCSBackendInfo * diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index da85eafe1..64e625bd8 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -1128,7 +1128,8 @@ const CCSBackendInfo gconfBackendInfo = "GSettings Configuration Backend", "GSettings Configuration Backend for libccs", TRUE, - TRUE + TRUE, + 1 }; static const CCSBackendInfo * -- GitLab From c592358350513686a8e0777a110738eadd15974e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 18:23:11 +0800 Subject: [PATCH 216/562] Fix build on dynamic wrapper --- compizconfig/libcompizconfig/src/main.c | 65 +++++-------------------- 1 file changed, 13 insertions(+), 52 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 79eb89254..398e064df 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -321,11 +321,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) -<<<<<<< TREE - ccsInfo ("Backend : %s", ccsBackendGetName ((CCSBackend *) cPrivate->backend)); -======= - ccsInfo ("Backend : %s", ccsBackendGetInfo (cPrivate->backend)->name); ->>>>>>> MERGE-SOURCE + ccsInfo ("Backend : %s", ccsBackendGetInfo ((CCSBackend *) cPrivate->backend)->name); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -1234,7 +1230,7 @@ ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *DYNAMIC_BACKEND_ { DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); - return ccsBackendHasIntegrationSupport (bcPrivate->backend); + return ccsBackendGetInfo (bcPrivate->backend)->integrationSupport; } Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) @@ -1413,7 +1409,8 @@ ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRI { DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); - return ccsBackendHasProfileSupport (bcPrivate->backend); + return ccsBackendGetInfo (bcPrivate->backend)->profileSupport; + } static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) @@ -1423,46 +1420,18 @@ static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *DY return bcPrivate->backend; } -static Bool ccsDynamicBackendInitWrapper (CCSBackend *backend, CCSContext *context) -{ - DYNAMIC_BACKEND_PRIV (backend); - - return ccsBackendInit (bcPrivate->backend, context); -} - -static char * ccsDynamicBackendGetNameWrapper (CCSBackend *backend) -{ - DYNAMIC_BACKEND_PRIV (backend); - - return ccsBackendGetName (bcPrivate->backend); -} - -static char * ccsDynamicBackendGetShortDescWrapper (CCSBackend *backend) +static const CCSBackendInfo * ccsDynamicBackendGetInfoWrapper (CCSBackend *backend) { DYNAMIC_BACKEND_PRIV (backend); - return ccsBackendGetShortDesc (bcPrivate->backend); + return ccsBackendGetInfo (bcPrivate->backend); } -static char * ccsDynamicBackendGetLongDescWrapper (CCSBackend *backend) -{ - DYNAMIC_BACKEND_PRIV (backend); - - return ccsBackendGetName (bcPrivate->backend); -} - -static Bool ccsDynamicBackendHasIntegrationSupportWrapper (CCSBackend *backend) -{ - DYNAMIC_BACKEND_PRIV (backend); - - return ccsBackendHasIntegrationSupport (bcPrivate->backend); -} - -static Bool ccsDynamicBackendHasProfileSupportWrapper (CCSBackend *backend) +static Bool ccsDynamicBackendInitWrapper (CCSBackend *backend, CCSContext *context) { DYNAMIC_BACKEND_PRIV (backend); - return ccsBackendHasProfileSupport (bcPrivate->backend); + return ccsBackendInit (bcPrivate->backend, context); } static Bool ccsDynamicBackendFiniWrapper (CCSBackend *backend) @@ -1545,7 +1514,7 @@ static Bool ccsDynamicBackendGetSettingIsIntegratedWrapper (CCSBackend *backend, DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasGetSettingIsIntegrated (bcPrivate->backend) && - ccsBackendHasIntegrationSupport (bcPrivate->backend)) + ccsDynamicBackendSupportsIntegration ((CCSDynamicBackend *) backend)) return ccsBackendGetSettingIsIntegrated (bcPrivate->backend, setting); return FALSE; @@ -1566,7 +1535,7 @@ static CCSStringList ccsDynamicBackendGetExistingProfilesWrapper (CCSBackend *ba DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasGetExistingProfiles (bcPrivate->backend) && - ccsBackendHasProfileSupport (bcPrivate->backend)) + ccsDynamicBackendSupportsProfiles ((CCSDynamicBackend *) backend)) return ccsBackendGetExistingProfiles (bcPrivate->backend, context); static CCSStringList sl = NULL; @@ -1579,7 +1548,7 @@ static Bool ccsDynamicBackendDeleteProfileWrapper (CCSBackend *backend, CCSConte DYNAMIC_BACKEND_PRIV (backend); if (ccsBackendHasDeleteProfile (bcPrivate->backend) && - ccsBackendHasProfileSupport (bcPrivate->backend)) + ccsDynamicBackendSupportsProfiles ((CCSDynamicBackend *) backend)) return ccsBackendDeleteProfile (bcPrivate->backend, context, profile); return FALSE; @@ -3000,11 +2969,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; -<<<<<<< TREE - return (*(GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->getName) ((CCSBackend *) cPrivate->backend); -======= - return ccsBackendGetInfo (cPrivate->backend)->name; ->>>>>>> MERGE-SOURCE + return ccsBackendGetInfo ((CCSBackend *) cPrivate->backend)->name; } const char * @@ -5492,11 +5457,7 @@ static const CCSSettingInterface ccsDefaultSettingInterface = const CCSBackendInterface ccsDynamicBackendInterfaceWrapper = { - ccsDynamicBackendGetNameWrapper, - ccsDynamicBackendGetShortDescWrapper, - ccsDynamicBackendGetLongDescWrapper, - ccsDynamicBackendHasIntegrationSupportWrapper, - ccsDynamicBackendHasProfileSupportWrapper, + ccsDynamicBackendGetInfoWrapper, ccsDynamicBackendExecuteEventsWrapper, ccsDynamicBackendInitWrapper, ccsDynamicBackendFiniWrapper, -- GitLab From 23fc35af03a7fd1582958c5447922db3badbf15d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 18:27:31 +0800 Subject: [PATCH 217/562] bcPrivate -> dbPrivate --- .../libcompizconfig/src/ccs-private.h | 2 +- compizconfig/libcompizconfig/src/main.c | 82 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index d3c4f12db..af020cff7 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -32,7 +32,7 @@ #define SETTING_PRIV(s) \ CCSSettingPrivate *sPrivate = (CCSSettingPrivate *) ccsObjectGetPrivate (s); #define DYNAMIC_BACKEND_PRIV(bc) \ - CCSDynamicBackendPrivate *bcPrivate = (CCSDynamicBackendPrivate *) ccsObjectGetPrivate (bc); + CCSDynamicBackendPrivate *dbPrivate = (CCSDynamicBackendPrivate *) ccsObjectGetPrivate (bc); extern Bool basicMetadata; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 398e064df..798d11503 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1070,10 +1070,10 @@ ccsFreeDynamicBackend (CCSDynamicBackend *DynamicBackend) { DYNAMIC_BACKEND_PRIV (DynamicBackend); - ccsBackendUnref (bcPrivate->backend); + ccsBackendUnref (dbPrivate->backend); - if (bcPrivate->dlhand) - dlclose (bcPrivate->dlhand); + if (dbPrivate->dlhand) + dlclose (dbPrivate->dlhand); ccsObjectFinalize (DynamicBackend); free (DynamicBackend); @@ -1096,7 +1096,7 @@ CCSDynamicBackend * ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand) { CCSDynamicBackend *dynamicBackend = calloc (1, sizeof (CCSDynamicBackend)); - CCSDynamicBackendPrivate *bcPrivate = NULL; + CCSDynamicBackendPrivate *dbPrivate = NULL; if (!dynamicBackend) return NULL; @@ -1104,18 +1104,18 @@ ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBack ccsObjectInit (dynamicBackend, &ccsDefaultObjectAllocator); ccsDynamicBackendRef (dynamicBackend); - bcPrivate = calloc (1, sizeof (CCSDynamicBackendPrivate)); + dbPrivate = calloc (1, sizeof (CCSDynamicBackendPrivate)); - if (!bcPrivate) + if (!dbPrivate) { ccsDynamicBackendUnref (dynamicBackend); return NULL; } - bcPrivate->dlhand = dlhand; - bcPrivate->backend = backend; + dbPrivate->dlhand = dlhand; + dbPrivate->backend = backend; - ccsObjectSetPrivate (dynamicBackend, (CCSPrivate *) bcPrivate); + ccsObjectSetPrivate (dynamicBackend, (CCSPrivate *) dbPrivate); ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendWrapperInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendInterface, GET_INTERFACE_TYPE (CCSDynamicBackendInterface)); @@ -1230,7 +1230,7 @@ ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *DYNAMIC_BACKEND_ { DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); - return ccsBackendGetInfo (bcPrivate->backend)->integrationSupport; + return ccsBackendGetInfo (dbPrivate->backend)->integrationSupport; } Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) @@ -1393,7 +1393,7 @@ ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIViti { DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); - return ccsBackendHasReadSetting (bcPrivate->backend); + return ccsBackendHasReadSetting (dbPrivate->backend); } static Bool @@ -1401,7 +1401,7 @@ ccsDynamicBackendSupportsWriteDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVit { DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); - return ccsBackendHasWriteSetting (bcPrivate->backend); + return ccsBackendHasWriteSetting (dbPrivate->backend); } static Bool @@ -1409,7 +1409,7 @@ ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRI { DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); - return ccsBackendGetInfo (bcPrivate->backend)->profileSupport; + return ccsBackendGetInfo (dbPrivate->backend)->profileSupport; } @@ -1417,44 +1417,44 @@ static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *DY { DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); - return bcPrivate->backend; + return dbPrivate->backend; } static const CCSBackendInfo * ccsDynamicBackendGetInfoWrapper (CCSBackend *backend) { DYNAMIC_BACKEND_PRIV (backend); - return ccsBackendGetInfo (bcPrivate->backend); + return ccsBackendGetInfo (dbPrivate->backend); } static Bool ccsDynamicBackendInitWrapper (CCSBackend *backend, CCSContext *context) { DYNAMIC_BACKEND_PRIV (backend); - return ccsBackendInit (bcPrivate->backend, context); + return ccsBackendInit (dbPrivate->backend, context); } static Bool ccsDynamicBackendFiniWrapper (CCSBackend *backend) { DYNAMIC_BACKEND_PRIV (backend); - return ccsBackendFini (bcPrivate->backend); + return ccsBackendFini (dbPrivate->backend); } static void ccsDynamicBackendExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasExecuteEvents (bcPrivate->backend)) - ccsBackendExecuteEvents (bcPrivate->backend, flags); + if (ccsBackendHasExecuteEvents (dbPrivate->backend)) + ccsBackendExecuteEvents (dbPrivate->backend, flags); } static Bool ccsDynamicBackendReadInitWrapper (CCSBackend *backend, CCSContext *context) { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasReadInit (bcPrivate->backend)) - return ccsBackendReadInit (bcPrivate->backend, context); + if (ccsBackendHasReadInit (dbPrivate->backend)) + return ccsBackendReadInit (dbPrivate->backend, context); return TRUE; } @@ -1463,24 +1463,24 @@ static void ccsDynamicBackendReadSettingWrapper (CCSBackend *backend, CCSContext { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasReadSetting (bcPrivate->backend)) - ccsBackendReadSetting (bcPrivate->backend, context, setting); + if (ccsBackendHasReadSetting (dbPrivate->backend)) + ccsBackendReadSetting (dbPrivate->backend, context, setting); } static void ccsDynamicBackendReadDoneWrapper (CCSBackend *backend, CCSContext *context) { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasReadDone (bcPrivate->backend)) - ccsBackendReadDone (bcPrivate->backend, context); + if (ccsBackendHasReadDone (dbPrivate->backend)) + ccsBackendReadDone (dbPrivate->backend, context); } static Bool ccsDynamicBackendWriteInitWrapper (CCSBackend *backend, CCSContext *context) { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasWriteInit (bcPrivate->backend)) - return ccsBackendWriteInit (bcPrivate->backend, context); + if (ccsBackendHasWriteInit (dbPrivate->backend)) + return ccsBackendWriteInit (dbPrivate->backend, context); return TRUE; } @@ -1489,33 +1489,33 @@ static void ccsDynamicBackendWriteSettingWrapper (CCSBackend *backend, CCSContex { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasWriteSetting (bcPrivate->backend)) - ccsBackendWriteSetting (bcPrivate->backend, context, setting); + if (ccsBackendHasWriteSetting (dbPrivate->backend)) + ccsBackendWriteSetting (dbPrivate->backend, context, setting); } static void ccsDynamicBackendWriteDoneWrapper (CCSBackend *backend, CCSContext *context) { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasWriteDone (bcPrivate->backend)) - ccsBackendWriteDone (bcPrivate->backend, context); + if (ccsBackendHasWriteDone (dbPrivate->backend)) + ccsBackendWriteDone (dbPrivate->backend, context); } static void ccsDynamicBackendUpdateSettingWrapper (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasUpdateSetting (bcPrivate->backend)) - ccsBackendUpdateSetting (bcPrivate->backend, context, plugin, setting); + if (ccsBackendHasUpdateSetting (dbPrivate->backend)) + ccsBackendUpdateSetting (dbPrivate->backend, context, plugin, setting); } static Bool ccsDynamicBackendGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasGetSettingIsIntegrated (bcPrivate->backend) && + if (ccsBackendHasGetSettingIsIntegrated (dbPrivate->backend) && ccsDynamicBackendSupportsIntegration ((CCSDynamicBackend *) backend)) - return ccsBackendGetSettingIsIntegrated (bcPrivate->backend, setting); + return ccsBackendGetSettingIsIntegrated (dbPrivate->backend, setting); return FALSE; } @@ -1524,8 +1524,8 @@ static Bool ccsDynamicBackendGetSettingIsReadOnlyWrapper (CCSBackend *backend, C { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasGetSettingIsReadOnly (bcPrivate->backend)) - return ccsBackendGetSettingIsReadOnly (bcPrivate->backend, setting); + if (ccsBackendHasGetSettingIsReadOnly (dbPrivate->backend)) + return ccsBackendGetSettingIsReadOnly (dbPrivate->backend, setting); return FALSE; } @@ -1534,9 +1534,9 @@ static CCSStringList ccsDynamicBackendGetExistingProfilesWrapper (CCSBackend *ba { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasGetExistingProfiles (bcPrivate->backend) && + if (ccsBackendHasGetExistingProfiles (dbPrivate->backend) && ccsDynamicBackendSupportsProfiles ((CCSDynamicBackend *) backend)) - return ccsBackendGetExistingProfiles (bcPrivate->backend, context); + return ccsBackendGetExistingProfiles (dbPrivate->backend, context); static CCSStringList sl = NULL; @@ -1547,9 +1547,9 @@ static Bool ccsDynamicBackendDeleteProfileWrapper (CCSBackend *backend, CCSConte { DYNAMIC_BACKEND_PRIV (backend); - if (ccsBackendHasDeleteProfile (bcPrivate->backend) && + if (ccsBackendHasDeleteProfile (dbPrivate->backend) && ccsDynamicBackendSupportsProfiles ((CCSDynamicBackend *) backend)) - return ccsBackendDeleteProfile (bcPrivate->backend, context, profile); + return ccsBackendDeleteProfile (dbPrivate->backend, context, profile); return FALSE; } -- GitLab From 8089c8b0e0ec3678cb8843fbe5afa17e255d037d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 18:36:36 +0800 Subject: [PATCH 218/562] Added a GetName wrapper to DynamicBackend --- compizconfig/libcompizconfig/include/ccs-backend.h | 3 +++ compizconfig/libcompizconfig/src/main.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index c0274b103..9284f51c5 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -137,6 +137,7 @@ struct _CCSDynamicBackend CCSObject object; }; +typedef const char * (*CCSDynamicBackendGetBackendName) (CCSDynamicBackend *); typedef Bool (*CCSDynamicBackendSupportsRead) (CCSDynamicBackend *); typedef Bool (*CCSDynamicBackendSupportsWrite) (CCSDynamicBackend *); typedef Bool (*CCSDynamicBackendSupportsProfiles) (CCSDynamicBackend *); @@ -145,6 +146,7 @@ typedef CCSBackend * (*CCSDynamicBackendGetRawBackend) (CCSDynamicBackend *); struct _CCSDynamicBackendInterface { + CCSDynamicBackendGetBackendName getBackendName; CCSDynamicBackendSupportsRead supportsRead; CCSDynamicBackendSupportsWrite supportsWrite; CCSDynamicBackendSupportsProfiles supportsProfiles; @@ -152,6 +154,7 @@ struct _CCSDynamicBackendInterface CCSDynamicBackendGetRawBackend getRawBackend; }; +const char * ccsDynamicBackendGetBackendName (CCSDynamicBackend *); Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *); Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *); Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 798d11503..53154b42d 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1233,6 +1233,11 @@ ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *DYNAMIC_BACKEND_ return ccsBackendGetInfo (dbPrivate->backend)->integrationSupport; } +const char * ccsDynamicBackendGetBackendName (CCSDynamicBackend *backend) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->getBackendName) (backend); +} + Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsRead) (DYNAMIC_BACKEND_PRIVities); @@ -1388,6 +1393,14 @@ Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *na return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (backend, context, name); } +static const char * +ccsDynamicBackendGetBackendNameDefault (CCSDynamicBackend *backend) +{ + DYNAMIC_BACKEND_PRIV (backend); + + return ccsBackendGetInfo (dbPrivate->backend)->name; +} + static Bool ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) { @@ -5476,6 +5489,7 @@ const CCSBackendInterface ccsDynamicBackendInterfaceWrapper = const CCSDynamicBackendInterface ccsDefaultDynamicBackendInterface = { + ccsDynamicBackendGetBackendNameDefault, ccsDynamicBackendSupportsReadDefault, ccsDynamicBackendSupportsWriteDefault, ccsDynamicBackendSupportsIntegrationDefault, -- GitLab From 695759173f6865b1abf9c8e271b60dc2a5f60e99 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 18:38:45 +0800 Subject: [PATCH 219/562] Apply law of demeter --- compizconfig/libcompizconfig/src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 53154b42d..a638616b7 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -321,7 +321,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", ccsBackendGetInfo ((CCSBackend *) cPrivate->backend)->name); + ccsInfo ("Backend : %s", ccsDynamicBackendGetBackendName (cPrivate->backend)); ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); ccsInfo ("Profile : %s", (cPrivate->profile && strlen (cPrivate->profile)) ? @@ -1176,7 +1176,7 @@ ccsSetBackendDefault (CCSContext * context, char *name) { /* no action needed if the backend is the same */ - if (strcmp (ccsBackendGetInfo ((CCSBackend *) cPrivate->backend)->name, name) == 0) + if (strcmp (ccsDynamicBackendGetBackendName (cPrivate->backend), name) == 0) return TRUE; ccsDynamicBackendUnref (cPrivate->backend); @@ -2982,7 +2982,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return ccsBackendGetInfo ((CCSBackend *) cPrivate->backend)->name; + return ccsDynamicBackendGetBackendName (cPrivate->backend); } const char * -- GitLab From 4ccfb666872c69e18e320f695510a7dab538684d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 18:40:50 +0800 Subject: [PATCH 220/562] Fix DYNAMIC_BACKEND_PRIVities f'n'r abomination, obviously we meant "backend" --- compizconfig/libcompizconfig/src/main.c | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index a638616b7..7d22f2c6b 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -1226,9 +1226,9 @@ const CCSBackendInfo * ccsBackendGetInfo (CCSBackend *backend) } static Bool -ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *backend) { - DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendGetInfo (dbPrivate->backend)->integrationSupport; } @@ -1238,29 +1238,29 @@ const char * ccsDynamicBackendGetBackendName (CCSDynamicBackend *backend) return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->getBackendName) (backend); } -Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *backend) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsRead) (DYNAMIC_BACKEND_PRIVities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsRead) (backend); } -Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *backend) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsWrite) (DYNAMIC_BACKEND_PRIVities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsWrite) (backend); } -Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *backend) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsProfiles) (DYNAMIC_BACKEND_PRIVities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsProfiles) (backend); } -Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *backend) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->supportsIntegration) (DYNAMIC_BACKEND_PRIVities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsIntegration) (backend); } -CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *backend) { - return (*(GET_INTERFACE (CCSDynamicBackendInterface, DYNAMIC_BACKEND_PRIVities))->getRawBackend) (DYNAMIC_BACKEND_PRIVities); + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->getRawBackend) (backend); } Bool ccsBackendHasExecuteEvents (CCSBackend *backend) @@ -1402,33 +1402,33 @@ ccsDynamicBackendGetBackendNameDefault (CCSDynamicBackend *backend) } static Bool -ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *backend) { - DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendHasReadSetting (dbPrivate->backend); } static Bool -ccsDynamicBackendSupportsWriteDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +ccsDynamicBackendSupportsWriteDefault (CCSDynamicBackend *backend) { - DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendHasWriteSetting (dbPrivate->backend); } static Bool -ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *backend) { - DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); + DYNAMIC_BACKEND_PRIV (backend); return ccsBackendGetInfo (dbPrivate->backend)->profileSupport; } -static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *DYNAMIC_BACKEND_PRIVities) +static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *backend) { - DYNAMIC_BACKEND_PRIV (DYNAMIC_BACKEND_PRIVities); + DYNAMIC_BACKEND_PRIV (backend); return dbPrivate->backend; } -- GitLab From ea54a70c538f2e0dee2c1f8b1196d472c715434c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 18:52:12 +0800 Subject: [PATCH 221/562] Make the mock backend compile --- .../tests/compizconfig_test_ccs_backend.cpp | 12 ++----- .../compizconfig_ccs_backend_mock.cpp | 6 +--- .../compizconfig_ccs_backend_mock.h | 36 +++---------------- 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp index a534c3ef5..4c96a98ce 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp @@ -20,11 +20,7 @@ TEST(CCSBackendTest, TestMock) CCSStringList profiles = NULL; - EXPECT_CALL (*mock, getName ()); - EXPECT_CALL (*mock, getShortDesc ()); - EXPECT_CALL (*mock, getLongDesc ()); - EXPECT_CALL (*mock, hasProfileSupport ()); - EXPECT_CALL (*mock, hasIntegrationSupport ()); + EXPECT_CALL (*mock, getInfo ()); EXPECT_CALL (*mock, executeEvents (_)); EXPECT_CALL (*mock, init (_)); EXPECT_CALL (*mock, fini ()); @@ -39,11 +35,7 @@ TEST(CCSBackendTest, TestMock) EXPECT_CALL (*mock, getExistingProfiles (_)).WillRepeatedly (Return (profiles)); EXPECT_CALL (*mock, deleteProfile (_, _)); - ccsBackendGetName (backend); - ccsBackendGetShortDesc (backend); - ccsBackendGetLongDesc (backend); - ccsBackendHasProfileSupport (backend); - ccsBackendHasIntegrationSupport (backend); + ccsBackendGetInfo (backend); ccsBackendExecuteEvents (backend, 0); ccsBackendInit (backend, NULL); ccsBackendFini (backend); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp index 58e70e50e..1b64fd853 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp @@ -7,11 +7,7 @@ CCSBackendInterface CCSBackendGMockInterface = { - CCSBackendGMock::ccsBackendGetName, - CCSBackendGMock::ccsBackendGetShortDesc, - CCSBackendGMock::ccsBackendGetLongDesc, - CCSBackendGMock::ccsBackendHasIntegrationSupport, - CCSBackendGMock::ccsBackendHasProfileSupport, + CCSBackendGMock::ccsBackendGetInfo, CCSBackendGMock::ccsBackendExecuteEvents, CCSBackendGMock::ccsBackendInit, CCSBackendGMock::ccsBackendFini, diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index e0824c213..01041c6c0 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -12,11 +12,7 @@ class CCSBackendGMockInterface virtual ~CCSBackendGMockInterface () {}; - virtual char * getName () = 0; - virtual char * getShortDesc () = 0; - virtual char * getLongDesc () = 0; - virtual Bool hasProfileSupport () = 0; - virtual Bool hasIntegrationSupport () = 0; + virtual const CCSBackendInfo * getInfo () = 0; virtual void executeEvents (unsigned int) = 0; virtual Bool init (CCSContext *context) = 0; virtual Bool fini () = 0; @@ -39,11 +35,7 @@ class CCSBackendGMock : public: /* Mock implementations */ - MOCK_METHOD0 (getName, char * ()); - MOCK_METHOD0 (getShortDesc, char * ()); - MOCK_METHOD0 (getLongDesc, char * ()); - MOCK_METHOD0 (hasProfileSupport, Bool ()); - MOCK_METHOD0 (hasIntegrationSupport, Bool ()); + MOCK_METHOD0 (getInfo, const CCSBackendInfo * ()); MOCK_METHOD1 (executeEvents, void (unsigned int)); MOCK_METHOD1 (init, Bool (CCSContext *)); MOCK_METHOD0 (fini, Bool ()); @@ -62,29 +54,9 @@ class CCSBackendGMock : public: /* Thunking C to C++ */ - static char * ccsBackendGetName (CCSBackend *backend) + static const CCSBackendInfo * ccsBackendGetInfo (CCSBackend *backend) { - return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getName (); - } - - static char * ccsBackendGetShortDesc (CCSBackend *backend) - { - return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getShortDesc (); - } - - static char * ccsBackendGetLongDesc (CCSBackend *backend) - { - return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getLongDesc (); - } - - static Bool ccsBackendHasIntegrationSupport (CCSBackend *backend) - { - return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->hasIntegrationSupport (); - } - - static Bool ccsBackendHasProfileSupport (CCSBackend *backend) - { - return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->hasProfileSupport (); + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getInfo (); } static void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags) -- GitLab From be03efab4d6fd596fbb5a27897d206aa9bb1695f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 18:53:17 +0800 Subject: [PATCH 222/562] Easier to just use ReturnNull () --- .../libcompizconfig/tests/compizconfig_test_ccs_backend.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp index 4c96a98ce..9e4099beb 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp @@ -6,7 +6,7 @@ #include "compizconfig_ccs_backend_mock.h" using ::testing::_; -using ::testing::Return; +using ::testing::ReturnNull; class CCSBackendTest : public ::testing::Test @@ -18,8 +18,6 @@ TEST(CCSBackendTest, TestMock) CCSBackend *backend = ccsMockBackendNew (); CCSBackendGMock *mock = (CCSBackendGMock *) ccsObjectGetPrivate (backend); - CCSStringList profiles = NULL; - EXPECT_CALL (*mock, getInfo ()); EXPECT_CALL (*mock, executeEvents (_)); EXPECT_CALL (*mock, init (_)); @@ -32,7 +30,7 @@ TEST(CCSBackendTest, TestMock) EXPECT_CALL (*mock, writeDone (_)); EXPECT_CALL (*mock, getSettingIsIntegrated (_)); EXPECT_CALL (*mock, getSettingIsReadOnly (_)); - EXPECT_CALL (*mock, getExistingProfiles (_)).WillRepeatedly (Return (profiles)); + EXPECT_CALL (*mock, getExistingProfiles (_)).WillRepeatedly (ReturnNull ()); EXPECT_CALL (*mock, deleteProfile (_, _)); ccsBackendGetInfo (backend); -- GitLab From 40f25818607545f5bc28a226a66c0742b7e161e0 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 19:00:33 +0800 Subject: [PATCH 223/562] Require testing fixtures to provide a GetInfo () which mirrors GetInfo in BackendInterface and rename CCSBackendConformanceTest to CCSBackendConformanceTestParameterized --- ...nfig_test_ccs_mock_backend_conformance.cpp | 14 ++++ .../tests/compizconfig_backend_concept_test.h | 68 ++++++++++--------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 04529f292..5b60d778b 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -46,6 +46,15 @@ class ValueForKeyRetreival namespace { void doNothingWithCCSSetting (CCSSetting *) {}; + + const CCSBackendInfo mockBackendInfo = + { + "mock", + "Mock Backend", + "Mock Backend for libccs", + TRUE, + TRUE + }; } class MockCCSBackendConceptTestEnvironment : @@ -83,6 +92,11 @@ class MockCCSBackendConceptTestEnvironment : return mBackend; } + const CCSBackendInfo * GetInfo () + { + return &mockBackendInfo; + } + void TearDown (CCSBackend *backend) { ccsFreeMockBackend (backend); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 3389820b8..9d3bd1b6e 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -197,6 +197,8 @@ class CCSBackendConceptTestEnvironmentInterface CCSContextGMock *gmockContext) = 0; virtual void TearDown (CCSBackend *) = 0; + virtual const CCSBackendInfo * GetInfo () = 0; + virtual void PreWrite (CCSContextGMock *, CCSPluginGMock *, CCSSettingGMock *, @@ -699,14 +701,14 @@ class CCSBackendConceptTestParam : }; -class CCSBackendConformanceTest : +class CCSBackendConformanceTestParameterized : public ::testing::TestWithParam { public: - virtual ~CCSBackendConformanceTest () {} + virtual ~CCSBackendConformanceTestParameterized () {} - CCSBackendConformanceTest () : + CCSBackendConformanceTestParameterized () : profileName ("mock") { } @@ -718,7 +720,7 @@ class CCSBackendConformanceTest : virtual void SetUp () { - CCSBackendConformanceTest::SpawnContext (context); + CCSBackendConformanceTestParameterized::SpawnContext (context); gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); @@ -728,7 +730,7 @@ class CCSBackendConformanceTest : virtual void TearDown () { - CCSBackendConformanceTest::GetParam ()->TearDown (mBackend); + CCSBackendConformanceTestParameterized::GetParam ()->TearDown (mBackend); } protected: @@ -1030,7 +1032,7 @@ GenerateTestingParametersForBackendInterface () } class CCSBackendConformanceTestReadWrite : - public CCSBackendConformanceTest + public CCSBackendConformanceTestParameterized { public: @@ -1038,14 +1040,14 @@ class CCSBackendConformanceTestReadWrite : virtual void SetUp () { - CCSBackendConformanceTest::SetUp (); + CCSBackendConformanceTestParameterized::SetUp (); pluginName = "mock"; settingName = GetParam ()->keyname (); VALUE = GetParam ()->value (); - CCSBackendConformanceTest::SpawnPlugin (pluginName, context, plugin); - CCSBackendConformanceTest::SpawnSetting (settingName, GetParam ()->type (), plugin, setting); + CCSBackendConformanceTestParameterized::SpawnPlugin (pluginName, context, plugin); + CCSBackendConformanceTestParameterized::SpawnSetting (settingName, GetParam ()->type (), plugin, setting); gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin.get ()); gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); @@ -1053,7 +1055,7 @@ class CCSBackendConformanceTestReadWrite : virtual void TearDown () { - CCSBackendConformanceTest::TearDown (); + CCSBackendConformanceTestParameterized::TearDown (); } protected: @@ -1070,61 +1072,61 @@ class CCSBackendConformanceTestReadWrite : TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) { - SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Read"); + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "Read"); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->nativeWrite (CCSBackendConformanceTestParameterized::GetParam ()->testEnv (), pluginName, settingName, VALUE); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setReadExpectation () (gmockSetting, VALUE); - ccsBackendReadSetting (CCSBackendConformanceTest::GetBackend (), context.get (), setting.get ()); + ccsBackendReadSetting (CCSBackendConformanceTestParameterized::GetBackend (), context.get (), setting.get ()); } TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) { - SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "UpdateMocked"); + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "UpdateMocked"); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->nativeWrite (CCSBackendConformanceTestParameterized::GetParam ()->testEnv (), pluginName, settingName, VALUE); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setReadExpectation () (gmockSetting, VALUE); - ccsBackendUpdateSetting (CCSBackendConformanceTest::GetBackend (), context.get (), plugin.get (), setting.get ()); + ccsBackendUpdateSetting (CCSBackendConformanceTestParameterized::GetBackend (), context.get (), plugin.get (), setting.get ()); } TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) { - SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "UpdateMocked"); + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "UpdateMocked"); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->nativeWrite (CCSBackendConformanceTest::GetParam ()->testEnv (), + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->nativeWrite (CCSBackendConformanceTestParameterized::GetParam ()->testEnv (), pluginName, settingName, VALUE); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setReadExpectation () (gmockSetting, VALUE); EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (plugin.get ())); EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (setting.get ())); - EXPECT_TRUE (CCSBackendConformanceTest::GetParam ()->testEnv ()->UpdateSettingAtKey (pluginName, settingName)); + EXPECT_TRUE (CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->UpdateSettingAtKey (pluginName, settingName)); } TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) { - SCOPED_TRACE (CCSBackendConformanceTest::GetParam ()->what () + "Write"); + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "Write"); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); - CCSBackendConformanceTest::GetParam ()->setWriteExpectationAndWrite () (pluginName, + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setWriteExpectationAndWrite () (pluginName, settingName, VALUE, setting, boost::bind (ccsBackendWriteSetting, - CCSBackendConformanceTest::GetBackend (), + CCSBackendConformanceTestParameterized::GetBackend (), context.get (), setting.get ()), GetParam ()->testEnv ()); - CCSBackendConformanceTest::GetParam ()->testEnv ()->PostWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); } -- GitLab From 8df8c395066f5ea0f5b475be7296479923d35908 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 19:46:50 +0800 Subject: [PATCH 224/562] Test the GetInfo function of the backend and refactor as appropriate --- ...nfig_test_ccs_mock_backend_conformance.cpp | 5 +- .../tests/compizconfig_backend_concept_test.h | 122 ++++++++++++++---- 2 files changed, 98 insertions(+), 29 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 5b60d778b..8afa6627a 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -94,6 +94,8 @@ class MockCCSBackendConceptTestEnvironment : const CCSBackendInfo * GetInfo () { + EXPECT_CALL (*mBackendGMock, getInfo ()).WillOnce (Return (&mockBackendInfo)); + return &mockBackendInfo; } @@ -530,4 +532,5 @@ class MockCCSBackendConceptTestEnvironment : INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWrite, compizconfig::test::GenerateTestingParametersForBackendInterface ()); - +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInfo, + ::testing::Values (boost::shared_static_cast (boost::make_shared > ()))); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 9d3bd1b6e..e8d4bc0c9 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -292,6 +292,8 @@ class CCSBackendConceptTestEnvironmentFactoryInterface { public: + typedef boost::shared_ptr Ptr; + virtual ~CCSBackendConceptTestEnvironmentFactoryInterface () {} virtual CCSBackendConceptTestEnvironmentInterface::Ptr ConstructTestEnv () = 0; @@ -701,40 +703,19 @@ class CCSBackendConceptTestParam : }; -class CCSBackendConformanceTestParameterized : - public ::testing::TestWithParam +class CCSBackendConformanceSpawnObjectsTestFixtureBase { - public: - - virtual ~CCSBackendConformanceTestParameterized () {} + protected: - CCSBackendConformanceTestParameterized () : + CCSBackendConformanceSpawnObjectsTestFixtureBase () : profileName ("mock") { } - CCSBackend * GetBackend () - { - return mBackend; - } - - virtual void SetUp () + virtual ~CCSBackendConformanceSpawnObjectsTestFixtureBase () { - CCSBackendConformanceTestParameterized::SpawnContext (context); - gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context); - - ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); - - mBackend = GetParam ()->testEnv ()->SetUp (context.get (), gmockContext); - } - - virtual void TearDown () - { - CCSBackendConformanceTestParameterized::GetParam ()->TearDown (mBackend); } - protected: - /* Having the returned context, setting and plugin * as out params is awkward, but GTest doesn't let * you use ASSERT_* unless the function returns void @@ -780,16 +761,78 @@ class CCSBackendConformanceTestParameterized : ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&(mSpawnedSettingInfo.back ()))); } - protected: + void + SetupContext () + { + SpawnContext (context); + gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context.get ()); + + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); + } + + CCSBackend * GetBackend () + { + return mBackend; + } boost::shared_ptr context; CCSContextGMock *gmockContext; + CCSBackend *mBackend; private: std::vector mSpawnedSettingInfo; - CCSBackend *mBackend; - std::string profileName; + std::string profileName; +}; + +class CCSBackendConformanceTestParameterizedByBackendFixture : + public CCSBackendConformanceSpawnObjectsTestFixtureBase, + public ::testing::TestWithParam +{ + public: + + CCSBackendConformanceTestParameterizedByBackendFixture () : + mTestEnv (GetParam ()->ConstructTestEnv ()) + { + } + + virtual void SetUp () + { + SetupContext (); + mBackend = mTestEnv->SetUp (context.get (), gmockContext); + } + + virtual void TearDown () + { + if (mTestEnv) + mTestEnv->TearDown (mBackend); + + mTestEnv.reset (); + } + + protected: + + CCSBackendConceptTestEnvironmentInterface::Ptr mTestEnv; +}; + +class CCSBackendConformanceTestParameterized : + public CCSBackendConformanceSpawnObjectsTestFixtureBase, + public ::testing::TestWithParam +{ + public: + + virtual ~CCSBackendConformanceTestParameterized () {} + + virtual void SetUp () + { + SetupContext (); + mBackend = GetParam ()->testEnv ()->SetUp (context.get (), gmockContext); + } + + virtual void TearDown () + { + CCSBackendConformanceTestParameterized::GetParam ()->TearDown (mBackend); + } }; namespace compizconfig @@ -1130,7 +1173,30 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) } +class CCSBackendConformanceTestInfo : + public CCSBackendConformanceTestParameterizedByBackendFixture +{ +}; + +TEST_P (CCSBackendConformanceTestInfo, TestGetInfo) +{ + const CCSBackendInfo *knownBackendInfo = mTestEnv->GetInfo (); + const CCSBackendInfo *retreivedBackendInfo = ccsBackendGetInfo (GetBackend ()); + + EXPECT_THAT (retreivedBackendInfo->name, Eq (knownBackendInfo->name)); + EXPECT_THAT (retreivedBackendInfo->shortDesc, Eq (knownBackendInfo->shortDesc)); + EXPECT_THAT (retreivedBackendInfo->longDesc, Eq (knownBackendInfo->longDesc)); + + if (knownBackendInfo->profileSupport) + EXPECT_TRUE (retreivedBackendInfo->profileSupport); + else + EXPECT_FALSE (retreivedBackendInfo->profileSupport); + if (knownBackendInfo->integrationSupport) + EXPECT_TRUE (retreivedBackendInfo->integrationSupport); + else + EXPECT_FALSE (retreivedBackendInfo->integrationSupport); +} #endif -- GitLab From 174991136bd6c1ab3f04fbac94b8dd5b4ded966e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 19:54:20 +0800 Subject: [PATCH 225/562] Move the backend info to the util lib --- .../gsettings_backend_shared/gsettings_util.c | 10 ++++++++++ .../gsettings_backend_shared/gsettings_util.h | 2 ++ compizconfig/gsettings/src/gsettings.c | 10 ---------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index b4f3fd550..cac656283 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -6,6 +6,16 @@ INTERFACE_TYPE (CCSGSettingsBackendInterface); +const CCSBackendInfo gsettingsBackendInfo = +{ + "gsettings", + "GSettings Configuration Backend", + "GSettings Configuration Backend for libccs", + TRUE, + TRUE, + 1 +}; + int voidcmp0 (const void *v1, const void *v2) { return g_strcmp0 ((const char *) v1, (const char *) v2); diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 4581599f0..2692e5576 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -13,6 +13,8 @@ COMPIZCONFIG_BEGIN_DECLS typedef struct _CCSGSettingsBackendPrivate CCSGSettingsBackendPrivate; typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; +extern const CCSBackendInfo gsettingsBackendInfo; + typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, GObject *); typedef GSettings * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CCSBackend *backend, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 1035e3324..08343e4e6 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -840,16 +840,6 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) return ret; } -const CCSBackendInfo gsettingsBackendInfo = -{ - "gsettings", - "GSettings Configuration Backend", - "GSettings Configuration Backend for libccs", - TRUE, - TRUE, - 1 -}; - static const CCSBackendInfo * getInfo (CCSBackend *backend) { -- GitLab From 30359a95f053f2bb07a8abe7c095ced2b5a848f2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 19:57:26 +0800 Subject: [PATCH 226/562] Enable info tests for gsettigs --- .../gsettings/tests/test_gsettings_conformance.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 9a0b9b098..4e01256eb 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -46,6 +46,11 @@ class CCSGSettingsBackendEnv : { } + const CCSBackendInfo * GetInfo () + { + return &gsettingsBackendInfo; + } + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) { CCSGSettingsBackendInterface *overloadedInterface = NULL; @@ -437,3 +442,5 @@ const std::string CCSGSettingsBackendEnv::profileName = "mock"; INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestReadWrite, compizconfig::test::GenerateTestingParametersForBackendInterface ()); +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestInfo, + ::testing::Values (boost::shared_static_cast (boost::make_shared > ()))); -- GitLab From 8e7407a25c3cddfa8ff84931f23252ad07a8e166 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 20:10:29 +0800 Subject: [PATCH 227/562] Law of demeter --- .../compizconfig_test_ccs_mock_backend_conformance.cpp | 2 +- compizconfig/tests/compizconfig_backend_concept_test.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 8afa6627a..2e55f9cc0 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -533,4 +533,4 @@ INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWri compizconfig::test::GenerateTestingParametersForBackendInterface ()); INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInfo, - ::testing::Values (boost::shared_static_cast (boost::make_shared > ()))); + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index e8d4bc0c9..6bbdec99c 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1071,6 +1071,15 @@ GenerateTestingParametersForBackendInterface () return ::testing::ValuesIn (testParam); } + +template +::testing::internal::ParamGenerator +GenerateTestingEnvFactoryBackendInterface () +{ + boost::shared_ptr f (boost::make_shared > ()); + return ::testing::Values (f); +} + } } -- GitLab From e8352a903ce193dde513a8d7016fd2bc0de0a6c9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 20:13:03 +0800 Subject: [PATCH 228/562] Use the much more sensible, law of demeter friendly version --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 4e01256eb..ab5e053b4 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -443,4 +443,4 @@ INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestRe compizconfig::test::GenerateTestingParametersForBackendInterface ()); INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestInfo, - ::testing::Values (boost::shared_static_cast (boost::make_shared > ()))); + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); -- GitLab From 1b4be4bff7acfad31abf7211421490553c4cda9a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 20:14:30 +0800 Subject: [PATCH 229/562] Remove dead voidcmp0 --- .../gsettings/gsettings_backend_shared/gsettings_util.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index cac656283..8fb6d6340 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -16,11 +16,6 @@ const CCSBackendInfo gsettingsBackendInfo = 1 }; -int voidcmp0 (const void *v1, const void *v2) -{ - return g_strcmp0 ((const char *) v1, (const char *) v2); -} - GList * variantTypeToPossibleSettingType (const gchar *vt) { -- GitLab From c60c63aef1ee7dff930c7336aa57b90dfd82a231 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 20:16:39 +0800 Subject: [PATCH 230/562] plugins-with-set-values doesn't exist --- compizconfig/gsettings/src/gsettings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 08343e4e6..438fad056 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -620,7 +620,7 @@ ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend, const ch /* This looks weird, we are leaking this ... */ GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); - g_settings_reset (profileSettings, "plugins-with-set-values"); + g_settings_reset (profileSettings, "plugins-with-set-keys"); g_free (profileSettingsPath); } -- GitLab From b374e886aab9059296817f7b6d8c194b498304c3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 1 Aug 2012 20:25:26 +0800 Subject: [PATCH 231/562] ClearPluginsWithSetKeys should operate on the current profile settings --- .../gsettings_backend_shared/gsettings_util.c | 6 +++--- .../gsettings_backend_shared/gsettings_util.h | 4 ++-- compizconfig/gsettings/src/gsettings.c | 20 ++++++++----------- .../tests/ccs_gsettings_backend_mock.h | 8 ++++---- .../gsettings/tests/test_gsettings_tests.cpp | 4 +--- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 8fb6d6340..9e173a176 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1072,7 +1072,7 @@ deleteProfile (CCSBackend *backend, profiles = ccsGSettingsBackendGetExistingProfiles (backend); ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); - ccsGSettingsBackendClearPluginsWithSetKeys (backend, profile); + ccsGSettingsBackendClearPluginsWithSetKeys (backend); removeItemFromVariant (&profiles, profile); @@ -1152,9 +1152,9 @@ ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend) } void -ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *profile) +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend) { - (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendClearPluginsWithSetKeys) (backend, profile); + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendClearPluginsWithSetKeys) (backend); } void diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 2692e5576..64db221a0 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -31,7 +31,7 @@ typedef void (*CCSGSettingsBackendSetExistingProfiles) (CCSBackend *backend, GVa typedef void (*CCSGSettingsBackendSetCurrentProfile) (CCSBackend *backend, const gchar *value); typedef GVariant * (*CCSGSettingsBackendGetPluginsWithSetKeys) (CCSBackend *backend); -typedef void (*CCSGSettingsBackendClearPluginsWithSetKeys) (CCSBackend *backend, const char *profile); +typedef void (*CCSGSettingsBackendClearPluginsWithSetKeys) (CCSBackend *backend); typedef void (*CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile) (CCSBackend *backend, CCSContext *, GVariant *, const char *); @@ -242,7 +242,7 @@ GVariant * ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend); void -ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *profile); +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend); void ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 438fad056..c08c68fc6 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -590,11 +590,14 @@ static void ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *value) { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + gchar *profilePath = makeCompizProfilePath (value); /* Change the current profile and current profile settings */ - free (priv->currentProfile); + if (priv->currentProfile) + free (priv->currentProfile); - gchar *profilePath = makeCompizProfilePath (value); + if (priv->currentProfileSettings) + free (priv->currentProfileSettings); priv->currentProfile = strdup (value); priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); @@ -608,21 +611,14 @@ GVariant * ccsGSettingsBackendGetPluginsWithSetKeysDefault (CCSBackend *backend) { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - return g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); } void -ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend, const char *profile) +ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend) { - char *profileSettingsPath = makeCompizProfilePath (profile); - - /* This looks weird, we are leaking this ... */ - GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); - - g_settings_reset (profileSettings, "plugins-with-set-keys"); - - g_free (profileSettingsPath); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + g_settings_reset (priv->currentProfileSettings, "plugins-with-set-keys"); } static void diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h index df8a3c3e7..a629aa059 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -31,7 +31,7 @@ class CCSGSettingsBackendGMockInterface virtual void setExistingProfiles (GVariant *) = 0; virtual void setCurrentProfile (const gchar *) = 0; virtual GVariant * getPluginsWithSetKeys () = 0; - virtual void clearPluginsWithSetKeys (const char *) = 0; + virtual void clearPluginsWithSetKeys () = 0; virtual void unsetAllChangedPluginKeysInProfile (CCSContext *, GVariant *, const char *) = 0; virtual gboolean updateProfile (CCSContext *) = 0; virtual void updateCurrentProfileName (const char *) = 0; @@ -59,7 +59,7 @@ class CCSGSettingsBackendGMock : MOCK_METHOD1 (setExistingProfiles, void (GVariant *)); MOCK_METHOD1 (setCurrentProfile, void (const gchar *)); MOCK_METHOD0 (getPluginsWithSetKeys, GVariant * ()); - MOCK_METHOD1 (clearPluginsWithSetKeys, void (const char *)); + MOCK_METHOD0 (clearPluginsWithSetKeys, void ()); MOCK_METHOD3 (unsetAllChangedPluginKeysInProfile, void (CCSContext *, GVariant *, const char *)); MOCK_METHOD1 (updateProfile, gboolean (CCSContext *)); MOCK_METHOD1 (updateCurrentProfileName, void (const char *)); @@ -138,9 +138,9 @@ class CCSGSettingsBackendGMock : } static void - ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend, const char *profile) + ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend) { - return (reinterpret_cast (ccsObjectGetPrivate (backend)))->clearPluginsWithSetKeys (profile); + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->clearPluginsWithSetKeys (); } static void diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 980a2d374..24b1313ee 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -190,7 +190,7 @@ TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) EXPECT_CALL (*mockBackend, getPluginsWithSetKeys ()).WillOnce (ReturnNull ()); EXPECT_CALL (*mockBackend, unsetAllChangedPluginKeysInProfile (context.get (), NULL, Eq (currentProfile))); - EXPECT_CALL (*mockBackend, clearPluginsWithSetKeys (Eq (currentProfile))); + EXPECT_CALL (*mockBackend, clearPluginsWithSetKeys ()); EXPECT_CALL (*mockBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillOnce (Return (existingProfiles)); @@ -202,8 +202,6 @@ TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) EXPECT_CALL (*mockBackend, updateProfile (context.get ())); deleteProfile (backend.get (), context.get (), currentProfile.c_str ()); - - //g_variant_unref (existingProfiles); } TEST_F(CCSGSettingsTestIndependent, TestGetSchemaNameForPlugin) -- GitLab From f1859221a28bc5fe9b1268f2c74b09cb05dd5aff Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 09:04:16 +0800 Subject: [PATCH 232/562] Tests for ReadInit/ReadDone/WriteInit/WriteDone --- ...nfig_test_ccs_mock_backend_conformance.cpp | 27 ++++++++ .../tests/compizconfig_backend_concept_test.h | 65 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 2e55f9cc0..8b52bf32c 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -104,6 +104,30 @@ class MockCCSBackendConceptTestEnvironment : ccsFreeMockBackend (backend); } + void SetReadInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, readInit (context)).WillOnce (Return (TRUE)); + } + + void SetReadDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, readDone (context)); + } + + void SetWriteInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, writeInit (context)).WillOnce (Return (TRUE)); + } + + void SetWriteDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, writeDone (context)); + } + void PreWrite (CCSContextGMock *gmockContext, CCSPluginGMock *gmockPlugin, CCSSettingGMock *gmockSetting, @@ -534,3 +558,6 @@ INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWri INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInfo, compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInitFiniFuncs, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 6bbdec99c..406eae989 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -197,6 +197,18 @@ class CCSBackendConceptTestEnvironmentInterface CCSContextGMock *gmockContext) = 0; virtual void TearDown (CCSBackend *) = 0; + virtual void SetReadInitExpectation (CCSContext *, + CCSContextGMock *) = 0; + + virtual void SetReadDoneExpectation (CCSContext *, + CCSContextGMock *) = 0; + + virtual void SetWriteInitExpectation (CCSContext *, + CCSContextGMock *) = 0; + + virtual void SetWriteDoneExpectation (CCSContext *, + CCSContextGMock *) = 0; + virtual const CCSBackendInfo * GetInfo () = 0; virtual void PreWrite (CCSContextGMock *, @@ -1207,5 +1219,58 @@ TEST_P (CCSBackendConformanceTestInfo, TestGetInfo) EXPECT_FALSE (retreivedBackendInfo->integrationSupport); } +class CCSBackendConformanceTestInitFiniFuncs : + public CCSBackendConformanceTestParameterizedByBackendFixture +{ +}; + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestReadInit) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->readInit) + { + mTestEnv->SetReadInitExpectation (context.get (), gmockContext); + ccsBackendReadInit (backend, context.get ()); + } +} + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestReadDone) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->readDone) + { + mTestEnv->SetReadDoneExpectation (context.get (), gmockContext); + ccsBackendReadDone (backend, context.get ()); + } +} + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestWriteInit) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->writeInit) + { + mTestEnv->SetWriteInitExpectation (context.get (), gmockContext); + ccsBackendWriteInit (backend, context.get ()); + } +} + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestWriteDone) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->writeDone) + { + mTestEnv->SetWriteDoneExpectation (context.get (), gmockContext); + ccsBackendWriteDone (backend, context.get ()); + } +} + #endif -- GitLab From e5f1844d8e678e564ff95daea15781581aa7b0b9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 09:05:04 +0800 Subject: [PATCH 233/562] UpdateMocked -> UpdateKeyed --- compizconfig/tests/compizconfig_backend_concept_test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 406eae989..0401a067a 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1162,7 +1162,7 @@ TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) { - SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "UpdateMocked"); + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "UpdateKeyed"); CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); CCSBackendConformanceTestParameterized::GetParam ()->nativeWrite (CCSBackendConformanceTestParameterized::GetParam ()->testEnv (), -- GitLab From 2da0856b7081843efb1137db562159b96add6feb Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 14:08:23 +0800 Subject: [PATCH 234/562] Added expectation stubs and fix crash --- compizconfig/gsettings/src/gsettings.c | 2 +- .../tests/test_gsettings_conformance.cpp | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index c08c68fc6..7dc25aeac 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -597,7 +597,7 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v free (priv->currentProfile); if (priv->currentProfileSettings) - free (priv->currentProfileSettings); + g_object_unref (priv->currentProfileSettings); priv->currentProfile = strdup (value); priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index ab5e053b4..3b089e4fa 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -97,6 +97,27 @@ class CCSGSettingsBackendEnv : ccsFreeDynamicBackend (mBackend); } + void SetReadInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + + } + + void SetReadDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + } + + void SetWriteInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + } + + void SetWriteDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + } + void PreWrite (CCSContextGMock *gmockContext, CCSPluginGMock *gmockPlugin, CCSSettingGMock *gmockSetting, -- GitLab From dc59d2ec8cb1cfac9634538a0b37d0d6062431f2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 14:09:31 +0800 Subject: [PATCH 235/562] s/free/g_object_unref --- compizconfig/gsettings/src/gsettings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index c08c68fc6..7dc25aeac 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -597,7 +597,7 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v free (priv->currentProfile); if (priv->currentProfileSettings) - free (priv->currentProfileSettings); + g_object_unref (priv->currentProfileSettings); priv->currentProfile = strdup (value); priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); -- GitLab From 285b892ee0271a7c35250ac0a2e6916e73860dba Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 14:57:07 +0800 Subject: [PATCH 236/562] Instantiate the tests and set the right expectations --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 3b089e4fa..3da50de93 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -100,7 +100,7 @@ class CCSGSettingsBackendEnv : void SetReadInitExpectation (CCSContext *context, CCSContextGMock *gmockContext) { - + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (profileName.c_str ())); } void SetReadDoneExpectation (CCSContext *context, @@ -111,6 +111,7 @@ class CCSGSettingsBackendEnv : void SetWriteInitExpectation (CCSContext *context, CCSContextGMock *gmockContext) { + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (profileName.c_str ())); } void SetWriteDoneExpectation (CCSContext *context, @@ -465,3 +466,6 @@ INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestRe INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestInfo, compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestInitFiniFuncs, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); -- GitLab From 737e172dc4975531c00efe5a1ed303c9889dbea5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 15:21:07 +0800 Subject: [PATCH 237/562] Test coverage for providing huge keys to TestTranslateKeyForGSettings --- .../gsettings/tests/test_gsettings_tests.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 24b1313ee..3bd27977f 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -275,6 +275,32 @@ TEST_F(CCSGSettingsTestIndependent, TestTranslateUpperToLowerForGSettings) EXPECT_EQ (std::string (keyname), "plugin-option"); } +TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForGSettingsNoTrunc) +{ + std::string keyname ("FoO_BaR"); + std::string expected ("foo-bar"); + + CharacterWrapper translated (translateKeyForGSettings (keyname.c_str ())); + + EXPECT_EQ (std::string (translated), expected); +} + +TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForGSettingsTrunc) +{ + const unsigned int OVER_KEY_SIZE = MAX_GSETTINGS_KEY_SIZE + 1; + std::string keyname; + + for (unsigned int i = 0; i <= OVER_KEY_SIZE - 1; i++) + keyname.push_back ('a'); + + ASSERT_EQ (keyname.size (), OVER_KEY_SIZE); + + CharacterWrapper translated (translateKeyForGSettings (keyname.c_str ())); + std::string stringOfTranslated (translated); + + EXPECT_EQ (stringOfTranslated.size (), MAX_GSETTINGS_KEY_SIZE); +} + TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForCCS) { std::string keyname ("plugin-option"); -- GitLab From cf8f34623a12145f9d7a729a7f21b125dcddf6a4 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 15:25:15 +0800 Subject: [PATCH 238/562] Cover the case where a decompose path is wrong --- .../gsettings/tests/test_gsettings_tests.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 3bd27977f..b787d4d6b 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -378,6 +378,22 @@ TEST_F(CCSGSettingsTestIndependent, TestDecomposeGSettingsPath) g_free (pluginName); } +TEST_F(CCSGSettingsTestIndependent, TestDecomposeGSettingsPathBadPathname) +{ + std::string compiz_gsettings_path ("org/this/path/is/wrong/"); + std::string fake_option_path ("PROFILENAME/plugins/PLUGINNAME"); + + compiz_gsettings_path += fake_option_path; + + CharacterWrapper pluginName (strdup ("aaa")); + char *pluginNameC = pluginName; + unsigned int screenNum = 1; + + EXPECT_FALSE (decomposeGSettingsPath (compiz_gsettings_path.c_str (), &pluginNameC, &screenNum)); + EXPECT_EQ (std::string (pluginNameC), "aaa"); + EXPECT_EQ (screenNum, 1); +} + TEST_F(CCSGSettingsTestIndependent, TestMakeCompizProfilePath) { gchar *a = makeCompizProfilePath ("alpha"); -- GitLab From a91a4930ba572e5d608c196977bdcd04187b48f8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 15:27:17 +0800 Subject: [PATCH 239/562] Always expect unknown types are invalid --- compizconfig/gsettings/tests/test_gsettings_tests.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index b787d4d6b..23b9d0af5 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -488,6 +488,11 @@ namespace GVariantSubtypeWrappers { return g_variant_type_is_array (g_variant_get_type (v)); } + + gboolean unknown (GVariant *) + { + return FALSE; + } } struct ArrayVariantInfo @@ -504,6 +509,7 @@ namespace const char *vInt = "i"; const char *vDouble = "d"; const char *vArray = "as"; + const char *vUnknown = ""; ArrayVariantInfo arrayVariantInfo[] = { @@ -517,7 +523,8 @@ namespace { &GVariantSubtypeWrappers::edge, TypeEdge, vString }, { &GVariantSubtypeWrappers::integer, TypeInt, vInt }, { &GVariantSubtypeWrappers::doubleprecision, TypeFloat, vDouble }, - { &GVariantSubtypeWrappers::list, TypeList, vArray } + { &GVariantSubtypeWrappers::list, TypeList, vArray }, + { &GVariantSubtypeWrappers::unknown, TypeNum, vUnknown } }; } -- GitLab From 61950f42313417bf189713ed00e01c2b2d8399f5 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 18:07:02 +0800 Subject: [PATCH 240/562] Generic tests for readList* --- .../gsettings_backend_shared/gsettings_util.h | 16 ++ .../gsettings/tests/test_gsettings_tests.cpp | 259 ++++++++++++++++++ 2 files changed, 275 insertions(+) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 64db221a0..28cdaf2ba 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -202,6 +202,22 @@ void removeItemFromVariant (GVariant **variant, const char *string); +CCSSettingValueList +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); + +CCSSettingValueList +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); + +CCSSettingValueList +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); + +CCSSettingValueList +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); + +CCSSettingValueList +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); + + gboolean ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context); diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 23b9d0af5..e79265c45 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -22,6 +22,7 @@ using ::testing::AllOf; using ::testing::Not; using ::testing::Matcher; using ::testing::Eq; +using ::testing::NiceMock; class GVariantSubtypeMatcher : public ::testing::MatcherInterface @@ -1149,3 +1150,261 @@ TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeGood) g_variant_unref (v); } + +typedef CCSSettingValueList (*ReadValueListOfDataTypeFunc) (GVariantIter *, guint nItems, CCSSetting *setting); + +class ReadListValueTypeTestParam +{ + public: + + typedef boost::function ReadValueListFunc; + typedef boost::function GVariantPopulator; + typedef boost::function CCSSettingValueListPopulator; + + ReadListValueTypeTestParam (const ReadValueListFunc &readFunc, + const GVariantPopulator &variantPopulator, + const CCSSettingValueListPopulator &listPopulator, + const CCSSettingType &type) : + mReadFunc (readFunc), + mVariantPopulator (variantPopulator), + mListPopulator (listPopulator), + mType (type) + { + } + + CCSSettingValueList read (GVariantIter *iter, guint nItems, CCSSetting *setting) const + { + return mReadFunc (iter, nItems, setting); + } + + boost::shared_ptr populateVariant () const + { + return boost::shared_ptr (mVariantPopulator (), boost::bind (g_variant_unref, _1)); + } + + boost::shared_ptr <_CCSSettingValueList> populateList (CCSSetting *setting) const + { + return boost::shared_ptr <_CCSSettingValueList> (mListPopulator (setting), boost::bind (ccsSettingValueListFree, _1, TRUE)); + } + + CCSSettingType type () const { return mType; } + + private: + + ReadValueListFunc mReadFunc; + GVariantPopulator mVariantPopulator; + CCSSettingValueListPopulator mListPopulator; + CCSSettingType mType; + +}; + +namespace compizconfig +{ + namespace test + { + namespace impl + { + Bool boolValues[] = { TRUE, FALSE, TRUE }; + int intValues[] = { 1, 2, 3 }; + float floatValues[] = { 1.0, 2.0, 3.0 }; + const char * stringValues[] = { "foo", "grill", "bar" }; + const char * matchValues[] = { "type=foo", "class=bar", "xid=42" }; + + const unsigned int NUM_COLOR_VALUES = 3; + + CCSSettingColorValue * + getColorValueList () + { + static const unsigned short max = std::numeric_limits ::max (); + static const unsigned short maxD2 = max / 2; + static const unsigned short maxD4 = max / 4; + static const unsigned short maxD8 = max / 8; + + static CCSSettingColorValue colorValues[NUM_COLOR_VALUES] = { { .color = { maxD2, maxD4, maxD8, max } }, + { .color = { maxD8, maxD4, maxD2, max } }, + { .color = { max, maxD4, maxD2, maxD8 } } + }; + static bool colorValueListInitialized = false; + + if (!colorValueListInitialized) + { + for (unsigned int i = 0; i < NUM_COLOR_VALUES; i++) + { + CharacterWrapper s (ccsColorToString (&colorValues[i])); + + ccsStringToColor (s, &colorValues[i]); + } + + colorValueListInitialized = true; + } + + return colorValues; + } +/* + CCSSettingKeyValue keyValue = { XK_A, + (1 << 0)}; + + CCSSettingButtonValue buttonValue = { 1, + (1 << 0), + (1 << 1) }; +*/ + + namespace populators + { + namespace variant + { + GVariant * boolean () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ab")); + g_variant_builder_add (&vb, "b", boolValues[0]); + g_variant_builder_add (&vb, "b", boolValues[1]); + g_variant_builder_add (&vb, "b", boolValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * integer () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ai")); + g_variant_builder_add (&vb, "i", intValues[0]); + g_variant_builder_add (&vb, "i", intValues[1]); + g_variant_builder_add (&vb, "i", intValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * doubleprecision () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ad")); + g_variant_builder_add (&vb, "d", floatValues[0]); + g_variant_builder_add (&vb, "d", floatValues[1]); + g_variant_builder_add (&vb, "d", floatValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * string () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&vb, "s", stringValues[0]); + g_variant_builder_add (&vb, "s", stringValues[1]); + g_variant_builder_add (&vb, "s", stringValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * color () + { + GVariantBuilder vb; + + CharacterWrapper s1 (ccsColorToString (&(getColorValueList ()[0]))); + CharacterWrapper s2 (ccsColorToString (&(getColorValueList ()[1]))); + CharacterWrapper s3 (ccsColorToString (&(getColorValueList ()[2]))); + + char * c1 = s1; + char * c2 = s2; + char * c3 = s3; + + g_variant_builder_init (&vb, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&vb, "s", c1); + g_variant_builder_add (&vb, "s", c2); + g_variant_builder_add (&vb, "s", c3); + return g_variant_builder_end (&vb); + } + } + + namespace list + { + CCSSettingValueList boolean (CCSSetting *setting) + { + return ccsGetValueListFromBoolArray (boolValues, sizeof (boolValues) / sizeof (boolValues[0]), setting); + } + + CCSSettingValueList integer (CCSSetting *setting) + { + return ccsGetValueListFromIntArray (intValues, sizeof (intValues) / sizeof (intValues[0]), setting); + } + + CCSSettingValueList doubleprecision (CCSSetting *setting) + { + return ccsGetValueListFromFloatArray (floatValues, sizeof (floatValues) / sizeof (floatValues[0]), setting); + } + + CCSSettingValueList string (CCSSetting *setting) + { + return ccsGetValueListFromStringArray (stringValues, sizeof (stringValues) / sizeof (stringValues[0]), setting); + } + + CCSSettingValueList color (CCSSetting *setting) + { + return ccsGetValueListFromColorArray (getColorValueList (), 3, setting); + } + } + } + } + } +} + +class CCSGSettingsTestReadListValueTypes : + public ::testing::TestWithParam +{ +}; + +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueGoodAllocation) +{ + boost::shared_ptr variant = GetParam ().populateVariant (); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + CCSSettingInfo info = + { + .forList = + { + GetParam ().type (), + NULL + } + }; + + boost::shared_ptr <_CCSSettingValueList> valueList (GetParam ().populateList (mockSetting.get ())); + GVariantIter iter; + + g_variant_iter_init (&iter, variant.get ()); + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); + + boost::shared_ptr <_CCSSettingValueList> readValueList (GetParam ().read (&iter, 3, mockSetting.get ()), + boost::bind (ccsSettingValueListFree, _1, TRUE)); +} + +namespace variant_populators = compizconfig::test::impl::populators::variant; +namespace list_populators = compizconfig::test::impl::populators::list; + +ReadListValueTypeTestParam readListValueTypeTestParam[] = +{ + ReadListValueTypeTestParam (boost::bind (readBoolListValue, _1, _2, _3), + boost::bind (variant_populators::boolean), + boost::bind (list_populators::boolean, _1), + TypeBool), + ReadListValueTypeTestParam (boost::bind (readIntListValue, _1, _2, _3), + boost::bind (variant_populators::integer), + boost::bind (list_populators::integer, _1), + TypeInt), + ReadListValueTypeTestParam (boost::bind (readFloatListValue, _1, _2, _3), + boost::bind (variant_populators::doubleprecision), + boost::bind (list_populators::doubleprecision, _1), + TypeFloat), + ReadListValueTypeTestParam (boost::bind (readStringListValue, _1, _2, _3), + boost::bind (variant_populators::string), + boost::bind (list_populators::string, _1), + TypeBool), + ReadListValueTypeTestParam (boost::bind (readColorListValue, _1, _2, _3), + boost::bind (variant_populators::color), + boost::bind (list_populators::color, _1), + TypeColor) +}; + +INSTANTIATE_TEST_CASE_P (TestGSettingsReadListValueParameterized, CCSGSettingsTestReadListValueTypes, + ::testing::ValuesIn (readListValueTypeTestParam)); -- GitLab From 6f5a1295f114706274c48ca5a6c4f40751582791 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 18:19:27 +0800 Subject: [PATCH 241/562] Moved some of the value combiners into their own header file --- .../tests/compizconfig_backend_concept_test.h | 75 ++------------- .../tests/compizconfig_test_value_combiners.h | 96 +++++++++++++++++++ 2 files changed, 105 insertions(+), 66 deletions(-) create mode 100644 compizconfig/tests/compizconfig_test_value_combiners.h diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 0401a067a..a000b01ba 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -23,6 +23,7 @@ #include #include "gtest_shared_characterwrapper.h" +#include "compizconfig_test_value_combiners.h" using ::testing::Eq; using ::testing::SetArgPointee; @@ -851,54 +852,8 @@ namespace compizconfig { namespace test { -namespace impl -{ - -Bool boolValues[] = { TRUE, FALSE, TRUE }; -int intValues[] = { 1, 2, 3 }; -float floatValues[] = { 1.0, 2.0, 3.0 }; -const char * stringValues[] = { "foo", "grill", "bar" }; -const char * matchValues[] = { "type=foo", "class=bar", "xid=42" }; - -const unsigned int NUM_COLOR_VALUES = 3; - -CCSSettingColorValue * -getColorValueList () -{ - static const unsigned short max = std::numeric_limits ::max (); - static const unsigned short maxD2 = max / 2; - static const unsigned short maxD4 = max / 4; - static const unsigned short maxD8 = max / 8; - - static CCSSettingColorValue colorValues[NUM_COLOR_VALUES] = { { .color = { maxD2, maxD4, maxD8, max } }, - { .color = { maxD8, maxD4, maxD2, max } }, - { .color = { max, maxD4, maxD2, maxD8 } } - }; - static bool colorValueListInitialized = false; - - if (!colorValueListInitialized) - { - for (unsigned int i = 0; i < NUM_COLOR_VALUES; i++) - { - CharacterWrapper s (ccsColorToString (&colorValues[i])); - - ccsStringToColor (s, &colorValues[i]); - } - - colorValueListInitialized = true; - } - - return colorValues; -} - -CCSSettingKeyValue keyValue = { XK_A, - (1 << 0)}; -CCSSettingButtonValue buttonValue = { 1, - (1 << 0), - (1 << 1) }; - -} +namespace list_populators = impl::populators::list; typedef boost::function ConstructorFunc; @@ -1014,9 +969,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetEdgeWriteExpectation, _1, _2, _3, _4, _5, _6), "TestEdge"), boost::make_shared (backendEnvFactory, - VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromIntArray, - impl::intValues, - sizeof (impl::intValues) / sizeof (impl::intValues[0]), _1), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::integer, _1), TypeInt, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, @@ -1025,9 +978,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListInt"), boost::make_shared (backendEnvFactory, - VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromFloatArray, - impl::floatValues, - sizeof (impl::floatValues) / sizeof (impl::floatValues[0]), _1), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::doubleprecision, _1), TypeFloat, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, @@ -1036,9 +987,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListFloat"), boost::make_shared (backendEnvFactory, - VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromBoolArray, - impl::boolValues, - sizeof (impl::boolValues) / sizeof (impl::boolValues[0]), _1), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::boolean, _1), TypeBool, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, @@ -1047,9 +996,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListBool"), boost::make_shared (backendEnvFactory, - VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromStringArray, - impl::stringValues, - sizeof (impl::stringValues) / sizeof (impl::stringValues[0]), _1), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::string, _1), TypeString, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, @@ -1058,9 +1005,7 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListString"), boost::make_shared (backendEnvFactory, - VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromMatchArray, - impl::matchValues, - sizeof (impl::matchValues) / sizeof (impl::matchValues[0]), _1), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::match, _1), TypeMatch, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, @@ -1069,10 +1014,8 @@ GenerateTestingParametersForBackendInterface () boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), "TestListMatch"), boost::make_shared (backendEnvFactory, - VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (ccsGetValueListFromColorArray, - impl::getColorValueList (), - impl::NUM_COLOR_VALUES, _1), - TypeColor, true)), + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::color, _1), + TypeColor, true)), &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, TypeList, "color_list_setting", diff --git a/compizconfig/tests/compizconfig_test_value_combiners.h b/compizconfig/tests/compizconfig_test_value_combiners.h new file mode 100644 index 000000000..4a586a06e --- /dev/null +++ b/compizconfig/tests/compizconfig_test_value_combiners.h @@ -0,0 +1,96 @@ +#ifndef _COMPIZCONFIG_TEST_VALUE_COMBINERS_H +#define _COMPIZCONFIG_TEST_VALUE_COMBINERS_H + +#include +#include +#include + +namespace compizconfig +{ + namespace test + { + namespace impl + { + Bool boolValues[] = { TRUE, FALSE, TRUE }; + int intValues[] = { 1, 2, 3 }; + float floatValues[] = { 1.0, 2.0, 3.0 }; + const char * stringValues[] = { "foo", "grill", "bar" }; + const char * matchValues[] = { "type=foo", "class=bar", "xid=42" }; + + const unsigned int NUM_COLOR_VALUES = 3; + + CCSSettingColorValue * + getColorValueList () + { + static const unsigned short max = std::numeric_limits ::max (); + static const unsigned short maxD2 = max / 2; + static const unsigned short maxD4 = max / 4; + static const unsigned short maxD8 = max / 8; + + static CCSSettingColorValue colorValues[NUM_COLOR_VALUES] = { { .color = { maxD2, maxD4, maxD8, max } }, + { .color = { maxD8, maxD4, maxD2, max } }, + { .color = { max, maxD4, maxD2, maxD8 } } + }; + static bool colorValueListInitialized = false; + + if (!colorValueListInitialized) + { + for (unsigned int i = 0; i < NUM_COLOR_VALUES; i++) + { + CharacterWrapper s (ccsColorToString (&colorValues[i])); + + ccsStringToColor (s, &colorValues[i]); + } + + colorValueListInitialized = true; + } + + return colorValues; + } + CCSSettingKeyValue keyValue = { XK_A, + (1 << 0)}; + + CCSSettingButtonValue buttonValue = { 1, + (1 << 0), + (1 << 1) }; + + namespace populators + { + namespace list + { + CCSSettingValueList boolean (CCSSetting *setting) + { + return ccsGetValueListFromBoolArray (boolValues, sizeof (boolValues) / sizeof (boolValues[0]), setting); + } + + CCSSettingValueList integer (CCSSetting *setting) + { + return ccsGetValueListFromIntArray (intValues, sizeof (intValues) / sizeof (intValues[0]), setting); + } + + CCSSettingValueList doubleprecision (CCSSetting *setting) + { + return ccsGetValueListFromFloatArray (floatValues, sizeof (floatValues) / sizeof (floatValues[0]), setting); + } + + CCSSettingValueList string (CCSSetting *setting) + { + return ccsGetValueListFromStringArray (stringValues, sizeof (stringValues) / sizeof (stringValues[0]), setting); + } + + CCSSettingValueList match (CCSSetting *setting) + { + return ccsGetValueListFromMatchArray (matchValues, sizeof (matchValues) / sizeof (matchValues[0]), setting); + } + + CCSSettingValueList color (CCSSetting *setting) + { + return ccsGetValueListFromColorArray (getColorValueList (), 3, setting); + } + } + } + } + } +} + +#endif -- GitLab From ef4a0e8deb69593335c075f1b4c7dc011012e832 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 2 Aug 2012 18:28:40 +0800 Subject: [PATCH 242/562] Remove duplication --- .../gsettings/tests/test_gsettings_tests.cpp | 74 +------------------ 1 file changed, 1 insertion(+), 73 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index e79265c45..4ec90f794 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -10,6 +10,7 @@ #include "compizconfig_ccs_context_mock.h" #include "compizconfig_ccs_setting_mock.h" #include "gtest_shared_characterwrapper.h" +#include "compizconfig_test_value_combiners.h" using ::testing::Values; using ::testing::ValuesIn; @@ -1204,51 +1205,6 @@ namespace compizconfig { namespace impl { - Bool boolValues[] = { TRUE, FALSE, TRUE }; - int intValues[] = { 1, 2, 3 }; - float floatValues[] = { 1.0, 2.0, 3.0 }; - const char * stringValues[] = { "foo", "grill", "bar" }; - const char * matchValues[] = { "type=foo", "class=bar", "xid=42" }; - - const unsigned int NUM_COLOR_VALUES = 3; - - CCSSettingColorValue * - getColorValueList () - { - static const unsigned short max = std::numeric_limits ::max (); - static const unsigned short maxD2 = max / 2; - static const unsigned short maxD4 = max / 4; - static const unsigned short maxD8 = max / 8; - - static CCSSettingColorValue colorValues[NUM_COLOR_VALUES] = { { .color = { maxD2, maxD4, maxD8, max } }, - { .color = { maxD8, maxD4, maxD2, max } }, - { .color = { max, maxD4, maxD2, maxD8 } } - }; - static bool colorValueListInitialized = false; - - if (!colorValueListInitialized) - { - for (unsigned int i = 0; i < NUM_COLOR_VALUES; i++) - { - CharacterWrapper s (ccsColorToString (&colorValues[i])); - - ccsStringToColor (s, &colorValues[i]); - } - - colorValueListInitialized = true; - } - - return colorValues; - } -/* - CCSSettingKeyValue keyValue = { XK_A, - (1 << 0)}; - - CCSSettingButtonValue buttonValue = { 1, - (1 << 0), - (1 << 1) }; -*/ - namespace populators { namespace variant @@ -1312,34 +1268,6 @@ namespace compizconfig return g_variant_builder_end (&vb); } } - - namespace list - { - CCSSettingValueList boolean (CCSSetting *setting) - { - return ccsGetValueListFromBoolArray (boolValues, sizeof (boolValues) / sizeof (boolValues[0]), setting); - } - - CCSSettingValueList integer (CCSSetting *setting) - { - return ccsGetValueListFromIntArray (intValues, sizeof (intValues) / sizeof (intValues[0]), setting); - } - - CCSSettingValueList doubleprecision (CCSSetting *setting) - { - return ccsGetValueListFromFloatArray (floatValues, sizeof (floatValues) / sizeof (floatValues[0]), setting); - } - - CCSSettingValueList string (CCSSetting *setting) - { - return ccsGetValueListFromStringArray (stringValues, sizeof (stringValues) / sizeof (stringValues[0]), setting); - } - - CCSSettingValueList color (CCSSetting *setting) - { - return ccsGetValueListFromColorArray (getColorValueList (), 3, setting); - } - } } } } -- GitLab From 303e6cdacbce0e2fdbfbb9a26cdc724b6574bffb Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 09:20:34 +0800 Subject: [PATCH 243/562] Test for bad allocation too --- .../gsettings_backend_shared/gsettings_util.c | 32 ++++---- .../gsettings_backend_shared/gsettings_util.h | 12 +-- compizconfig/gsettings/src/gsettings.c | 2 +- .../gsettings/tests/test_gsettings_tests.cpp | 59 +++++++++++--- .../libcompizconfig/tests/CMakeLists.txt | 2 +- .../tests/compizconfig_test_ccs_object.cpp | 78 +------------------ 6 files changed, 75 insertions(+), 110 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 9e173a176..7c20fc334 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -494,10 +494,10 @@ getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCS } CCSSettingValueList -readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) { CCSSettingValueList list = NULL; - Bool *array = malloc (nItems * sizeof (Bool)); + Bool *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (Bool)); Bool *arrayCounter = array; gboolean value; @@ -515,10 +515,10 @@ readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) } CCSSettingValueList -readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) { CCSSettingValueList list = NULL; - int *array = malloc (nItems * sizeof (int)); + int *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (int)); int *arrayCounter = array; gint value; @@ -536,10 +536,10 @@ readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) } CCSSettingValueList -readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) { CCSSettingValueList list = NULL; - float *array = malloc (nItems * sizeof (float)); + float *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (float)); float *arrayCounter = array; gdouble value; @@ -557,10 +557,10 @@ readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) } CCSSettingValueList -readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) { CCSSettingValueList list = NULL; - const gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); + const gchar **array = (*ai->calloc_) (ai->allocator, 1, (nItems + 1) * sizeof (gchar *)); const gchar **arrayCounter = array; gchar *value; @@ -580,11 +580,11 @@ readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) } CCSSettingValueList -readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) { CCSSettingValueList list = NULL; char *colorValue; - CCSSettingColorValue *array = calloc (1, nItems * sizeof (CCSSettingColorValue)); + CCSSettingColorValue *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (CCSSettingColorValue)); unsigned int i = 0; if (!array) @@ -604,7 +604,7 @@ readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting) } CCSSettingValueList -readListValue (GVariant *gsettingsValue, CCSSetting *setting) +readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *ai) { CCSSettingType listType = ccsSettingGetInfo (setting)->forList.listType; gboolean hasVariantType; @@ -623,20 +623,20 @@ readListValue (GVariant *gsettingsValue, CCSSetting *setting) switch (listType) { case TypeBool: - list = readBoolListValue (&iter, nItems, setting); + list = readBoolListValue (&iter, nItems, setting, ai); break; case TypeInt: - list = readIntListValue (&iter, nItems, setting); + list = readIntListValue (&iter, nItems, setting, ai); break; case TypeFloat: - list = readFloatListValue (&iter, nItems, setting); + list = readFloatListValue (&iter, nItems, setting, ai); break; case TypeString: case TypeMatch: - list = readStringListValue (&iter, nItems, setting); + list = readStringListValue (&iter, nItems, setting, ai); break; case TypeColor: - list = readColorListValue (&iter, nItems, setting); + list = readColorListValue (&iter, nItems, setting, ai); break; default: break; diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 28cdaf2ba..5c7adfb22 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -158,7 +158,7 @@ CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *suc unsigned int readEdgeFromVariant (GVariant *gsettingsValue); CCSSettingValueList -readListValue (GVariant *gsettingsValue, CCSSetting *setting); +readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *allocator); Bool writeListValue (CCSSettingValueList list, @@ -203,19 +203,19 @@ removeItemFromVariant (GVariant **variant, const char *string); CCSSettingValueList -readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); CCSSettingValueList -readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); CCSSettingValueList -readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); CCSSettingValueList -readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); CCSSettingValueList -readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting); +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); gboolean diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 7dc25aeac..274628f85 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -313,7 +313,7 @@ readOption (CCSBackend *backend, CCSSetting * setting) break; case TypeList: { - CCSSettingValueList list = readListValue (gsettingsValue, setting); + CCSSettingValueList list = readListValue (gsettingsValue, setting, &ccsDefaultObjectAllocator); if (list) { diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 4ec90f794..30756558e 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -11,6 +11,7 @@ #include "compizconfig_ccs_setting_mock.h" #include "gtest_shared_characterwrapper.h" #include "compizconfig_test_value_combiners.h" +#include "compizconfig_ccs_mocked_allocator.h" using ::testing::Values; using ::testing::ValuesIn; @@ -24,6 +25,8 @@ using ::testing::Not; using ::testing::Matcher; using ::testing::Eq; using ::testing::NiceMock; +using ::testing::StrictMock; +using ::testing::IsNull; class GVariantSubtypeMatcher : public ::testing::MatcherInterface @@ -1158,7 +1161,10 @@ class ReadListValueTypeTestParam { public: - typedef boost::function ReadValueListFunc; + typedef boost::function ReadValueListFunc; typedef boost::function GVariantPopulator; typedef boost::function CCSSettingValueListPopulator; @@ -1173,9 +1179,12 @@ class ReadListValueTypeTestParam { } - CCSSettingValueList read (GVariantIter *iter, guint nItems, CCSSetting *setting) const + CCSSettingValueList read (GVariantIter *iter, + guint nItems, + CCSSetting *setting, + CCSObjectAllocationInterface *allocator) const { - return mReadFunc (iter, nItems, setting); + return mReadFunc (iter, nItems, setting, allocator); } boost::shared_ptr populateVariant () const @@ -1303,8 +1312,40 @@ TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueGoodAllocation) ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); - boost::shared_ptr <_CCSSettingValueList> readValueList (GetParam ().read (&iter, 3, mockSetting.get ()), + boost::shared_ptr <_CCSSettingValueList> readValueList (GetParam ().read (&iter, + 3, + mockSetting.get (), + &ccsDefaultObjectAllocator), boost::bind (ccsSettingValueListFree, _1, TRUE)); + + EXPECT_TRUE (ccsCompareLists (valueList.get (), readValueList.get (), info.forList)); +} + +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueBadAllocation) +{ + boost::shared_ptr variant = GetParam ().populateVariant (); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + StrictMock objectAllocationGMock; + FailingObjectAllocation fakeFailingAllocator; + + CCSObjectAllocationInterface failingAllocatorGMock = failingAllocator; + failingAllocatorGMock.allocator = reinterpret_cast (&objectAllocationGMock); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + GVariantIter iter; + g_variant_iter_init (&iter, variant.get ()); + + EXPECT_CALL (objectAllocationGMock, calloc_ (_, _)).WillOnce (Invoke (&fakeFailingAllocator, + &FailingObjectAllocation::calloc_)); + + boost::shared_ptr <_CCSSettingValueList> readValueList (GetParam ().read (&iter, + 3, + mockSetting.get (), + &failingAllocatorGMock)); + + EXPECT_THAT (readValueList.get (), IsNull ()); } namespace variant_populators = compizconfig::test::impl::populators::variant; @@ -1312,23 +1353,23 @@ namespace list_populators = compizconfig::test::impl::populators::list; ReadListValueTypeTestParam readListValueTypeTestParam[] = { - ReadListValueTypeTestParam (boost::bind (readBoolListValue, _1, _2, _3), + ReadListValueTypeTestParam (boost::bind (readBoolListValue, _1, _2, _3, _4), boost::bind (variant_populators::boolean), boost::bind (list_populators::boolean, _1), TypeBool), - ReadListValueTypeTestParam (boost::bind (readIntListValue, _1, _2, _3), + ReadListValueTypeTestParam (boost::bind (readIntListValue, _1, _2, _3, _4), boost::bind (variant_populators::integer), boost::bind (list_populators::integer, _1), TypeInt), - ReadListValueTypeTestParam (boost::bind (readFloatListValue, _1, _2, _3), + ReadListValueTypeTestParam (boost::bind (readFloatListValue, _1, _2, _3, _4), boost::bind (variant_populators::doubleprecision), boost::bind (list_populators::doubleprecision, _1), TypeFloat), - ReadListValueTypeTestParam (boost::bind (readStringListValue, _1, _2, _3), + ReadListValueTypeTestParam (boost::bind (readStringListValue, _1, _2, _3, _4), boost::bind (variant_populators::string), boost::bind (list_populators::string, _1), TypeBool), - ReadListValueTypeTestParam (boost::bind (readColorListValue, _1, _2, _3), + ReadListValueTypeTestParam (boost::bind (readColorListValue, _1, _2, _3, _4), boost::bind (variant_populators::color), boost::bind (list_populators::color, _1), TypeColor) diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 74a0d627f..13457a2ed 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,4 +1,4 @@ - include_directories (${GTEST_INCLUDE_DIRS}) +include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) include_directories (${CMAKE_SOURCE_DIR}/tests/shared) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp index e9e5e9a07..3389f68d3 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp @@ -6,6 +6,7 @@ #include #include +#include using ::testing::_; using ::testing::Return; @@ -217,83 +218,6 @@ TEST(CCSObjectTest, TestFinalizeFreesEverything) EXPECT_EQ (NULL, ((CCSObject *) to)->interface_types); } -class AllocationInterface -{ - public: - - virtual void * realloc_ (void *, size_t) = 0; - virtual void * malloc_ (size_t) = 0; - virtual void * calloc_ (size_t, size_t) = 0; - virtual void free_ (void *) = 0; - - public: - - static void * wrapRealloc (void *o, void *a , size_t b) - { - AllocationInterface *ao = static_cast (o); - return ao->realloc_ (a, b); - } - - static void * wrapMalloc (void *o, size_t a) - { - AllocationInterface *ao = static_cast (o); - return ao->malloc_ (a); - } - - static void * wrapCalloc (void *o, size_t a, size_t b) - { - AllocationInterface *ao = static_cast (o); - return ao->calloc_ (a, b); - } - - static void wrapFree (void *o, void *a) - { - AllocationInterface *ao = static_cast (o); - ao->free_ (a); - } -}; - -class ObjectAllocationGMock : - public AllocationInterface -{ - public: - - MOCK_METHOD2 (realloc_, void * (void *, size_t)); - MOCK_METHOD1 (malloc_, void * (size_t)); - MOCK_METHOD2 (calloc_, void * (size_t, size_t)); - MOCK_METHOD1 (free_, void (void *)); - -}; - -class FailingObjectReallocation : - public AllocationInterface -{ - public: - - FailingObjectReallocation (unsigned int sc) : - successCount (sc) - { - } - - void * realloc_ (void *a, size_t b) { unsigned int c = successCount--; if (c) return realloc (a, b); else return NULL; } - void * malloc_ (size_t a) { return malloc (a); } - void * calloc_ (size_t n, size_t a) { return calloc (n, a); } - void free_ (void *a) { free (a); } - - private: - - unsigned int successCount; -}; - -CCSObjectAllocationInterface failingAllocator = -{ - AllocationInterface::wrapRealloc, - AllocationInterface::wrapMalloc, - AllocationInterface::wrapCalloc, - AllocationInterface::wrapFree, - NULL -}; - TEST(CCSObjectTest, TestReallocFailures) { TestingObjectWrapper *to = (TestingObjectWrapper *) calloc (1, sizeof (TestingObjectWrapper)); -- GitLab From 32dd643e79922e84608b19ae352d2afaf77e30d9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 09:25:55 +0800 Subject: [PATCH 244/562] Test through the list value read dispatch too --- .../gsettings/tests/test_gsettings_tests.cpp | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 30756558e..37c3eb7d7 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1321,6 +1321,39 @@ TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueGoodAllocation) EXPECT_TRUE (ccsCompareLists (valueList.get (), readValueList.get (), info.forList)); } +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueThroughListValueDispatch) +{ + boost::shared_ptr variant = GetParam ().populateVariant (); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + CCSSettingInfo info = + { + .forList = + { + GetParam ().type (), + NULL + } + }; + + boost::shared_ptr <_CCSSettingValueList> valueList (GetParam ().populateList (mockSetting.get ())); + GVariantIter iter; + + g_variant_iter_init (&iter, variant.get ()); + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); + + boost::shared_ptr <_CCSSettingValueList> readValueList (readListValue (variant.get (), + mockSetting.get (), + &ccsDefaultObjectAllocator), + boost::bind (ccsSettingValueListFree, _1, TRUE)); + + EXPECT_TRUE (ccsCompareLists (valueList.get (), readValueList.get (), info.forList)); +} + TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueBadAllocation) { boost::shared_ptr variant = GetParam ().populateVariant (); @@ -1368,7 +1401,7 @@ ReadListValueTypeTestParam readListValueTypeTestParam[] = ReadListValueTypeTestParam (boost::bind (readStringListValue, _1, _2, _3, _4), boost::bind (variant_populators::string), boost::bind (list_populators::string, _1), - TypeBool), + TypeString), ReadListValueTypeTestParam (boost::bind (readColorListValue, _1, _2, _3, _4), boost::bind (variant_populators::color), boost::bind (list_populators::color, _1), -- GitLab From 065968bc07f17844aa7567480bd5404581143884 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 09:34:32 +0800 Subject: [PATCH 245/562] Test what happens when we read invalid list types --- .../gsettings/tests/test_gsettings_tests.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 37c3eb7d7..ceef6e6fd 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1410,3 +1410,45 @@ ReadListValueTypeTestParam readListValueTypeTestParam[] = INSTANTIATE_TEST_CASE_P (TestGSettingsReadListValueParameterized, CCSGSettingsTestReadListValueTypes, ::testing::ValuesIn (readListValueTypeTestParam)); + +class CCSGSettingsBackendReadListValueBadTypesTest : + public ::testing::TestWithParam +{ +}; + +TEST_P (CCSGSettingsBackendReadListValueBadTypesTest, TestGSettingsReadListValueFailsOnNonVariantTypes) +{ + GVariant *variant = NULL; + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + CCSSettingInfo info = + { + .forList = + { + GetParam (), + NULL + } + }; + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); + + EXPECT_THAT (readListValue (variant, mockSetting.get (), &ccsDefaultObjectAllocator), IsNull ()); +} + +CCSSettingType readListValueNonVariantTypes[] = +{ + TypeAction, + TypeKey, + TypeButton, + TypeEdge, + TypeBell, + TypeList, + TypeNum +}; + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendReadListValueBadTypesTestParameterized, + CCSGSettingsBackendReadListValueBadTypesTest, + ::testing::ValuesIn (readListValueNonVariantTypes)); -- GitLab From f6d5a2a98f541c40c05450ec3822fe08caf0b015 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 09:40:33 +0800 Subject: [PATCH 246/562] Make sure the other profile sticks around too --- .../gsettings/gsettings_backend_shared/gsettings_util.c | 2 ++ compizconfig/gsettings/tests/test_gsettings_tests.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 7c20fc334..3e9246ce9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -954,6 +954,8 @@ insertIfNotEqual (GVariantBuilder *builder, const char *item, void *userData) { const char *cmp = (const char *) userData; + printf ("cmp: %s %s\n", item, cmp); + if (g_strcmp0 (item, cmp)) g_variant_builder_add (builder, "s", item); } diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index ceef6e6fd..de8c96488 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -184,12 +184,14 @@ TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) CCSGSettingsBackendGMock *mockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); std::string currentProfile ("foo"); + std::string otherProfile ("other"); GVariant *existingProfiles = NULL; GVariantBuilder existingProfilesBuilder; g_variant_builder_init (&existingProfilesBuilder, G_VARIANT_TYPE ("as")); g_variant_builder_add (&existingProfilesBuilder, "s", currentProfile.c_str ()); + g_variant_builder_add (&existingProfilesBuilder, "s", otherProfile.c_str ()); existingProfiles = g_variant_builder_end (&existingProfilesBuilder); @@ -202,7 +204,10 @@ TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) EXPECT_CALL (*mockBackend, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), Not (GVariantHasValueInArray ("s", currentProfile.c_str (), - boost::bind (streq, _1, _2)))))); + boost::bind (streq, _1, _2))), + GVariantHasValueInArray ("s", + otherProfile.c_str (), + boost::bind (streq, _1, _2))))); EXPECT_CALL (*mockBackend, updateProfile (context.get ())); -- GitLab From f07a2cc0ddbd47fe82d1e246d701ceed5d9a8528 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 09:51:18 +0800 Subject: [PATCH 247/562] Tests for UpdateCurrentProfileDefault --- .../gsettings/tests/test_gsettings_tests.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index de8c96488..ca6cdaf70 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1457,3 +1457,39 @@ CCSSettingType readListValueNonVariantTypes[] = INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendReadListValueBadTypesTestParameterized, CCSGSettingsBackendReadListValueBadTypesTest, ::testing::ValuesIn (readListValueNonVariantTypes)); + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplCurrentProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (currentProfile.c_str ())); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplDifferentProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + std::string otherProfile ("other"); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (otherProfile.c_str ())); + EXPECT_CALL (*gmockGSettingsBackend, updateCurrentProfileName (Eq (otherProfile))); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} -- GitLab From 5e8a99d3fdaf78deb99b9ec63df5c76633aeed96 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 09:55:55 +0800 Subject: [PATCH 248/562] Handle the NULL and empty string cases, fix a crash --- .../gsettings_backend_shared/gsettings_util.c | 7 +++- .../gsettings/tests/test_gsettings_tests.cpp | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 3e9246ce9..dccb6b1ab 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1042,10 +1042,13 @@ gboolean ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context) { const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); - char *profile = strdup (ccsGetProfile (context)); + const char *ccsProfile = ccsGetProfile (context); + char *profile = NULL; - if (!profile) + if (!ccsProfile) profile = strdup (DEFAULTPROF); + else + profile = strdup (ccsProfile); if (!strlen (profile)) { diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index ca6cdaf70..6559a5f0e 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1493,3 +1493,41 @@ TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplDifferentProfil ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); } + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplNullProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + std::string otherProfile ("other"); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockGSettingsBackend, updateCurrentProfileName (Eq (std::string (DEFAULTPROF)))); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplEmptyStringProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + std::string otherProfile (""); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (otherProfile.c_str ())); + EXPECT_CALL (*gmockGSettingsBackend, updateCurrentProfileName (Eq (std::string (DEFAULTPROF)))); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} -- GitLab From b8efd17ee8b6933533dd0a11dedc76faa0c60332 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 20:08:12 +0800 Subject: [PATCH 249/562] Added missing files, stubs etc --- .../gsettings_backend_shared/CMakeLists.txt | 1 + .../ccs_gsettings_interface.h | 34 +++++++ .../ccs_gsettings_interface_wrapper.c | 1 + .../ccs_gsettings_interface_wrapper.h | 19 ++++ .../gsettings_backend_shared/gsettings_util. | 0 compizconfig/gsettings/tests/CMakeLists.txt | 1 + .../tests/test_gsettings_wrapper.cpp | 46 ++++++++++ .../tests/compizconfig_ccs_mocked_allocator.h | 91 +++++++++++++++++++ 8 files changed, 193 insertions(+) create mode 100644 compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h create mode 100644 compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c create mode 100644 compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h create mode 100644 compizconfig/gsettings/gsettings_backend_shared/gsettings_util. create mode 100644 compizconfig/gsettings/tests/test_gsettings_wrapper.cpp create mode 100644 compizconfig/tests/compizconfig_ccs_mocked_allocator.h diff --git a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt index 2b402f7f2..0d025d1c9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt +++ b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt @@ -16,6 +16,7 @@ if (GSETTINGS_UTIL_FOUND) ${compiz_BINARY_DIR}/compizconfig/libcompizconfig) add_library (gsettings_backend_shared SHARED + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_interface_wrapper.c ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_constants.c ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_util.c) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h new file mode 100644 index 000000000..a38e03989 --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h @@ -0,0 +1,34 @@ +#ifndef _CCS_GSETTINGS_INTERFACE_H +#define _CCS_GSETTINGS_INTERFACE_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +#include +#include + +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; +typedef struct _CCSGSettingsWrapperInterface CCSGSettingsWrapperInterface; + +typedef void (*CCSGSettingsWrapperSetValue) (CCSGSettingsWrapper *, const char *, GVariant *); +typedef GVariant * (*CCSGSettingsWrapperGetValue) (CCSGSettingsWrapper *, const char *); +typedef void (*CCSGSettingsWrapperResetKey) (CCSGSettingsWrapper *, const char *); +typedef const char ** (*CCSGSettingsWrapperListKeys) (CCSGSettingsWrapper *); + +struct _CCSGSettingsWrapperInterface +{ + CCSGSettingsWrapperSetValue gsettingsWrapperSetValue; + CCSGSettingsWrapperGetValue gsettingsWrapperGetValue; + CCSGSettingsWrapperResetKey gsettingsWrapperResetKey; + CCSGSettingsWrapperListKeys gsettingsWrapperListKeys; +}; + +struct _CCSGSettingsWrapper +{ + CCSObject object; +}; + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c new file mode 100644 index 000000000..42bcdd731 --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -0,0 +1 @@ +#include "ccs_gsettings_interface_wrapper.h" diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h new file mode 100644 index 000000000..286600f5f --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h @@ -0,0 +1,19 @@ +#ifndef _CCS_GSETTINGS_INTERFACE_WRAPPER_H +#define _CCS_GSETTINGS_INTERFACE_WRAPPER_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +#include "ccs_gsettings_interface.h" + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, + const char *path); + +void +ccsFreeGSettingsWrapper (CCSGSettingsWrapper *); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util. b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util. new file mode 100644 index 000000000..e69de29bb diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 90c9abbe5..b518f6449 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -14,6 +14,7 @@ add_library (compizconfig_ccs_gsettings_backend_mock STATIC add_executable (compizconfig_test_gsettings ${CMAKE_CURRENT_SOURCE_DIR}/wrap_gsettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wrap_gsettings.h ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.h) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp new file mode 100644 index 000000000..52f8d8a01 --- /dev/null +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include "test_gsettings_tests.h" +#include + +class TestGSettingsWrapperWithMemoryBackendEnv : + public ::testing::Test +{ + public: + + virtual void SetUp () + { + g_setenv ("GSETTINGS_BACKEND", "memory", 1); + } + + virtual void TearDown () + { + g_unsetenv ("GSETTINGS_BACKEND"); + } +}; + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestWrapperConstruction) +{ + FAIL (); +} + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestSetValueOnWrapper) +{ + FAIL (); +} + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestGetValueOnWrapper) +{ + FAIL (); +} + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestResetKeyOnWrapper) +{ + FAIL (); +} + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestListKeysOnWrapper) +{ + FAIL (); +} diff --git a/compizconfig/tests/compizconfig_ccs_mocked_allocator.h b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h new file mode 100644 index 000000000..dabb25a6a --- /dev/null +++ b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h @@ -0,0 +1,91 @@ +#ifndef _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H +#define _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H +class AllocationInterface +{ + public: + + virtual void * realloc_ (void *, size_t) = 0; + virtual void * malloc_ (size_t) = 0; + virtual void * calloc_ (size_t, size_t) = 0; + virtual void free_ (void *) = 0; + + public: + + static void * wrapRealloc (void *o, void *a , size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->realloc_ (a, b); + } + + static void * wrapMalloc (void *o, size_t a) + { + AllocationInterface *ao = static_cast (o); + return ao->malloc_ (a); + } + + static void * wrapCalloc (void *o, size_t a, size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->calloc_ (a, b); + } + + static void wrapFree (void *o, void *a) + { + AllocationInterface *ao = static_cast (o); + ao->free_ (a); + } +}; + +class ObjectAllocationGMock : + public AllocationInterface +{ + public: + + MOCK_METHOD2 (realloc_, void * (void *, size_t)); + MOCK_METHOD1 (malloc_, void * (size_t)); + MOCK_METHOD2 (calloc_, void * (size_t, size_t)); + MOCK_METHOD1 (free_, void (void *)); + +}; + +class FailingObjectReallocation : + public AllocationInterface +{ + public: + + FailingObjectReallocation (unsigned int sc) : + successCount (sc) + { + } + + void * realloc_ (void *a, size_t b) { unsigned int c = successCount--; if (c) return realloc (a, b); else return NULL; } + void * malloc_ (size_t a) { return malloc (a); } + void * calloc_ (size_t n, size_t a) { return calloc (n, a); } + void free_ (void *a) { free (a); } + + private: + + unsigned int successCount; +}; + +class FailingObjectAllocation : + public AllocationInterface +{ + public: + + void * realloc_ (void *a, size_t b) { return NULL; } + void * malloc_ (size_t a) { return NULL; } + void * calloc_ (size_t n, size_t a) { return NULL; } + void free_ (void *a) { } +}; + +CCSObjectAllocationInterface failingAllocator = +{ + AllocationInterface::wrapRealloc, + AllocationInterface::wrapMalloc, + AllocationInterface::wrapCalloc, + AllocationInterface::wrapFree, + NULL +}; + +#endif -- GitLab From 77a9107a3619c480e9f418b02fb061f0ac83328a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Fri, 3 Aug 2012 20:52:29 +0800 Subject: [PATCH 250/562] Pass the object allocator too --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 3da50de93..08a1f35c2 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -407,7 +407,7 @@ class CCSGSettingsBackendEnv : CharacterWrapper (translateKeyForGSettings (key.c_str ())), CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), TypeList); - return readListValue (variant, setting); + return readListValue (variant, setting, &ccsDefaultObjectAllocator); } void PreUpdate (CCSContextGMock *gmockContext, -- GitLab From 50cf4745200d5baaa78607594109033c0b053ab0 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 09:05:18 +0800 Subject: [PATCH 251/562] First steps to getting the wrapper under test --- compizconfig/CMakeLists.txt | 1 + .../ccs_gsettings_interface_wrapper.c | 12 +++++++++ compizconfig/gsettings/tests/CMakeLists.txt | 4 +-- .../tests/backend-conformance-config.h.in | 2 -- .../tests/gsettings-mock-schemas-config.h.in | 7 +++++ .../tests/test_gsettings_conformance.cpp | 7 +---- .../tests/test_gsettings_wrapper.cpp | 26 ++++++++++++++++++- compizconfig/tests/CMakeLists.txt | 2 ++ .../tests/backend-conformance-config.h.in | 1 + 9 files changed, 51 insertions(+), 11 deletions(-) delete mode 100644 compizconfig/gsettings/tests/backend-conformance-config.h.in create mode 100644 compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in create mode 100644 compizconfig/tests/CMakeLists.txt create mode 100644 compizconfig/tests/backend-conformance-config.h.in diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index 869e2c490..c21e8902d 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -12,6 +12,7 @@ add_subdirectory (gsettings) if (COMPIZ_BUILD_TESTING) add_subdirectory (mocks) + add_subdirectory (tests) endif (COMPIZ_BUILD_TESTING) add_custom_target (pyclean) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 42bcdd731..66ddc7304 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -1 +1,13 @@ #include "ccs_gsettings_interface_wrapper.h" + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, + const char *path) +{ + return NULL; +} + +void +ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) +{ +} diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index ce2e76046..e9f7200e8 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -36,8 +36,8 @@ target_link_libraries (compizconfig_test_gsettings ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/backend-conformance-config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/backend-conformance-config.h) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/gsettings-mock-schemas-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/gsettings-mock-schemas-config.h) add_custom_command (OUTPUT ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml diff --git a/compizconfig/gsettings/tests/backend-conformance-config.h.in b/compizconfig/gsettings/tests/backend-conformance-config.h.in deleted file mode 100644 index 95a2a8a40..000000000 --- a/compizconfig/gsettings/tests/backend-conformance-config.h.in +++ /dev/null @@ -1,2 +0,0 @@ -#define BACKEND_BINARY_PATH "@CMAKE_BINARY_DIR@/compizconfig/gsettings" -#define MOCK_SCHEMA_PATH "@CMAKE_BINARY_DIR@/generated/glib-2.0/schemas" diff --git a/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in b/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in new file mode 100644 index 000000000..c26889995 --- /dev/null +++ b/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in @@ -0,0 +1,7 @@ +#define MOCK_SCHEMA_PATH "@CMAKE_BINARY_DIR@/generated/glib-2.0/schemas" + +namespace +{ +const std::string MOCK_SCHEMA ("org.compiz.mock"); +const std::string MOCK_PATH (MOCK_SCHEMA_PATH); +} diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 08a1f35c2..4626d5443 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -6,6 +6,7 @@ #include #include "backend-conformance-config.h" +#include "gsettings-mock-schemas-config.h" #include #include @@ -16,12 +17,6 @@ using ::testing::AtLeast; using ::testing::Pointee; using ::testing::ReturnNull; -namespace -{ -const std::string MOCK_SCHEMA ("org.compiz.mock"); -const std::string MOCK_PATH (MOCK_SCHEMA_PATH); -} - class CCSGSettingsBackendEnv : public CCSBackendConceptTestEnvironmentInterface { diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 52f8d8a01..8d177eb7d 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -1,28 +1,52 @@ #include #include +#include +#include +#include + #include "test_gsettings_tests.h" +#include "gsettings-mock-schemas-config.h" #include +using ::testing::NotNull; + class TestGSettingsWrapperWithMemoryBackendEnv : public ::testing::Test { public: + TestGSettingsWrapperWithMemoryBackendEnv () : + mockSchema ("org.compiz.mock"), + mockPath ("/org/compiz/mock/mock") + { + } + virtual void SetUp () { + g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); g_setenv ("GSETTINGS_BACKEND", "memory", 1); } virtual void TearDown () { g_unsetenv ("GSETTINGS_BACKEND"); + g_unsetenv ("GSETTINGS_SCHEMA_DIR"); } + + protected: + + std::string mockSchema; + std::string mockPath; }; TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestWrapperConstruction) { - FAIL (); + boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), + mockPath.c_str ()), + boost::bind (ccsFreeGSettingsWrapper, _1)); + + EXPECT_THAT (wrapper.get (), NotNull ()); } TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestSetValueOnWrapper) diff --git a/compizconfig/tests/CMakeLists.txt b/compizconfig/tests/CMakeLists.txt new file mode 100644 index 000000000..44c9feeb4 --- /dev/null +++ b/compizconfig/tests/CMakeLists.txt @@ -0,0 +1,2 @@ +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/backend-conformance-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/backend-conformance-config.h) diff --git a/compizconfig/tests/backend-conformance-config.h.in b/compizconfig/tests/backend-conformance-config.h.in new file mode 100644 index 000000000..0db3f2ea4 --- /dev/null +++ b/compizconfig/tests/backend-conformance-config.h.in @@ -0,0 +1 @@ +#define BACKEND_BINARY_PATH "@CMAKE_BINARY_DIR@/compizconfig/gsettings" -- GitLab From c7cdb08ef1428b9f84941a9914222492b28e70fa Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 09:20:20 +0800 Subject: [PATCH 252/562] Bootstrapped wrapper tests --- compizconfig/CMakeLists.txt | 1 + .../ccs_gsettings_interface_wrapper.c | 12 +++++++++ compizconfig/gsettings/tests/CMakeLists.txt | 6 ++++- .../tests/gsettings-mock-schemas-config.h.in | 7 +++++ .../tests/test_gsettings_wrapper.cpp | 26 ++++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index 869e2c490..c21e8902d 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -12,6 +12,7 @@ add_subdirectory (gsettings) if (COMPIZ_BUILD_TESTING) add_subdirectory (mocks) + add_subdirectory (tests) endif (COMPIZ_BUILD_TESTING) add_custom_target (pyclean) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 42bcdd731..66ddc7304 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -1 +1,13 @@ #include "ccs_gsettings_interface_wrapper.h" + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, + const char *path) +{ + return NULL; +} + +void +ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) +{ +} diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index b518f6449..0230a789d 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,4 +1,5 @@ -include_directories (${CMAKE_CURRENT_SOURCE_DIR} +include_directories (${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig @@ -30,4 +31,7 @@ target_link_libraries (compizconfig_test_gsettings ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/gsettings-mock-schemas-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/gsettings-mock-schemas-config.h) + compiz_discover_tests (compizconfig_test_gsettings COVERAGE gsettings_backend_shared) diff --git a/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in b/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in new file mode 100644 index 000000000..c26889995 --- /dev/null +++ b/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in @@ -0,0 +1,7 @@ +#define MOCK_SCHEMA_PATH "@CMAKE_BINARY_DIR@/generated/glib-2.0/schemas" + +namespace +{ +const std::string MOCK_SCHEMA ("org.compiz.mock"); +const std::string MOCK_PATH (MOCK_SCHEMA_PATH); +} diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 52f8d8a01..7f24f3d8a 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -1,28 +1,52 @@ #include #include +#include +#include +#include + #include "test_gsettings_tests.h" +#include #include +using ::testing::NotNull; + class TestGSettingsWrapperWithMemoryBackendEnv : public ::testing::Test { public: + TestGSettingsWrapperWithMemoryBackendEnv () : + mockSchema ("org.compiz.mock"), + mockPath ("/org/compiz/mock/mock") + { + } + virtual void SetUp () { + g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); g_setenv ("GSETTINGS_BACKEND", "memory", 1); } virtual void TearDown () { g_unsetenv ("GSETTINGS_BACKEND"); + g_unsetenv ("GSETTINGS_SCHEMA_DIR"); } + + protected: + + std::string mockSchema; + std::string mockPath; }; TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestWrapperConstruction) { - FAIL (); + boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), + mockPath.c_str ()), + boost::bind (ccsFreeGSettingsWrapper, _1)); + + EXPECT_THAT (wrapper.get (), NotNull ()); } TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestSetValueOnWrapper) -- GitLab From b0aa91446aa231dc96064f5450e3bbb4ce275d07 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 09:44:00 +0800 Subject: [PATCH 253/562] Added the mock gschema too --- compizconfig/gsettings/tests/CMakeLists.txt | 16 +++++- .../tests/org.compiz.mock.gschema.xml | 53 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 compizconfig/gsettings/tests/org.compiz.mock.gschema.xml diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 0230a789d..1e43fc523 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,5 +1,7 @@ -include_directories (${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} +include (CompizGSettings) + +include_directories (${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig @@ -31,6 +33,16 @@ target_link_libraries (compizconfig_test_gsettings ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) +add_custom_command (OUTPUT ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml + COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml + VERBATIM) + +add_custom_target (compiz_gsettings_mock_schema ALL + DEPENDS ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml) + +add_gsettings_schema_to_recompilation_list (compiz_gsettings_mock_schema) + configure_file (${CMAKE_CURRENT_SOURCE_DIR}/gsettings-mock-schemas-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/gsettings-mock-schemas-config.h) diff --git a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml new file mode 100644 index 000000000..1d3d8491b --- /dev/null +++ b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml @@ -0,0 +1,53 @@ + + + + + 0 + + + false + + + 0.0 + + + "" + + + "" + + + false + + + "" + + + "" + + + "" + + + "" + + + [0] + + + [0.0] + + + [true] + + + [""] + + + [""] + + + [""] + + + -- GitLab From 4675957b14284221bb5569715e1a4802b85db242 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 09:52:07 +0800 Subject: [PATCH 254/562] Backend conformance config really belongs in gsettings --- compizconfig/CMakeLists.txt | 1 - compizconfig/gsettings/tests/CMakeLists.txt | 3 +++ .../{ => gsettings}/tests/backend-conformance-config.h.in | 0 compizconfig/tests/CMakeLists.txt | 2 -- 4 files changed, 3 insertions(+), 3 deletions(-) rename compizconfig/{ => gsettings}/tests/backend-conformance-config.h.in (100%) delete mode 100644 compizconfig/tests/CMakeLists.txt diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index c21e8902d..869e2c490 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -12,7 +12,6 @@ add_subdirectory (gsettings) if (COMPIZ_BUILD_TESTING) add_subdirectory (mocks) - add_subdirectory (tests) endif (COMPIZ_BUILD_TESTING) add_custom_target (pyclean) diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index fce92d2f1..20c368937 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -59,6 +59,9 @@ add_custom_target (compiz_gsettings_mock_schema ALL add_gsettings_schema_to_recompilation_list (compiz_gsettings_mock_schema) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/backend-conformance-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/backend-conformance-config.h) + target_link_libraries (compizconfig_test_gsettings_conformance gsettings_backend_shared compizconfig_ccs_setting_mock diff --git a/compizconfig/tests/backend-conformance-config.h.in b/compizconfig/gsettings/tests/backend-conformance-config.h.in similarity index 100% rename from compizconfig/tests/backend-conformance-config.h.in rename to compizconfig/gsettings/tests/backend-conformance-config.h.in diff --git a/compizconfig/tests/CMakeLists.txt b/compizconfig/tests/CMakeLists.txt deleted file mode 100644 index 44c9feeb4..000000000 --- a/compizconfig/tests/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/backend-conformance-config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/backend-conformance-config.h) -- GitLab From 446300bbd60926f6d93b08dbdcc9badd222f29b3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 09:52:39 +0800 Subject: [PATCH 255/562] Don't add tests subdirectory --- compizconfig/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index c21e8902d..869e2c490 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -12,7 +12,6 @@ add_subdirectory (gsettings) if (COMPIZ_BUILD_TESTING) add_subdirectory (mocks) - add_subdirectory (tests) endif (COMPIZ_BUILD_TESTING) add_custom_target (pyclean) -- GitLab From 60091aea10dd14c613369f8d9712c290a449ef1c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 10:59:23 +0800 Subject: [PATCH 256/562] Wrote passing allocation interface for the gsettings wrapper --- .../ccs_gsettings_interface.h | 2 + .../ccs_gsettings_interface_wrapper.c | 201 +++++++++++++++++- .../ccs_gsettings_interface_wrapper.h | 3 +- .../tests/test_gsettings_wrapper.cpp | 6 +- 4 files changed, 208 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h index a38e03989..3dd5ee791 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h @@ -29,6 +29,8 @@ struct _CCSGSettingsWrapper CCSObject object; }; +unsigned int ccsCCSGSettingsWrapperInterfaceGetType (); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 66ddc7304..b3cb27356 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -1,13 +1,210 @@ +#include #include "ccs_gsettings_interface_wrapper.h" +typedef struct _CCSGSettingsWrapperPrivate CCSGSettingsWrapperPrivate; + +struct _CCSGSettingsWrapperPrivate +{ + GSettings *settings; + char *schema; + char *path; +}; + +#define GSETTINGS_WRAPPER_PRIVATE(w) \ + CCSGSettingsWrapperPrivate *gswPrivate = (CCSGSettingsWrapperPrivate *) ccsObjectGetPrivate (w); + +static GVariant * ccsGSettingsWrapperGetValueDefault (CCSGSettingsWrapper *wrapper, const char *key) +{ + return NULL; +} + +static void ccsGSettingsWrapperSetValueDefault (CCSGSettingsWrapper *wrapper, const char *key, GVariant *variant) +{ +} + +static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, const char *key) +{ +} + +static const char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper) +{ + return NULL; +} + +const CCSGSettingsWrapperInterface interface = +{ + ccsGSettingsWrapperSetValueDefault, + ccsGSettingsWrapperGetValueDefault, + ccsGSettingsWrapperResetKeyDefault, + ccsGSettingsWrapperListKeysDefault +}; + +INTERFACE_TYPE (CCSGSettingsWrapperInterface); + +static CCSGSettingsWrapperPrivate * +allocatePrivateWrapper (CCSObjectAllocationInterface *ai, CCSGSettingsWrapper *wrapper) +{ + CCSGSettingsWrapperPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsWrapper)); + + if (!priv) + { + (*ai->free_) (ai->allocator, wrapper); + return NULL; + } + + return priv; +} + +static CCSGSettingsWrapper * +allocateWrapper (CCSObjectAllocationInterface *ai) +{ + CCSGSettingsWrapper *wrapper = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsWrapper)); + + if (!wrapper) + return NULL; + + return wrapper; +} + +static void +freeWrapperAndPriv (CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + (*ai->free_) (ai->allocator, priv); + (*ai->free_) (ai->allocator, wrapper); +} + +static GSettings * +newGSettingsWithPath (const char *schema, + const char *path, + CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + GSettings *settings = g_settings_new_with_path (schema, path); + + if (!settings) + { + freeWrapperAndPriv (wrapper, priv, ai); + return NULL; + } + + return settings; +} + +static GSettings * +newGSettings (const char *schema, + CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + GSettings *settings = g_settings_new (schema); + + if (!settings) + { + freeWrapperAndPriv (wrapper, priv, ai); + return NULL; + } + + return settings; +} + +static Bool +allocateWrapperData (CCSObjectAllocationInterface *ai, + CCSGSettingsWrapper **wrapper, + CCSGSettingsWrapperPrivate **priv) +{ + *wrapper = allocateWrapper (ai); + + if (!*wrapper) + return FALSE; + + *priv = allocatePrivateWrapper (ai, *wrapper); + + if (!*priv) + return FALSE; + + return TRUE; +} + +static void +initCCSGSettingsWrapperObject (CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + ccsObjectInit (wrapper, ai); + ccsObjectAddInterface (wrapper, (const CCSInterface *) &interface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); + ccsObjectSetPrivate (wrapper, (CCSPrivate *) priv); +} + CCSGSettingsWrapper * ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, - const char *path) + const char *path, + CCSObjectAllocationInterface *ai) { - return NULL; + CCSGSettingsWrapper *wrapper = NULL; + CCSGSettingsWrapperPrivate *priv = NULL; + + if (!allocateWrapperData (ai, &wrapper, &priv)) + return NULL; + + priv->schema = g_strdup (schema); + priv->path = g_strdup (path); + priv->settings = newGSettingsWithPath (schema, path, wrapper, priv, ai); + + if (!priv->settings) + return NULL; + + initCCSGSettingsWrapperObject (wrapper, priv, ai); + + return wrapper; +} + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchema (const char *schema, + CCSObjectAllocationInterface *ai) +{ + CCSGSettingsWrapper *wrapper = NULL; + CCSGSettingsWrapperPrivate *priv = NULL; + + if (!allocateWrapperData (ai, &wrapper, &priv)) + return NULL; + + priv->schema = g_strdup (schema); + priv->settings = newGSettings (schema, wrapper, priv, ai); + + if (!priv->settings) + return NULL; + + GValue pathValue = G_VALUE_INIT; + g_value_init (&pathValue, G_TYPE_STRING); + g_object_get_property (G_OBJECT (priv->settings), "path", &pathValue); + + priv->path = g_value_dup_string (&pathValue); + + g_value_unset (&pathValue); + + initCCSGSettingsWrapperObject (wrapper, priv, ai); + + return wrapper; } void ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) { + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + if (gswPrivate->settings) + g_object_unref (gswPrivate->settings); + + if (gswPrivate->path) + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + gswPrivate->path); + + if (gswPrivate->schema) + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + gswPrivate->schema); + + ccsObjectFinalize (wrapper); } diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h index 286600f5f..be3304b9d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h @@ -9,7 +9,8 @@ COMPIZCONFIG_BEGIN_DECLS CCSGSettingsWrapper * ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, - const char *path); + const char *path, + CCSObjectAllocationInterface *ai); void ccsFreeGSettingsWrapper (CCSGSettingsWrapper *); diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 7f24f3d8a..36b8f8110 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "test_gsettings_tests.h" #include #include @@ -24,6 +26,7 @@ class TestGSettingsWrapperWithMemoryBackendEnv : virtual void SetUp () { + g_type_init (); g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); g_setenv ("GSETTINGS_BACKEND", "memory", 1); } @@ -43,7 +46,8 @@ class TestGSettingsWrapperWithMemoryBackendEnv : TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestWrapperConstruction) { boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), - mockPath.c_str ()), + mockPath.c_str (), + &ccsDefaultObjectAllocator), boost::bind (ccsFreeGSettingsWrapper, _1)); EXPECT_THAT (wrapper.get (), NotNull ()); -- GitLab From 06f5fc8efc537edd349e84f36e17e4a73fb104d3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:03:20 +0800 Subject: [PATCH 257/562] Don't lose memory --- .../ccs_gsettings_interface_wrapper.c | 3 +++ compizconfig/gsettings/tests/test_gsettings_wrapper.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index b3cb27356..91faf59ca 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -207,4 +207,7 @@ ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) gswPrivate->schema); ccsObjectFinalize (wrapper); + + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + wrapper); } diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 36b8f8110..08fa24acf 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -26,15 +26,18 @@ class TestGSettingsWrapperWithMemoryBackendEnv : virtual void SetUp () { - g_type_init (); + g_setenv ("G_SLICE", "always-malloc", 1); g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); g_setenv ("GSETTINGS_BACKEND", "memory", 1); + + g_type_init (); } virtual void TearDown () { g_unsetenv ("GSETTINGS_BACKEND"); g_unsetenv ("GSETTINGS_SCHEMA_DIR"); + g_unsetenv ("G_SLICE"); } protected: -- GitLab From b854dfbbae6a8e98377ada2a7d9813cb0c396e52 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:17:35 +0800 Subject: [PATCH 258/562] Failing test for GetGSettingsWrapper, added other boilerplate that was missing --- .../gsettings_backend_shared/CMakeLists.txt | 1 + .../ccs_gsettings_interface.c | 38 +++++++++++++++++++ .../ccs_gsettings_interface.h | 9 +++++ .../ccs_gsettings_interface_wrapper.c | 10 +++-- .../tests/test_gsettings_wrapper.cpp | 10 +++++ 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c diff --git a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt index 0d025d1c9..bc5737d2c 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt +++ b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt @@ -17,6 +17,7 @@ if (GSETTINGS_UTIL_FOUND) add_library (gsettings_backend_shared SHARED ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_interface_wrapper.c + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_interface.c ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_constants.c ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_util.c) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c new file mode 100644 index 000000000..9484f5a5f --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c @@ -0,0 +1,38 @@ +#include +#include "ccs_gsettings_interface.h" + +INTERFACE_TYPE (CCSGSettingsWrapperInterface); + +void +ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *wrapper, + const char *key, + GVariant *value) +{ + (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperSetValue) (wrapper, key, value); +} + +GVariant * +ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *wrapper, + const char *key) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetValue) (wrapper, key); +} + +void +ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *wrapper, + const char *key) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperResetKey) (wrapper, key); +} + +const char ** +ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperListKeys) (wrapper); +} + +GSettings * +ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetGSettings) (wrapper); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h index 3dd5ee791..f2ed78b33 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h @@ -6,6 +6,7 @@ COMPIZCONFIG_BEGIN_DECLS #include +#include #include typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; @@ -15,6 +16,7 @@ typedef void (*CCSGSettingsWrapperSetValue) (CCSGSettingsWrapper *, const char * typedef GVariant * (*CCSGSettingsWrapperGetValue) (CCSGSettingsWrapper *, const char *); typedef void (*CCSGSettingsWrapperResetKey) (CCSGSettingsWrapper *, const char *); typedef const char ** (*CCSGSettingsWrapperListKeys) (CCSGSettingsWrapper *); +typedef GSettings * (*CCSGSettingsWrapperGetGSettings) (CCSGSettingsWrapper *); struct _CCSGSettingsWrapperInterface { @@ -22,6 +24,7 @@ struct _CCSGSettingsWrapperInterface CCSGSettingsWrapperGetValue gsettingsWrapperGetValue; CCSGSettingsWrapperResetKey gsettingsWrapperResetKey; CCSGSettingsWrapperListKeys gsettingsWrapperListKeys; + CCSGSettingsWrapperGetGSettings gsettingsWrapperGetGSettings; }; struct _CCSGSettingsWrapper @@ -29,6 +32,12 @@ struct _CCSGSettingsWrapper CCSObject object; }; +void ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *, const char *, GVariant *); +GVariant * ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *, const char *); +void ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *, const char *); +const char ** ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *); +GSettings * ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *); + unsigned int ccsCCSGSettingsWrapperInterfaceGetType (); COMPIZCONFIG_END_DECLS diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 91faf59ca..8aecab22c 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -31,16 +31,20 @@ static const char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wr return NULL; } +static GSettings * ccsGSettingsWrapperGetGSettingsDefault (CCSGSettingsWrapper *wrapper) +{ + return NULL; +} + const CCSGSettingsWrapperInterface interface = { ccsGSettingsWrapperSetValueDefault, ccsGSettingsWrapperGetValueDefault, ccsGSettingsWrapperResetKeyDefault, - ccsGSettingsWrapperListKeysDefault + ccsGSettingsWrapperListKeysDefault, + ccsGSettingsWrapperGetGSettingsDefault }; -INTERFACE_TYPE (CCSGSettingsWrapperInterface); - static CCSGSettingsWrapperPrivate * allocatePrivateWrapper (CCSObjectAllocationInterface *ai, CCSGSettingsWrapper *wrapper) { diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 08fa24acf..2f13e4879 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -56,6 +56,16 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestWrapperConstruction) EXPECT_THAT (wrapper.get (), NotNull ()); } +TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestGetGSettingsWrapper) +{ + boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), + mockPath.c_str (), + &ccsDefaultObjectAllocator), + boost::bind (ccsFreeGSettingsWrapper, _1)); + + EXPECT_THAT (ccsGSettingsWrapperGetGSettings (wrapper.get ()), NotNull ()); +} + TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestSetValueOnWrapper) { FAIL (); -- GitLab From 0ddc69d132fb7ded201d7c3641f59df48093cd17 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:19:34 +0800 Subject: [PATCH 259/562] Make that test pass --- .../ccs_gsettings_interface_wrapper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 8aecab22c..6b50ff4e3 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -33,7 +33,9 @@ static const char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wr static GSettings * ccsGSettingsWrapperGetGSettingsDefault (CCSGSettingsWrapper *wrapper) { - return NULL; + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return gswPrivate->settings; } const CCSGSettingsWrapperInterface interface = -- GitLab From d6adbbfe1df3084f54575c72a4c8e53b6965046b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:31:28 +0800 Subject: [PATCH 260/562] Refactored the testing classes so that we automatically get settings and wrapper --- .../tests/test_gsettings_wrapper.cpp | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 2f13e4879..2506af8c0 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -24,6 +24,8 @@ class TestGSettingsWrapperWithMemoryBackendEnv : { } + virtual CCSObjectAllocationInterface * GetAllocator () = 0; + virtual void SetUp () { g_setenv ("G_SLICE", "always-malloc", 1); @@ -44,9 +46,44 @@ class TestGSettingsWrapperWithMemoryBackendEnv : std::string mockSchema; std::string mockPath; + boost::shared_ptr wrapper; + GSettings *settings; +}; + +class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator : + public TestGSettingsWrapperWithMemoryBackendEnv +{ + protected: + + CCSObjectAllocationInterface * GetAllocator () + { + return &ccsDefaultObjectAllocator; + } +}; + +class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit : + public TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator +{ + public: + + virtual void SetUp () + { + TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator::SetUp (); + + wrapper.reset (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), + mockPath.c_str (), + GetAllocator ()), + boost::bind (ccsFreeGSettingsWrapper, _1)); + + ASSERT_THAT (wrapper.get (), NotNull ()); + + settings = ccsGSettingsWrapperGetGSettings (wrapper.get ()); + + ASSERT_THAT (settings, NotNull ()); + } }; -TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestWrapperConstruction) +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestWrapperConstruction) { boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), @@ -56,32 +93,33 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestWrapperConstruction) EXPECT_THAT (wrapper.get (), NotNull ()); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestGetGSettingsWrapper) +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestGetGSettingsWrapper) { boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), &ccsDefaultObjectAllocator), boost::bind (ccsFreeGSettingsWrapper, _1)); + ASSERT_THAT (wrapper.get (), NotNull ()); EXPECT_THAT (ccsGSettingsWrapperGetGSettings (wrapper.get ()), NotNull ()); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestSetValueOnWrapper) +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestSetValueOnWrapper) { FAIL (); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestGetValueOnWrapper) +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetValueOnWrapper) { FAIL (); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestResetKeyOnWrapper) +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestResetKeyOnWrapper) { FAIL (); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnv, TestListKeysOnWrapper) +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListKeysOnWrapper) { FAIL (); } -- GitLab From db6a87576d789fa84daca779e35584d29bc1b64d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:38:13 +0800 Subject: [PATCH 261/562] Failing test TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit.TestSetValueOnWrapper --- .../gsettings/tests/test_gsettings_wrapper.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 2506af8c0..c271e2bad 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -106,7 +106,17 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestGetGSettingsW TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestSetValueOnWrapper) { - FAIL (); + const unsigned int VALUE = 2; + const std::string KEY ("integer-setting"); + boost::shared_ptr variant (g_variant_new ("i", VALUE, NULL), + boost::bind (g_variant_unref, _1)); + ccsGSettingsWrapperSetValue (wrapper.get (), KEY.c_str (), variant.get ()); + + boost::shared_ptr value (g_settings_get_value (settings, KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + int v = g_variant_get_int32 (value.get ()); + EXPECT_EQ (VALUE, v); } TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetValueOnWrapper) -- GitLab From 4f76b49cdb25a05cca9a1f2e24b42055aa237290 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:39:54 +0800 Subject: [PATCH 262/562] Make that test pass --- .../gsettings_backend_shared/ccs_gsettings_interface_wrapper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 6b50ff4e3..607d281c9 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -20,6 +20,9 @@ static GVariant * ccsGSettingsWrapperGetValueDefault (CCSGSettingsWrapper *wrapp static void ccsGSettingsWrapperSetValueDefault (CCSGSettingsWrapper *wrapper, const char *key, GVariant *variant) { + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + g_settings_set_value (gswPrivate->settings, key, variant); } static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, const char *key) -- GitLab From 12391e416859e1f95ddd2b32e40fd3503f405311 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:43:12 +0800 Subject: [PATCH 263/562] Failing test TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit.TestGetValueOnWrapper --- .../gsettings/tests/test_gsettings_wrapper.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index c271e2bad..1865cd9df 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -121,7 +121,17 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestSetVa TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetValueOnWrapper) { - FAIL (); + const double VALUE = 3.0; + const std::string KEY ("float-setting"); + boost::shared_ptr variant (g_variant_new ("i", VALUE, NULL), + boost::bind (g_variant_unref, _1)); + g_settings_set_value (settings, KEY.c_str (), variant.get ()); + boost::shared_ptr value (ccsGSettingsWrapperGetValue (wrapper.get (), + KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + double v = (double) g_variant_get_double (value.get ()); + EXPECT_EQ (VALUE, v); } TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestResetKeyOnWrapper) -- GitLab From f27c4642ec862d26e70f036b00fd0a3418893f81 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:44:34 +0800 Subject: [PATCH 264/562] Make it pass --- .../ccs_gsettings_interface_wrapper.c | 4 +++- compizconfig/gsettings/tests/test_gsettings_wrapper.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 607d281c9..a348ed549 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -15,7 +15,9 @@ struct _CCSGSettingsWrapperPrivate static GVariant * ccsGSettingsWrapperGetValueDefault (CCSGSettingsWrapper *wrapper, const char *key) { - return NULL; + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return g_settings_get_value (gswPrivate->settings, key); } static void ccsGSettingsWrapperSetValueDefault (CCSGSettingsWrapper *wrapper, const char *key, GVariant *variant) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 1865cd9df..945c3cd8a 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -123,7 +123,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetVa { const double VALUE = 3.0; const std::string KEY ("float-setting"); - boost::shared_ptr variant (g_variant_new ("i", VALUE, NULL), + boost::shared_ptr variant (g_variant_new ("d", VALUE, NULL), boost::bind (g_variant_unref, _1)); g_settings_set_value (settings, KEY.c_str (), variant.get ()); boost::shared_ptr value (ccsGSettingsWrapperGetValue (wrapper.get (), -- GitLab From 5ecf314ead74dc055c916f322f01e1a6b6817563 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:51:27 +0800 Subject: [PATCH 265/562] Failing test TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit.TestResetKeyOnWrappe --- .../tests/test_gsettings_wrapper.cpp | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 945c3cd8a..2ac271458 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -1,3 +1,5 @@ +#include + #include #include @@ -12,6 +14,7 @@ #include using ::testing::NotNull; +using ::testing::Eq; class TestGSettingsWrapperWithMemoryBackendEnv : public ::testing::Test @@ -136,7 +139,29 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetVa TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestResetKeyOnWrapper) { - FAIL (); + const char * DEFAULT = ""; + const char * VALUE = "foo"; + const std::string KEY ("string-setting"); + boost::shared_ptr variant (g_variant_new ("s", VALUE, NULL), + boost::bind (g_variant_unref, _1)); + ccsGSettingsWrapperSetValue (wrapper.get (), KEY.c_str (), variant.get ()); + + boost::shared_ptr value (g_settings_get_value (settings, KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + gsize length; + const char *v = g_variant_get_string (value.get (), &length); + ASSERT_EQ (strlen (VALUE), length); + ASSERT_THAT (v, Eq (VALUE)); + + ccsGSettingsWrapperResetKey (wrapper.get (), v); + + value.reset (g_settings_get_value (settings, KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + v = g_variant_get_string (value.get (), &length); + ASSERT_EQ (strlen (DEFAULT), length); + ASSERT_THAT (v, Eq (DEFAULT)); } TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListKeysOnWrapper) -- GitLab From 6b5e2e546870313f80c138cdc4f13f8156ab346a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 11:54:58 +0800 Subject: [PATCH 266/562] Make the test pass --- .../ccs_gsettings_interface_wrapper.c | 3 +++ compizconfig/gsettings/tests/test_gsettings_wrapper.cpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index a348ed549..7e47a375b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -29,6 +29,9 @@ static void ccsGSettingsWrapperSetValueDefault (CCSGSettingsWrapper *wrapper, co static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, const char *key) { + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + g_settings_reset (gswPrivate->settings, key); } static const char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 2ac271458..f6c116530 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -150,16 +150,16 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestReset boost::bind (g_variant_unref, _1)); gsize length; - const char *v = g_variant_get_string (value.get (), &length); + std::string v (g_variant_get_string (value.get (), &length)); ASSERT_EQ (strlen (VALUE), length); ASSERT_THAT (v, Eq (VALUE)); - ccsGSettingsWrapperResetKey (wrapper.get (), v); + ccsGSettingsWrapperResetKey (wrapper.get (), KEY.c_str ()); value.reset (g_settings_get_value (settings, KEY.c_str ()), boost::bind (g_variant_unref, _1)); - v = g_variant_get_string (value.get (), &length); + v = std::string (g_variant_get_string (value.get (), &length)); ASSERT_EQ (strlen (DEFAULT), length); ASSERT_THAT (v, Eq (DEFAULT)); } -- GitLab From c74822271e513ca362ccc77792065c61029c06f4 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 12:01:24 +0800 Subject: [PATCH 267/562] Failing test TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit.TestListKeysOnWrapper (updated API too) --- .../ccs_gsettings_interface.c | 2 +- .../ccs_gsettings_interface.h | 4 ++-- .../ccs_gsettings_interface_wrapper.c | 2 +- .../gsettings/tests/test_gsettings_wrapper.cpp | 12 +++++++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c index 9484f5a5f..c4e8830c5 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c @@ -25,7 +25,7 @@ ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *wrapper, return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperResetKey) (wrapper, key); } -const char ** +char ** ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *wrapper) { return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperListKeys) (wrapper); diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h index f2ed78b33..f432adb09 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h @@ -15,7 +15,7 @@ typedef struct _CCSGSettingsWrapperInterface CCSGSettingsWrapperInterface; typedef void (*CCSGSettingsWrapperSetValue) (CCSGSettingsWrapper *, const char *, GVariant *); typedef GVariant * (*CCSGSettingsWrapperGetValue) (CCSGSettingsWrapper *, const char *); typedef void (*CCSGSettingsWrapperResetKey) (CCSGSettingsWrapper *, const char *); -typedef const char ** (*CCSGSettingsWrapperListKeys) (CCSGSettingsWrapper *); +typedef char ** (*CCSGSettingsWrapperListKeys) (CCSGSettingsWrapper *); typedef GSettings * (*CCSGSettingsWrapperGetGSettings) (CCSGSettingsWrapper *); struct _CCSGSettingsWrapperInterface @@ -35,7 +35,7 @@ struct _CCSGSettingsWrapper void ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *, const char *, GVariant *); GVariant * ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *, const char *); void ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *, const char *); -const char ** ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *); +char **ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *); GSettings * ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *); unsigned int ccsCCSGSettingsWrapperInterfaceGetType (); diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 7e47a375b..f7942d53b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -34,7 +34,7 @@ static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, co g_settings_reset (gswPrivate->settings, key); } -static const char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper) +static char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper) { return NULL; } diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index f6c116530..608455063 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -166,5 +166,15 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestReset TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListKeysOnWrapper) { - FAIL (); + const char * EXPECTED_KEYS[] = + { + "bar" + }; + + boost::shared_ptr keys (ccsGSettingsWrapperListKeys (wrapper.get ()), + boost::bind (g_strfreev, _1)); + + ASSERT_EQ (g_strv_length (keys.get ()), + sizeof (EXPECTED_KEYS) / + sizeof (EXPECTED_KEYS[0])); } -- GitLab From 768f235bfaf99328be3d96073e6e9590eb7d7811 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 12:05:38 +0800 Subject: [PATCH 268/562] Make that test pass --- .../ccs_gsettings_interface_wrapper.c | 4 +++- .../gsettings/tests/test_gsettings_wrapper.cpp | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index f7942d53b..8f2324776 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -36,7 +36,9 @@ static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, co static char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper) { - return NULL; + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return g_settings_list_keys (gswPrivate->settings); } static GSettings * ccsGSettingsWrapperGetGSettingsDefault (CCSGSettingsWrapper *wrapper) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 608455063..35c6bc87a 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -168,7 +168,22 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListK { const char * EXPECTED_KEYS[] = { - "bar" + "bell-setting", + "bool-list-setting", + "boolean-setting", + "button-setting", + "color-list-setting", + "color-setting", + "edge-setting", + "float-list-setting", + "float-setting", + "int-list-setting", + "integer-setting", + "key-setting", + "match-list-setting", + "match-setting", + "string-list-setting", + "string-setting" }; boost::shared_ptr keys (ccsGSettingsWrapperListKeys (wrapper.get ()), -- GitLab From 2c366c976ac70fc352dd5cad5351669285893c8f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 12:11:19 +0800 Subject: [PATCH 269/562] Fix weird unref behaviour in g_settings_reset --- compizconfig/gsettings/tests/test_gsettings_wrapper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 35c6bc87a..ed7660999 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -154,6 +154,10 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestReset ASSERT_EQ (strlen (VALUE), length); ASSERT_THAT (v, Eq (VALUE)); + /* g_settings_reset appears to unref the value, + * so we need to keep it alive */ + g_variant_ref (value.get ()); + ccsGSettingsWrapperResetKey (wrapper.get (), KEY.c_str ()); value.reset (g_settings_get_value (settings, KEY.c_str ()), -- GitLab From 1eeaff21e0093b55056ff88df3a10f0adcce9ef4 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 12:21:36 +0800 Subject: [PATCH 270/562] Move CCSREF_OBJ definition to ccs-object.h --- compizconfig/libcompizconfig/include/ccs-object.h | 11 +++++++++++ compizconfig/libcompizconfig/src/main.c | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-object.h b/compizconfig/libcompizconfig/include/ccs-object.h index c01f0fc2e..1c96d2fcb 100644 --- a/compizconfig/libcompizconfig/include/ccs-object.h +++ b/compizconfig/libcompizconfig/include/ccs-object.h @@ -124,6 +124,17 @@ ccsAllocateType (); #define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) +#define CCSREF_OBJ(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + ccsObjectRef (d); \ + } \ + \ + void ccs##type##Unref (dtype *d) \ + { \ + ccsObjectUnref (d, ccsFree##type); \ + } \ + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 7d22f2c6b..cd5d53535 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -987,17 +987,6 @@ CCSREF (IntDesc, CCSIntDesc) CCSREF (StrRestriction, CCSStrRestriction) CCSREF (StrExtension, CCSStrExtension) -#define CCSREF_OBJ(type,dtype) \ - void ccs##type##Ref (dtype *d) \ - { \ - ccsObjectRef (d); \ - } \ - \ - void ccs##type##Unref (dtype *d) \ - { \ - ccsObjectUnref (d, ccsFree##type); \ - } \ - CCSREF_OBJ (Plugin, CCSPlugin) CCSREF_OBJ (Setting, CCSSetting) CCSREF_OBJ (Backend, CCSBackend) -- GitLab From 9245814726e15507f07e7b3f991ada403273032f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:23:54 +0800 Subject: [PATCH 271/562] Converted everything over to use the wrapper interface, some tests are disabled as they don't compile, added failing tests to areas where we had to expand the wrapper interface --- .../ccs_gsettings_interface.c | 27 +++++ .../ccs_gsettings_interface.h | 14 +++ .../ccs_gsettings_interface_wrapper.c | 70 ++++++++---- .../ccs_gsettings_interface_wrapper.h | 5 +- .../gsettings_backend_shared/gsettings_util.c | 35 +++--- .../gsettings_backend_shared/gsettings_util.h | 30 +++--- compizconfig/gsettings/src/gsettings.c | 102 +++++++++++------- compizconfig/gsettings/src/gsettings.h | 5 +- .../tests/ccs_gsettings_backend_mock.h | 20 ++-- .../gsettings/tests/test_gsettings_tests.cpp | 4 +- .../tests/test_gsettings_wrapper.cpp | 43 ++++++++ .../libcompizconfig/include/ccs-defs.h | 18 ++++ compizconfig/libcompizconfig/include/ccs.h | 19 ---- 13 files changed, 262 insertions(+), 130 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c index c4e8830c5..a93efd0e8 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c @@ -2,6 +2,7 @@ #include "ccs_gsettings_interface.h" INTERFACE_TYPE (CCSGSettingsWrapperInterface); +CCSREF_OBJ (GSettingsWrapper, CCSGSettingsWrapper); void ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *wrapper, @@ -36,3 +37,29 @@ ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *wrapper) { return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetGSettings) (wrapper); } + +const char * +ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetSchemaName) (wrapper); +} + +const char * +ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetPath) (wrapper); +} + +void +ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *wrapper, + GCallback callback, + gpointer data) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperConnectToChangedSignal) (wrapper, callback, data); +} + +void +ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperFree) (wrapper); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h index f432adb09..01484fff4 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h @@ -17,6 +17,10 @@ typedef GVariant * (*CCSGSettingsWrapperGetValue) (CCSGSettingsWrapper *, const typedef void (*CCSGSettingsWrapperResetKey) (CCSGSettingsWrapper *, const char *); typedef char ** (*CCSGSettingsWrapperListKeys) (CCSGSettingsWrapper *); typedef GSettings * (*CCSGSettingsWrapperGetGSettings) (CCSGSettingsWrapper *); +typedef const char * (*CCSGSettingsWrapperGetSchemaName) (CCSGSettingsWrapper *); +typedef const char * (*CCSGSettingsWrapperGetPath) (CCSGSettingsWrapper *); +typedef void (*CCSGSettingsWrapperConnectToChangedSignal) (CCSGSettingsWrapper *, GCallback, gpointer); +typedef void (*CCSGSettingsWrapperFree) (CCSGSettingsWrapper *); struct _CCSGSettingsWrapperInterface { @@ -25,6 +29,10 @@ struct _CCSGSettingsWrapperInterface CCSGSettingsWrapperResetKey gsettingsWrapperResetKey; CCSGSettingsWrapperListKeys gsettingsWrapperListKeys; CCSGSettingsWrapperGetGSettings gsettingsWrapperGetGSettings; + CCSGSettingsWrapperGetSchemaName gsettingsWrapperGetSchemaName; + CCSGSettingsWrapperGetPath gsettingsWrapperGetPath; + CCSGSettingsWrapperConnectToChangedSignal gsettingsWrapperConnectToChangedSignal; + CCSGSettingsWrapperFree gsettingsWrapperFree; }; struct _CCSGSettingsWrapper @@ -37,9 +45,15 @@ GVariant * ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *, const char *); void ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *, const char *); char **ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *); GSettings * ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *); +const char * ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *); +const char * ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *); +void ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *, GCallback, gpointer); +void ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper); unsigned int ccsCCSGSettingsWrapperInterfaceGetType (); +CCSREF_HDR (GSettingsWrapper, CCSGSettingsWrapper); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 8f2324776..d03a590b8 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -48,13 +48,59 @@ static GSettings * ccsGSettingsWrapperGetGSettingsDefault (CCSGSettingsWrapper * return gswPrivate->settings; } +static const char * +ccsGSettingsWrapperGetSchemaNameDefault (CCSGSettingsWrapper *wrapper) +{ + return NULL; +} + +static const char * +ccsGSettingsWrapperGetPathDefault (CCSGSettingsWrapper *wrapper) +{ + return NULL; +} + +void +ccsGSettingsWrapperConnectToChangedSignalDefault (CCSGSettingsWrapper *wrapper, + GCallback callback, + gpointer data) +{ + //g_signal_connect (object, "changed", (GCallback) valueChanged, (gpointer) backend); +} + +static void +ccsFreeGSettingsWrapperDefault (CCSGSettingsWrapper *wrapper) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + if (gswPrivate->settings) + g_object_unref (gswPrivate->settings); + + if (gswPrivate->path) + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + gswPrivate->path); + + if (gswPrivate->schema) + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + gswPrivate->schema); + + ccsObjectFinalize (wrapper); + + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + wrapper); +} + const CCSGSettingsWrapperInterface interface = { ccsGSettingsWrapperSetValueDefault, ccsGSettingsWrapperGetValueDefault, ccsGSettingsWrapperResetKeyDefault, ccsGSettingsWrapperListKeysDefault, - ccsGSettingsWrapperGetGSettingsDefault + ccsGSettingsWrapperGetGSettingsDefault, + ccsGSettingsWrapperGetSchemaNameDefault, + ccsGSettingsWrapperGetPathDefault, + ccsGSettingsWrapperConnectToChangedSignalDefault, + ccsFreeGSettingsWrapperDefault }; static CCSGSettingsWrapperPrivate * @@ -205,25 +251,3 @@ ccsGSettingsWrapperNewForSchema (const char *schema, return wrapper; } - -void -ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) -{ - GSETTINGS_WRAPPER_PRIVATE (wrapper); - - if (gswPrivate->settings) - g_object_unref (gswPrivate->settings); - - if (gswPrivate->path) - (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, - gswPrivate->path); - - if (gswPrivate->schema) - (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, - gswPrivate->schema); - - ccsObjectFinalize (wrapper); - - (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, - wrapper); -} diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h index be3304b9d..4535f10ee 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h @@ -12,8 +12,9 @@ ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, const char *path, CCSObjectAllocationInterface *ai); -void -ccsFreeGSettingsWrapper (CCSGSettingsWrapper *); +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchema (const char *schema, + CCSObjectAllocationInterface *ai); COMPIZCONFIG_END_DECLS diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index dccb6b1ab..5665abe7a 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -51,23 +51,18 @@ variantTypeToPossibleSettingType (const gchar *vt) return possibleTypesList; } -GObject * -findObjectInListWithPropertySchemaName (const gchar *schemaName, - GList *iter) +CCSGSettingsWrapper * +findCCSGSettingsWrapperBySchemaName (const gchar *schemaName, + GList *iter) { while (iter) { - GObject *obj = (GObject *) iter->data; - gchar *name = NULL; + CCSGSettingsWrapper *obj = iter->data; + const gchar *name = ccsGSettingsWrapperGetSchemaName (obj); - g_object_get (obj, - "schema", - &name, NULL); if (g_strcmp0 (name, schemaName) != 0) obj = NULL; - g_free (name); - if (obj) return obj; else @@ -341,7 +336,7 @@ attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *l } Bool -findSettingAndPluginToUpdateFromPath (GSettings *settings, +findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, const char *path, const gchar *keyName, CCSContext *context, @@ -366,7 +361,7 @@ findSettingAndPluginToUpdateFromPath (GSettings *settings, { /* Couldn't find setting straight off the bat, * try and find the best match */ - GVariant *value = g_settings_get_value (settings, keyName); + GVariant *value = ccsGSettingsWrapperGetValue (settings, keyName); if (value) { @@ -401,7 +396,7 @@ findSettingAndPluginToUpdateFromPath (GSettings *settings, Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, - GSettings *settings, + CCSGSettingsWrapper *settings, gchar *keyName, CCSBackendUpdateFunc updateSetting) { @@ -412,7 +407,7 @@ updateSettingWithGSettingsKeyName (CCSBackend *backend, CCSSetting *setting; Bool ret = TRUE; - g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); + pathOrig = strdup (ccsGSettingsWrapperGetPath (settings)); if (findSettingAndPluginToUpdateFromPath (settings, pathOrig, keyName, context, &plugin, &setting, &uncleanKeyName)) (*updateSetting) (backend, context, plugin, setting); @@ -480,9 +475,9 @@ checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gc } GVariant * -getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCSSettingType type) +getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pathName, CCSSettingType type) { - GVariant *gsettingsValue = g_settings_get_value (settings, key); + GVariant *gsettingsValue = ccsGSettingsWrapperGetValue (settings, key); if (!checkReadVariantIsValid (gsettingsValue, type, pathName)) { @@ -934,11 +929,11 @@ Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) } void -writeVariantToKey (GSettings *settings, +writeVariantToKey (CCSGSettingsWrapper *settings, const char *key, GVariant *value) { - g_settings_set_value (settings, key, value); + ccsGSettingsWrapperSetValue (settings, key, value); } typedef void (*VariantItemCheckAndInsertFunc) (GVariantBuilder *, const char *item, void *userData); @@ -1100,12 +1095,12 @@ ccsGSettingsBackendGetContext (CCSBackend *backend) void ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, - GObject *object) + CCSGSettingsWrapper *object) { (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendConnectToChangedSignal) (backend, object); } -GSettings * +CCSGSettingsWrapper * ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, const char *plugin, const char *path, diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 5c7adfb22..6978e11d1 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -10,17 +10,19 @@ COMPIZCONFIG_BEGIN_DECLS #include #include +#include "ccs_gsettings_interface.h" + typedef struct _CCSGSettingsBackendPrivate CCSGSettingsBackendPrivate; typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; extern const CCSBackendInfo gsettingsBackendInfo; typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); -typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, GObject *); -typedef GSettings * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CCSBackend *backend, - const char *plugin, - const char *path, - CCSContext *context); +typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, CCSGSettingsWrapper *); +typedef CCSGSettingsWrapper * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context); typedef void (*CCSGSettingsBackendRegisterGConfClient) (CCSBackend *backend); typedef void (*CCSGSettingsBackendUnregisterGConfClient) (CCSBackend *backend); @@ -94,9 +96,9 @@ appendToPluginsWithSetKeysList (const gchar *plugin, char ***newWrittenPlugins, gsize *newWrittenPluginsSize); -GObject * -findObjectInListWithPropertySchemaName (const gchar *schemaName, - GList *iter); +CCSGSettingsWrapper * +findCCSGSettingsWrapperBySchemaName (const gchar *schemaName, + GList *iter); CCSSettingList filterAllSettingsMatchingType (CCSSettingType type, @@ -110,7 +112,7 @@ CCSSetting * attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *lossyName, CCSSettingType type); Bool -findSettingAndPluginToUpdateFromPath (GSettings *settings, +findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, const char *path, const gchar *keyName, CCSContext *context, @@ -119,7 +121,7 @@ findSettingAndPluginToUpdateFromPath (GSettings *settings, char **uncleanKeyName); Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, - GSettings *settings, + CCSGSettingsWrapper *settings, gchar *keyName, CCSBackendUpdateFunc updateSetting); @@ -139,7 +141,7 @@ Bool checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName); GVariant * -getVariantAtKey (GSettings *settings, const char *key, const char *pathName, CCSSettingType type); +getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pathName, CCSSettingType type); const char * readStringFromVariant (GVariant *gsettingsValue); @@ -181,7 +183,7 @@ Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant); Bool writeEdgeToVariant (unsigned int edges, GVariant **variant); -void writeVariantToKey (GSettings *settings, +void writeVariantToKey (CCSGSettingsWrapper *settings, const char *key, GVariant *value); @@ -228,9 +230,9 @@ CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend); void -ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, GObject *object); +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, CCSGSettingsWrapper *object); -GSettings * +CCSGSettingsWrapper * ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, const char *plugin, const char *path, diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 274628f85..a179e3a4c 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -34,6 +34,7 @@ #define CCS_LOG_DOMAIN "gsettings" #include "gsettings.h" +#include static void valueChanged (GSettings *settings, @@ -46,13 +47,13 @@ static void writeIntegratedOption (CCSBackend *backend, CCSSetting *setting, int index); -static GSettings * +static CCSGSettingsWrapper * ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backend, const char *plugin, const char *path, CCSContext *context) { - GSettings *settingsObj = NULL; + CCSGSettingsWrapper *settingsObj = NULL; gchar *schemaName = getSchemaNameForPlugin (plugin); GVariant *writtenPlugins; gsize newWrittenPluginsSize; @@ -60,7 +61,7 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - settingsObj = (GSettings *) findObjectInListWithPropertySchemaName (schemaName, priv->settingsList); + settingsObj = findCCSGSettingsWrapperBySchemaName (schemaName, priv->settingsList); if (settingsObj) { @@ -70,10 +71,8 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen /* No existing settings object found for this schema, create one */ - settingsObj = g_settings_new_with_path (schemaName, path); - - ccsGSettingsBackendConnectToChangedSignal (backend, G_OBJECT (settingsObj)); - + settingsObj = ccsGSettingsWrapperNewForSchemaWithPath (schemaName, path, &ccsDefaultObjectAllocator); + ccsGSettingsBackendConnectToChangedSignal (backend, settingsObj); priv->settingsList = g_list_append (priv->settingsList, (void *) settingsObj); /* Also write the plugin name to the list of modified plugins so @@ -82,12 +81,15 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen * store keys that have changed from their defaults ... though * gsettings doesn't seem to give you a way to get all of the schemas */ - writtenPlugins = g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); + writtenPlugins = ccsGSettingsWrapperGetValue (priv->currentProfileSettings, "plugins-with-set-keys"); appendToPluginsWithSetKeysList (plugin, writtenPlugins, &newWrittenPlugins, &newWrittenPluginsSize); - g_settings_set_strv (priv->currentProfileSettings, "plugins-with-set-keys", (const gchar * const *)newWrittenPlugins); + GVariant *newWrittenPluginsVariant = g_variant_new_strv ((const gchar * const *) newWrittenPlugins, newWrittenPluginsSize); + ccsGSettingsWrapperSetValue (priv->currentProfileSettings, "plugins-with-set-keys", newWrittenPluginsVariant); + + g_variant_unref (newWrittenPluginsVariant); g_variant_unref (writtenPlugins); g_free (schemaName); g_strfreev (newWrittenPlugins); @@ -99,13 +101,13 @@ static gchar * makeSettingPath (const char *currentProfile, CCSSetting *setting) { return makeCompizPluginPath (currentProfile, - ccsPluginGetName (ccsSettingGetParent (setting))); + ccsPluginGetName (ccsSettingGetParent (setting))); } -static GSettings * +static CCSGSettingsWrapper * getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) { - GSettings *ret = NULL; + CCSGSettingsWrapper *ret = NULL; CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); gchar *pathName = makeSettingPath (priv->currentProfile, setting); @@ -154,8 +156,19 @@ valueChanged (GSettings *settings, gpointer user_data) { CCSBackend *backend = (CCSBackend *)user_data; + GValue schemaNameValue = G_VALUE_INIT; + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + + g_value_init (&schemaNameValue, G_TYPE_STRING); + g_object_get_property (G_OBJECT (settings), "schema-id", &schemaNameValue); + + const char *schemaName = g_value_get_string (&schemaNameValue); + CCSGSettingsWrapper *wrapper = findCCSGSettingsWrapperBySchemaName (schemaName, priv->settingsList); + + g_value_unset (&schemaNameValue); - updateSettingWithGSettingsKeyName (backend, settings, keyName, updateSetting); + updateSettingWithGSettingsKeyName (backend, wrapper, keyName, updateSetting); } static Bool @@ -175,7 +188,7 @@ static GVariant * getVariantForCCSSetting (CCSBackend *backend, CCSSetting *setting) { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = getNameForCCSSetting (setting); gchar *pathName = makeSettingPath (priv->currentProfile, setting); GVariant *gsettingsValue = getVariantAtKey (settings, @@ -358,11 +371,10 @@ writeIntegratedOption (CCSBackend *backend, static void resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) { - GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); - + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - g_settings_reset (settings, cleanSettingName); + ccsGSettingsWrapperResetKey (settings, cleanSettingName); free (cleanSettingName); } @@ -370,7 +382,7 @@ resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) void writeOption (CCSBackend *backend, CCSSetting * setting) { - GSettings *settings = getSettingsObjectForCCSSetting (backend, setting); + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); GVariant *gsettingsValue = NULL; Bool success = FALSE; @@ -507,7 +519,7 @@ getCurrentProfileName (CCSBackend *backend) CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - value = g_settings_get_value (priv->compizconfigSettings, "current-profile"); + value = ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "current-profile"); if (value) ret = strdup (g_variant_get_string (value, NULL)); @@ -538,9 +550,9 @@ ccsGSettingsBackendGetContextDefault (CCSBackend *backend) } static void -ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, GObject *object) +ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, CCSGSettingsWrapper *wrapper) { - g_signal_connect (object, "changed", (GCallback) valueChanged, (gpointer) backend); + ccsGSettingsWrapperConnectToChangedSignal (wrapper, (GCallback) valueChanged, (gpointer) backend); } static void @@ -575,7 +587,7 @@ ccsGSettingsBackendGetExistingProfilesDefault (CCSBackend *backend) { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - return g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); + return ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "existing-profiles"); } static void @@ -583,7 +595,7 @@ ccsGSettingsBackendSetExistingProfilesDefault (CCSBackend *backend, GVariant *va { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - g_settings_set_value (priv->compizconfigSettings, "existing-profiles", value); + ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "existing-profiles", value); } static void @@ -597,13 +609,18 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v free (priv->currentProfile); if (priv->currentProfileSettings) - g_object_unref (priv->currentProfileSettings); + ccsGSettingsWrapperUnref (priv->currentProfileSettings); priv->currentProfile = strdup (value); - priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); + priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, + profilePath, + backend->object.object_allocation->allocator); - g_settings_set (priv->compizconfigSettings, "current-profile", "s", value, NULL); + GVariant *currentProfileVariant = g_variant_new ("s", value, NULL); + ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "current-profile", currentProfileVariant); + + g_variant_unref (currentProfileVariant); g_free (profilePath); } @@ -611,14 +628,14 @@ GVariant * ccsGSettingsBackendGetPluginsWithSetKeysDefault (CCSBackend *backend) { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - return g_settings_get_value (priv->currentProfileSettings, "plugins-with-set-keys"); + return ccsGSettingsWrapperGetValue (priv->currentProfileSettings, "plugins-with-set-keys"); } void ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend) { CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - g_settings_reset (priv->currentProfileSettings, "plugins-with-set-keys"); + ccsGSettingsWrapperResetKey (priv->currentProfileSettings, "plugins-with-set-keys"); } static void @@ -633,7 +650,7 @@ ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backen g_variant_iter_init (&iter, pluginsWithChangedKeys); while (g_variant_iter_loop (&iter, "s", &plugin)) { - GSettings *settings; + CCSGSettingsWrapper *settings; gchar *pathName = makeCompizPluginPath (profile, plugin); settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); @@ -644,12 +661,12 @@ ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backen * we don't because we autogenerate schemas ... */ if (settings) { - char **keys = g_settings_list_keys (settings); + char **keys = ccsGSettingsWrapperListKeys (settings); char **key_ptr; /* Unset all the keys */ for (key_ptr = keys; *key_ptr; key_ptr++) - g_settings_reset (settings, *key_ptr); + ccsGSettingsWrapperResetKey (settings, *key_ptr); g_strfreev (keys); } @@ -689,11 +706,13 @@ initBackend (CCSBackend *backend, CCSContext * context) ccsObjectSetPrivate (backend, (CCSPrivate *) priv); - priv->compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); - + priv->compizconfigSettings = ccsGSettingsWrapperNewForSchema (COMPIZCONFIG_SCHEMA_ID, + backend->object.object_allocation->allocator); priv->currentProfile = getCurrentProfileName (backend); currentProfilePath = makeCompizProfilePath (priv->currentProfile); - priv->currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath); + priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, + currentProfilePath, + backend->object.object_allocation->allocator); priv->context = context; g_free (currentProfilePath); @@ -701,6 +720,12 @@ initBackend (CCSBackend *backend, CCSContext * context) return TRUE; } +static void +ccsGSettingsWrapperDestroyNotify (gpointer o) +{ + ccsGSettingsWrapperUnref ((CCSGSettingsWrapper *) o); +} + static Bool finiBackend (CCSBackend *backend) { @@ -716,17 +741,16 @@ finiBackend (CCSBackend *backend) priv->currentProfile = NULL; } - g_list_free_full (priv->settingsList, g_object_unref); - + g_list_free_full (priv->settingsList, ccsGSettingsWrapperDestroyNotify); priv->settingsList = NULL; if (priv->currentProfileSettings) { - g_object_unref (priv->currentProfileSettings); + ccsGSettingsWrapperUnref (priv->currentProfileSettings); priv->currentProfileSettings = NULL; } - g_object_unref (G_OBJECT (priv->compizconfigSettings)); + ccsGSettingsWrapperUnref (priv->compizconfigSettings); priv->compizconfigSettings = NULL; @@ -820,7 +844,7 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - value = g_settings_get_value (priv->compizconfigSettings, "existing-profiles"); + value = ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "existing-profiles"); g_variant_iter_init (&iter, value); while (g_variant_iter_loop (&iter, "s", &profile)) { diff --git a/compizconfig/gsettings/src/gsettings.h b/compizconfig/gsettings/src/gsettings.h index b29b6f024..5d9b8fdc0 100644 --- a/compizconfig/gsettings/src/gsettings.h +++ b/compizconfig/gsettings/src/gsettings.h @@ -62,6 +62,7 @@ #include #endif +#include typedef enum { OptionInt, @@ -74,8 +75,8 @@ typedef enum { struct _CCSGSettingsBackendPrivate { GList *settingsList; - GSettings *compizconfigSettings; - GSettings *currentProfileSettings; + CCSGSettingsWrapper *compizconfigSettings; + CCSGSettingsWrapper *currentProfileSettings; char *currentProfile; CCSContext *context; diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h index a629aa059..ef05a1b3b 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -20,10 +20,10 @@ class CCSGSettingsBackendGMockInterface virtual ~CCSGSettingsBackendGMockInterface () {} virtual CCSContext * getContext () = 0; - virtual void connectToChangedSignal (GObject *) = 0; - virtual GSettings * getSettingsObjectForPluginWithPath (const char * plugin, - const char * path, - CCSContext * context) = 0; + virtual void connectToChangedSignal (CCSGSettingsWrapper *) = 0; + virtual CCSGSettingsWrapper * getSettingsObjectForPluginWithPath (const char * plugin, + const char * path, + CCSContext * context) = 0; virtual void registerGConfClient () = 0; virtual void unregisterGConfClient () = 0; virtual const char * getCurrentProfile () = 0; @@ -48,10 +48,10 @@ class CCSGSettingsBackendGMock : } MOCK_METHOD0 (getContext, CCSContext * ()); - MOCK_METHOD1 (connectToChangedSignal, void (GObject *)); - MOCK_METHOD3 (getSettingsObjectForPluginWithPath, GSettings * (const char * plugin, - const char * path, - CCSContext * context)); + MOCK_METHOD1 (connectToChangedSignal, void (CCSGSettingsWrapper *)); + MOCK_METHOD3 (getSettingsObjectForPluginWithPath, CCSGSettingsWrapper * (const char * plugin, + const char * path, + CCSContext * context)); MOCK_METHOD0 (registerGConfClient, void ()); MOCK_METHOD0 (unregisterGConfClient, void ()); MOCK_METHOD0 (getCurrentProfile, const char * ()); @@ -79,12 +79,12 @@ class CCSGSettingsBackendGMock : } static void - ccsGSettingsBackendConnectToValueChangedSignal (CCSBackend *backend, GObject *object) + ccsGSettingsBackendConnectToValueChangedSignal (CCSBackend *backend, CCSGSettingsWrapper *object) { (reinterpret_cast (ccsObjectGetPrivate (backend)))->connectToChangedSignal(object); } - static GSettings * + static CCSGSettingsWrapper * ccsGSettingsBackendGetSettingsObjectForPluginWithPath (CCSBackend *backend, const char *plugin, const char *path, diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 6559a5f0e..53eead75b 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -12,6 +12,7 @@ #include "gtest_shared_characterwrapper.h" #include "compizconfig_test_value_combiners.h" #include "compizconfig_ccs_mocked_allocator.h" +//#include "ccs_gsettings_wrapper_mock.h" using ::testing::Values; using ::testing::ValuesIn; @@ -663,7 +664,7 @@ TEST_F(CCSGSettingsTestPluginsWithSetKeysGVariantSetup, TestAppendToPluginsWithS EXPECT_EQ (std::string (newWrittenPlugins[0]), std::string ("foo")); EXPECT_EQ (std::string (newWrittenPlugins[1]), std::string ("bar")); } - +/* class CCSGSettingsTestGObjectListWithProperty : public CCSGSettingsTestIndependent { @@ -717,6 +718,7 @@ TEST_F(CCSGSettingsTestGObjectListWithProperty, TestNoFindNonexistingObjectWithS EXPECT_EQ (NULL, findObjectInListWithPropertySchemaName ("foo", objectSchemaList)); } +*/ class CCSGSettingsTestFindSettingLossy : public CCSGSettingsTestIndependent diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index ed7660999..054a867c2 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -197,3 +197,46 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListK sizeof (EXPECTED_KEYS) / sizeof (EXPECTED_KEYS[0])); } + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetSchemaName) +{ + FAIL (); +} + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetPath) +{ + FAIL (); +} + +namespace signal_test +{ + class VerificationInterface + { + public: + + virtual ~VerificationInterface () {} + virtual void Verify (GSettings *settings, gchar *keyname) = 0; + }; + + class VerificationMock : + public VerificationInterface + { + public: + + MOCK_METHOD2 (Verify, void (GSettings *settings, gchar *keyname)); + }; + + + void dummyChangedSignal (GSettings *s, + gchar *keyName, + gpointer user_data) + { + VerificationInterface *verifier = reinterpret_cast (user_data); + verifier->Verify (s, keyName); + } +} + +TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestConnectToChangedSignal) +{ + FAIL (); +} diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h b/compizconfig/libcompizconfig/include/ccs-defs.h index 5c1bb43d7..1da27ac33 100644 --- a/compizconfig/libcompizconfig/include/ccs-defs.h +++ b/compizconfig/libcompizconfig/include/ccs-defs.h @@ -47,6 +47,24 @@ COMPIZCONFIG_BEGIN_DECLS #define FALSE 0 #endif +/** + * reference counting + * + * ccsSettingRef + * References the settings object so it can be kept in a list and + * unreferenced later with freeObj (mixed with objects that need + * to be freed and need not be freed) + * + * ccsSettingUnref + * Unreferences the settings object, when the reference count reaches + * zero, the object is freed + * + */ + +#define CCSREF_HDR(type,dtype) \ + void ccs##type##Ref (dtype *); \ + void ccs##type##Unref (dtype *); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index dced698b5..7833c58f5 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -92,25 +92,6 @@ CCSLIST_HDR (IntDesc, CCSIntDesc) CCSLIST_HDR (StrRestriction, CCSStrRestriction) CCSLIST_HDR (StrExtension, CCSStrExtension) - -/** - * reference counting - * - * ccsSettingRef - * References the settings object so it can be kept in a list and - * unreferenced later with freeObj (mixed with objects that need - * to be freed and need not be freed) - * - * ccsSettingUnref - * Unreferences the settings object, when the reference count reaches - * zero, the object is freed - * - */ - -#define CCSREF_HDR(type,dtype) \ - void ccs##type##Ref (dtype *); \ - void ccs##type##Unref (dtype *); - CCSREF_HDR (Plugin, CCSPlugin) CCSREF_HDR (Setting, CCSSetting) CCSREF_HDR (String, CCSString) -- GitLab From 67eb5da100251e20c28487f5b4e014f339912d5b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:25:55 +0800 Subject: [PATCH 272/562] Failing test TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit.TestGetSchemaName --- compizconfig/gsettings/tests/test_gsettings_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 054a867c2..a0cdc60eb 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -200,7 +200,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListK TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetSchemaName) { - FAIL (); + EXPECT_THAT (ccsGSettingsWrapperGetSchemaName (wrapper.get ()), Eq (mockSchema)); } TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetPath) -- GitLab From 63df8bd68fbc2fbc9b351345d76f8cb76a601ec7 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:27:00 +0800 Subject: [PATCH 273/562] Make it pass --- .../ccs_gsettings_interface_wrapper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index d03a590b8..8ccb82f88 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -51,7 +51,9 @@ static GSettings * ccsGSettingsWrapperGetGSettingsDefault (CCSGSettingsWrapper * static const char * ccsGSettingsWrapperGetSchemaNameDefault (CCSGSettingsWrapper *wrapper) { - return NULL; + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return gswPrivate->schema; } static const char * -- GitLab From cc1bf5de5da86d929495dbbfd59b78ce2491931c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:28:07 +0800 Subject: [PATCH 274/562] Segfaulting test TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetPath --- compizconfig/gsettings/tests/test_gsettings_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index a0cdc60eb..df42e2a41 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -205,7 +205,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetSc TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetPath) { - FAIL (); + EXPECT_THAT (ccsGSettingsWrapperGetPath (wrapper.get ()), Eq (mockPath)); } namespace signal_test -- GitLab From 23431f6645b6d63d0ffdd21b9afe965b39410f44 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:28:47 +0800 Subject: [PATCH 275/562] Make it pass --- .../ccs_gsettings_interface_wrapper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 8ccb82f88..f2666a98b 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -59,7 +59,9 @@ ccsGSettingsWrapperGetSchemaNameDefault (CCSGSettingsWrapper *wrapper) static const char * ccsGSettingsWrapperGetPathDefault (CCSGSettingsWrapper *wrapper) { - return NULL; + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return gswPrivate->path; } void -- GitLab From 45614ba009c0ab75b297f302de0b55aa1b9b4cec Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:50:30 +0800 Subject: [PATCH 276/562] Failing test TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit.TestConnectToChangedSignal --- .../ccs_gsettings_interface_wrapper.c | 2 +- .../gsettings/tests/test_gsettings_wrapper.cpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index f2666a98b..c5a9dff64 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -69,7 +69,7 @@ ccsGSettingsWrapperConnectToChangedSignalDefault (CCSGSettingsWrapper *wrapper, GCallback callback, gpointer data) { - //g_signal_connect (object, "changed", (GCallback) valueChanged, (gpointer) backend); + //g_signal_connect (object, "changed", callback, data); } static void diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index df42e2a41..0f5946ce7 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -238,5 +238,20 @@ namespace signal_test TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestConnectToChangedSignal) { - FAIL (); + std::string keyname ("int-setting"); + signal_test::VerificationMock mv; + + EXPECT_CALL (mv, Verify (settings, Eq (keyname))); + + ccsGSettingsWrapperConnectToChangedSignal (wrapper.get (), + (GCallback) signal_test::dummyChangedSignal, + (gpointer) static_cast (&mv)); + + g_signal_emit_by_name (G_OBJECT (settings), + "changed", + G_TYPE_SETTINGS, + settings, + G_TYPE_STRING, + keyname.c_str (), + NULL); } -- GitLab From 4bbab32277139f4cad402cf6f6d4076985294804 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:58:49 +0800 Subject: [PATCH 277/562] Make it pass --- .../ccs_gsettings_interface_wrapper.c | 4 +++- .../gsettings/tests/test_gsettings_wrapper.cpp | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index c5a9dff64..5e67e27c4 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -69,7 +69,9 @@ ccsGSettingsWrapperConnectToChangedSignalDefault (CCSGSettingsWrapper *wrapper, GCallback callback, gpointer data) { - //g_signal_connect (object, "changed", callback, data); + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + g_signal_connect (gswPrivate->settings, "changed", callback, data); } static void diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 0f5946ce7..913a01ac4 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -15,6 +15,8 @@ using ::testing::NotNull; using ::testing::Eq; +using ::testing::_; + class TestGSettingsWrapperWithMemoryBackendEnv : public ::testing::Test @@ -241,7 +243,11 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestConne std::string keyname ("int-setting"); signal_test::VerificationMock mv; - EXPECT_CALL (mv, Verify (settings, Eq (keyname))); + /* We're not able to verify the keyname + * at the moment, need a person who knows + * GSignal better than I do to figure this + * one out */ + EXPECT_CALL (mv, Verify (settings, _)); ccsGSettingsWrapperConnectToChangedSignal (wrapper.get (), (GCallback) signal_test::dummyChangedSignal, @@ -249,9 +255,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestConne g_signal_emit_by_name (G_OBJECT (settings), "changed", - G_TYPE_SETTINGS, settings, - G_TYPE_STRING, keyname.c_str (), NULL); } -- GitLab From dcdd4856a7f8092e681001dce8e6c975d39c8709 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 13:59:29 +0800 Subject: [PATCH 278/562] Remove dbg message --- .../gsettings/gsettings_backend_shared/gsettings_util.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 5665abe7a..2e998cdd0 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -949,8 +949,6 @@ insertIfNotEqual (GVariantBuilder *builder, const char *item, void *userData) { const char *cmp = (const char *) userData; - printf ("cmp: %s %s\n", item, cmp); - if (g_strcmp0 (item, cmp)) g_variant_builder_add (builder, "s", item); } -- GitLab From 2a8b03c337d25fb3ea6327f6a0d196e0f3cbb4f0 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 19:49:25 +0800 Subject: [PATCH 279/562] Provide the right pointer --- compizconfig/gsettings/src/gsettings.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index a179e3a4c..05ef4f037 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -614,7 +614,7 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v priv->currentProfile = strdup (value); priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, profilePath, - backend->object.object_allocation->allocator); + &backend->object.object_allocation); GVariant *currentProfileVariant = g_variant_new ("s", value, NULL); @@ -707,12 +707,12 @@ initBackend (CCSBackend *backend, CCSContext * context) ccsObjectSetPrivate (backend, (CCSPrivate *) priv); priv->compizconfigSettings = ccsGSettingsWrapperNewForSchema (COMPIZCONFIG_SCHEMA_ID, - backend->object.object_allocation->allocator); + &backend->object.object_allocation); priv->currentProfile = getCurrentProfileName (backend); currentProfilePath = makeCompizProfilePath (priv->currentProfile); priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, currentProfilePath, - backend->object.object_allocation->allocator); + &backend->object.object_allocation); priv->context = context; g_free (currentProfilePath); -- GitLab From bd04d9dbd28e751cf250cce3e97c31833b99906e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 19:54:47 +0800 Subject: [PATCH 280/562] Not ** --- compizconfig/gsettings/src/gsettings.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 05ef4f037..b387d2d62 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -614,7 +614,7 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v priv->currentProfile = strdup (value); priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, profilePath, - &backend->object.object_allocation); + backend->object.object_allocation); GVariant *currentProfileVariant = g_variant_new ("s", value, NULL); @@ -707,12 +707,12 @@ initBackend (CCSBackend *backend, CCSContext * context) ccsObjectSetPrivate (backend, (CCSPrivate *) priv); priv->compizconfigSettings = ccsGSettingsWrapperNewForSchema (COMPIZCONFIG_SCHEMA_ID, - &backend->object.object_allocation); + backend->object.object_allocation); priv->currentProfile = getCurrentProfileName (backend); currentProfilePath = makeCompizProfilePath (priv->currentProfile); priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, currentProfilePath, - &backend->object.object_allocation); + backend->object.object_allocation); priv->context = context; g_free (currentProfilePath); -- GitLab From 99b657f0049cccad630b059a99e8cb1b75be6a79 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sat, 4 Aug 2012 19:59:49 +0800 Subject: [PATCH 281/562] Update for API changes --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 4626d5443..ad341686c 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -29,7 +29,7 @@ class CCSGSettingsBackendEnv : } /* A wrapper to prevent signals from being added */ - static void connectToSignalWrapper (CCSBackend *backend, GObject *object) + static void connectToSignalWrapper (CCSBackend *backend, CCSGSettingsWrapper *wrapper) { }; @@ -445,7 +445,7 @@ class CCSGSettingsBackendEnv : private: - GSettings *mSettings; + CCSGSettingsWrapper *mSettings; CCSContext *mContext; CCSDynamicBackend *mBackend; CCSBackend *mGSettingsBackend; -- GitLab From 1787b26c907e93c5fcc110c5138969383be5a192 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 10:52:20 +0800 Subject: [PATCH 282/562] Added mocks for GSettingsWrapper and re-enable the find wrapper tests --- compizconfig/gsettings/tests/CMakeLists.txt | 5 + .../tests/ccs_gsettings_wrapper_mock.cpp | 50 ++++++++ .../tests/ccs_gsettings_wrapper_mock.h | 113 ++++++++++++++++++ .../gsettings/tests/test_gsettings_tests.cpp | 73 ++++++----- .../tests/test_gsettings_wrapper.cpp | 8 +- 5 files changed, 212 insertions(+), 37 deletions(-) create mode 100644 compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp create mode 100644 compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 1e43fc523..2b963cf02 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -10,6 +10,10 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) +add_library (compizconfig_ccs_gsettings_wrapper_mock STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_wrapper_mock.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_wrapper_mock.h) + add_library (compizconfig_ccs_gsettings_backend_mock STATIC ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.h) @@ -29,6 +33,7 @@ target_link_libraries (compizconfig_test_gsettings compizconfig_ccs_setting_mock compizconfig_ccs_context_mock compizconfig_ccs_gsettings_backend_mock + compizconfig_ccs_gsettings_wrapper_mock ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) diff --git a/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp new file mode 100644 index 000000000..f2c6dab2d --- /dev/null +++ b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp @@ -0,0 +1,50 @@ +#include + +const CCSGSettingsWrapperInterface mockInterface = +{ + CCSGSettingsWrapperGMock::ccsGSettingsWrapperSetValue, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetValue, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperResetKey, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperListKeys, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetGSettings, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetSchemaName, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetPath, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperConnectToChangedSignal, + CCSGSettingsWrapperGMock::ccsFreeGSettingsWrapper +}; + +CCSGSettingsWrapper * +ccsMockGSettingsWrapperNew () +{ + CCSGSettingsWrapper *wrapper = (CCSGSettingsWrapper *) calloc (1, sizeof (CCSGSettingsWrapper)); + + if (!wrapper) + return NULL; + + CCSGSettingsWrapperGMock *gmockWrapper = new CCSGSettingsWrapperGMock (wrapper); + + if (!gmockWrapper) + { + free (wrapper); + return NULL; + } + + ccsObjectInit (wrapper, &ccsDefaultObjectAllocator); + ccsObjectAddInterface (wrapper, (const CCSInterface *) &mockInterface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); + ccsObjectSetPrivate (wrapper, (CCSPrivate *) gmockWrapper); + + return wrapper; +} + +void +ccsMockGSettingsWrapperFree (CCSGSettingsWrapper *wrapper) +{ + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper)); + + delete gmockWrapper; + + ccsObjectSetPrivate (wrapper, NULL); + ccsObjectFinalize (wrapper); + free (wrapper); +} + diff --git a/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h new file mode 100644 index 000000000..d8b92e83c --- /dev/null +++ b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h @@ -0,0 +1,113 @@ +#ifndef _COMPIZCONFIG_CCS_GSETTINGS_WRAPPER_MOCK +#define _COMPIZCONFIG_CCS_GSETTINGS_WRAPPER_MOCK + +#include +#include + +#include + +CCSGSettingsWrapper * ccsMockGSettingsWrapperNew (); +void ccsMockGSettingsWrapperFree (CCSGSettingsWrapper *); + +class CCSGSettingsWrapperMockInterface +{ + public: + + virtual ~CCSGSettingsWrapperMockInterface () {} + virtual void setValue (const char *, GVariant *) = 0; + virtual GVariant * getValue (const char *) = 0; + virtual void resetKey (const char *) = 0; + virtual char ** listKeys () = 0; + virtual GSettings * getGSettings () = 0; + virtual const char * getSchemaName () = 0; + virtual const char * getPath () = 0; + virtual void connectToChangedSignal (GCallback, gpointer) = 0; +}; + +class CCSGSettingsWrapperGMock : + public CCSGSettingsWrapperMockInterface +{ + public: + + CCSGSettingsWrapperGMock (CCSGSettingsWrapper *wrapper) : + mWrapper (wrapper) + { + } + + MOCK_METHOD2 (setValue, void (const char *, GVariant *)); + MOCK_METHOD1 (getValue, GVariant * (const char *)); + MOCK_METHOD1 (resetKey, void (const char *)); + MOCK_METHOD0 (listKeys, char ** ()); + MOCK_METHOD0 (getGSettings, GSettings * ()); + MOCK_METHOD0 (getSchemaName, const char * ()); + MOCK_METHOD0 (getPath, const char * ()); + MOCK_METHOD2 (connectToChangedSignal, void (GCallback, gpointer)); + + private: + + CCSGSettingsWrapper *mWrapper; + + public: + + static void + ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *wrapper, + const char *key, + GVariant *value) + { + reinterpret_cast (ccsObjectGetPrivate (wrapper))->setValue (key, value); + } + + static GVariant * + ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *wrapper, + const char *key) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getValue (key); + } + + static void + ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *wrapper, + const char *key) + { + reinterpret_cast (ccsObjectGetPrivate (wrapper))->resetKey (key); + } + + static char ** + ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->listKeys (); + } + + static GSettings * + ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getGSettings (); + } + + static const char * + ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getSchemaName (); + } + + static const char * + ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getPath (); + } + + static void + ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *wrapper, + GCallback callback, + gpointer data) + { + reinterpret_cast (ccsObjectGetPrivate (wrapper))->connectToChangedSignal (callback, data); + } + + static void + ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) + { + ccsMockGSettingsWrapperFree (wrapper); + } +}; + +#endif diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 53eead75b..1b2f35d36 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -12,7 +12,7 @@ #include "gtest_shared_characterwrapper.h" #include "compizconfig_test_value_combiners.h" #include "compizconfig_ccs_mocked_allocator.h" -//#include "ccs_gsettings_wrapper_mock.h" +#include "ccs_gsettings_wrapper_mock.h" using ::testing::Values; using ::testing::ValuesIn; @@ -664,61 +664,72 @@ TEST_F(CCSGSettingsTestPluginsWithSetKeysGVariantSetup, TestAppendToPluginsWithS EXPECT_EQ (std::string (newWrittenPlugins[0]), std::string ("foo")); EXPECT_EQ (std::string (newWrittenPlugins[1]), std::string ("bar")); } -/* -class CCSGSettingsTestGObjectListWithProperty : + +class CCSGSettingsTestGSettingsWrapperWithSchemaName : public CCSGSettingsTestIndependent { public: - virtual void SetUp () - { - g_type_init (); + typedef std::tr1::tuple , CCSGSettingsWrapperGMock *> WrapperMock; - objectSchemaList = NULL; + CCSGSettingsTestGSettingsWrapperWithSchemaName () : + objectSchemaGList (NULL) + { } - virtual void TearDown () + ~CCSGSettingsTestGSettingsWrapperWithSchemaName () { - GList *iter = objectSchemaList; - - while (iter) - { - g_object_unref ((GObject *) iter->data); - iter = g_list_next (iter); - } - - g_list_free (objectSchemaList); - objectSchemaList = NULL; + g_list_free (objectSchemaGList); } - CCSGSettingsWrapGSettings * AddObjectWithSchemaName (const std::string &schemaName) + WrapperMock + AddObject () { - CCSGSettingsWrapGSettings *wrapGSettingsObject = - compizconfig_gsettings_wrap_gsettings_new (COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, schemaName.c_str ()); - objectSchemaList = g_list_append (objectSchemaList, wrapGSettingsObject); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); - return wrapGSettingsObject; + objectSchemaGList = g_list_append (objectSchemaGList, wrapper.get ()); + objectSchemaList.push_back (wrapper); + + return WrapperMock (wrapper, gmockWrapper); } + static const std::string VALUE_FOO; + static const std::string VALUE_BAR; + static const std::string VALUE_BAZ; + protected: - GList *objectSchemaList; + GList *objectSchemaGList; + std::vector > objectSchemaList; }; -TEST_F(CCSGSettingsTestGObjectListWithProperty, TestFindExistingObjectWithSchema) +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_FOO = "foo"; +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_BAR = "bar"; +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_BAZ = "baz"; + +TEST_F(CCSGSettingsTestGSettingsWrapperWithSchemaName, TestFindExistingObjectWithSchema) { - GObject *obj = reinterpret_cast (AddObjectWithSchemaName ("foo")); + WrapperMock wr1 (AddObject ()); + WrapperMock wr2 (AddObject ()); + + EXPECT_CALL (*(std::tr1::get <1> (wr1)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAR.c_str ())); + EXPECT_CALL (*(std::tr1::get <1> (wr2)), getSchemaName ()).WillRepeatedly (Return (VALUE_FOO.c_str ())); - EXPECT_EQ (findObjectInListWithPropertySchemaName ("foo", objectSchemaList), obj); + EXPECT_EQ (findCCSGSettingsWrapperBySchemaName (VALUE_FOO.c_str (), objectSchemaGList), (std::tr1::get <0> (wr2)).get ()); } -TEST_F(CCSGSettingsTestGObjectListWithProperty, TestNoFindNonexistingObjectWithSchema) +TEST_F(CCSGSettingsTestGSettingsWrapperWithSchemaName, TestNoFindNonexistingObjectWithSchema) { - AddObjectWithSchemaName ("bar"); + WrapperMock wr1 (AddObject ()); + WrapperMock wr2 (AddObject ()); + + EXPECT_CALL (*(std::tr1::get <1> (wr1)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAR.c_str ())); + EXPECT_CALL (*(std::tr1::get <1> (wr2)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAZ.c_str ())); - EXPECT_EQ (NULL, findObjectInListWithPropertySchemaName ("foo", objectSchemaList)); + EXPECT_THAT (findCCSGSettingsWrapperBySchemaName (VALUE_FOO.c_str (), objectSchemaGList), IsNull ()); } -*/ class CCSGSettingsTestFindSettingLossy : public CCSGSettingsTestIndependent diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 913a01ac4..67fcce5dc 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -144,11 +144,11 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestReset const char * DEFAULT = ""; const char * VALUE = "foo"; const std::string KEY ("string-setting"); - boost::shared_ptr variant (g_variant_new ("s", VALUE, NULL), + boost::shared_ptr variant (g_variant_ref_sink (g_variant_new ("s", VALUE, NULL)), boost::bind (g_variant_unref, _1)); ccsGSettingsWrapperSetValue (wrapper.get (), KEY.c_str (), variant.get ()); - boost::shared_ptr value (g_settings_get_value (settings, KEY.c_str ()), + boost::shared_ptr value (g_variant_ref_sink (g_settings_get_value (settings, KEY.c_str ())), boost::bind (g_variant_unref, _1)); gsize length; @@ -156,10 +156,6 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestReset ASSERT_EQ (strlen (VALUE), length); ASSERT_THAT (v, Eq (VALUE)); - /* g_settings_reset appears to unref the value, - * so we need to keep it alive */ - g_variant_ref (value.get ()); - ccsGSettingsWrapperResetKey (wrapper.get (), KEY.c_str ()); value.reset (g_settings_get_value (settings, KEY.c_str ()), -- GitLab From a40e5b55eb47f74f774494adf53f0d010b675482 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 11:26:02 +0800 Subject: [PATCH 283/562] Nuke CCSGSettingsWrapGSettings from orbit --- compizconfig/gsettings/tests/CMakeLists.txt | 2 - .../gsettings/tests/test_gsettings_tests.cpp | 1 - .../gsettings/tests/wrap_gsettings.cpp | 200 ------------------ compizconfig/gsettings/tests/wrap_gsettings.h | 44 ---- 4 files changed, 247 deletions(-) delete mode 100644 compizconfig/gsettings/tests/wrap_gsettings.cpp delete mode 100644 compizconfig/gsettings/tests/wrap_gsettings.h diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 2b963cf02..d45fd40cd 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -19,11 +19,9 @@ add_library (compizconfig_ccs_gsettings_backend_mock STATIC ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.h) add_executable (compizconfig_test_gsettings - ${CMAKE_CURRENT_SOURCE_DIR}/wrap_gsettings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/wrap_gsettings.h ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.h) link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 1b2f35d36..5fdf289fd 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -5,7 +5,6 @@ #include "test_gsettings_tests.h" #include "gsettings.h" -#include "wrap_gsettings.h" #include "ccs_gsettings_backend_mock.h" #include "compizconfig_ccs_context_mock.h" #include "compizconfig_ccs_setting_mock.h" diff --git a/compizconfig/gsettings/tests/wrap_gsettings.cpp b/compizconfig/gsettings/tests/wrap_gsettings.cpp deleted file mode 100644 index 6063da7f3..000000000 --- a/compizconfig/gsettings/tests/wrap_gsettings.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include - -static void compizconfig_gsettings_wrap_gsettings_default_init (CCSGSettingsWrapGSettingsInterface *interface); - -G_DEFINE_INTERFACE (CCSGSettingsWrapGSettings, compizconfig_gsettings_wrap_gsettings, G_TYPE_OBJECT) - -static void compizconfig_gsettings_wrap_gsettings_default_init (CCSGSettingsWrapGSettingsInterface *klass) -{ - g_object_interface_install_property (klass, - g_param_spec_string ("schema", - "schema", - "Schema Name", - "invalid.invalid", - static_cast (G_PARAM_CONSTRUCT_ONLY | - G_PARAM_WRITABLE | - G_PARAM_READABLE))); -} - -CCSGSettingsWrapGSettings * -compizconfig_gsettings_wrap_gsettings_new (GType type, const gchar *name) -{ - GValue name_v = G_VALUE_INIT; - - g_value_init (&name_v, G_TYPE_STRING); - - g_value_set_string (&name_v, name); - - GParameter param[1] = - { - { "schema", name_v } - }; - - CCSGSettingsWrapGSettings *wrap_gsettings = COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS (g_object_newv (type, 1, param)); - - g_value_unset (&name_v); - - return wrap_gsettings; -} - -G_BEGIN_DECLS - -#define COMPIZCONFIG_GSETTINGS_MOCK_WRAP_GSETTINGS(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettings)) - -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_GSETTINGS_CONCRETE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsClass)) - -#define COMPIZCONFIG_GSETTINGS_IS_MOCK_WRAP_GSETTINGS(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS) - -#define COMPIZCONFIG_GSETTINGS_IS_MOCK_WRAP_GSETTINGS_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS)) - -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_GSETTINGS_CONCRETE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsClass)) - -typedef struct { - GObject parent; -} CCSGSettingsMockWrapGSettings; - -typedef struct { - GObjectClass parent_class; -} CCSGSettingsMockWrapGSettingsClass; - -G_END_DECLS - -static void compizconfig_gsettings_mock_wrap_gsettings_interface_init (CCSGSettingsWrapGSettingsInterface *interface); - -G_DEFINE_TYPE_WITH_CODE (CCSGSettingsMockWrapGSettings, compizconfig_gsettings_mock_wrap_gsettings, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, - compizconfig_gsettings_mock_wrap_gsettings_interface_init)) - -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsPrivate)) - -typedef struct _CCSGSettingsMockWrapGSettingsPrivate CCSGSettingsMockWrapGSettingsPrivate; - -struct _CCSGSettingsMockWrapGSettingsPrivate -{ - gchar *name; -}; - -static void -compizconfig_gsettings_mock_wrap_gsettings_dispose (GObject *object) -{ - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); - G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->dispose (object); - - if (priv->name) - g_free (priv->name); - - priv->name = NULL; -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_finalize (GObject *object) -{ - G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->finalize (object); -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_interface_init (CCSGSettingsWrapGSettingsInterface *interface) -{ -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); - - switch (property_id) - { - case COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME: - if (priv->name) - g_free (priv->name); - - priv->name = g_value_dup_string (value); - break; - default: - g_assert_not_reached (); - break; - } -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); - - switch (property_id) - { - case COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME: - g_value_set_string (value, priv->name); - break; - default: - g_assert_not_reached (); - break; - } -} - -static GObject * -compizconfig_gsettings_mock_wrap_gsettings_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construction_properties) -{ - GObject *object; - CCSGSettingsMockWrapGSettingsPrivate *priv; - - { - object = G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->constructor (type, - n_construct_properties, - construction_properties); - } - - priv = GET_PRIVATE (object); - - for (guint i = 0; i < n_construct_properties; i++) - { - if (g_strcmp0 (construction_properties[i].pspec->name, "schema") == 0) - { - if (!priv->name) - priv->name = g_value_dup_string (construction_properties[i].value); - } - else - { - g_assert_not_reached (); - } - } - - return object; -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_class_init (CCSGSettingsMockWrapGSettingsClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (CCSGSettingsMockWrapGSettingsPrivate)); - - object_class->dispose = compizconfig_gsettings_mock_wrap_gsettings_dispose; - object_class->finalize = compizconfig_gsettings_mock_wrap_gsettings_finalize; - object_class->set_property = compizconfig_gsettings_mock_wrap_gsettings_set_property; - object_class->get_property = compizconfig_gsettings_mock_wrap_gsettings_get_property; - object_class->constructor = compizconfig_gsettings_mock_wrap_gsettings_constructor; - - g_object_class_override_property (G_OBJECT_CLASS (klass), - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME, - "schema"); -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_init (CCSGSettingsMockWrapGSettings *self) -{ -} diff --git a/compizconfig/gsettings/tests/wrap_gsettings.h b/compizconfig/gsettings/tests/wrap_gsettings.h deleted file mode 100644 index 97e4f2414..000000000 --- a/compizconfig/gsettings/tests/wrap_gsettings.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _COMPIZ_COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS -#define _COMPIZ_COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS - -#include - -G_BEGIN_DECLS - -#define COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, CCSGSettingsWrapGSettings)) - -#define COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, CCSGSettingsWrapGSettingsInterface)) - -#define COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS (compizconfig_gsettings_wrap_gsettings_get_type()) - -GType compizconfig_gsettings_wrap_gsettings_get_type (void); - -typedef struct _CCSGSettingsWrapGSettings CCSGSettingsWrapGSettings; /* dummy typedef */ -typedef struct _CCSGSettingsWrapGSettingsInterface CCSGSettingsWrapGSettingsInterface; - -struct _CCSGSettingsWrapGSettingsInterface { - GTypeInterface parent; - -}; - -enum -{ - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME = 1, - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_NUM = 2 -}; - -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS (compizconfig_gsettings_mock_wrap_gsettings_get_type ()) - -GType compizconfig_gsettings_mock_wrap_gsettings_get_type (); - -/** - * compizconfig_gsettings_wrap_gsettings_new: - * @type: (in) (transfer none): a GType of the object type to be created - * @name: (in) (transfer none): schema name - * Return value: (transfer full): a new CCSGSettingsWrapGSettings - */ -CCSGSettingsWrapGSettings * compizconfig_gsettings_wrap_gsettings_new (GType type, const gchar *name); - -G_END_DECLS - -#endif -- GitLab From 66f33e1a71d9057d51a2071f7a0f4fcd7efefee6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 11:34:16 +0800 Subject: [PATCH 284/562] Ref the objects before we give them to clients --- .../gsettings_backend_shared/ccs_gsettings_interface_wrapper.c | 1 + compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c index 5e67e27c4..b07e75c6f 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -204,6 +204,7 @@ initCCSGSettingsWrapperObject (CCSGSettingsWrapper *wrapper, ccsObjectInit (wrapper, ai); ccsObjectAddInterface (wrapper, (const CCSInterface *) &interface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); ccsObjectSetPrivate (wrapper, (CCSPrivate *) priv); + ccsGSettingsWrapperRef (wrapper); } CCSGSettingsWrapper * diff --git a/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp index f2c6dab2d..c0c659ec6 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp +++ b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp @@ -33,6 +33,8 @@ ccsMockGSettingsWrapperNew () ccsObjectAddInterface (wrapper, (const CCSInterface *) &mockInterface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); ccsObjectSetPrivate (wrapper, (CCSPrivate *) gmockWrapper); + ccsGSettingsWrapperRef (wrapper); + return wrapper; } -- GitLab From 8711babc59238b6ab705155ec48eefc715dff3ae Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 12:17:19 +0800 Subject: [PATCH 285/562] Test fixture for CCSGSettingsTestFindSettingAndPluginToUpdateFromPath --- .../gsettings/tests/test_gsettings_tests.cpp | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 5fdf289fd..9a5f0d970 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1543,3 +1543,70 @@ TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplEmptyStringProf ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); } + +class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : + public CCSGSettingsTestIndependent +{ + public: + + CCSGSettingsTestFindSettingAndPluginToUpdateFromPath () : + wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (&ccsGSettingsWrapperUnref, _1)), + gmockWrapper (reinterpret_cast (ccsObjectGetPrivate (wrapper.get ()))), + context (ccsMockContextNew (), + boost::bind (ccsFreeMockContext, _1)), + gmockContext (reinterpret_cast (ccsObjectGetPrivate (context.get ()))), + plugin (NULL), + setting (NULL), + uncleanKeyName (NULL) + { + } + + ~CCSGSettingsTestFindSettingAndPluginToUpdateFromPath () + { + if (plugin) + ccsPluginUnref (plugin); + + if (setting) + ccsSettingUnref (setting); + + if (uncleanKeyName) + free (uncleanKeyName); + } + + void SetPathAndKeyname (const std::string &setPath, + const std::string &setKeyName) + { + path = setPath; + keyName = setKeyName; + } + + protected: + + boost::shared_ptr wrapper; + CCSGSettingsWrapperGMock *gmockWrapper; + boost::shared_ptr context; + CCSContextGMock *gmockContext; + std::string path; + std::string keyName; + CCSPlugin *plugin; + CCSSetting *setting; + char *uncleanKeyName; +}; + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFindSettingAndPluginToUpdateFromPathBadPath) +{ + SetPathAndKeyname ("/wrong", "foo"); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_THAT (plugin, IsNull ()); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, IsNull ()); +} -- GitLab From cc21349eee4c6472f0cbc89bb5c9a7743fdb4c34 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 13:34:07 +0800 Subject: [PATCH 286/562] Comprehensive test coverage for FindSettingAndPluginToUpdateFromPath and some cleanup, fix leaks etc --- .../gsettings_backend_shared/gsettings_util.c | 2 +- compizconfig/gsettings/tests/CMakeLists.txt | 1 + .../gsettings/tests/test_gsettings_tests.cpp | 204 +++++++++++++++++- .../gsettings/tests/test_gsettings_tests.h | 41 ++++ .../tests/test_gsettings_wrapper.cpp | 45 ++-- 5 files changed, 261 insertions(+), 32 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 2e998cdd0..a749cfcc2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -357,7 +357,7 @@ findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, *uncleanKeyName = translateKeyForCCS (keyName); *setting = ccsFindSetting (*plugin, *uncleanKeyName); - if (!setting) + if (!*setting) { /* Couldn't find setting straight off the bat, * try and find the best match */ diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 61e5eaff4..9f3632192 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -32,6 +32,7 @@ add_executable (compizconfig_test_gsettings_conformance target_link_libraries (compizconfig_test_gsettings gsettings_backend_shared compizconfig_ccs_setting_mock + compizconfig_ccs_plugin_mock compizconfig_ccs_context_mock compizconfig_ccs_gsettings_backend_mock compizconfig_ccs_gsettings_wrapper_mock diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 9a5f0d970..e2501c344 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -7,6 +7,7 @@ #include "gsettings.h" #include "ccs_gsettings_backend_mock.h" #include "compizconfig_ccs_context_mock.h" +#include "compizconfig_ccs_plugin_mock.h" #include "compizconfig_ccs_setting_mock.h" #include "gtest_shared_characterwrapper.h" #include "compizconfig_test_value_combiners.h" @@ -611,6 +612,7 @@ class CCSGSettingsTestPluginsWithSetKeysGVariantSetup : virtual void SetUp () { + CCSGSettingsTestIndependent::SetUp (); builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); g_variant_builder_add (builder, "s", "foo"); @@ -628,6 +630,7 @@ class CCSGSettingsTestPluginsWithSetKeysGVariantSetup : { g_variant_unref (writtenPlugins); g_strfreev (newWrittenPlugins); + CCSGSettingsTestIndependent::TearDown (); } protected: @@ -674,11 +677,13 @@ class CCSGSettingsTestGSettingsWrapperWithSchemaName : CCSGSettingsTestGSettingsWrapperWithSchemaName () : objectSchemaGList (NULL) { + CCSGSettingsTestIndependent::SetUp (); } ~CCSGSettingsTestGSettingsWrapperWithSchemaName () { g_list_free (objectSchemaGList); + CCSGSettingsTestIndependent::TearDown (); } WrapperMock @@ -737,6 +742,7 @@ class CCSGSettingsTestFindSettingLossy : virtual void SetUp () { + CCSGSettingsTestIndependent::SetUp (); settingList = NULL; } @@ -744,6 +750,7 @@ class CCSGSettingsTestFindSettingLossy : { ccsSettingListFree (settingList, TRUE); settingList = NULL; + CCSGSettingsTestIndependent::TearDown (); } CCSSetting * AddMockSettingWithNameAndType (char *name, @@ -984,14 +991,18 @@ namespace typedef boost::function PopulateFunc; - GListContainerEqualityBase (const PopulateFunc &populateGList) : - mList (populateGList ()) + GListContainerEqualityBase (const PopulateFunc &populateGList) { + g_setenv ("G_SLICE", "always-malloc", 1); + mList = populateGList (); + g_unsetenv ("G_SLICE"); } - GListContainerEqualityBase (const GListContainerEqualityBase &other) : - mList (g_list_copy (other.mList)) + GListContainerEqualityBase (const GListContainerEqualityBase &other) { + g_setenv ("G_SLICE", "always-malloc", 1); + mList = g_list_copy (other.mList); + g_unsetenv ("G_SLICE"); } GListContainerEqualityBase & @@ -1594,7 +1605,7 @@ class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : char *uncleanKeyName; }; -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFindSettingAndPluginToUpdateFromPathBadPath) +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestBadPath) { SetPathAndKeyname ("/wrong", "foo"); @@ -1610,3 +1621,186 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFindSettingAnd EXPECT_THAT (setting, IsNull ()); EXPECT_THAT (uncleanKeyName, IsNull ()); } + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoPluginFound) +{ + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", "foo-bar"); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (ReturnNull ()); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_THAT (plugin, IsNull ()); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, IsNull ()); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoSettingFound) +{ + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (ReturnNull ()); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoundAndNoTypeMatches) +{ + GVariant *value = g_variant_new_int16 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoundAndNoSettingMatches) +{ + GVariant *value = g_variant_new_int32 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + boost::shared_ptr mockSetting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + /* Maybe we should fix ccsSettingGetName to return + * const char * instead of char * */ + CharacterWrapper settingNameInList (strdup ("fbrarr")); + char *settingNameInListC = settingNameInList; + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + boost::shared_ptr <_CCSSettingList> settingList (ccsSettingListAppend (NULL, mockSetting.get ()), + boost::bind (ccsSettingListFree, _1, FALSE)); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + EXPECT_CALL (*gmockPlugin, getPluginSettings ()).WillOnce (Return (settingList.get ())); + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeInt)); + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (settingNameInListC)); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingMatches) +{ + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + CCSSetting *mockSetting = ccsMockSettingNew (); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (Return (mockSetting)); + EXPECT_TRUE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, mockSetting); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFoundSetting) +{ + GVariant *value = g_variant_new_int32 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + CCSSetting *mockSetting = ccsMockSettingNew (); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + /* Maybe we should fix ccsSettingGetName to return + * const char * instead of char * */ + CharacterWrapper settingNameInList (strdup ("foo_bar")); + char *settingNameInListC = settingNameInList; + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + boost::shared_ptr <_CCSSettingList> settingList (ccsSettingListAppend (NULL, mockSetting), + boost::bind (ccsSettingListFree, _1, FALSE)); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + EXPECT_CALL (*gmockPlugin, getPluginSettings ()).WillOnce (Return (settingList.get ())); + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeInt)); + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (settingNameInListC)); + + EXPECT_TRUE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, mockSetting); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.h b/compizconfig/gsettings/tests/test_gsettings_tests.h index cbc9c18a3..356ef0276 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.h +++ b/compizconfig/gsettings/tests/test_gsettings_tests.h @@ -1,4 +1,11 @@ +#ifndef _COMPIZCONFIG_TEST_GSETTINGS_TESTS_H +#define _COMPIZCONFIG_TEST_GSETTINGS_TESTS_H + #include +#include +#include + +#include using ::testing::TestWithParam; @@ -37,5 +44,39 @@ class CCSGSettingsTest : class CCSGSettingsTestIndependent : public ::testing::Test { + public: + + virtual void SetUp () + { + g_setenv ("G_SLICE", "always-malloc", 1); + } + + virtual void TearDown () + { + g_unsetenv ("G_SLICE"); + } +}; + +class CCSGSettingsTestWithMemoryBackend : + public CCSGSettingsTestIndependent +{ + public: + + virtual void SetUp () + { + CCSGSettingsTestIndependent::SetUp (); + g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); + g_setenv ("GSETTINGS_BACKEND", "memory", 1); + + g_type_init (); + } + + virtual void TearDown () + { + g_unsetenv ("GSETTINGS_BACKEND"); + g_unsetenv ("GSETTINGS_SCHEMA_DIR"); + CCSGSettingsTestIndependent::TearDown (); + } }; +#endif diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 67fcce5dc..47ea55e39 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -10,7 +10,6 @@ #include #include "test_gsettings_tests.h" -#include #include using ::testing::NotNull; @@ -18,12 +17,12 @@ using ::testing::Eq; using ::testing::_; -class TestGSettingsWrapperWithMemoryBackendEnv : - public ::testing::Test +class CCSGSettingsWrapperTest : + public CCSGSettingsTestWithMemoryBackend { public: - TestGSettingsWrapperWithMemoryBackendEnv () : + CCSGSettingsWrapperTest () : mockSchema ("org.compiz.mock"), mockPath ("/org/compiz/mock/mock") { @@ -33,18 +32,12 @@ class TestGSettingsWrapperWithMemoryBackendEnv : virtual void SetUp () { - g_setenv ("G_SLICE", "always-malloc", 1); - g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); - g_setenv ("GSETTINGS_BACKEND", "memory", 1); - - g_type_init (); + CCSGSettingsTestWithMemoryBackend::SetUp (); } virtual void TearDown () { - g_unsetenv ("GSETTINGS_BACKEND"); - g_unsetenv ("GSETTINGS_SCHEMA_DIR"); - g_unsetenv ("G_SLICE"); + CCSGSettingsTestWithMemoryBackend::TearDown (); } protected: @@ -55,8 +48,8 @@ class TestGSettingsWrapperWithMemoryBackendEnv : GSettings *settings; }; -class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator : - public TestGSettingsWrapperWithMemoryBackendEnv +class CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest : + public CCSGSettingsWrapperTest { protected: @@ -66,14 +59,14 @@ class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator : } }; -class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit : - public TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator +class CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest : + public CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest { public: virtual void SetUp () { - TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator::SetUp (); + CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest::SetUp (); wrapper.reset (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), @@ -88,7 +81,7 @@ class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit : } }; -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestWrapperConstruction) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest, TestWrapperConstruction) { boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), @@ -98,7 +91,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestWrapperConstr EXPECT_THAT (wrapper.get (), NotNull ()); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestGetGSettingsWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest, TestGetGSettingsWrapper) { boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), @@ -109,7 +102,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestGetGSettingsW EXPECT_THAT (ccsGSettingsWrapperGetGSettings (wrapper.get ()), NotNull ()); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestSetValueOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestSetValueOnWrapper) { const unsigned int VALUE = 2; const std::string KEY ("integer-setting"); @@ -124,7 +117,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestSetVa EXPECT_EQ (VALUE, v); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetValueOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetValueOnWrapper) { const double VALUE = 3.0; const std::string KEY ("float-setting"); @@ -139,7 +132,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetVa EXPECT_EQ (VALUE, v); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestResetKeyOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestResetKeyOnWrapper) { const char * DEFAULT = ""; const char * VALUE = "foo"; @@ -166,7 +159,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestReset ASSERT_THAT (v, Eq (DEFAULT)); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListKeysOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestListKeysOnWrapper) { const char * EXPECTED_KEYS[] = { @@ -196,12 +189,12 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListK sizeof (EXPECTED_KEYS[0])); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetSchemaName) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetSchemaName) { EXPECT_THAT (ccsGSettingsWrapperGetSchemaName (wrapper.get ()), Eq (mockSchema)); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetPath) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetPath) { EXPECT_THAT (ccsGSettingsWrapperGetPath (wrapper.get ()), Eq (mockPath)); } @@ -234,7 +227,7 @@ namespace signal_test } } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestConnectToChangedSignal) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestConnectToChangedSignal) { std::string keyname ("int-setting"); signal_test::VerificationMock mv; -- GitLab From 5049759ed1171d77b0d9b28c49c4c26efd257ae3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 13:35:32 +0800 Subject: [PATCH 287/562] Test fixture for CCSGSettingsTestFindSettingAndPluginToUpdateFromPath --- .../gsettings/tests/test_gsettings_tests.cpp | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 5fdf289fd..9a5f0d970 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1543,3 +1543,70 @@ TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplEmptyStringProf ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); } + +class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : + public CCSGSettingsTestIndependent +{ + public: + + CCSGSettingsTestFindSettingAndPluginToUpdateFromPath () : + wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (&ccsGSettingsWrapperUnref, _1)), + gmockWrapper (reinterpret_cast (ccsObjectGetPrivate (wrapper.get ()))), + context (ccsMockContextNew (), + boost::bind (ccsFreeMockContext, _1)), + gmockContext (reinterpret_cast (ccsObjectGetPrivate (context.get ()))), + plugin (NULL), + setting (NULL), + uncleanKeyName (NULL) + { + } + + ~CCSGSettingsTestFindSettingAndPluginToUpdateFromPath () + { + if (plugin) + ccsPluginUnref (plugin); + + if (setting) + ccsSettingUnref (setting); + + if (uncleanKeyName) + free (uncleanKeyName); + } + + void SetPathAndKeyname (const std::string &setPath, + const std::string &setKeyName) + { + path = setPath; + keyName = setKeyName; + } + + protected: + + boost::shared_ptr wrapper; + CCSGSettingsWrapperGMock *gmockWrapper; + boost::shared_ptr context; + CCSContextGMock *gmockContext; + std::string path; + std::string keyName; + CCSPlugin *plugin; + CCSSetting *setting; + char *uncleanKeyName; +}; + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFindSettingAndPluginToUpdateFromPathBadPath) +{ + SetPathAndKeyname ("/wrong", "foo"); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_THAT (plugin, IsNull ()); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, IsNull ()); +} -- GitLab From 4ae8125065541bccbf116836642b1612f199d5dc Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 13:35:47 +0800 Subject: [PATCH 288/562] Comprehensive test coverage for FindSettingAndPluginToUpdateFromPath and some cleanup, fix leaks etc --- .../gsettings_backend_shared/gsettings_util.c | 2 +- compizconfig/gsettings/tests/CMakeLists.txt | 1 + .../gsettings/tests/test_gsettings_tests.cpp | 204 +++++++++++++++++- .../gsettings/tests/test_gsettings_tests.h | 41 ++++ .../tests/test_gsettings_wrapper.cpp | 45 ++-- 5 files changed, 261 insertions(+), 32 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 2e998cdd0..a749cfcc2 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -357,7 +357,7 @@ findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, *uncleanKeyName = translateKeyForCCS (keyName); *setting = ccsFindSetting (*plugin, *uncleanKeyName); - if (!setting) + if (!*setting) { /* Couldn't find setting straight off the bat, * try and find the best match */ diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index d45fd40cd..9d06c3730 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -29,6 +29,7 @@ link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) target_link_libraries (compizconfig_test_gsettings gsettings_backend_shared compizconfig_ccs_setting_mock + compizconfig_ccs_plugin_mock compizconfig_ccs_context_mock compizconfig_ccs_gsettings_backend_mock compizconfig_ccs_gsettings_wrapper_mock diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 9a5f0d970..e2501c344 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -7,6 +7,7 @@ #include "gsettings.h" #include "ccs_gsettings_backend_mock.h" #include "compizconfig_ccs_context_mock.h" +#include "compizconfig_ccs_plugin_mock.h" #include "compizconfig_ccs_setting_mock.h" #include "gtest_shared_characterwrapper.h" #include "compizconfig_test_value_combiners.h" @@ -611,6 +612,7 @@ class CCSGSettingsTestPluginsWithSetKeysGVariantSetup : virtual void SetUp () { + CCSGSettingsTestIndependent::SetUp (); builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); g_variant_builder_add (builder, "s", "foo"); @@ -628,6 +630,7 @@ class CCSGSettingsTestPluginsWithSetKeysGVariantSetup : { g_variant_unref (writtenPlugins); g_strfreev (newWrittenPlugins); + CCSGSettingsTestIndependent::TearDown (); } protected: @@ -674,11 +677,13 @@ class CCSGSettingsTestGSettingsWrapperWithSchemaName : CCSGSettingsTestGSettingsWrapperWithSchemaName () : objectSchemaGList (NULL) { + CCSGSettingsTestIndependent::SetUp (); } ~CCSGSettingsTestGSettingsWrapperWithSchemaName () { g_list_free (objectSchemaGList); + CCSGSettingsTestIndependent::TearDown (); } WrapperMock @@ -737,6 +742,7 @@ class CCSGSettingsTestFindSettingLossy : virtual void SetUp () { + CCSGSettingsTestIndependent::SetUp (); settingList = NULL; } @@ -744,6 +750,7 @@ class CCSGSettingsTestFindSettingLossy : { ccsSettingListFree (settingList, TRUE); settingList = NULL; + CCSGSettingsTestIndependent::TearDown (); } CCSSetting * AddMockSettingWithNameAndType (char *name, @@ -984,14 +991,18 @@ namespace typedef boost::function PopulateFunc; - GListContainerEqualityBase (const PopulateFunc &populateGList) : - mList (populateGList ()) + GListContainerEqualityBase (const PopulateFunc &populateGList) { + g_setenv ("G_SLICE", "always-malloc", 1); + mList = populateGList (); + g_unsetenv ("G_SLICE"); } - GListContainerEqualityBase (const GListContainerEqualityBase &other) : - mList (g_list_copy (other.mList)) + GListContainerEqualityBase (const GListContainerEqualityBase &other) { + g_setenv ("G_SLICE", "always-malloc", 1); + mList = g_list_copy (other.mList); + g_unsetenv ("G_SLICE"); } GListContainerEqualityBase & @@ -1594,7 +1605,7 @@ class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : char *uncleanKeyName; }; -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFindSettingAndPluginToUpdateFromPathBadPath) +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestBadPath) { SetPathAndKeyname ("/wrong", "foo"); @@ -1610,3 +1621,186 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFindSettingAnd EXPECT_THAT (setting, IsNull ()); EXPECT_THAT (uncleanKeyName, IsNull ()); } + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoPluginFound) +{ + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", "foo-bar"); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (ReturnNull ()); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_THAT (plugin, IsNull ()); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, IsNull ()); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoSettingFound) +{ + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (ReturnNull ()); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoundAndNoTypeMatches) +{ + GVariant *value = g_variant_new_int16 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoundAndNoSettingMatches) +{ + GVariant *value = g_variant_new_int32 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + boost::shared_ptr mockSetting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + /* Maybe we should fix ccsSettingGetName to return + * const char * instead of char * */ + CharacterWrapper settingNameInList (strdup ("fbrarr")); + char *settingNameInListC = settingNameInList; + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + boost::shared_ptr <_CCSSettingList> settingList (ccsSettingListAppend (NULL, mockSetting.get ()), + boost::bind (ccsSettingListFree, _1, FALSE)); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + EXPECT_CALL (*gmockPlugin, getPluginSettings ()).WillOnce (Return (settingList.get ())); + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeInt)); + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (settingNameInListC)); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingMatches) +{ + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + CCSSetting *mockSetting = ccsMockSettingNew (); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (Return (mockSetting)); + EXPECT_TRUE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, mockSetting); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFoundSetting) +{ + GVariant *value = g_variant_new_int32 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + CCSSetting *mockSetting = ccsMockSettingNew (); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + /* Maybe we should fix ccsSettingGetName to return + * const char * instead of char * */ + CharacterWrapper settingNameInList (strdup ("foo_bar")); + char *settingNameInListC = settingNameInList; + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + boost::shared_ptr <_CCSSettingList> settingList (ccsSettingListAppend (NULL, mockSetting), + boost::bind (ccsSettingListFree, _1, FALSE)); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + EXPECT_CALL (*gmockPlugin, getPluginSettings ()).WillOnce (Return (settingList.get ())); + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeInt)); + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (settingNameInListC)); + + EXPECT_TRUE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, mockSetting); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.h b/compizconfig/gsettings/tests/test_gsettings_tests.h index cbc9c18a3..356ef0276 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.h +++ b/compizconfig/gsettings/tests/test_gsettings_tests.h @@ -1,4 +1,11 @@ +#ifndef _COMPIZCONFIG_TEST_GSETTINGS_TESTS_H +#define _COMPIZCONFIG_TEST_GSETTINGS_TESTS_H + #include +#include +#include + +#include using ::testing::TestWithParam; @@ -37,5 +44,39 @@ class CCSGSettingsTest : class CCSGSettingsTestIndependent : public ::testing::Test { + public: + + virtual void SetUp () + { + g_setenv ("G_SLICE", "always-malloc", 1); + } + + virtual void TearDown () + { + g_unsetenv ("G_SLICE"); + } +}; + +class CCSGSettingsTestWithMemoryBackend : + public CCSGSettingsTestIndependent +{ + public: + + virtual void SetUp () + { + CCSGSettingsTestIndependent::SetUp (); + g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); + g_setenv ("GSETTINGS_BACKEND", "memory", 1); + + g_type_init (); + } + + virtual void TearDown () + { + g_unsetenv ("GSETTINGS_BACKEND"); + g_unsetenv ("GSETTINGS_SCHEMA_DIR"); + CCSGSettingsTestIndependent::TearDown (); + } }; +#endif diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 67fcce5dc..47ea55e39 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -10,7 +10,6 @@ #include #include "test_gsettings_tests.h" -#include #include using ::testing::NotNull; @@ -18,12 +17,12 @@ using ::testing::Eq; using ::testing::_; -class TestGSettingsWrapperWithMemoryBackendEnv : - public ::testing::Test +class CCSGSettingsWrapperTest : + public CCSGSettingsTestWithMemoryBackend { public: - TestGSettingsWrapperWithMemoryBackendEnv () : + CCSGSettingsWrapperTest () : mockSchema ("org.compiz.mock"), mockPath ("/org/compiz/mock/mock") { @@ -33,18 +32,12 @@ class TestGSettingsWrapperWithMemoryBackendEnv : virtual void SetUp () { - g_setenv ("G_SLICE", "always-malloc", 1); - g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); - g_setenv ("GSETTINGS_BACKEND", "memory", 1); - - g_type_init (); + CCSGSettingsTestWithMemoryBackend::SetUp (); } virtual void TearDown () { - g_unsetenv ("GSETTINGS_BACKEND"); - g_unsetenv ("GSETTINGS_SCHEMA_DIR"); - g_unsetenv ("G_SLICE"); + CCSGSettingsTestWithMemoryBackend::TearDown (); } protected: @@ -55,8 +48,8 @@ class TestGSettingsWrapperWithMemoryBackendEnv : GSettings *settings; }; -class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator : - public TestGSettingsWrapperWithMemoryBackendEnv +class CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest : + public CCSGSettingsWrapperTest { protected: @@ -66,14 +59,14 @@ class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator : } }; -class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit : - public TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator +class CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest : + public CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest { public: virtual void SetUp () { - TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator::SetUp (); + CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest::SetUp (); wrapper.reset (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), @@ -88,7 +81,7 @@ class TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit : } }; -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestWrapperConstruction) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest, TestWrapperConstruction) { boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), @@ -98,7 +91,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestWrapperConstr EXPECT_THAT (wrapper.get (), NotNull ()); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestGetGSettingsWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest, TestGetGSettingsWrapper) { boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), mockPath.c_str (), @@ -109,7 +102,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocator, TestGetGSettingsW EXPECT_THAT (ccsGSettingsWrapperGetGSettings (wrapper.get ()), NotNull ()); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestSetValueOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestSetValueOnWrapper) { const unsigned int VALUE = 2; const std::string KEY ("integer-setting"); @@ -124,7 +117,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestSetVa EXPECT_EQ (VALUE, v); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetValueOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetValueOnWrapper) { const double VALUE = 3.0; const std::string KEY ("float-setting"); @@ -139,7 +132,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetVa EXPECT_EQ (VALUE, v); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestResetKeyOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestResetKeyOnWrapper) { const char * DEFAULT = ""; const char * VALUE = "foo"; @@ -166,7 +159,7 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestReset ASSERT_THAT (v, Eq (DEFAULT)); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListKeysOnWrapper) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestListKeysOnWrapper) { const char * EXPECTED_KEYS[] = { @@ -196,12 +189,12 @@ TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestListK sizeof (EXPECTED_KEYS[0])); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetSchemaName) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetSchemaName) { EXPECT_THAT (ccsGSettingsWrapperGetSchemaName (wrapper.get ()), Eq (mockSchema)); } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestGetPath) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetPath) { EXPECT_THAT (ccsGSettingsWrapperGetPath (wrapper.get ()), Eq (mockPath)); } @@ -234,7 +227,7 @@ namespace signal_test } } -TEST_F (TestGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInit, TestConnectToChangedSignal) +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestConnectToChangedSignal) { std::string keyname ("int-setting"); signal_test::VerificationMock mv; -- GitLab From 5cce8546d50c5186a36f69a6cab0837879708da0 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 14:32:37 +0800 Subject: [PATCH 289/562] Rename and add a testcase for failing to find a key on the update function --- .../gsettings_backend_shared/gsettings_util.c | 2 +- .../gsettings_backend_shared/gsettings_util.h | 2 +- .../gsettings/tests/test_gsettings_tests.cpp | 40 ++++++++++++++----- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index a749cfcc2..3c72f908d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -397,7 +397,7 @@ findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, CCSGSettingsWrapper *settings, - gchar *keyName, + const gchar *keyName, CCSBackendUpdateFunc updateSetting) { CCSContext *context = ccsGSettingsBackendGetContext (backend); diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 6978e11d1..a71a9462f 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -122,7 +122,7 @@ findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, CCSGSettingsWrapper *settings, - gchar *keyName, + const gchar *keyName, CCSBackendUpdateFunc updateSetting); GList * diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index e2501c344..01826dd85 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1555,14 +1555,17 @@ TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplEmptyStringProf ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); } -class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : +class CCSGSettingsUpdateHandlersTest : public CCSGSettingsTestIndependent { public: - CCSGSettingsTestFindSettingAndPluginToUpdateFromPath () : + CCSGSettingsUpdateHandlersTest () : + gsettingsBackend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)), + gmockBackend (reinterpret_cast (ccsObjectGetPrivate (gsettingsBackend.get ()))), wrapper (ccsMockGSettingsWrapperNew (), - boost::bind (&ccsGSettingsWrapperUnref, _1)), + boost::bind (ccsGSettingsWrapperUnref, _1)), gmockWrapper (reinterpret_cast (ccsObjectGetPrivate (wrapper.get ()))), context (ccsMockContextNew (), boost::bind (ccsFreeMockContext, _1)), @@ -1573,7 +1576,7 @@ class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : { } - ~CCSGSettingsTestFindSettingAndPluginToUpdateFromPath () + ~CCSGSettingsUpdateHandlersTest () { if (plugin) ccsPluginUnref (plugin); @@ -1594,6 +1597,8 @@ class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : protected: + boost::shared_ptr gsettingsBackend; + CCSGSettingsBackendGMock *gmockBackend; boost::shared_ptr wrapper; CCSGSettingsWrapperGMock *gmockWrapper; boost::shared_ptr context; @@ -1605,7 +1610,7 @@ class CCSGSettingsTestFindSettingAndPluginToUpdateFromPath : char *uncleanKeyName; }; -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestBadPath) +TEST_F (CCSGSettingsUpdateHandlersTest, TestBadPath) { SetPathAndKeyname ("/wrong", "foo"); @@ -1622,7 +1627,7 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestBadPath) EXPECT_THAT (uncleanKeyName, IsNull ()); } -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoPluginFound) +TEST_F (CCSGSettingsUpdateHandlersTest, TestNoPluginFound) { SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", "foo-bar"); @@ -1641,7 +1646,7 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoPluginFound) EXPECT_THAT (uncleanKeyName, IsNull ()); } -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoSettingFound) +TEST_F (CCSGSettingsUpdateHandlersTest, TestNoSettingFound) { CCSPlugin *mockPlugin = ccsMockPluginNew (); CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); @@ -1668,7 +1673,7 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestNoSettingFound EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); } -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoundAndNoTypeMatches) +TEST_F (CCSGSettingsUpdateHandlersTest, TestSettingNotFoundAndNoTypeMatches) { GVariant *value = g_variant_new_int16 (2); CCSPlugin *mockPlugin = ccsMockPluginNew (); @@ -1696,7 +1701,7 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoun EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); } -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoundAndNoSettingMatches) +TEST_F (CCSGSettingsUpdateHandlersTest, TestSettingNotFoundAndNoSettingMatches) { GVariant *value = g_variant_new_int32 (2); CCSPlugin *mockPlugin = ccsMockPluginNew (); @@ -1738,7 +1743,7 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingNotFoun EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); } -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingMatches) +TEST_F (CCSGSettingsUpdateHandlersTest, TestSettingMatches) { CCSPlugin *mockPlugin = ccsMockPluginNew (); CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); @@ -1764,7 +1769,7 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestSettingMatches EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); } -TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFoundSetting) +TEST_F (CCSGSettingsUpdateHandlersTest, TestFoundSetting) { GVariant *value = g_variant_new_int32 (2); CCSPlugin *mockPlugin = ccsMockPluginNew (); @@ -1804,3 +1809,16 @@ TEST_F (CCSGSettingsTestFindSettingAndPluginToUpdateFromPath, TestFoundSetting) EXPECT_THAT (setting, mockSetting); EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); } + +TEST_F (CCSGSettingsUpdateHandlersTest, TestUnfindableSettingToUpdateSetttingsWithGSettingsKeyName) +{ + SetPathAndKeyname ("/wrong", "bad-key"); + + EXPECT_CALL (*gmockBackend, getContext ()).WillOnce (Return (context.get ())); + EXPECT_CALL (*gmockWrapper, getPath ()).WillOnce (Return (path.c_str ())); + + EXPECT_FALSE (updateSettingWithGSettingsKeyName (gsettingsBackend.get (), + wrapper.get (), + keyName.c_str (), + NULL)); +} -- GitLab From 09cee79312fae12c67d813b803436beea49f6c92 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 14:44:58 +0800 Subject: [PATCH 290/562] Test cases for getVariantAtKey --- .../gsettings/tests/test_gsettings_tests.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 01826dd85..cfff53e99 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1822,3 +1822,35 @@ TEST_F (CCSGSettingsUpdateHandlersTest, TestUnfindableSettingToUpdateSetttingsWi keyName.c_str (), NULL)); } + +TEST_F (CCSGSettingsTestIndependent, TestGetVariantAtKeySuccess) +{ + CCSSettingType TYPE = TypeInt; + const std::string KEY ("good-key"); + const std::string PATH ("/org/compiz/mock/plugins/mock"); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + boost::shared_ptr value (g_variant_ref_sink (g_variant_new_int32 (2)), + boost::bind (g_variant_unref, _1)); + + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); + + EXPECT_CALL (*gmockWrapper, getValue (Eq (KEY))).WillOnce (Return (value.get ())); + EXPECT_EQ (getVariantAtKey (wrapper.get (), KEY.c_str (), PATH.c_str (), TYPE), value.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestGetVariantAtKeyFailure) +{ + CCSSettingType TYPE = TypeString; + const std::string KEY ("good-key"); + const std::string PATH ("/org/compiz/mock/plugins/mock"); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + boost::shared_ptr value (g_variant_ref_sink (g_variant_new_int32 (2)), + boost::bind (g_variant_unref, _1)); + + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); + + EXPECT_CALL (*gmockWrapper, getValue (Eq (KEY))).WillOnce (Return (value.get ())); + EXPECT_THAT (getVariantAtKey (wrapper.get (), KEY.c_str (), PATH.c_str (), TYPE), IsNull ()); +} -- GitLab From b9776a44bd4427e31089ad954b21d41140b736a3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 15:12:52 +0800 Subject: [PATCH 291/562] Moved some code that should be common out --- .../gsettings_backend_shared/gsettings_util.c | 33 +++++++++++++++++++ .../gsettings_backend_shared/gsettings_util.h | 8 +++++ compizconfig/gsettings/src/gsettings.c | 32 ------------------ 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 3c72f908d..faa0c0bcf 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1017,6 +1017,39 @@ removeItemFromVariant (GVariant **variant, *variant = g_variant_builder_end (&newVariantBuilder); } +void +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) +{ + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); + char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); + + ccsGSettingsWrapperResetKey (settings, cleanSettingName); + + free (cleanSettingName); +} + +gchar * +makeSettingPath (const char *currentProfile, CCSSetting *setting) +{ + return makeCompizPluginPath (currentProfile, + ccsPluginGetName (ccsSettingGetParent (setting))); +} + +CCSGSettingsWrapper * +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) +{ + CCSGSettingsWrapper *ret = NULL; + gchar *pathName = makeSettingPath (ccsGSettingsBackendGetCurrentProfile (backend), setting); + + ret = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, + ccsPluginGetName (ccsSettingGetParent (setting)), + pathName, + ccsPluginGetContext (ccsSettingGetParent (setting))); + + g_free (pathName); + return ret; +} + void ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile) { diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index a71a9462f..4607245bf 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -219,6 +219,14 @@ readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSO CCSSettingValueList readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); +gchar * +makeSettingPath (const char *currentProfile, CCSSetting *setting); + +CCSGSettingsWrapper * +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting); + +void +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting); gboolean ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context); diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index b387d2d62..127b0874b 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -97,28 +97,7 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen return settingsObj; } -static gchar * -makeSettingPath (const char *currentProfile, CCSSetting *setting) -{ - return makeCompizPluginPath (currentProfile, - ccsPluginGetName (ccsSettingGetParent (setting))); -} - -static CCSGSettingsWrapper * -getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) -{ - CCSGSettingsWrapper *ret = NULL; - CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); - gchar *pathName = makeSettingPath (priv->currentProfile, setting); - - ret = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, - ccsPluginGetName (ccsSettingGetParent (setting)), - pathName, - ccsPluginGetContext (ccsSettingGetParent (setting))); - g_free (pathName); - return ret; -} static Bool isIntegratedOption (CCSSetting *setting, @@ -368,17 +347,6 @@ writeIntegratedOption (CCSBackend *backend, return; } -static void -resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) -{ - CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - ccsGSettingsWrapperResetKey (settings, cleanSettingName); - - free (cleanSettingName); -} - void writeOption (CCSBackend *backend, CCSSetting * setting) { -- GitLab From ad87b2e8a830a4fd148bd0e0563b5ddf2a8b5cd2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 15:41:14 +0800 Subject: [PATCH 292/562] Some very messy looking tests for resetOptionToDefault and makeSettingPath --- .../gsettings/tests/test_gsettings_tests.cpp | 84 ++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index cfff53e99..bb0351dcf 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1846,11 +1846,89 @@ TEST_F (CCSGSettingsTestIndependent, TestGetVariantAtKeyFailure) const std::string PATH ("/org/compiz/mock/plugins/mock"); boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), boost::bind (ccsGSettingsWrapperUnref, _1)); - boost::shared_ptr value (g_variant_ref_sink (g_variant_new_int32 (2)), - boost::bind (g_variant_unref, _1)); + GVariant *value = g_variant_new_int32 (2); CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); - EXPECT_CALL (*gmockWrapper, getValue (Eq (KEY))).WillOnce (Return (value.get ())); + EXPECT_CALL (*gmockWrapper, getValue (Eq (KEY))).WillOnce (Return (value)); EXPECT_THAT (getVariantAtKey (wrapper.get (), KEY.c_str (), PATH.c_str (), TYPE), IsNull ()); } + +TEST_F (CCSGSettingsTestIndependent, TestMakeSettingPath) +{ + CharacterWrapper PLUGIN (strdup ("mock")); + char *PLUGIN_STR = PLUGIN; + std::string PROFILE ("mock"); + std::string EXPECTED_PATH ("/org/compiz/profiles/mock/plugins/mock/"); + boost::shared_ptr plugin (ccsMockPluginNew (), + boost::bind (ccsPluginUnref, _1)); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (plugin)); + boost::shared_ptr setting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (setting)); + + EXPECT_CALL (*gmockSetting, getParent ()).WillOnce (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, getName ()).WillOnce (Return (PLUGIN_STR)); + + CharacterWrapper path (makeSettingPath (PROFILE.c_str (), setting.get ())); + std::string pathString (path); + + EXPECT_EQ (pathString, EXPECTED_PATH); +} + +TEST_F (CCSGSettingsTestIndependent, TestFindSettingsObject) +{ + CharacterWrapper PLUGIN (strdup ("mock")); + char *PLUGIN_STR = PLUGIN; + std::string PROFILE ("mock"); + std::string EXPECTED_PATH ("/org/compiz/profiles/mock/plugins/mock/"); + boost::shared_ptr plugin (ccsMockPluginNew (), + boost::bind (ccsPluginUnref, _1)); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (plugin)); + boost::shared_ptr setting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (setting)); + + EXPECT_CALL (*gmockSetting, getParent ()).WillOnce (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, getName ()).WillOnce (Return (PLUGIN_STR)); + + CharacterWrapper path (makeSettingPath (PROFILE.c_str (), setting.get ())); + std::string pathString (path); + + EXPECT_EQ (pathString, EXPECTED_PATH); +} + +TEST_F (CCSGSettingsTestIndependent, TestResetOptionToDefault) +{ + CharacterWrapper SETTING_NAME (strdup ("Mock_setting")); + char *SETTING_NAME_STR = SETTING_NAME; + CharacterWrapper TRANSLATED_SETTING_NAME (translateKeyForGSettings (SETTING_NAME)); + CharacterWrapper PLUGIN (strdup ("mock")); + char *PLUGIN_STR = PLUGIN; + std::string PROFILE ("mock"); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); + boost::shared_ptr plugin (ccsMockPluginNew (), + boost::bind (ccsPluginUnref, _1)); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (plugin)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + boost::shared_ptr setting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (setting.get ())); + + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (SETTING_NAME_STR)); + EXPECT_CALL (*gmockSetting, getParent ()).WillRepeatedly (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, getName ()).WillRepeatedly (Return (PLUGIN_STR)); + EXPECT_CALL (*gmockPlugin, getContext ()).WillRepeatedly (ReturnNull ()); + + EXPECT_CALL (*gmockBackend, getSettingsObjectForPluginWithPath (Eq (std::string (PLUGIN)), + _, + IsNull ())).WillOnce (Return (wrapper.get ())); + + EXPECT_CALL (*gmockWrapper, resetKey (Eq (std::string (TRANSLATED_SETTING_NAME)))); + + resetOptionToDefault (backend.get (), setting.get ()); +} -- GitLab From fec066cb0820d9898ac16c31c023ebed40630b27 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 16:24:25 +0800 Subject: [PATCH 293/562] A very oversized test for ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault --- .../gsettings_backend_shared/gsettings_util.c | 35 +++++++++ .../gsettings_backend_shared/gsettings_util.h | 7 ++ compizconfig/gsettings/src/gsettings.c | 35 --------- .../gsettings/tests/test_gsettings_tests.cpp | 75 +++++++++++++++++++ 4 files changed, 117 insertions(+), 35 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index faa0c0bcf..35a8f230d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1117,6 +1117,41 @@ deleteProfile (CCSBackend *backend, return TRUE; } +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, + CCSContext *context, + GVariant *pluginsWithChangedKeys, + const char * profile) +{ + GVariantIter iter; + char *plugin; + + g_variant_iter_init (&iter, pluginsWithChangedKeys); + while (g_variant_iter_loop (&iter, "s", &plugin)) + { + CCSGSettingsWrapper *settings; + gchar *pathName = makeCompizPluginPath (profile, plugin); + + settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); + g_free (pathName); + + /* The GSettings documentation says not to use this API + * because we should know our own schema ... though really + * we don't because we autogenerate schemas ... */ + if (settings) + { + char **keys = ccsGSettingsWrapperListKeys (settings); + char **key_ptr; + + /* Unset all the keys */ + for (key_ptr = keys; *key_ptr; key_ptr++) + ccsGSettingsWrapperResetKey (settings, *key_ptr); + + g_strfreev (keys); + } + } +} + CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend) { diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 4607245bf..ef322cb59 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -284,6 +284,13 @@ ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const c gboolean ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context); +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, + CCSContext *context, + GVariant *pluginsWithChangedKeys, + const char * profile); + + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 127b0874b..848e78bfe 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -606,41 +606,6 @@ ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend) ccsGSettingsWrapperResetKey (priv->currentProfileSettings, "plugins-with-set-keys"); } -static void -ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, - CCSContext *context, - GVariant *pluginsWithChangedKeys, - const char * profile) -{ - GVariantIter iter; - char *plugin; - - g_variant_iter_init (&iter, pluginsWithChangedKeys); - while (g_variant_iter_loop (&iter, "s", &plugin)) - { - CCSGSettingsWrapper *settings; - gchar *pathName = makeCompizPluginPath (profile, plugin); - - settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); - g_free (pathName); - - /* The GSettings documentation says not to use this API - * because we should know our own schema ... though really - * we don't because we autogenerate schemas ... */ - if (settings) - { - char **keys = ccsGSettingsWrapperListKeys (settings); - char **key_ptr; - - /* Unset all the keys */ - for (key_ptr = keys; *key_ptr; key_ptr++) - ccsGSettingsWrapperResetKey (settings, *key_ptr); - - g_strfreev (keys); - } - } -} - static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendGetContextDefault, ccsGSettingsBackendConnectToValueChangedSignalDefault, diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index bb0351dcf..082f828a5 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "test_gsettings_tests.h" #include "gsettings.h" @@ -1932,3 +1933,77 @@ TEST_F (CCSGSettingsTestIndependent, TestResetOptionToDefault) resetOptionToDefault (backend.get (), setting.get ()); } + +TEST_F (CCSGSettingsTestIndependent, TestUnsetAllChangedPluginKeysInProfileDefaultImpl) +{ + std::string PLUGIN_FOO ("foo"); + std::string PLUGIN_BAR ("bar"); + + std::string KEY_EXAMPLE_ONE ("example-one"); + std::string KEY_EXAMPLE_TWO ("example-two"); + std::string KEY_EXAMPLE_THREE ("example-three"); + + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (ccsFreeMockContext, _1)); + + GVariantBuilder pluginsWithChangedKeysBuilder; + + const unsigned short NUM_KEYS = 3; + + gchar ** fooKeys = (gchar **) calloc (1, sizeof (char *) * (NUM_KEYS + 1)); + fooKeys[0] = g_strdup (KEY_EXAMPLE_ONE.c_str ()); + fooKeys[1] = g_strdup (KEY_EXAMPLE_TWO.c_str ()); + fooKeys[2] = g_strdup (KEY_EXAMPLE_THREE.c_str ()); + fooKeys[3] = NULL; + + gchar ** barKeys = (gchar **) calloc (1, sizeof (char *) * (NUM_KEYS + 1)); + barKeys[0] = g_strdup (KEY_EXAMPLE_ONE.c_str ()); + barKeys[1] = g_strdup (KEY_EXAMPLE_TWO.c_str ()); + barKeys[2] = g_strdup (KEY_EXAMPLE_THREE.c_str ()); + barKeys[3] = NULL; + + g_variant_builder_init (&pluginsWithChangedKeysBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&pluginsWithChangedKeysBuilder, "s", PLUGIN_FOO.c_str ()); + g_variant_builder_add (&pluginsWithChangedKeysBuilder, "s", PLUGIN_BAR.c_str ()); + + boost::shared_ptr pluginsWithChangedKeys (g_variant_ref_sink (g_variant_builder_end (&pluginsWithChangedKeysBuilder)), + boost::bind (g_variant_unref, _1)); + + boost::shared_ptr wrapperForFoo (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapperForFoo = reinterpret_cast (ccsObjectGetPrivate (wrapperForFoo.get ())); + boost::shared_ptr wrapperForBar (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapperForBar = reinterpret_cast (ccsObjectGetPrivate (wrapperForBar.get ())); + + + /* Get the settings wrapper */ + EXPECT_CALL (*gmockBackend, getSettingsObjectForPluginWithPath (Eq (PLUGIN_FOO), _, context.get ())).WillOnce (Return (wrapperForFoo.get ())); + + /* List the keys */ + EXPECT_CALL (*gmockWrapperForFoo, listKeys ()).WillOnce (Return (fooKeys)); + + /* Unset all the keys */ + EXPECT_CALL (*gmockWrapperForFoo, resetKey (Eq (KEY_EXAMPLE_ONE))); + EXPECT_CALL (*gmockWrapperForFoo, resetKey (Eq (KEY_EXAMPLE_TWO))); + EXPECT_CALL (*gmockWrapperForFoo, resetKey (Eq (KEY_EXAMPLE_THREE))); + + /* Get the settings wrapper */ + EXPECT_CALL (*gmockBackend, getSettingsObjectForPluginWithPath (Eq (PLUGIN_BAR), _, context.get ())).WillOnce (Return (wrapperForBar.get ())); + + /* List the keys */ + EXPECT_CALL (*gmockWrapperForBar, listKeys ()).WillOnce (Return (barKeys)); + + /* Unset all the keys */ + EXPECT_CALL (*gmockWrapperForBar, resetKey (Eq (KEY_EXAMPLE_ONE))); + EXPECT_CALL (*gmockWrapperForBar, resetKey (Eq (KEY_EXAMPLE_TWO))); + EXPECT_CALL (*gmockWrapperForBar, resetKey (Eq (KEY_EXAMPLE_THREE))); + + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (backend.get (), + context.get (), + pluginsWithChangedKeys.get (), + "mock"); +} -- GitLab From 6bae21ef55b1eba1994aeeabe58cbc63f21637ff Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 16:28:28 +0800 Subject: [PATCH 294/562] Fix missing unexpected mock function call --- compizconfig/gsettings/tests/test_gsettings_tests.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 082f828a5..b0ec41d29 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1925,6 +1925,7 @@ TEST_F (CCSGSettingsTestIndependent, TestResetOptionToDefault) EXPECT_CALL (*gmockPlugin, getName ()).WillRepeatedly (Return (PLUGIN_STR)); EXPECT_CALL (*gmockPlugin, getContext ()).WillRepeatedly (ReturnNull ()); + EXPECT_CALL (*gmockBackend, getCurrentProfile ()).WillRepeatedly (Return (PROFILE.c_str ())); EXPECT_CALL (*gmockBackend, getSettingsObjectForPluginWithPath (Eq (std::string (PLUGIN)), _, IsNull ())).WillOnce (Return (wrapper.get ())); -- GitLab From 02835dc6fd6da88c7a163395a30e89ce599b19bb Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 17:00:43 +0800 Subject: [PATCH 295/562] Added profile test fixture to the conformance test - first item - list existing profiles --- ...nfig_test_ccs_mock_backend_conformance.cpp | 29 ++++++++++++++ .../tests/compizconfig_backend_concept_test.h | 38 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 8b52bf32c..5b3ad8027 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -104,6 +104,31 @@ class MockCCSBackendConceptTestEnvironment : ccsFreeMockBackend (backend); } + void AddProfile (const std::string &profile) + { + mProfiles.push_back (profile); + } + + void SetGetExistingProfilesExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + CCSStringList stringList = NULL; + + for (std::vector ::iterator it = mProfiles.begin (); + it != mProfiles.end (); + ++it) + { + CCSString *string = reinterpret_cast (calloc (1, sizeof (CCSString))); + + string->value = strdup ((*it).c_str ()); + ccsStringRef (string); + + stringList = ccsStringListAppend (stringList, string); + } + + EXPECT_CALL (*mBackendGMock, getExistingProfiles (context)).WillOnce (Return (stringList)); + } + void SetReadInitExpectation (CCSContext *context, CCSContextGMock *gmockContext) { @@ -551,6 +576,7 @@ class MockCCSBackendConceptTestEnvironment : CCSBackendGMock *mBackendGMock; CCSContext *mContext; std::map mValues; + std::vector mProfiles; }; INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWrite, @@ -561,3 +587,6 @@ INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInfo, INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInitFiniFuncs, compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestProfileHandling, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index a000b01ba..1d49d9d21 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -198,6 +198,10 @@ class CCSBackendConceptTestEnvironmentInterface CCSContextGMock *gmockContext) = 0; virtual void TearDown (CCSBackend *) = 0; + virtual void AddProfile (const std::string &profile) = 0; + virtual void SetGetExistingProfilesExpectation (CCSContext *, + CCSContextGMock *) = 0; + virtual void SetReadInitExpectation (CCSContext *, CCSContextGMock *) = 0; @@ -1215,5 +1219,39 @@ TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestWriteDone) } } +class CCSBackendConformanceTestProfileHandling : + public CCSBackendConformanceTestParameterizedByBackendFixture +{ + public: + + static const std::string PROFILE_FOO; + static const std::string PROFILE_BAR; +}; + +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_FOO ("foo"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar"); + +TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + CCSStringList iter = existingProfiles.get (); + + ASSERT_EQ (ccsStringListLength (iter), 2); + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_BAR)); + } +} + #endif -- GitLab From a45219543275e9937a83278d7a9fad08150bad2a Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 18:37:15 +0800 Subject: [PATCH 296/562] Tests for deleting profiles --- ...nfig_test_ccs_mock_backend_conformance.cpp | 33 ++++++++++ .../tests/compizconfig_backend_concept_test.h | 66 +++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 5b3ad8027..505c29991 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -89,6 +89,13 @@ class MockCCSBackendConceptTestEnvironment : this, &MockCCSBackendConceptTestEnvironment::WriteValueToMap))); + ON_CALL (*mBackendGMock, deleteProfile (_, _)) + .WillByDefault ( + WithArgs <1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::DeleteProfile))); + return mBackend; } @@ -129,6 +136,14 @@ class MockCCSBackendConceptTestEnvironment : EXPECT_CALL (*mBackendGMock, getExistingProfiles (context)).WillOnce (Return (stringList)); } + void SetDeleteProfileExpectation (const std::string &profileForDeletion, + CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, deleteProfile (context, + Eq (profileForDeletion))); + } + void SetReadInitExpectation (CCSContext *context, CCSContextGMock *gmockContext) { @@ -403,6 +418,24 @@ class MockCCSBackendConceptTestEnvironment : protected: + bool DeleteProfile (const std::string &profileToDelete) + { + std::vector ::iterator it = std::find (mProfiles.begin (), + mProfiles.end (), + profileToDelete); + + if (it != mProfiles.end ()) + { + mProfiles.erase (it); + return true; + } + else + { + return false; + } + + } + void ReadValueIntoSetting (CCSSetting *setting) { std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 1d49d9d21..6e9050776 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -26,6 +26,7 @@ #include "compizconfig_test_value_combiners.h" using ::testing::Eq; +using ::testing::IsNull; using ::testing::SetArgPointee; using ::testing::DoAll; using ::testing::Return; @@ -201,6 +202,9 @@ class CCSBackendConceptTestEnvironmentInterface virtual void AddProfile (const std::string &profile) = 0; virtual void SetGetExistingProfilesExpectation (CCSContext *, CCSContextGMock *) = 0; + virtual void SetDeleteProfileExpectation (const std::string &, + CCSContext *, + CCSContextGMock *) = 0; virtual void SetReadInitExpectation (CCSContext *, CCSContextGMock *) = 0; @@ -1253,5 +1257,67 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) } } +TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); + + /* Make sure that backends know what profile is being deleted */ + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); + EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + + /* Check to make sure that the profile is no longer there */ + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + CCSStringList iter = existingProfiles.get (); + + ASSERT_EQ (ccsStringListLength (iter), 1); + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next), IsNull ()); + } +} + +TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentProfile) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); + + /* Make sure that backends know what profile is being deleted */ + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); + EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + + /* Check to make sure that the profile is no longer there */ + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + CCSStringList iter = existingProfiles.get (); + + ASSERT_EQ (ccsStringListLength (iter), 1); + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next), IsNull ()); + } +} + #endif -- GitLab From 37fab5a309af07f5722f94a39aa17933a70bf463 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 18:56:38 +0800 Subject: [PATCH 297/562] Added testable AddProfile method to CCSGSettingsBackend, some tests failing --- .../gsettings_backend_shared/gsettings_util.c | 20 ++++++++++-- .../gsettings_backend_shared/gsettings_util.h | 10 ++++++ compizconfig/gsettings/src/gsettings.c | 3 +- .../tests/ccs_gsettings_backend_mock.cpp | 1 + .../tests/ccs_gsettings_backend_mock.h | 8 +++++ .../tests/compizconfig_backend_concept_test.h | 31 +++++++++++++++++++ 6 files changed, 70 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 35a8f230d..8a69f8ef7 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1050,17 +1050,27 @@ getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) return ret; } -void -ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile) +gboolean +ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, const char *profile) { GVariant *profiles; + gboolean ret = FALSE; profiles = ccsGSettingsBackendGetExistingProfiles (backend); if (appendStringToVariantIfUnique (&profiles, profile)) + { + ret = TRUE; ccsGSettingsBackendSetExistingProfiles (backend, profiles); + } g_variant_unref (profiles); + return ret; +} +void +ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile) +{ + ccsGSettingsBackendAddProfile (backend, profile); ccsGSettingsBackendSetCurrentProfile (backend, profile); } @@ -1244,5 +1254,11 @@ ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *pr (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUpdateCurrentProfileName) (backend, profile); } +void +ccsGSettingsBackendAddProfile (CCSBackend *backend, const char *profile) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendAddProfile) (backend, profile); +} + CCSContext * ccsGSettingsBackendGetContext (CCSBackend *backend); diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index ef322cb59..f9905634a 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -40,6 +40,8 @@ typedef void (*CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile) (CCSBacken typedef gboolean (*CCSGSettingsBackendUpdateProfile) (CCSBackend *, CCSContext *); typedef void (*CCSGSettingsBackendUpdateCurrentProfileName) (CCSBackend *backend, const char *profile); +typedef gboolean (*CCSGSettingsBackendAddProfile) (CCSBackend *backend, const char *profile); + struct _CCSGSettingsBackendInterface { CCSGSettingsBackendGetContext gsettingsBackendGetContext; @@ -56,6 +58,7 @@ struct _CCSGSettingsBackendInterface CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile gsettingsBackendUnsetAllChangedPluginKeysInProfile; CCSGSettingsBackendUpdateProfile gsettingsBackendUpdateProfile; CCSGSettingsBackendUpdateCurrentProfileName gsettingsBackendUpdateCurrentProfileName; + CCSGSettingsBackendAddProfile gsettingsBackendAddProfile; }; unsigned int ccsCCSGSettingsBackendInterfaceGetType (); @@ -276,6 +279,10 @@ ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, GVariant *pluginKeys, const char *profile); +void +ccsGSettingsBackendAddProfile (CCSBackend *backend, + const char *profile); + /* Default implementations, should be moved */ void @@ -290,6 +297,9 @@ ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backen GVariant *pluginsWithChangedKeys, const char * profile); +gboolean ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, + const char *profile); + COMPIZCONFIG_END_DECLS diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 848e78bfe..00d744ecb 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -620,7 +620,8 @@ static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { ccsGSettingsBackendClearPluginsWithSetKeysDefault, ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault, ccsGSettingsBackendUpdateProfileDefault, - ccsGSettingsBackendUpdateCurrentProfileNameDefault + ccsGSettingsBackendUpdateCurrentProfileNameDefault, + ccsGSettingsBackendAddProfileDefault }; static Bool diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp index 632c7f765..aca2a5638 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp @@ -21,6 +21,7 @@ CCSGSettingsBackendInterface ccsGSettingsBackendGMockInterface = CCSGSettingsBackendGMock::ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile, CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateProfile, CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateCurrentProfileName, + CCSGSettingsBackendGMock::ccsGSettingsBackendAddProfile }; CCSBackend * diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h index ef05a1b3b..9017f507b 100644 --- a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -35,6 +35,7 @@ class CCSGSettingsBackendGMockInterface virtual void unsetAllChangedPluginKeysInProfile (CCSContext *, GVariant *, const char *) = 0; virtual gboolean updateProfile (CCSContext *) = 0; virtual void updateCurrentProfileName (const char *) = 0; + virtual gboolean addProfile (const char *) = 0; }; class CCSGSettingsBackendGMock : @@ -63,6 +64,7 @@ class CCSGSettingsBackendGMock : MOCK_METHOD3 (unsetAllChangedPluginKeysInProfile, void (CCSContext *, GVariant *, const char *)); MOCK_METHOD1 (updateProfile, gboolean (CCSContext *)); MOCK_METHOD1 (updateCurrentProfileName, void (const char *)); + MOCK_METHOD1 (addProfile, gboolean (const char *)); CCSBackend * getBackend () { return mBackend; } @@ -163,6 +165,12 @@ class CCSGSettingsBackendGMock : { return (reinterpret_cast (ccsObjectGetPrivate (backend)))->updateCurrentProfileName (profile); } + + static gboolean + ccsGSettingsBackendAddProfile (CCSBackend *backend, const char *profile) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->addProfile (profile); + } }; #endif diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 6e9050776..fc05998dd 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1319,5 +1319,36 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr } } +TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); + + /* Make sure that backends know what profile is being deleted */ + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_BAR.c_str ())); + + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); + EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + + /* Check to make sure that the profile is no longer there */ + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + CCSStringList iter = existingProfiles.get (); + + ASSERT_EQ (ccsStringListLength (iter), 1); + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next), IsNull ()); + } +} + #endif -- GitLab From 50c0b32c1768506c05f1f0acc24560ae44e2f568 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 22:01:44 +0800 Subject: [PATCH 298/562] Added stubs for tests, fixed double unrefs due to GSettings' really annoying stealing behaviour --- compizconfig/gsettings/src/gsettings.c | 2 -- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 00d744ecb..49892f91d 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -89,7 +89,6 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen ccsGSettingsWrapperSetValue (priv->currentProfileSettings, "plugins-with-set-keys", newWrittenPluginsVariant); - g_variant_unref (newWrittenPluginsVariant); g_variant_unref (writtenPlugins); g_free (schemaName); g_strfreev (newWrittenPlugins); @@ -588,7 +587,6 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "current-profile", currentProfileVariant); - g_variant_unref (currentProfileVariant); g_free (profilePath); } diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index ad341686c..898e0d216 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -92,6 +92,12 @@ class CCSGSettingsBackendEnv : ccsFreeDynamicBackend (mBackend); } + void AddProfile (const std::string &profile) {} + void SetGetExistingProfilesExpectation (CCSContext *context, + CCSContextGMock *gmockContext) {} + void SetDeleteProfileExpectation (const std::string &profileToDelete, + CCSContext *context, CCSContextGMock *gmockContext) {} + void SetReadInitExpectation (CCSContext *context, CCSContextGMock *gmockContext) { -- GitLab From 6933dd77c6fa533d32740670e383c086c47c0d86 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 22:16:43 +0800 Subject: [PATCH 299/562] Instantiate the CCSBackendConformanceTestProfileHandling suite for the GSettings backend conformance test --- compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 898e0d216..ac3e08119 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -470,3 +470,6 @@ INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestIn INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestInitFiniFuncs, compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestProfileHandling, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); -- GitLab From 8a4d97575550b4d330d58ef80c1aae050359a2ed Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 22:23:48 +0800 Subject: [PATCH 300/562] Fix more double unref --- .../gsettings/gsettings_backend_shared/gsettings_util.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 8a69f8ef7..2c40e25a4 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1062,8 +1062,9 @@ ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, const char *profile) ret = TRUE; ccsGSettingsBackendSetExistingProfiles (backend, profiles); } + else + g_variant_unref (profiles); - g_variant_unref (profiles); return ret; } @@ -1120,8 +1121,6 @@ deleteProfile (CCSBackend *backend, /* Remove the profile from existing-profiles */ ccsGSettingsBackendSetExistingProfiles (backend, profiles); - g_variant_unref (profiles); - ccsGSettingsBackendUpdateProfile (backend, context); return TRUE; -- GitLab From 4b73d0167d6826572fe00cb5bef988bca35171b1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 22:25:32 +0800 Subject: [PATCH 301/562] SetValue consumes the reference, no need to g_variant_unref --- .../gsettings/gsettings_backend_shared/gsettings_util.c | 5 ++--- compizconfig/gsettings/src/gsettings.c | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 8a69f8ef7..2c40e25a4 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1062,8 +1062,9 @@ ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, const char *profile) ret = TRUE; ccsGSettingsBackendSetExistingProfiles (backend, profiles); } + else + g_variant_unref (profiles); - g_variant_unref (profiles); return ret; } @@ -1120,8 +1121,6 @@ deleteProfile (CCSBackend *backend, /* Remove the profile from existing-profiles */ ccsGSettingsBackendSetExistingProfiles (backend, profiles); - g_variant_unref (profiles); - ccsGSettingsBackendUpdateProfile (backend, context); return TRUE; diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 00d744ecb..49892f91d 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -89,7 +89,6 @@ ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backen ccsGSettingsWrapperSetValue (priv->currentProfileSettings, "plugins-with-set-keys", newWrittenPluginsVariant); - g_variant_unref (newWrittenPluginsVariant); g_variant_unref (writtenPlugins); g_free (schemaName); g_strfreev (newWrittenPlugins); @@ -588,7 +587,6 @@ ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *v ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "current-profile", currentProfileVariant); - g_variant_unref (currentProfileVariant); g_free (profilePath); } -- GitLab From 90910ef8baec494402d551f38fed32684fba74f9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 22:30:19 +0800 Subject: [PATCH 302/562] Added AddProfile stub --- .../gsettings/tests/test_gsettings_conformance.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index ac3e08119..b2d79ca63 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -92,9 +92,16 @@ class CCSGSettingsBackendEnv : ccsFreeDynamicBackend (mBackend); } - void AddProfile (const std::string &profile) {} + void AddProfile (const std::string &profile) + { + ccsGSettingsBackendAddProfile (mGSettingsBackend, profile.c_str ()); + } + void SetGetExistingProfilesExpectation (CCSContext *context, - CCSContextGMock *gmockContext) {} + CCSContextGMock *gmockContext) + { + } + void SetDeleteProfileExpectation (const std::string &profileToDelete, CCSContext *context, CCSContextGMock *gmockContext) {} -- GitLab From e4b4ff3fd4c1b9296b8828e7607c2d6991edf7e7 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 22:37:39 +0800 Subject: [PATCH 303/562] Default profile is implicitly added --- ...nfig_test_ccs_mock_backend_conformance.cpp | 3 +++ .../tests/compizconfig_backend_concept_test.h | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 505c29991..3a77f430f 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -96,6 +96,9 @@ class MockCCSBackendConceptTestEnvironment : this, &MockCCSBackendConceptTestEnvironment::DeleteProfile))); + /* Always have a Default profile */ + AddProfile ("Default"); + return mBackend; } diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 6e9050776..634075a09 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1228,10 +1228,12 @@ class CCSBackendConformanceTestProfileHandling : { public: + static const std::string PROFILE_DEFAULT; static const std::string PROFILE_FOO; static const std::string PROFILE_BAR; }; +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_DEFAULT ("Default"); const std::string CCSBackendConformanceTestProfileHandling::PROFILE_FOO ("foo"); const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar"); @@ -1251,9 +1253,12 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 2); - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_BAR)); + ASSERT_EQ (ccsStringListLength (iter), 3); + + /* Default profile must always be there */ + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_BAR)); } } @@ -1282,9 +1287,10 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 1); - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next), IsNull ()); + ASSERT_EQ (ccsStringListLength (iter), 2); + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); } } @@ -1313,9 +1319,10 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 1); - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next), IsNull ()); + ASSERT_EQ (ccsStringListLength (iter), 2); + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); } } -- GitLab From a9ca2cc1b3b0e926b125239e351704590e4b4140 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 5 Aug 2012 23:15:30 +0800 Subject: [PATCH 304/562] Add default and current profiles correctly --- compizconfig/gsettings/src/gsettings.c | 2 +- ...nfig_test_ccs_mock_backend_conformance.cpp | 25 +++++++- .../tests/compizconfig_backend_concept_test.h | 62 ++++++++++++------- 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 49892f91d..bda145da0 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -781,7 +781,7 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) while (g_variant_iter_loop (&iter, "s", &profile)) { CCSString *str = malloc (sizeof (CCSString)); - + str->value = strdup (profile); ret = ccsStringListAppend (ret, str); diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 3a77f430f..83b6a054e 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -96,9 +96,6 @@ class MockCCSBackendConceptTestEnvironment : this, &MockCCSBackendConceptTestEnvironment::DeleteProfile))); - /* Always have a Default profile */ - AddProfile ("Default"); - return mBackend; } @@ -124,15 +121,37 @@ class MockCCSBackendConceptTestEnvironment : { CCSStringList stringList = NULL; + CCSString *defaultProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + CCSString *currentProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + + EXPECT_CALL (*gmockContext, getProfile ()); + + defaultProfile->value = strdup ("Default"); + currentProfile->value = strdup (ccsGetProfile (context)); + + ccsStringRef (defaultProfile); + ccsStringRef (currentProfile); + + stringList = ccsStringListAppend (stringList, defaultProfile); + stringList = ccsStringListAppend (stringList, currentProfile); + + printf ("%s %s\n", defaultProfile->value, currentProfile->value); + for (std::vector ::iterator it = mProfiles.begin (); it != mProfiles.end (); ++it) { + if (*it == defaultProfile->value || + *it == currentProfile->value) + continue; + CCSString *string = reinterpret_cast (calloc (1, sizeof (CCSString))); string->value = strdup ((*it).c_str ()); ccsStringRef (string); + printf ("%s\n", string->value); + stringList = ccsStringListAppend (stringList, string); } diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index a2bace3ee..8a70bc026 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1228,14 +1228,18 @@ class CCSBackendConformanceTestProfileHandling : { public: + static const std::string PROFILE_MOCK; static const std::string PROFILE_DEFAULT; static const std::string PROFILE_FOO; static const std::string PROFILE_BAR; + static const std::string PROFILE_BAZ; }; +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_MOCK ("mock"); const std::string CCSBackendConformanceTestProfileHandling::PROFILE_DEFAULT ("Default"); const std::string CCSBackendConformanceTestProfileHandling::PROFILE_FOO ("foo"); const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAZ ("baz"); TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) { @@ -1253,12 +1257,16 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 3); + ASSERT_EQ (ccsStringListLength (iter), 4); /* Default profile must always be there */ EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_BAR)); + + /* Current profile should also be there */ + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + + EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next->next->data)->value, Eq (PROFILE_BAR)); } } @@ -1274,9 +1282,6 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); - /* Make sure that backends know what profile is being deleted */ - ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); - mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); @@ -1287,10 +1292,16 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 2); + ASSERT_EQ (ccsStringListLength (iter), 3); + + /* Default profile must always be there */ EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); + + /* Current profile should also be there */ + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + + EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next->next), IsNull ()); } } @@ -1304,13 +1315,10 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr mTestEnv->AddProfile (PROFILE_FOO); mTestEnv->AddProfile (PROFILE_BAR); - CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); - - /* Make sure that backends know what profile is being deleted */ - ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + CharacterWrapper PROFILE_BAZ_CHAR (strdup (PROFILE_BAZ.c_str ())); - mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); - EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAZ, context.get (), gmockContext); + EXPECT_FALSE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAZ_CHAR)); /* Check to make sure that the profile is no longer there */ mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); @@ -1319,10 +1327,16 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 2); + ASSERT_EQ (ccsStringListLength (iter), 4); + + /* Default profile must always be there */ EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); + + /* Current profile should also be there */ + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + + EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next->next->data)->value, Eq (PROFILE_BAR)); } } @@ -1344,6 +1358,9 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + /* Now that we've deleted the profile, getProfile can no longer refer to it */ + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + /* Check to make sure that the profile is no longer there */ mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), @@ -1351,9 +1368,12 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 1); - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next), IsNull ()); + ASSERT_EQ (ccsStringListLength (iter), 2); + /* Default profile must always be there */ + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); + } } -- GitLab From 4e01a26b2cf063443131017f49e9414d55b75c95 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 00:05:14 +0800 Subject: [PATCH 305/562] Handle default and current profile cases in the tests a little better --- .../gsettings_backend_shared/gsettings_util.c | 33 ++++++++++++++----- .../gsettings_backend_shared/gsettings_util.h | 5 ++- .../tests/test_gsettings_conformance.cpp | 15 ++++++++- .../tests/compizconfig_backend_concept_test.h | 6 ++-- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 2c40e25a4..b2c3ed10a 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -944,13 +944,21 @@ typedef struct _FindItemInVariantData const char *item; } FindItemInVariantData; +typedef struct _InsertIfNotEqualData +{ + gboolean skipped; + const char *item; +} InsertIfNotEqualData; + static void insertIfNotEqual (GVariantBuilder *builder, const char *item, void *userData) { - const char *cmp = (const char *) userData; + InsertIfNotEqualData *data = (InsertIfNotEqualData *) userData; - if (g_strcmp0 (item, cmp)) + if (g_strcmp0 (item, data->item)) g_variant_builder_add (builder, "s", item); + else + data->skipped = TRUE; } static void @@ -1003,18 +1011,25 @@ appendStringToVariantIfUnique (GVariant **variant, return !findItemData.found; } -void -removeItemFromVariant (GVariant **variant, - const char *string) +gboolean removeItemFromVariant (GVariant **variant, + const char *string) { GVariantBuilder newVariantBuilder; + InsertIfNotEqualData data = + { + FALSE, + string + }; + g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as")); - rebuildVariant (&newVariantBuilder, *variant, insertIfNotEqual, (void *) string); + rebuildVariant (&newVariantBuilder, *variant, insertIfNotEqual, (void *) &data); g_variant_unref (*variant); *variant = g_variant_builder_end (&newVariantBuilder); + + return data.skipped; } void @@ -1109,6 +1124,7 @@ deleteProfile (CCSBackend *backend, GVariant *plugins; GVariant *profiles; const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); + gboolean ret = FALSE; plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); profiles = ccsGSettingsBackendGetExistingProfiles (backend); @@ -1116,14 +1132,13 @@ deleteProfile (CCSBackend *backend, ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); ccsGSettingsBackendClearPluginsWithSetKeys (backend); - removeItemFromVariant (&profiles, profile); + ret = removeItemFromVariant (&profiles, profile); /* Remove the profile from existing-profiles */ ccsGSettingsBackendSetExistingProfiles (backend, profiles); - ccsGSettingsBackendUpdateProfile (backend, context); - return TRUE; + return ret; } void diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index f9905634a..caf2179af 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -203,9 +203,8 @@ gboolean appendStringToVariantIfUnique (GVariant **variant, const char *string); -void -removeItemFromVariant (GVariant **variant, - const char *string); +gboolean removeItemFromVariant (GVariant **variant, + const char *string); CCSSettingValueList readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index b2d79ca63..78d15b75b 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -89,6 +89,15 @@ class CCSGSettingsBackendEnv : g_unsetenv ("GSETTINGS_BACKEND"); g_unsetenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); + GVariantBuilder noProfilesBuilder; + g_variant_builder_init (&noProfilesBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&noProfilesBuilder, "s", "Default"); + GVariant *noProfiles = g_variant_builder_end (&noProfilesBuilder); + + ccsGSettingsBackendClearPluginsWithSetKeys (mGSettingsBackend); + ccsGSettingsBackendSetExistingProfiles (mGSettingsBackend, noProfiles); + ccsGSettingsBackendSetCurrentProfile (mGSettingsBackend, "Default"); + ccsFreeDynamicBackend (mBackend); } @@ -103,7 +112,11 @@ class CCSGSettingsBackendEnv : } void SetDeleteProfileExpectation (const std::string &profileToDelete, - CCSContext *context, CCSContextGMock *gmockContext) {} + CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*gmockContext, getProfile ()); + } void SetReadInitExpectation (CCSContext *context, CCSContextGMock *gmockContext) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 8a70bc026..d54de37e8 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1356,11 +1356,12 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_BAR.c_str ())); mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); - EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); - /* Now that we've deleted the profile, getProfile can no longer refer to it */ + /* Before deleting the profile, getProfile can no longer refer to it */ ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + /* Check to make sure that the profile is no longer there */ mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), @@ -1373,7 +1374,6 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); - } } -- GitLab From a59cd7b98681922b400ea0158e18b53a963f0cd8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 00:09:13 +0800 Subject: [PATCH 306/562] Need to change the result of getProfile a little earlier --- compizconfig/tests/compizconfig_backend_concept_test.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 634075a09..a11f86067 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1310,6 +1310,9 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); + + /* Before deleting the profile, getProfile can no longer refer to it */ + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); /* Check to make sure that the profile is no longer there */ -- GitLab From 42946918255e562d10475190e78786830e4d8906 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 00:16:32 +0800 Subject: [PATCH 307/562] Handle the mock profile correctly (backport) --- .../tests/compizconfig_backend_concept_test.h | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index a11f86067..540b82e1d 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1233,10 +1233,6 @@ class CCSBackendConformanceTestProfileHandling : static const std::string PROFILE_BAR; }; -const std::string CCSBackendConformanceTestProfileHandling::PROFILE_DEFAULT ("Default"); -const std::string CCSBackendConformanceTestProfileHandling::PROFILE_FOO ("foo"); -const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar"); - TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) { CCSBackend *backend = GetBackend (); @@ -1253,12 +1249,16 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 3); + ASSERT_EQ (ccsStringListLength (iter), 4); /* Default profile must always be there */ EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_BAR)); + + /* Current profile should also be there */ + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + + EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next->next->data)->value, Eq (PROFILE_BAR)); } } @@ -1274,9 +1274,6 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); - /* Make sure that backends know what profile is being deleted */ - ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); - mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); @@ -1287,10 +1284,16 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) CCSStringList iter = existingProfiles.get (); - ASSERT_EQ (ccsStringListLength (iter), 2); + ASSERT_EQ (ccsStringListLength (iter), 3); + + /* Default profile must always be there */ EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); + + /* Current profile should also be there */ + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + + EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next->next), IsNull ()); } } @@ -1299,6 +1302,42 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr CCSBackend *backend = GetBackend (); CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + CharacterWrapper PROFILE_BAZ_CHAR (strdup (PROFILE_BAZ.c_str ())); + + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAZ, context.get (), gmockContext); + + EXPECT_FALSE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAZ_CHAR)); + + /* Check to make sure that the profile is no longer there */ + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + CCSStringList iter = existingProfiles.get (); + + ASSERT_EQ (ccsStringListLength (iter), 4); + + /* Default profile must always be there */ + EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + + /* Current profile should also be there */ + EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + + EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); + EXPECT_THAT (reinterpret_cast (iter->next->next->next->data)->value, Eq (PROFILE_BAR)); + } +} + +TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + if (backendInterface->getExistingProfiles) { mTestEnv->AddProfile (PROFILE_FOO); @@ -1307,12 +1346,13 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); /* Make sure that backends know what profile is being deleted */ - ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_BAR.c_str ())); mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); /* Before deleting the profile, getProfile can no longer refer to it */ ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); /* Check to make sure that the profile is no longer there */ @@ -1323,6 +1363,7 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr CCSStringList iter = existingProfiles.get (); ASSERT_EQ (ccsStringListLength (iter), 2); + /* Default profile must always be there */ EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); -- GitLab From b42b1d60c1adc4b870b0b33f7382d93f180615aa Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 00:34:57 +0800 Subject: [PATCH 308/562] Added a matcher for CCS Lists --- .../tests/compizconfig_backend_concept_test.h | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 540b82e1d..371494781 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -178,6 +178,66 @@ class CCSListWrapper : boost::shared_ptr mSettingReference; }; +template +class ItemInCCSListMatcher : + public ::testing::MatcherInterface +{ + public: + + typedef boost::function CmpFunc; + + ItemInCCSListMatcher (const I &item, + const CmpFunc &func) : + mItem (item), + mFunc (func) + { + } + + virtual bool MatchAndExplain (L list, MatchResultListener *listener) const + { + L iter = list; + + while (iter) + { + if (mFunc (*(reinterpret_cast (iter->data)), + mItem)) + return true; + } + + return false; + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "found in list"; + } + + virtual void DescribeNegationTo (std::ostream *os) const + { + *os << "not found in list"; + } + + private: + + const I & mItem; + CmpFunc mFunc; +}; + +template +Matcher IsItemInCCSList (const I &item, + const typename ItemInCCSListMatcher ::CmpFunc &cmp) +{ + return MakeMatcher (new ItemInCCSListMatcher (item, cmp)); +} + +namespace +{ + bool ccsStringCmp (const CCSString &a, const CCSString &b) + { + return std::string (a.value) == b.value; + } +} + typedef boost::variant Date: Mon, 6 Aug 2012 00:35:33 +0800 Subject: [PATCH 309/562] Added missing constants --- compizconfig/tests/compizconfig_backend_concept_test.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 371494781..1b41e3d56 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1288,11 +1288,19 @@ class CCSBackendConformanceTestProfileHandling : { public: + static const std::string PROFILE_MOCK; static const std::string PROFILE_DEFAULT; static const std::string PROFILE_FOO; static const std::string PROFILE_BAR; + static const std::string PROFILE_BAZ; }; +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_MOCK ("mock"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_DEFAULT ("Default"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_FOO ("foo"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAZ ("baz"); + TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) { CCSBackend *backend = GetBackend (); -- GitLab From 6fcbdbc980440623a8ae5c3f251dd74e6c601d90 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 00:46:37 +0800 Subject: [PATCH 310/562] Improved IsItemInCCSList matcher, now it can be passed matchers --- .../tests/compizconfig_backend_concept_test.h | 50 +++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 1b41e3d56..118bf81dd 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -126,6 +126,33 @@ operator<< (::std::ostream &os, const CCSSettingButtonValue &v) return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl; } +bool +operator== (const CCSString &lhs, + const std::string &rhs) +{ + if (rhs == lhs.value) + return true; + + return false; +} + +bool +operator== (const std::string &lhs, + const CCSString &rhs) +{ + if (lhs == rhs.value) + return true; + + return false; +} + +::std::ostream & +operator<< (::std::ostream &os, CCSString &string) +{ + os << string.value << std::endl; + return os; +} + class CCSListWrapper : boost::noncopyable { @@ -184,12 +211,8 @@ class ItemInCCSListMatcher : { public: - typedef boost::function CmpFunc; - - ItemInCCSListMatcher (const I &item, - const CmpFunc &func) : - mItem (item), - mFunc (func) + ItemInCCSListMatcher (const Matcher &matcher) : + mMatcher (matcher) { } @@ -199,8 +222,7 @@ class ItemInCCSListMatcher : while (iter) { - if (mFunc (*(reinterpret_cast (iter->data)), - mItem)) + if (mMatcher.MatchAndExplain ((*(reinterpret_cast (iter->data))))) return true; } @@ -209,25 +231,23 @@ class ItemInCCSListMatcher : virtual void DescribeTo (std::ostream *os) const { - *os << "found in list"; + *os << "found in list (" << mMatcher.DescribeTo (os) << ")"; } virtual void DescribeNegationTo (std::ostream *os) const { - *os << "not found in list"; + *os << "not found in list (" << mMatcher.DescribeNegationTo (os) << ")"; } private: - const I & mItem; - CmpFunc mFunc; + const Matcher & mMatcher; }; template -Matcher IsItemInCCSList (const I &item, - const typename ItemInCCSListMatcher ::CmpFunc &cmp) +Matcher IsItemInCCSList (const Matcher &matcher) { - return MakeMatcher (new ItemInCCSListMatcher (item, cmp)); + return MakeMatcher (new ItemInCCSListMatcher (matcher)); } namespace -- GitLab From 73199ea6129b168719801caba1a4c91093e43d47 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 00:55:45 +0800 Subject: [PATCH 311/562] Use the matcher --- .../tests/compizconfig_backend_concept_test.h | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index 118bf81dd..b3f2e1a79 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -222,7 +222,7 @@ class ItemInCCSListMatcher : while (iter) { - if (mMatcher.MatchAndExplain ((*(reinterpret_cast (iter->data))))) + if (mMatcher.MatchAndExplain ((*(reinterpret_cast (iter->data))), listener)) return true; } @@ -231,12 +231,16 @@ class ItemInCCSListMatcher : virtual void DescribeTo (std::ostream *os) const { - *os << "found in list (" << mMatcher.DescribeTo (os) << ")"; + *os << "found in list ("; + mMatcher.DescribeTo (os); + *os << ")"; } virtual void DescribeNegationTo (std::ostream *os) const { - *os << "not found in list (" << mMatcher.DescribeNegationTo (os) << ")"; + *os << "not found in list ("; + mMatcher.DescribeNegationTo (os); + *os << ")"; } private: @@ -1321,6 +1325,17 @@ const std::string CCSBackendConformanceTestProfileHandling::PROFILE_FOO ("foo"); const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar"); const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAZ ("baz"); +/* A workaround for templates inside of macros not + * expanding correctly */ +namespace +{ + Matcher + IsStringItemInStringCCSList (const Matcher &matcher) + { + return IsItemInCCSList (matcher); + } +} + TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) { CCSBackend *backend = GetBackend (); @@ -1340,7 +1355,7 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) ASSERT_EQ (ccsStringListLength (iter), 4); /* Default profile must always be there */ - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); /* Current profile should also be there */ EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); -- GitLab From 0a13692437042db5367b22f7b4ddc454bcbdf6f7 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 00:57:55 +0800 Subject: [PATCH 312/562] Backport default and mock profile handling from later branch --- ...nfig_test_ccs_mock_backend_conformance.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 3a77f430f..03ef15ee9 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -124,15 +124,37 @@ class MockCCSBackendConceptTestEnvironment : { CCSStringList stringList = NULL; + CCSString *defaultProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + CCSString *currentProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + + EXPECT_CALL (*gmockContext, getProfile ()); + + defaultProfile->value = strdup ("Default"); + currentProfile->value = strdup (ccsGetProfile (context)); + + ccsStringRef (defaultProfile); + ccsStringRef (currentProfile); + + stringList = ccsStringListAppend (stringList, defaultProfile); + stringList = ccsStringListAppend (stringList, currentProfile); + + printf ("%s %s\n", defaultProfile->value, currentProfile->value); + for (std::vector ::iterator it = mProfiles.begin (); it != mProfiles.end (); ++it) { + if (*it == defaultProfile->value || + *it == currentProfile->value) + continue; + CCSString *string = reinterpret_cast (calloc (1, sizeof (CCSString))); string->value = strdup ((*it).c_str ()); ccsStringRef (string); + printf ("%s\n", string->value); + stringList = ccsStringListAppend (stringList, string); } -- GitLab From 33324d48f96cc92a3343f420dc70ed1db5dbf713 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 01:05:42 +0800 Subject: [PATCH 313/562] Switch over to the matchers, kill debugging message --- ...nfig_test_ccs_mock_backend_conformance.cpp | 2 - .../tests/compizconfig_backend_concept_test.h | 56 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 03ef15ee9..4229b0504 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -153,8 +153,6 @@ class MockCCSBackendConceptTestEnvironment : string->value = strdup ((*it).c_str ()); ccsStringRef (string); - printf ("%s\n", string->value); - stringList = ccsStringListAppend (stringList, string); } diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index b3f2e1a79..36c99971b 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -224,6 +224,8 @@ class ItemInCCSListMatcher : { if (mMatcher.MatchAndExplain ((*(reinterpret_cast (iter->data))), listener)) return true; + + iter = iter->next; } return false; @@ -1350,18 +1352,17 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), boost::bind (ccsStringListFree, _1, TRUE)); - CCSStringList iter = existingProfiles.get (); - - ASSERT_EQ (ccsStringListLength (iter), 4); + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 4); /* Default profile must always be there */ EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); /* Current profile should also be there */ - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_MOCK))); - EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next->next->data)->value, Eq (PROFILE_BAR)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_BAR))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); } } @@ -1385,18 +1386,19 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), boost::bind (ccsStringListFree, _1, TRUE)); - CCSStringList iter = existingProfiles.get (); - - ASSERT_EQ (ccsStringListLength (iter), 3); + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 3); /* Default profile must always be there */ - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); /* Current profile should also be there */ - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_MOCK))); + + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); - EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next->next), IsNull ()); + /* PROFILE_BAR was deleted */ + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAR)))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); } } @@ -1421,18 +1423,17 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentPr boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), boost::bind (ccsStringListFree, _1, TRUE)); - CCSStringList iter = existingProfiles.get (); - - ASSERT_EQ (ccsStringListLength (iter), 4); + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 4); /* Default profile must always be there */ - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); /* Current profile should also be there */ - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_MOCK)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_MOCK))); - EXPECT_THAT (reinterpret_cast (iter->next->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next->next->data)->value, Eq (PROFILE_BAR)); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_BAR))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); } } @@ -1463,13 +1464,16 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), boost::bind (ccsStringListFree, _1, TRUE)); - CCSStringList iter = existingProfiles.get (); - - ASSERT_EQ (ccsStringListLength (iter), 2); + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 2); /* Default profile must always be there */ - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_DEFAULT)); - EXPECT_THAT (reinterpret_cast (iter->next->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next->next), IsNull ()); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); + + /* Old current profile shouldn't be there */ + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAR)))); + + /* New current profile should be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); } } -- GitLab From 5b058ac92215cbcae89b7cc6a1100ff27800bead Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 01:39:11 +0800 Subject: [PATCH 314/562] Correct expectations --- compizconfig/gsettings/src/gsettings.c | 3 +++ compizconfig/gsettings/tests/test_gsettings_conformance.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index bda145da0..7b6ebe47b 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -776,6 +776,9 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + /* Update the current profile in case it was changed compizconfig side */ + ccsGSettingsBackendUpdateProfile (backend, context); + value = ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "existing-profiles"); g_variant_iter_init (&iter, value); while (g_variant_iter_loop (&iter, "s", &profile)) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 78d15b75b..4d346d008 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -109,13 +109,14 @@ class CCSGSettingsBackendEnv : void SetGetExistingProfilesExpectation (CCSContext *context, CCSContextGMock *gmockContext) { + EXPECT_CALL (*gmockContext, getProfile ()).Times (AtLeast (1)); } void SetDeleteProfileExpectation (const std::string &profileToDelete, CCSContext *context, CCSContextGMock *gmockContext) { - EXPECT_CALL (*gmockContext, getProfile ()); + EXPECT_CALL (*gmockContext, getProfile ()).Times (AtLeast (1)); } void SetReadInitExpectation (CCSContext *context, -- GitLab From 489c78b2f87a9c437ca06a64ec0e6a44351371e1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 01:50:17 +0800 Subject: [PATCH 315/562] No const in pyx --- compizconfig/compizconfig-python/src/compizconfig.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/compizconfig-python/src/compizconfig.pyx b/compizconfig/compizconfig-python/src/compizconfig.pyx index fef0bc5ed..e06a82937 100644 --- a/compizconfig/compizconfig-python/src/compizconfig.pyx +++ b/compizconfig/compizconfig-python/src/compizconfig.pyx @@ -99,9 +99,9 @@ ctypedef CCSList CCSStrRestrictionList ctypedef CCSList CCSStrExtensionList cdef struct CCSBackendInfo: - const char * name - const char * shortDesc - const char * longDesc + char * name + char * shortDesc + char * longDesc Bool integrationSupport Bool profileSupport unsigned int refCount -- GitLab From ce9c2c69daef2c9ab844a1058affc27f2b14514f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 17:32:48 +0800 Subject: [PATCH 316/562] Initialize the string properly and reference it upon return. Fixes a leak --- compizconfig/gsettings/src/gsettings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index 49892f91d..86e25f347 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -780,10 +780,10 @@ getExistingProfiles (CCSBackend *backend, CCSContext *context) g_variant_iter_init (&iter, value); while (g_variant_iter_loop (&iter, "s", &profile)) { - CCSString *str = malloc (sizeof (CCSString)); - + CCSString *str = calloc (1, sizeof (CCSString)); str->value = strdup (profile); + ccsStringRef (str); ret = ccsStringListAppend (ret, str); } -- GitLab From 1ac95d9dff9ec29c49b5764cba2b89c3dc2c88d2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 21:38:50 +0800 Subject: [PATCH 317/562] Fixed a set of memory leaks in the GSettings conformance tests - we must be careful to unref the variants once they are read --- .../tests/test_gsettings_conformance.cpp | 162 ++++++++++++------ 1 file changed, 107 insertions(+), 55 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp index 4d346d008..a7419c9f6 100644 --- a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -17,11 +17,40 @@ using ::testing::AtLeast; using ::testing::Pointee; using ::testing::ReturnNull; +namespace +{ + template + class AutoDestroyHelper + { + public: + + typedef void (*SimpleDestructor) (T *); + typedef boost::shared_ptr TPtr; + + AutoDestroyHelper (T *t, + SimpleDestructor d) : + mShared (t, boost::bind (d, _1)) + { + } + + operator const TPtr & () + { + return mShared; + } + + private: + + TPtr mShared; + }; +} + class CCSGSettingsBackendEnv : public CCSBackendConceptTestEnvironmentInterface { public: + typedef boost::shared_ptr GVariantShared; + CCSGSettingsBackendEnv () : pluginToMatch ("mock") { @@ -94,11 +123,23 @@ class CCSGSettingsBackendEnv : g_variant_builder_add (&noProfilesBuilder, "s", "Default"); GVariant *noProfiles = g_variant_builder_end (&noProfilesBuilder); + GVariantBuilder pluginKeysBuilder; + g_variant_builder_init (&pluginKeysBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&pluginKeysBuilder, "s", "mock"); + GVariant *pluginKeys = g_variant_builder_end (&pluginKeysBuilder); + + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (mGSettingsBackend, + mContext, + pluginKeys, + ccsGSettingsBackendGetCurrentProfile ( + mGSettingsBackend)); ccsGSettingsBackendClearPluginsWithSetKeys (mGSettingsBackend); ccsGSettingsBackendSetExistingProfiles (mGSettingsBackend, noProfiles); ccsGSettingsBackendSetCurrentProfile (mGSettingsBackend, "Default"); ccsFreeDynamicBackend (mBackend); + + g_variant_unref (pluginKeys); } void AddProfile (const std::string &profile) @@ -315,52 +356,47 @@ class CCSGSettingsBackendEnv : Bool ReadBoolAtKey (const std::string &plugin, const std::string &key) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeBool); - return readBoolFromVariant (variant); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeBool)); + return readBoolFromVariant (variant.get ()); } int ReadIntegerAtKey (const std::string &plugin, const std::string &key) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeInt); - return readIntFromVariant (variant); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeInt)); + return readIntFromVariant (variant.get ()); } float ReadFloatAtKey (const std::string &plugin, const std::string &key) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeFloat); - return readFloatFromVariant (variant); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeFloat)); + return readFloatFromVariant (variant.get ()); } const char * ReadStringAtKey (const std::string &plugin, const std::string &key) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeString); - return readStringFromVariant (variant); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeString)); + return readStringFromVariant (variant.get ()); } CCSSettingColorValue ReadColorAtKey (const std::string &plugin, const std::string &key) { Bool success = FALSE; - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeColor); - CCSSettingColorValue value = readColorFromVariant (variant, &success); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeColor)); + CCSSettingColorValue value = readColorFromVariant (variant.get (), &success); EXPECT_TRUE (success); return value; } @@ -369,11 +405,10 @@ class CCSGSettingsBackendEnv : const std::string &key) { Bool success = FALSE; - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeKey); - CCSSettingKeyValue value = readKeyFromVariant (variant, &success); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeKey)); + CCSSettingKeyValue value = readKeyFromVariant (variant.get (), &success); EXPECT_TRUE (success); return value; } @@ -382,11 +417,10 @@ class CCSGSettingsBackendEnv : const std::string &key) { Bool success = FALSE; - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeButton); - CCSSettingButtonValue value = readButtonFromVariant (variant, &success); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeButton)); + CCSSettingButtonValue value = readButtonFromVariant (variant.get (), &success); EXPECT_TRUE (success); return value; } @@ -394,42 +428,38 @@ class CCSGSettingsBackendEnv : unsigned int ReadEdgeAtKey (const std::string &plugin, const std::string &key) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeEdge); - return readEdgeFromVariant (variant); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeEdge)); + return readEdgeFromVariant (variant.get ()); } const char * ReadMatchAtKey (const std::string &plugin, const std::string &key) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeMatch); - return readStringFromVariant (variant); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeMatch)); + return readStringFromVariant (variant.get ()); } Bool ReadBellAtKey (const std::string &plugin, const std::string &key) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeBell); - return readBoolFromVariant (variant); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeBell)); + return readBoolFromVariant (variant.get ()); } CCSSettingValueList ReadListAtKey (const std::string &plugin, const std::string &key, CCSSetting *setting) { - GVariant *variant = getVariantAtKey (mSettings, - CharacterWrapper (translateKeyForGSettings (key.c_str ())), - CharacterWrapper (makeCompizPluginPath (profileName.c_str (), plugin.c_str ())), - TypeList); - return readListValue (variant, setting, &ccsDefaultObjectAllocator); + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeList)); + return readListValue (variant.get (), setting, &ccsDefaultObjectAllocator); } void PreUpdate (CCSContextGMock *gmockContext, @@ -472,6 +502,28 @@ class CCSGSettingsBackendEnv : private: + GVariantShared + ReadVariantAtKeyToShared (const std::string &plugin, + const std::string &key, + CCSSettingType type) + { + CharacterWrapper translatedKey (translateKeyForGSettings (key.c_str ())); + CharacterWrapper pluginPath (makeCompizPluginPath (profileName.c_str (), + plugin.c_str ())); + + GVariant *rawVariant = getVariantAtKey (mSettings, + translatedKey, + pluginPath, + type); + + GVariantShared shared (AutoDestroyHelper (rawVariant, + g_variant_unref)); + + + + return shared; + } + CCSGSettingsWrapper *mSettings; CCSContext *mContext; CCSDynamicBackend *mBackend; -- GitLab From 1c3b776dc0fa512221eb0a3de6adc69caff2d1e8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 21:40:28 +0800 Subject: [PATCH 318/562] We aren't calling set_value with plugins, so we need to unref it --- .../gsettings/gsettings_backend_shared/gsettings_util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 2c40e25a4..f3f52d63d 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1123,6 +1123,10 @@ deleteProfile (CCSBackend *backend, ccsGSettingsBackendUpdateProfile (backend, context); + /* Since we do not call g_settings_set_value on + * plugins, we must also unref the variant */ + g_variant_unref (plugins); + return TRUE; } -- GitLab From 045cafef996c8ecaa4403b992be3ea33e061cc02 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 22:19:40 +0800 Subject: [PATCH 319/562] Update tests to reflect change in interface --- .../gsettings/tests/test_gsettings_tests.cpp | 48 +++++++++++-------- .../gsettings/tests/test_gsettings_tests.h | 4 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index b0ec41d29..af1e28f40 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -126,10 +126,20 @@ bool streq (const char * const &s1, const char * const &s2) } -TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) +class CCSGSettingsTestProfiles : + public CCSGSettingsTestIndependent { - g_type_init (); + public: + + static const std::string newProfileName; + static const std::string existingProfileName; +}; + +const std::string CCSGSettingsTestProfiles::existingProfileName ("ExistingProfile"); +const std::string CCSGSettingsTestProfiles::newProfileName ("NewProfile"); +TEST_F(CCSGSettingsTestProfiles, TestAddProfile) +{ boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), boost::bind (ccsGSettingsBackendGMockFree, _1)); CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); @@ -137,47 +147,45 @@ TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameAppendNew) GVariantBuilder builder; g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); - g_variant_builder_add (&builder, "s", "foo"); + g_variant_builder_add (&builder, "s", existingProfileName.c_str ()); GVariant *existingProfiles = g_variant_builder_end (&builder); - std::string newProfileName ("narr"); - EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); EXPECT_CALL (*gmock, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), GVariantHasValueInArray ("s", newProfileName.c_str (), boost::bind (streq, _1, _2))))); - EXPECT_CALL (*gmock, setCurrentProfile (Eq (newProfileName))); - ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), newProfileName.c_str ()); + ccsGSettingsBackendAddProfileDefault (backend.get (), newProfileName.c_str ()); } -TEST_F(CCSGSettingsTestIndependent, TestUpdateCurrentProfileNameExisting) +TEST_F(CCSGSettingsTestProfiles, TestUpdateCurrentProfileNameAppendNew) { - g_type_init (); - boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), boost::bind (ccsGSettingsBackendGMockFree, _1)); CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); - GVariantBuilder builder; + EXPECT_CALL (*gmock, addProfile (Eq (newProfileName))); + EXPECT_CALL (*gmock, setCurrentProfile (Eq (newProfileName))); - g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); - g_variant_builder_add (&builder, "s", "foo"); + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), newProfileName.c_str ()); +} - GVariant *existingProfiles = g_variant_builder_end (&builder); +TEST_F(CCSGSettingsTestProfiles, TestUpdateCurrentProfileNameExisting) +{ + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); - EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); - EXPECT_CALL (*gmock, setCurrentProfile (_)); + EXPECT_CALL (*gmock, addProfile (Eq (existingProfileName))); + EXPECT_CALL (*gmock, setCurrentProfile (Eq (existingProfileName))); - ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), "foo"); + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), existingProfileName.c_str ()); } -TEST_F(CCSGSettingsTestIndependent, TestDeleteProfileExistingProfile) +TEST_F(CCSGSettingsTestProfiles, TestDeleteProfileExistingProfile) { - g_type_init (); - boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), boost::bind (ccsGSettingsBackendGMockFree, _1)); boost::shared_ptr context (ccsMockContextNew (), diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.h b/compizconfig/gsettings/tests/test_gsettings_tests.h index 356ef0276..775280b75 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.h +++ b/compizconfig/gsettings/tests/test_gsettings_tests.h @@ -48,6 +48,8 @@ class CCSGSettingsTestIndependent : virtual void SetUp () { + g_type_init (); + g_setenv ("G_SLICE", "always-malloc", 1); } @@ -67,8 +69,6 @@ class CCSGSettingsTestWithMemoryBackend : CCSGSettingsTestIndependent::SetUp (); g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); g_setenv ("GSETTINGS_BACKEND", "memory", 1); - - g_type_init (); } virtual void TearDown () -- GitLab From a2f73277dba3a6d1d2b5969993049cc4fcc2d0b8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 22:26:53 +0800 Subject: [PATCH 320/562] Remove dupe file --- .../tests/gsettings-mock-schemas-config.h.in.moved | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in.moved diff --git a/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in.moved b/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in.moved deleted file mode 100644 index c26889995..000000000 --- a/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in.moved +++ /dev/null @@ -1,7 +0,0 @@ -#define MOCK_SCHEMA_PATH "@CMAKE_BINARY_DIR@/generated/glib-2.0/schemas" - -namespace -{ -const std::string MOCK_SCHEMA ("org.compiz.mock"); -const std::string MOCK_PATH (MOCK_SCHEMA_PATH); -} -- GitLab From 0eb3a0d4aacc73b96e9052bcbe954235278c385e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 22:28:30 +0800 Subject: [PATCH 321/562] Nuke duped function --- .../tests/compizconfig_backend_concept_test.h | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h index a0cdc1e0d..36c99971b 100644 --- a/compizconfig/tests/compizconfig_backend_concept_test.h +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -1477,36 +1477,5 @@ TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) } } -TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) -{ - CCSBackend *backend = GetBackend (); - CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); - - if (backendInterface->getExistingProfiles) - { - mTestEnv->AddProfile (PROFILE_FOO); - mTestEnv->AddProfile (PROFILE_BAR); - - CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); - - /* Make sure that backends know what profile is being deleted */ - ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_BAR.c_str ())); - - mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); - EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); - - /* Check to make sure that the profile is no longer there */ - mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); - boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), - boost::bind (ccsStringListFree, _1, TRUE)); - - CCSStringList iter = existingProfiles.get (); - - ASSERT_EQ (ccsStringListLength (iter), 1); - EXPECT_THAT (reinterpret_cast (iter->data)->value, Eq (PROFILE_FOO)); - EXPECT_THAT (reinterpret_cast (iter->next), IsNull ()); - } -} - #endif -- GitLab From 0846643ab4eda21b2ec83f6ac00ce2f48bf279e6 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 22:29:11 +0800 Subject: [PATCH 322/562] Don't add the default profile twice --- .../tests/compizconfig_test_ccs_mock_backend_conformance.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 4229b0504..e8db34069 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -1,4 +1,4 @@ -#include +\#include #include #include @@ -96,9 +96,6 @@ class MockCCSBackendConceptTestEnvironment : this, &MockCCSBackendConceptTestEnvironment::DeleteProfile))); - /* Always have a Default profile */ - AddProfile ("Default"); - return mBackend; } -- GitLab From 95c899f81d828652df24a28b7b012202a6e5384f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 22:29:34 +0800 Subject: [PATCH 323/562] Remove debug message --- .../tests/compizconfig_test_ccs_mock_backend_conformance.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index e8db34069..3632ac313 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -135,8 +135,6 @@ class MockCCSBackendConceptTestEnvironment : stringList = ccsStringListAppend (stringList, defaultProfile); stringList = ccsStringListAppend (stringList, currentProfile); - printf ("%s %s\n", defaultProfile->value, currentProfile->value); - for (std::vector ::iterator it = mProfiles.begin (); it != mProfiles.end (); ++it) -- GitLab From 35cb4e82eefdfdb8f58893c83102ffa2ddc883c1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 22:33:07 +0800 Subject: [PATCH 324/562] Fix stray \ --- .../tests/compizconfig_test_ccs_mock_backend_conformance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp index 3632ac313..809f4e766 100644 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -1,4 +1,4 @@ -\#include +#include #include #include -- GitLab From 4e5d9c32a1c13247123fb94bf258fae12807d8b8 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Mon, 6 Aug 2012 22:52:01 +0800 Subject: [PATCH 325/562] Fix some memory leaks in the gsettings tests --- compizconfig/gsettings/tests/test_gsettings_tests.cpp | 7 +++++-- compizconfig/gsettings/tests/test_gsettings_wrapper.cpp | 7 +++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index af1e28f40..26db45cd6 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -20,6 +20,7 @@ using ::testing::ValuesIn; using ::testing::Return; using ::testing::ReturnNull; using ::testing::Invoke; +using ::testing::WithArgs; using ::testing::MatcherInterface; using ::testing::MatchResultListener; using ::testing::AllOf; @@ -155,7 +156,8 @@ TEST_F(CCSGSettingsTestProfiles, TestAddProfile) EXPECT_CALL (*gmock, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), GVariantHasValueInArray ("s", newProfileName.c_str (), - boost::bind (streq, _1, _2))))); + boost::bind (streq, _1, _2))))) + .WillOnce (WithArgs <0> (Invoke (g_variant_unref))); ccsGSettingsBackendAddProfileDefault (backend.get (), newProfileName.c_str ()); } @@ -217,7 +219,8 @@ TEST_F(CCSGSettingsTestProfiles, TestDeleteProfileExistingProfile) boost::bind (streq, _1, _2))), GVariantHasValueInArray ("s", otherProfile.c_str (), - boost::bind (streq, _1, _2))))); + boost::bind (streq, _1, _2))))) + .WillOnce (WithArgs <0> (Invoke (g_variant_unref))); EXPECT_CALL (*mockBackend, updateProfile (context.get ())); diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp index 47ea55e39..df80cdb27 100644 --- a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -137,11 +137,10 @@ TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestRe const char * DEFAULT = ""; const char * VALUE = "foo"; const std::string KEY ("string-setting"); - boost::shared_ptr variant (g_variant_ref_sink (g_variant_new ("s", VALUE, NULL)), - boost::bind (g_variant_unref, _1)); - ccsGSettingsWrapperSetValue (wrapper.get (), KEY.c_str (), variant.get ()); + GVariant *variant = g_variant_new ("s", VALUE); + ccsGSettingsWrapperSetValue (wrapper.get (), KEY.c_str (), variant); - boost::shared_ptr value (g_variant_ref_sink (g_settings_get_value (settings, KEY.c_str ())), + boost::shared_ptr value (g_settings_get_value (settings, KEY.c_str ()), boost::bind (g_variant_unref, _1)); gsize length; -- GitLab From fb1b2a89dd9c89a21446f21710fc5d4af732bdb3 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 15:15:21 +0800 Subject: [PATCH 326/562] Revert superfluous change --- compizconfig/compizconfig-python/src/compizconfig.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/compizconfig-python/src/compizconfig.pyx b/compizconfig/compizconfig-python/src/compizconfig.pyx index e06a82937..59bf3600d 100644 --- a/compizconfig/compizconfig-python/src/compizconfig.pyx +++ b/compizconfig/compizconfig-python/src/compizconfig.pyx @@ -99,9 +99,9 @@ ctypedef CCSList CCSStrRestrictionList ctypedef CCSList CCSStrExtensionList cdef struct CCSBackendInfo: - char * name - char * shortDesc - char * longDesc + char * name + char * shortDesc + char * longDesc Bool integrationSupport Bool profileSupport unsigned int refCount -- GitLab From 8c8820b14428ccb3cac63cae03483277194352f2 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 15:35:32 +0800 Subject: [PATCH 327/562] Split out a bunch of files in compizconfig --- .../libcompizconfig/include/ccs-backend.h | 6 +- .../libcompizconfig/include/ccs-defs.h | 52 +++++ .../libcompizconfig/include/ccs-list.h | 85 ++++++++ .../libcompizconfig/include/ccs-object.h | 129 ++++++++++++ .../libcompizconfig/include/ccs-string.h | 47 +++++ compizconfig/libcompizconfig/include/ccs.h | 185 +----------------- 6 files changed, 325 insertions(+), 179 deletions(-) create mode 100644 compizconfig/libcompizconfig/include/ccs-defs.h create mode 100644 compizconfig/libcompizconfig/include/ccs-list.h create mode 100644 compizconfig/libcompizconfig/include/ccs-object.h create mode 100644 compizconfig/libcompizconfig/include/ccs-string.h diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 1377a64d5..6ed5ea30a 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -22,8 +22,12 @@ #ifndef CCS_BACKEND_H #define CCS_BACKEND_H -#include +#include +#include +#include +typedef struct _CCSSetting CCSSetting; +typedef struct _CCSContext CCSContext; typedef struct _CCSBackend CCSBackend; typedef struct _CCSBackendVTable CCSBackendVTable; diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h b/compizconfig/libcompizconfig/include/ccs-defs.h new file mode 100644 index 000000000..5c1bb43d7 --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-defs.h @@ -0,0 +1,52 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_DEFS_H +#define _CCS_DEFS_H + +#include /* for NULL */ + +#ifdef __cplusplus +# define COMPIZCONFIG_BEGIN_DECLS extern "C" { +# define COMPIZCONFIG_END_DECLS } +#else +# define COMPIZCONFIG_BEGIN_DECLS +# define COMPIZCONFIG_END_DECLS +#endif + + +COMPIZCONFIG_BEGIN_DECLS + +#ifndef Bool +#define Bool int +#endif + +#ifndef TRUE +#define TRUE ~0 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-list.h b/compizconfig/libcompizconfig/include/ccs-list.h new file mode 100644 index 000000000..9e758223f --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-list.h @@ -0,0 +1,85 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_LIST_H +#define _CCS_LIST_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +/** + * list functions: + * for each list there is a set of functions, explained using String as example + * + * ccsStringListAppend (list, item) + * Adds an item at the end of the list. Returns the new list. + * + * ccsStringListPrepend (list, item) + * Adds an item at the beginning of the list. Returns the new list. + * + * ccsStringListInsert (list, item, position) + * Adds an item at a given position. Position is 0-based. If position is + * larger than the amount of items in the list, the item is inserted at the + * end of the list. Returns the new list. + * + * ccsStringListInsertBefore (list, sibling, item) + * Inserts item before sibling into the list. If sibling is no list member, + * item is inserted at the end. Returns the new list. + * + * ccsStringListLength (list) + * Returns the amount of items in list. + * + * ccsStringListFind (list, item) + * Finds and returns an item matching . If nothing is found, returns NULL. + * + * ccsStringListGetItem (list, index) + * Returns the list item at position . If index is larger than the + * amount of items in the list, returns NULL. + * + * ccsStringListRemove (list, item, freeObj) + * Removes item from the list. If freeObj is TRUE, also frees the data item. + * Returns the new list. + * + * ccsStringListFree (list, freeObj) + * Frees the complete list. If freeObj is TRUE, also frees the data items. + * Returns the new list (NULL). + */ +#define CCSLIST_HDR(type,dtype) \ + typedef struct _CCS##type##List * CCS##type##List;\ + struct _CCS##type##List \ + { \ + dtype * data; \ + CCS##type##List next; \ + }; \ + CCS##type##List ccs##type##ListAppend (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListPrepend (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListInsert (CCS##type##List list, dtype *data, int position); \ + CCS##type##List ccs##type##ListInsertBefore (CCS##type##List list, CCS##type##List sibling, dtype *data); \ + unsigned int ccs##type##ListLength (CCS##type##List list); \ + CCS##type##List ccs##type##ListFind (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListGetItem (CCS##type##List list, unsigned int index); \ + CCS##type##List ccs##type##ListRemove (CCS##type##List list, dtype *data, Bool freeObj); \ + CCS##type##List ccs##type##ListFree (CCS##type##List list, Bool freeObj); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-object.h b/compizconfig/libcompizconfig/include/ccs-object.h new file mode 100644 index 000000000..c01f0fc2e --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-object.h @@ -0,0 +1,129 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2012 Canonical Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authored By: Sam Spilsbury + */ + +#ifndef _CCS_OBJECT_H +#define _CCS_OBJECT_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ +typedef struct _CCSPrivate CCSPrivate; /* Dummy typedef */ +typedef struct _CCSObject CCSObject; + +typedef void * (*reallocObjectProc) (void *, void *, size_t); +typedef void * (*mallocObjectProc) (void *, size_t); +typedef void * (*callocObjectProc) (void *, size_t, size_t); +typedef void (*freeObjectProc) (void *, void *); + +typedef struct _CCSObjectAllocationInterface +{ + reallocObjectProc realloc_; + mallocObjectProc malloc_; + callocObjectProc calloc_; + freeObjectProc free_; + void *allocator; +} CCSObjectAllocationInterface; + +extern CCSObjectAllocationInterface ccsDefaultObjectAllocator; + +struct _CCSObject +{ + CCSPrivate *priv; /* Private pointer for object storage */ + + const CCSInterface **interfaces; /* An array of interfaces that this object implements */ + int *interface_types; /* An array of interface types */ + unsigned int n_interfaces; + unsigned int n_allocated_interfaces; + + CCSObjectAllocationInterface *object_allocation; + + unsigned int refcnt; /* Reference count of this object */ +}; + +Bool +ccsObjectInit_ (CCSObject *object, CCSObjectAllocationInterface *interface); + +#define ccsObjectInit(o, interface) (ccsObjectInit_) (&(o)->object, interface) + +Bool +ccsObjectAddInterface_ (CCSObject *object, const CCSInterface *interface, int interface_type); + +#define ccsObjectAddInterface(o, interface, type) (ccsObjectAddInterface_) (&(o)->object, interface, type); + +Bool +ccsObjectRemoveInterface_ (CCSObject *object, int interface_type); + +#define ccsObjectRemoveInterface(o, interface_type) (ccsObjectRemoveInterface_) (&(o)->object, interface_type); + +const CCSInterface * ccsObjectGetInterface_ (CCSObject *object, int interface_type); + +#define ccsObjectGetInterface(o, interface_type) (ccsObjectGetInterface_) (&(o)->object, interface_type) + +#define ccsObjectRef(o) \ + do { ((o)->object).refcnt++; } while (FALSE) + +#define ccsObjectUnref(o, freeFunc) \ + do \ + { \ + ((o)->object).refcnt--; \ + if (!((o)->object).refcnt) \ + freeFunc (o); \ + } while (FALSE) + +CCSPrivate * +ccsObjectGetPrivate_ (CCSObject *object); + +#define ccsObjectGetPrivate(o) (ccsObjectGetPrivate_) (&(o)->object) + +void +ccsObjectSetPrivate_ (CCSObject *object, CCSPrivate *priv); + +#define ccsObjectSetPrivate(o, priv) (ccsObjectSetPrivate_) (&(o)->object, priv) + +void +ccsObjectFinalize_ (CCSObject *object); + +#define ccsObjectFinalize(o) (ccsObjectFinalize_) (&(o)->object) + +unsigned int +ccsAllocateType (); + +#define GET_INTERFACE_TYPE(Interface) \ + ccs##Interface##GetType () + +#define INTERFACE_TYPE(Interface) \ + unsigned int ccs##Interface##GetType () \ + { \ + static unsigned int type_id = 0; \ + if (!type_id) \ + type_id = ccsAllocateType (); \ + \ + return type_id; \ + } + +#define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-string.h b/compizconfig/libcompizconfig/include/ccs-string.h new file mode 100644 index 000000000..48dabde5e --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-string.h @@ -0,0 +1,47 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_STRING_H +#define _CCS_STRING_H + +/* Doesn't seem to make sense to have this header + * dependency, but we can only declare a typed list + * once */ +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSString CCSString; + +struct _CCSString +{ + char *value; + unsigned int refCount; +}; + +void ccsFreeString (CCSString *str); + +CCSLIST_HDR (String, CCSString); + +COMPIZCONFIG_END_DECLS + +#endif + diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 8fe054dad..608adfdf4 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -23,23 +23,13 @@ #define _CSS_H #include /* for NULL */ +#include +#include +#include +#include +#include -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifndef Bool -#define Bool int -#endif - -#ifndef TRUE -#define TRUE ~0 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif +COMPIZCONFIG_BEGIN_DECLS #ifndef CCS_LOG_DOMAIN #define CCS_LOG_DOMAIN NULL @@ -78,60 +68,6 @@ typedef enum void ccsLog (const char *domain, CCSLogLevel level, const char *fmt, ...); -/** - * list functions: - * for each list there is a set of functions, explained using String as example - * - * ccsStringListAppend (list, item) - * Adds an item at the end of the list. Returns the new list. - * - * ccsStringListPrepend (list, item) - * Adds an item at the beginning of the list. Returns the new list. - * - * ccsStringListInsert (list, item, position) - * Adds an item at a given position. Position is 0-based. If position is - * larger than the amount of items in the list, the item is inserted at the - * end of the list. Returns the new list. - * - * ccsStringListInsertBefore (list, sibling, item) - * Inserts item before sibling into the list. If sibling is no list member, - * item is inserted at the end. Returns the new list. - * - * ccsStringListLength (list) - * Returns the amount of items in list. - * - * ccsStringListFind (list, item) - * Finds and returns an item matching . If nothing is found, returns NULL. - * - * ccsStringListGetItem (list, index) - * Returns the list item at position . If index is larger than the - * amount of items in the list, returns NULL. - * - * ccsStringListRemove (list, item, freeObj) - * Removes item from the list. If freeObj is TRUE, also frees the data item. - * Returns the new list. - * - * ccsStringListFree (list, freeObj) - * Frees the complete list. If freeObj is TRUE, also frees the data items. - * Returns the new list (NULL). - */ -#define CCSLIST_HDR(type,dtype) \ - typedef struct _CCS##type##List * CCS##type##List;\ - struct _CCS##type##List \ - { \ - dtype * data; \ - CCS##type##List next; \ - }; \ - CCS##type##List ccs##type##ListAppend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListPrepend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListInsert (CCS##type##List list, dtype *data, int position); \ - CCS##type##List ccs##type##ListInsertBefore (CCS##type##List list, CCS##type##List sibling, dtype *data); \ - unsigned int ccs##type##ListLength (CCS##type##List list); \ - CCS##type##List ccs##type##ListFind (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListGetItem (CCS##type##List list, unsigned int index); \ - CCS##type##List ccs##type##ListRemove (CCS##type##List list, dtype *data, Bool freeObj); \ - CCS##type##List ccs##type##ListFree (CCS##type##List list, Bool freeObj); - typedef struct _CCSContext CCSContext; typedef struct _CCSPlugin CCSPlugin; typedef struct _CCSSetting CCSSetting; @@ -144,11 +80,9 @@ typedef struct _CCSBackendInfo CCSBackendInfo; typedef struct _CCSIntDesc CCSIntDesc; typedef struct _CCSStrRestriction CCSStrRestriction; typedef struct _CCSStrExtension CCSStrExtension; -typedef struct _CCSString CCSString; CCSLIST_HDR (Plugin, CCSPlugin) CCSLIST_HDR (Setting, CCSSetting) -CCSLIST_HDR (String, CCSString) CCSLIST_HDR (Group, CCSGroup) CCSLIST_HDR (SubGroup, CCSSubGroup) CCSLIST_HDR (SettingValue, CCSSettingValue) @@ -158,102 +92,6 @@ CCSLIST_HDR (IntDesc, CCSIntDesc) CCSLIST_HDR (StrRestriction, CCSStrRestriction) CCSLIST_HDR (StrExtension, CCSStrExtension) -typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ -typedef struct _CCSPrivate CCSPrivate; /* Dummy typedef */ -typedef struct _CCSObject CCSObject; - -typedef void * (*reallocObjectProc) (void *, void *, size_t); -typedef void * (*mallocObjectProc) (void *, size_t); -typedef void * (*callocObjectProc) (void *, size_t, size_t); -typedef void (*freeObjectProc) (void *, void *); - -typedef struct _CCSObjectAllocationInterface -{ - reallocObjectProc realloc_; - mallocObjectProc malloc_; - callocObjectProc calloc_; - freeObjectProc free_; - void *allocator; -} CCSObjectAllocationInterface; - -extern CCSObjectAllocationInterface ccsDefaultObjectAllocator; - -struct _CCSObject -{ - CCSPrivate *priv; /* Private pointer for object storage */ - - const CCSInterface **interfaces; /* An array of interfaces that this object implements */ - int *interface_types; /* An array of interface types */ - unsigned int n_interfaces; - unsigned int n_allocated_interfaces; - - CCSObjectAllocationInterface *object_allocation; - - unsigned int refcnt; /* Reference count of this object */ -}; - -Bool -ccsObjectInit_ (CCSObject *object, CCSObjectAllocationInterface *interface); - -#define ccsObjectInit(o, interface) (ccsObjectInit_) (&(o)->object, interface) - -Bool -ccsObjectAddInterface_ (CCSObject *object, const CCSInterface *interface, int interface_type); - -#define ccsObjectAddInterface(o, interface, type) (ccsObjectAddInterface_) (&(o)->object, interface, type); - -Bool -ccsObjectRemoveInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectRemoveInterface(o, interface_type) (ccsObjectRemoveInterface_) (&(o)->object, interface_type); - -const CCSInterface * ccsObjectGetInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectGetInterface(o, interface_type) (ccsObjectGetInterface_) (&(o)->object, interface_type) - -#define ccsObjectRef(o) \ - do { ((o)->object).refcnt++; } while (FALSE) - -#define ccsObjectUnref(o, freeFunc) \ - do \ - { \ - ((o)->object).refcnt--; \ - if (!((o)->object).refcnt) \ - freeFunc (o); \ - } while (FALSE) - -CCSPrivate * -ccsObjectGetPrivate_ (CCSObject *object); - -#define ccsObjectGetPrivate(o) (ccsObjectGetPrivate_) (&(o)->object) - -void -ccsObjectSetPrivate_ (CCSObject *object, CCSPrivate *priv); - -#define ccsObjectSetPrivate(o, priv) (ccsObjectSetPrivate_) (&(o)->object, priv) - -void -ccsObjectFinalize_ (CCSObject *object); - -#define ccsObjectFinalize(o) (ccsObjectFinalize_) (&(o)->object) - -unsigned int -ccsAllocateType (); - -#define GET_INTERFACE_TYPE(Interface) \ - ccs##Interface##GetType () - -#define INTERFACE_TYPE(Interface) \ - unsigned int ccs##Interface##GetType () \ - { \ - static unsigned int type_id = 0; \ - if (!type_id) \ - type_id = ccsAllocateType (); \ - \ - return type_id; \ - } - -#define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) /** * reference counting @@ -543,12 +381,6 @@ struct _CCSPluginConflict union _CCSSettingInfo; -struct _CCSString -{ - char *value; - unsigned int refCount; -}; - struct _CCSIntDesc { int value; /* value the description is assigned to */ @@ -916,7 +748,6 @@ void ccsFreeBackendInfo (CCSBackendInfo *value); void ccsFreeIntDesc (CCSIntDesc *value); void ccsFreeStrRestriction (CCSStrRestriction *restriction); void ccsFreeStrExtension (CCSStrExtension *extension); -void ccsFreeString (CCSString *str); @@ -1279,8 +1110,6 @@ CCSBackendInfoList ccsGetExistingBackends (void); CCSStrExtensionList ccsGetPluginStrExtensions (CCSPlugin *plugin); -#ifdef __cplusplus -} -#endif +COMPIZCONFIG_END_DECLS #endif -- GitLab From 713e786cf19c085d6ed9fea16c5c7056d24805fa Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 15:37:49 +0800 Subject: [PATCH 328/562] Added missing COMPIZCONFIG_BEGIN_DECLS etc --- compizconfig/libcompizconfig/include/ccs-backend.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 6ed5ea30a..f720b6850 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -22,10 +22,12 @@ #ifndef CCS_BACKEND_H #define CCS_BACKEND_H -#include +#include #include #include +COMPIZCONFIG_BEGIN_DECLS + typedef struct _CCSSetting CCSSetting; typedef struct _CCSContext CCSContext; typedef struct _CCSBackend CCSBackend; @@ -94,4 +96,6 @@ struct _CCSBackendVTable CCSBackendVTable* getBackendInfo (void); +COMPIZCONFIG_END_DECLS + #endif -- GitLab From a2b4f6f14d08bdf3db5086ee2809885c06dae9ec Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 15:38:54 +0800 Subject: [PATCH 329/562] Chnage order of includes --- compizconfig/libcompizconfig/include/ccs-backend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index f720b6850..e5d9e294c 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -23,8 +23,8 @@ #define CCS_BACKEND_H #include -#include #include +#include COMPIZCONFIG_BEGIN_DECLS -- GitLab From 103bde42b977dd5d55c6aca4d3837e3dc7f4ec6f Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 15:43:41 +0800 Subject: [PATCH 330/562] Constify --- compizconfig/libcompizconfig/include/ccs.h | 4 ++-- compizconfig/libcompizconfig/src/main.c | 10 +++++----- compizconfig/libcompizconfig/tests/mock-context.h | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 608adfdf4..25b6a16e1 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -153,11 +153,11 @@ typedef Bool (*CCSContextPluginIsActive) (CCSContext *context, char *name); typedef CCSPluginList (*CCSContextGetActivePluginList) (CCSContext *context); typedef CCSStringList (*CCSContextGetSortedPluginStringList) (CCSContext *context); typedef Bool (*CCSContextSetBackend) (CCSContext *context, char *name); -typedef char * (*CCSContextGetBackend) (CCSContext *context); +typedef const char * (*CCSContextGetBackend) (CCSContext *context); typedef void (*CCSContextSetIntegrationEnabled) (CCSContext *context, Bool value); typedef void (*CCSContextSetProfile) (CCSContext *context, char *name); typedef void (*CCSContextSetPluginListAutoSort) (CCSContext *context, Bool value); -typedef char * (*CCSContextGetProfile) (CCSContext *context); +typedef const char * (*CCSContextGetProfile) (CCSContext *context); typedef Bool (*CCSContextGetIntegrationEnabled) (CCSContext *context); typedef Bool (*CCSContextGetPluginListAutoSort) (CCSContext *context); typedef void (*CCSContextProcessEvents) (CCSContext *context, unsigned int flags); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 0a0bca61d..5355c93da 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -2542,7 +2542,7 @@ ccsGetSortedPluginStringList (CCSContext *context) return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetSortedPluginStringList) (context); } -char * +const char * ccsGetBackendDefault (CCSContext * context) { if (!context) @@ -2553,10 +2553,10 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return cPrivate->backend->vTable->name; + return ccsBackendGetInfo (cPrivate->backend)->name; } -char * +const char * ccsGetBackend (CCSContext *context) { return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetBackend) (context); @@ -2582,7 +2582,7 @@ ccsGetIntegrationEnabled (CCSContext *context) return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetIntegrationEnabled) (context); } -char * +const char * ccsGetProfileDefault (CCSContext * context) { if (!context) @@ -2593,7 +2593,7 @@ ccsGetProfileDefault (CCSContext * context) return cPrivate->profile; } -char * +const char * ccsGetProfile (CCSContext *context) { if (!context) diff --git a/compizconfig/libcompizconfig/tests/mock-context.h b/compizconfig/libcompizconfig/tests/mock-context.h index 1000d0d90..7e9b38110 100644 --- a/compizconfig/libcompizconfig/tests/mock-context.h +++ b/compizconfig/libcompizconfig/tests/mock-context.h @@ -26,12 +26,12 @@ class CCSContextGMockInterface virtual Bool pluginIsActive (char *name) = 0; virtual CCSPluginList getActivePluginList () = 0; virtual CCSStringList getSortedPluginStringList () = 0; - virtual char * getBackend () = 0; + virtual const char * getBackend () = 0; virtual Bool setBackend (char *name) = 0; virtual void setIntegrationEnabled (Bool value) = 0; virtual void setProfile (char *name) = 0; virtual void setPluginListAutoSort (Bool value) = 0; - virtual char * getProfile () = 0; + virtual const char * getProfile () = 0; virtual Bool getIntegrationEnabled () = 0; virtual Bool getPluginListAutoSort () = 0; virtual void processEvents (unsigned int flags) = 0; @@ -67,12 +67,12 @@ class CCSContextGMock : MOCK_METHOD1 (pluginIsActive, Bool (char *)); MOCK_METHOD0 (getActivePluginList, CCSPluginList ()); MOCK_METHOD0 (getSortedPluginStringList, CCSStringList ()); - MOCK_METHOD0 (getBackend, char * ()); + MOCK_METHOD0 (getBackend, const char * ()); MOCK_METHOD1 (setBackend, Bool (char *)); MOCK_METHOD1 (setIntegrationEnabled, void (Bool)); MOCK_METHOD1 (setProfile, void (char *)); MOCK_METHOD1 (setPluginListAutoSort, void (Bool)); - MOCK_METHOD0 (getProfile, char * ()); + MOCK_METHOD0 (getProfile, const char * ()); MOCK_METHOD0 (getIntegrationEnabled, Bool ()); MOCK_METHOD0 (getPluginListAutoSort, Bool ()); MOCK_METHOD1 (processEvents, void (unsigned int)); @@ -175,7 +175,7 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getSortedPluginStringList (); } - static char * + static const char * ccsGetBackend (CCSContext *context) { return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getBackend (); @@ -190,7 +190,7 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getIntegrationEnabled (); } - static char * + static const char * ccsGetProfile (CCSContext *context) { if (!context) -- GitLab From 8dc144cec6097d1bcf827d82414666fcb8f7f2dc Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 20:44:30 +0800 Subject: [PATCH 331/562] Fix some random build failures --- compizconfig/libcompizconfig/include/ccs.h | 4 ++-- compizconfig/libcompizconfig/src/main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index 25b6a16e1..dd51544ec 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -841,7 +841,7 @@ CCSStringList ccsGetSortedPluginStringList (CCSContext *context); Bool ccsSetBackend (CCSContext *context, char *name); /* Retrieves the name of the backend active for the context. */ -char * ccsGetBackend (CCSContext *context); +const char * ccsGetBackend (CCSContext *context); /* Enable/disable DE integration for a context. */ void ccsSetIntegrationEnabled (CCSContext *context, @@ -856,7 +856,7 @@ void ccsSetPluginListAutoSort (CCSContext *context, Bool value); /* Retrieve current profile of the context. */ -char * ccsGetProfile (CCSContext *context); +const char * ccsGetProfile (CCSContext *context); /* Retrieves current DE integration status for a context */ Bool ccsGetIntegrationEnabled (CCSContext *context); diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 5355c93da..fcb176a87 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -2553,7 +2553,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return ccsBackendGetInfo (cPrivate->backend)->name; + return cPrivate->backend->vTable->name; } const char * -- GitLab From a78cb9c9073d3f63252eb8f4daee55dfb56d6fc9 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 20:55:02 +0800 Subject: [PATCH 332/562] Require the backend mock to take the fake backend interface as a parameter --- .../compizconfig_ccs_backend_mock.cpp | 2 +- .../compizconfig_ccs_backend_mock.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp index 1b64fd853..5a65ab6c7 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp @@ -34,7 +34,7 @@ ccsMockBackendNew () ccsObjectInit (backend, &ccsDefaultObjectAllocator); - CCSBackendGMock *mock = new CCSBackendGMock (); + CCSBackendGMock *mock = new CCSBackendGMock (backend); ccsObjectSetPrivate (backend, (CCSPrivate *) mock); ccsObjectAddInterface (backend, (CCSInterface *) &CCSBackendGMockInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h index 01041c6c0..c36627b2a 100644 --- a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -1,3 +1,6 @@ +#ifndef _COMPIZCONFIG_CCS_BACKEND_MOCK_H +#define _COMPIZCONFIG_CCS_BACKEND_MOCK_H + #include #include @@ -34,6 +37,13 @@ class CCSBackendGMock : { public: + CCSBackendGMock (CCSBackend *b) : + mBackend (b) + { + } + + CCSBackend * backend () { return mBackend; } + /* Mock implementations */ MOCK_METHOD0 (getInfo, const CCSBackendInfo * ()); MOCK_METHOD1 (executeEvents, void (unsigned int)); @@ -51,6 +61,10 @@ class CCSBackendGMock : MOCK_METHOD1 (getExistingProfiles, CCSStringList (CCSContext *)); MOCK_METHOD2 (deleteProfile, Bool (CCSContext *, char *name)); + private: + + CCSBackend *mBackend; + public: /* Thunking C to C++ */ @@ -132,3 +146,5 @@ class CCSBackendGMock : }; extern CCSBackendInterface CCSBackendGMockInterface; + +#endif -- GitLab From 7bd5a5657fba991b25397c1fb07d015bc081ab09 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 20:59:26 +0800 Subject: [PATCH 333/562] Backport changes to mocks --- .../libcompizconfig/tests/context-mock.cpp | 2 +- .../libcompizconfig/tests/mock-context.h | 11 ++++++ .../libcompizconfig/tests/mock-plugin.h | 12 +++++++ .../libcompizconfig/tests/mock-setting.h | 18 +++++++--- .../libcompizconfig/tests/plugin-mock.cpp | 2 +- .../libcompizconfig/tests/setting-mock.cpp | 36 ++++++++++++++++--- 6 files changed, 70 insertions(+), 11 deletions(-) diff --git a/compizconfig/libcompizconfig/tests/context-mock.cpp b/compizconfig/libcompizconfig/tests/context-mock.cpp index c6b6faf70..6d53426c9 100644 --- a/compizconfig/libcompizconfig/tests/context-mock.cpp +++ b/compizconfig/libcompizconfig/tests/context-mock.cpp @@ -54,7 +54,7 @@ ccsMockContextNew () ccsObjectInit (context, &ccsDefaultObjectAllocator); - CCSContextGMock *mock = new CCSContextGMock (); + CCSContextGMock *mock = new CCSContextGMock (context); ccsObjectSetPrivate (context, (CCSPrivate *) mock); ccsObjectAddInterface (context, (CCSInterface *) &CCSContextGMockInterface, GET_INTERFACE_TYPE (CCSContextInterface)); diff --git a/compizconfig/libcompizconfig/tests/mock-context.h b/compizconfig/libcompizconfig/tests/mock-context.h index 7e9b38110..3f5246b9b 100644 --- a/compizconfig/libcompizconfig/tests/mock-context.h +++ b/compizconfig/libcompizconfig/tests/mock-context.h @@ -53,6 +53,13 @@ class CCSContextGMock : { public: + CCSContextGMock (CCSContext *c) : + mContext (c) + { + } + + CCSContext * context () { return mContext; } + MOCK_METHOD0 (getPlugins, CCSPluginList ()); MOCK_METHOD0 (getCategories, CCSPluginCategory * ()); MOCK_METHOD0 (getChangedSettings, CCSSettingList ()); @@ -88,6 +95,10 @@ class CCSContextGMock : MOCK_METHOD0 (checkForSettingsUpgrade, Bool ()); MOCK_METHOD0 (loadPlugins, void ()); + private: + + CCSContext *mContext; + public: /* Thunking from C interface callbacks to the virtual functions ... */ diff --git a/compizconfig/libcompizconfig/tests/mock-plugin.h b/compizconfig/libcompizconfig/tests/mock-plugin.h index bf4333d5e..36c9d6c0b 100644 --- a/compizconfig/libcompizconfig/tests/mock-plugin.h +++ b/compizconfig/libcompizconfig/tests/mock-plugin.h @@ -38,6 +38,14 @@ class CCSPluginGMock : { public: + CCSPluginGMock (CCSPlugin *p) : + mPlugin (p) + { + } + + CCSPlugin * + plugin () { return mPlugin; } + /* Mock implementations */ MOCK_METHOD0 (getName, char * ()); MOCK_METHOD0 (getShortDesc, char * ()); @@ -59,6 +67,10 @@ class CCSPluginGMock : MOCK_METHOD0 (readPluginSettings, void ()); MOCK_METHOD0 (getPluginStrExtensions, CCSStrExtensionList ()); + private: + + CCSPlugin *mPlugin; + public: /* Thunking C to C++ */ diff --git a/compizconfig/libcompizconfig/tests/mock-setting.h b/compizconfig/libcompizconfig/tests/mock-setting.h index e27dc03c3..70f0c6d5e 100644 --- a/compizconfig/libcompizconfig/tests/mock-setting.h +++ b/compizconfig/libcompizconfig/tests/mock-setting.h @@ -7,6 +7,7 @@ using ::testing::_; using ::testing::Return; CCSSetting * ccsMockSettingNew (); +CCSSetting * ccsNiceMockSettingNew (); void ccsFreeMockSetting (CCSSetting *); class CCSSettingGMockInterface @@ -64,6 +65,15 @@ class CCSSettingGMock : /* Mock implementations */ + CCSSettingGMock (CCSSetting *s) : + mSetting (s) + { + /* Teach GMock how to handle it */ + ON_CALL (*this, getType ()).WillByDefault (Return (TypeNum)); + } + + CCSSetting * setting () { return mSetting; } + MOCK_METHOD0 (getName, char * ()); MOCK_METHOD0 (getShortDesc, char * ()); MOCK_METHOD0 (getLongDesc, char * ()); @@ -105,11 +115,9 @@ class CCSSettingGMock : MOCK_METHOD0 (isIntegrated, Bool ()); MOCK_METHOD0 (isReadOnly, Bool ()); - CCSSettingGMock () - { - /* Teach GMock how to handle it */ - ON_CALL (*this, getType ()).WillByDefault (Return (TypeNum)); - } + private: + + CCSSetting *mSetting; public: diff --git a/compizconfig/libcompizconfig/tests/plugin-mock.cpp b/compizconfig/libcompizconfig/tests/plugin-mock.cpp index a7df78918..e27987a71 100644 --- a/compizconfig/libcompizconfig/tests/plugin-mock.cpp +++ b/compizconfig/libcompizconfig/tests/plugin-mock.cpp @@ -39,7 +39,7 @@ ccsMockPluginNew () ccsObjectInit (plugin, &ccsDefaultObjectAllocator); - CCSPluginGMock *mock = new CCSPluginGMock (); + CCSPluginGMock *mock = new CCSPluginGMock (plugin); ccsObjectSetPrivate (plugin, (CCSPrivate *) mock); ccsObjectAddInterface (plugin, (CCSInterface *) &CCSPluginGMockInterface, GET_INTERFACE_TYPE (CCSPluginInterface)); diff --git a/compizconfig/libcompizconfig/tests/setting-mock.cpp b/compizconfig/libcompizconfig/tests/setting-mock.cpp index c4bd7efdf..2701816cd 100644 --- a/compizconfig/libcompizconfig/tests/setting-mock.cpp +++ b/compizconfig/libcompizconfig/tests/setting-mock.cpp @@ -5,6 +5,8 @@ #include "mock-setting.h" +using ::testing::NiceMock; + CCSSettingInterface CCSSettingGMockInterface = { CCSSettingGMock::ccsSettingGetName, @@ -50,8 +52,8 @@ CCSSettingInterface CCSSettingGMockInterface = CCSSettingGMock::ccsSettingFree }; -CCSSetting * -ccsMockSettingNew () +static CCSSetting * +allocateSettingObjectWithMockInterface () { CCSSetting *setting = (CCSSetting *) calloc (1, sizeof (CCSSetting)); @@ -60,8 +62,6 @@ ccsMockSettingNew () ccsObjectInit (setting, &ccsDefaultObjectAllocator); - CCSSettingGMock *mock = new CCSSettingGMock (); - ccsObjectSetPrivate (setting, (CCSPrivate *) mock); ccsObjectAddInterface (setting, (CCSInterface *) &CCSSettingGMockInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); ccsSettingRef (setting); @@ -69,6 +69,34 @@ ccsMockSettingNew () return setting; } +CCSSetting * +ccsMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + CCSSettingGMock *mock = new CCSSettingGMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + +CCSSetting * +ccsNiceMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + NiceMock *mock = new NiceMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + void ccsFreeMockSetting (CCSSetting *setting) { -- GitLab From f6011eb058d8d8b2b436c9ce424fcf464ab7016d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:00:34 +0800 Subject: [PATCH 334/562] Remove superfluous changes to cmake file --- compizconfig/gsettings/tests/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index b30961a55..2ccab73d5 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,9 +1,7 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests - ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig - ${CMAKE_CURRENT_SOURCE_DIR}/../../tests - ${CMAKE_SOURCE_DIR}/tests/shared) + ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) -- GitLab From 2b1828502fafb0c33f5d26f0cfe01f9c880ad57b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:01:39 +0800 Subject: [PATCH 335/562] We need to include these directories --- compizconfig/gsettings/tests/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 2ccab73d5..b30961a55 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,7 +1,9 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests - ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) + ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig + ${CMAKE_CURRENT_SOURCE_DIR}/../../tests + ${CMAKE_SOURCE_DIR}/tests/shared) pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) -- GitLab From 535227e6c6309c3ead440063d1f2d67240a6bbab Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:13:12 +0800 Subject: [PATCH 336/562] Moved files to where they should be --- .../libcompizconfig/include/ccs-defs.h | 18 +++ .../libcompizconfig/include/ccs-defs.h.moved | 70 --------- .../libcompizconfig/include/ccs-list.h.moved | 85 ----------- .../libcompizconfig/include/ccs-object.h | 11 ++ .../include/ccs-object.h.moved | 140 ------------------ .../include/ccs-string.h.moved | 47 ------ 6 files changed, 29 insertions(+), 342 deletions(-) delete mode 100644 compizconfig/libcompizconfig/include/ccs-defs.h.moved delete mode 100644 compizconfig/libcompizconfig/include/ccs-list.h.moved delete mode 100644 compizconfig/libcompizconfig/include/ccs-object.h.moved delete mode 100644 compizconfig/libcompizconfig/include/ccs-string.h.moved diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h b/compizconfig/libcompizconfig/include/ccs-defs.h index 5c1bb43d7..1da27ac33 100644 --- a/compizconfig/libcompizconfig/include/ccs-defs.h +++ b/compizconfig/libcompizconfig/include/ccs-defs.h @@ -47,6 +47,24 @@ COMPIZCONFIG_BEGIN_DECLS #define FALSE 0 #endif +/** + * reference counting + * + * ccsSettingRef + * References the settings object so it can be kept in a list and + * unreferenced later with freeObj (mixed with objects that need + * to be freed and need not be freed) + * + * ccsSettingUnref + * Unreferences the settings object, when the reference count reaches + * zero, the object is freed + * + */ + +#define CCSREF_HDR(type,dtype) \ + void ccs##type##Ref (dtype *); \ + void ccs##type##Unref (dtype *); + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h.moved b/compizconfig/libcompizconfig/include/ccs-defs.h.moved deleted file mode 100644 index 1da27ac33..000000000 --- a/compizconfig/libcompizconfig/include/ccs-defs.h.moved +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Compiz configuration system library - * - * Copyright (C) 2007 Dennis Kasprzyk - * Copyright (C) 2007 Danny Baumann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library 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 - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _CCS_DEFS_H -#define _CCS_DEFS_H - -#include /* for NULL */ - -#ifdef __cplusplus -# define COMPIZCONFIG_BEGIN_DECLS extern "C" { -# define COMPIZCONFIG_END_DECLS } -#else -# define COMPIZCONFIG_BEGIN_DECLS -# define COMPIZCONFIG_END_DECLS -#endif - - -COMPIZCONFIG_BEGIN_DECLS - -#ifndef Bool -#define Bool int -#endif - -#ifndef TRUE -#define TRUE ~0 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -/** - * reference counting - * - * ccsSettingRef - * References the settings object so it can be kept in a list and - * unreferenced later with freeObj (mixed with objects that need - * to be freed and need not be freed) - * - * ccsSettingUnref - * Unreferences the settings object, when the reference count reaches - * zero, the object is freed - * - */ - -#define CCSREF_HDR(type,dtype) \ - void ccs##type##Ref (dtype *); \ - void ccs##type##Unref (dtype *); - -COMPIZCONFIG_END_DECLS - -#endif diff --git a/compizconfig/libcompizconfig/include/ccs-list.h.moved b/compizconfig/libcompizconfig/include/ccs-list.h.moved deleted file mode 100644 index 9e758223f..000000000 --- a/compizconfig/libcompizconfig/include/ccs-list.h.moved +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Compiz configuration system library - * - * Copyright (C) 2007 Dennis Kasprzyk - * Copyright (C) 2007 Danny Baumann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library 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 - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _CCS_LIST_H -#define _CCS_LIST_H - -#include - -COMPIZCONFIG_BEGIN_DECLS - -/** - * list functions: - * for each list there is a set of functions, explained using String as example - * - * ccsStringListAppend (list, item) - * Adds an item at the end of the list. Returns the new list. - * - * ccsStringListPrepend (list, item) - * Adds an item at the beginning of the list. Returns the new list. - * - * ccsStringListInsert (list, item, position) - * Adds an item at a given position. Position is 0-based. If position is - * larger than the amount of items in the list, the item is inserted at the - * end of the list. Returns the new list. - * - * ccsStringListInsertBefore (list, sibling, item) - * Inserts item before sibling into the list. If sibling is no list member, - * item is inserted at the end. Returns the new list. - * - * ccsStringListLength (list) - * Returns the amount of items in list. - * - * ccsStringListFind (list, item) - * Finds and returns an item matching . If nothing is found, returns NULL. - * - * ccsStringListGetItem (list, index) - * Returns the list item at position . If index is larger than the - * amount of items in the list, returns NULL. - * - * ccsStringListRemove (list, item, freeObj) - * Removes item from the list. If freeObj is TRUE, also frees the data item. - * Returns the new list. - * - * ccsStringListFree (list, freeObj) - * Frees the complete list. If freeObj is TRUE, also frees the data items. - * Returns the new list (NULL). - */ -#define CCSLIST_HDR(type,dtype) \ - typedef struct _CCS##type##List * CCS##type##List;\ - struct _CCS##type##List \ - { \ - dtype * data; \ - CCS##type##List next; \ - }; \ - CCS##type##List ccs##type##ListAppend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListPrepend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListInsert (CCS##type##List list, dtype *data, int position); \ - CCS##type##List ccs##type##ListInsertBefore (CCS##type##List list, CCS##type##List sibling, dtype *data); \ - unsigned int ccs##type##ListLength (CCS##type##List list); \ - CCS##type##List ccs##type##ListFind (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListGetItem (CCS##type##List list, unsigned int index); \ - CCS##type##List ccs##type##ListRemove (CCS##type##List list, dtype *data, Bool freeObj); \ - CCS##type##List ccs##type##ListFree (CCS##type##List list, Bool freeObj); - -COMPIZCONFIG_END_DECLS - -#endif diff --git a/compizconfig/libcompizconfig/include/ccs-object.h b/compizconfig/libcompizconfig/include/ccs-object.h index c01f0fc2e..1c96d2fcb 100644 --- a/compizconfig/libcompizconfig/include/ccs-object.h +++ b/compizconfig/libcompizconfig/include/ccs-object.h @@ -124,6 +124,17 @@ ccsAllocateType (); #define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) +#define CCSREF_OBJ(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + ccsObjectRef (d); \ + } \ + \ + void ccs##type##Unref (dtype *d) \ + { \ + ccsObjectUnref (d, ccsFree##type); \ + } \ + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/include/ccs-object.h.moved b/compizconfig/libcompizconfig/include/ccs-object.h.moved deleted file mode 100644 index 1c96d2fcb..000000000 --- a/compizconfig/libcompizconfig/include/ccs-object.h.moved +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Compiz configuration system library - * - * Copyright (C) 2012 Canonical Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library 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 - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authored By: Sam Spilsbury - */ - -#ifndef _CCS_OBJECT_H -#define _CCS_OBJECT_H - -#include - -COMPIZCONFIG_BEGIN_DECLS - -typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ -typedef struct _CCSPrivate CCSPrivate; /* Dummy typedef */ -typedef struct _CCSObject CCSObject; - -typedef void * (*reallocObjectProc) (void *, void *, size_t); -typedef void * (*mallocObjectProc) (void *, size_t); -typedef void * (*callocObjectProc) (void *, size_t, size_t); -typedef void (*freeObjectProc) (void *, void *); - -typedef struct _CCSObjectAllocationInterface -{ - reallocObjectProc realloc_; - mallocObjectProc malloc_; - callocObjectProc calloc_; - freeObjectProc free_; - void *allocator; -} CCSObjectAllocationInterface; - -extern CCSObjectAllocationInterface ccsDefaultObjectAllocator; - -struct _CCSObject -{ - CCSPrivate *priv; /* Private pointer for object storage */ - - const CCSInterface **interfaces; /* An array of interfaces that this object implements */ - int *interface_types; /* An array of interface types */ - unsigned int n_interfaces; - unsigned int n_allocated_interfaces; - - CCSObjectAllocationInterface *object_allocation; - - unsigned int refcnt; /* Reference count of this object */ -}; - -Bool -ccsObjectInit_ (CCSObject *object, CCSObjectAllocationInterface *interface); - -#define ccsObjectInit(o, interface) (ccsObjectInit_) (&(o)->object, interface) - -Bool -ccsObjectAddInterface_ (CCSObject *object, const CCSInterface *interface, int interface_type); - -#define ccsObjectAddInterface(o, interface, type) (ccsObjectAddInterface_) (&(o)->object, interface, type); - -Bool -ccsObjectRemoveInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectRemoveInterface(o, interface_type) (ccsObjectRemoveInterface_) (&(o)->object, interface_type); - -const CCSInterface * ccsObjectGetInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectGetInterface(o, interface_type) (ccsObjectGetInterface_) (&(o)->object, interface_type) - -#define ccsObjectRef(o) \ - do { ((o)->object).refcnt++; } while (FALSE) - -#define ccsObjectUnref(o, freeFunc) \ - do \ - { \ - ((o)->object).refcnt--; \ - if (!((o)->object).refcnt) \ - freeFunc (o); \ - } while (FALSE) - -CCSPrivate * -ccsObjectGetPrivate_ (CCSObject *object); - -#define ccsObjectGetPrivate(o) (ccsObjectGetPrivate_) (&(o)->object) - -void -ccsObjectSetPrivate_ (CCSObject *object, CCSPrivate *priv); - -#define ccsObjectSetPrivate(o, priv) (ccsObjectSetPrivate_) (&(o)->object, priv) - -void -ccsObjectFinalize_ (CCSObject *object); - -#define ccsObjectFinalize(o) (ccsObjectFinalize_) (&(o)->object) - -unsigned int -ccsAllocateType (); - -#define GET_INTERFACE_TYPE(Interface) \ - ccs##Interface##GetType () - -#define INTERFACE_TYPE(Interface) \ - unsigned int ccs##Interface##GetType () \ - { \ - static unsigned int type_id = 0; \ - if (!type_id) \ - type_id = ccsAllocateType (); \ - \ - return type_id; \ - } - -#define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) - -#define CCSREF_OBJ(type,dtype) \ - void ccs##type##Ref (dtype *d) \ - { \ - ccsObjectRef (d); \ - } \ - \ - void ccs##type##Unref (dtype *d) \ - { \ - ccsObjectUnref (d, ccsFree##type); \ - } \ - -COMPIZCONFIG_END_DECLS - -#endif diff --git a/compizconfig/libcompizconfig/include/ccs-string.h.moved b/compizconfig/libcompizconfig/include/ccs-string.h.moved deleted file mode 100644 index 48dabde5e..000000000 --- a/compizconfig/libcompizconfig/include/ccs-string.h.moved +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Compiz configuration system library - * - * Copyright (C) 2007 Dennis Kasprzyk - * Copyright (C) 2007 Danny Baumann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library 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 - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _CCS_STRING_H -#define _CCS_STRING_H - -/* Doesn't seem to make sense to have this header - * dependency, but we can only declare a typed list - * once */ -#include - -COMPIZCONFIG_BEGIN_DECLS - -typedef struct _CCSString CCSString; - -struct _CCSString -{ - char *value; - unsigned int refCount; -}; - -void ccsFreeString (CCSString *str); - -CCSLIST_HDR (String, CCSString); - -COMPIZCONFIG_END_DECLS - -#endif - -- GitLab From 282bf9def2ffabafe8932c349a00c67304510716 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:14:30 +0800 Subject: [PATCH 337/562] Rever some whitespace changes --- compizconfig/compizconfig-python/src/compizconfig.pyx | 6 +++--- compizconfig/libcompizconfig/tests/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compizconfig/compizconfig-python/src/compizconfig.pyx b/compizconfig/compizconfig-python/src/compizconfig.pyx index 59bf3600d..e06a82937 100644 --- a/compizconfig/compizconfig-python/src/compizconfig.pyx +++ b/compizconfig/compizconfig-python/src/compizconfig.pyx @@ -99,9 +99,9 @@ ctypedef CCSList CCSStrRestrictionList ctypedef CCSList CCSStrExtensionList cdef struct CCSBackendInfo: - char * name - char * shortDesc - char * longDesc + char * name + char * shortDesc + char * longDesc Bool integrationSupport Bool profileSupport unsigned int refCount diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index 13457a2ed..74a0d627f 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories (${GTEST_INCLUDE_DIRS}) + include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) include_directories (${CMAKE_SOURCE_DIR}/tests/shared) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) -- GitLab From 9b9814c1aefd34054e4b1dea6c935900e519fdd1 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:17:19 +0800 Subject: [PATCH 338/562] Put the typedefs in the right place --- compizconfig/libcompizconfig/include/ccs-backend.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 205bba665..bbf17b079 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -29,16 +29,13 @@ COMPIZCONFIG_BEGIN_DECLS typedef struct _CCSSetting CCSSetting; +typedef struct _CCSPlugin CCSPlugin; typedef struct _CCSContext CCSContext; typedef struct _CCSBackend CCSBackend; typedef struct _CCSBackendInfo CCSBackendInfo; typedef struct _CCSBackendPrivate CCSBackendPrivate; typedef struct _CCSBackendInterface CCSBackendInterface; -typedef struct _CCSContext CCSContext; -typedef struct _CCSPlugin CCSPlugin; -typedef struct _CCSSetting CCSSetting; - struct _CCSBackend { CCSObject object; -- GitLab From 8431aa23868ff153bcaac0b5bc755ed433139c6b Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:19:03 +0800 Subject: [PATCH 339/562] Remove dupe COMPIZCONFIG_END_DECLS --- compizconfig/libcompizconfig/include/ccs-backend.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index bbf17b079..3f9a2e3ba 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -149,6 +149,4 @@ CCSBackendInterface* getBackendInfo (void); COMPIZCONFIG_END_DECLS -COMPIZCONFIG_END_DECLS - #endif -- GitLab From efd21817dce5ac1675f47d2cbe415a90baa42775 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:22:35 +0800 Subject: [PATCH 340/562] Make the failing allocator shared --- .../libcompizconfig/tests/CMakeLists.txt | 1 + .../libcompizconfig/tests/mock-setting.h | 5 + .../libcompizconfig/tests/test-ccs-object.cpp | 78 +--------------- .../tests/compizconfig_ccs_mocked_allocator.h | 91 +++++++++++++++++++ 4 files changed, 98 insertions(+), 77 deletions(-) create mode 100644 compizconfig/tests/compizconfig_ccs_mocked_allocator.h diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index a37de9091..1ef5167b6 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_SOURCE_DIR}/compizconfig/tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) add_library (context-mock diff --git a/compizconfig/libcompizconfig/tests/mock-setting.h b/compizconfig/libcompizconfig/tests/mock-setting.h index 70f0c6d5e..59123b4fd 100644 --- a/compizconfig/libcompizconfig/tests/mock-setting.h +++ b/compizconfig/libcompizconfig/tests/mock-setting.h @@ -1,3 +1,6 @@ +#ifndef _COMPIZCONFIG_CCS_SETTING_MOCK +#define _COMPIZCONFIG_CCS_SETTING_MOCK + #include #include @@ -364,3 +367,5 @@ class CCSSettingGMock : }; extern CCSSettingInterface CCSSettingGMockInterface; + +#endif diff --git a/compizconfig/libcompizconfig/tests/test-ccs-object.cpp b/compizconfig/libcompizconfig/tests/test-ccs-object.cpp index e9e5e9a07..3389f68d3 100644 --- a/compizconfig/libcompizconfig/tests/test-ccs-object.cpp +++ b/compizconfig/libcompizconfig/tests/test-ccs-object.cpp @@ -6,6 +6,7 @@ #include #include +#include using ::testing::_; using ::testing::Return; @@ -217,83 +218,6 @@ TEST(CCSObjectTest, TestFinalizeFreesEverything) EXPECT_EQ (NULL, ((CCSObject *) to)->interface_types); } -class AllocationInterface -{ - public: - - virtual void * realloc_ (void *, size_t) = 0; - virtual void * malloc_ (size_t) = 0; - virtual void * calloc_ (size_t, size_t) = 0; - virtual void free_ (void *) = 0; - - public: - - static void * wrapRealloc (void *o, void *a , size_t b) - { - AllocationInterface *ao = static_cast (o); - return ao->realloc_ (a, b); - } - - static void * wrapMalloc (void *o, size_t a) - { - AllocationInterface *ao = static_cast (o); - return ao->malloc_ (a); - } - - static void * wrapCalloc (void *o, size_t a, size_t b) - { - AllocationInterface *ao = static_cast (o); - return ao->calloc_ (a, b); - } - - static void wrapFree (void *o, void *a) - { - AllocationInterface *ao = static_cast (o); - ao->free_ (a); - } -}; - -class ObjectAllocationGMock : - public AllocationInterface -{ - public: - - MOCK_METHOD2 (realloc_, void * (void *, size_t)); - MOCK_METHOD1 (malloc_, void * (size_t)); - MOCK_METHOD2 (calloc_, void * (size_t, size_t)); - MOCK_METHOD1 (free_, void (void *)); - -}; - -class FailingObjectReallocation : - public AllocationInterface -{ - public: - - FailingObjectReallocation (unsigned int sc) : - successCount (sc) - { - } - - void * realloc_ (void *a, size_t b) { unsigned int c = successCount--; if (c) return realloc (a, b); else return NULL; } - void * malloc_ (size_t a) { return malloc (a); } - void * calloc_ (size_t n, size_t a) { return calloc (n, a); } - void free_ (void *a) { free (a); } - - private: - - unsigned int successCount; -}; - -CCSObjectAllocationInterface failingAllocator = -{ - AllocationInterface::wrapRealloc, - AllocationInterface::wrapMalloc, - AllocationInterface::wrapCalloc, - AllocationInterface::wrapFree, - NULL -}; - TEST(CCSObjectTest, TestReallocFailures) { TestingObjectWrapper *to = (TestingObjectWrapper *) calloc (1, sizeof (TestingObjectWrapper)); diff --git a/compizconfig/tests/compizconfig_ccs_mocked_allocator.h b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h new file mode 100644 index 000000000..dabb25a6a --- /dev/null +++ b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h @@ -0,0 +1,91 @@ +#ifndef _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H +#define _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H +class AllocationInterface +{ + public: + + virtual void * realloc_ (void *, size_t) = 0; + virtual void * malloc_ (size_t) = 0; + virtual void * calloc_ (size_t, size_t) = 0; + virtual void free_ (void *) = 0; + + public: + + static void * wrapRealloc (void *o, void *a , size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->realloc_ (a, b); + } + + static void * wrapMalloc (void *o, size_t a) + { + AllocationInterface *ao = static_cast (o); + return ao->malloc_ (a); + } + + static void * wrapCalloc (void *o, size_t a, size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->calloc_ (a, b); + } + + static void wrapFree (void *o, void *a) + { + AllocationInterface *ao = static_cast (o); + ao->free_ (a); + } +}; + +class ObjectAllocationGMock : + public AllocationInterface +{ + public: + + MOCK_METHOD2 (realloc_, void * (void *, size_t)); + MOCK_METHOD1 (malloc_, void * (size_t)); + MOCK_METHOD2 (calloc_, void * (size_t, size_t)); + MOCK_METHOD1 (free_, void (void *)); + +}; + +class FailingObjectReallocation : + public AllocationInterface +{ + public: + + FailingObjectReallocation (unsigned int sc) : + successCount (sc) + { + } + + void * realloc_ (void *a, size_t b) { unsigned int c = successCount--; if (c) return realloc (a, b); else return NULL; } + void * malloc_ (size_t a) { return malloc (a); } + void * calloc_ (size_t n, size_t a) { return calloc (n, a); } + void free_ (void *a) { free (a); } + + private: + + unsigned int successCount; +}; + +class FailingObjectAllocation : + public AllocationInterface +{ + public: + + void * realloc_ (void *a, size_t b) { return NULL; } + void * malloc_ (size_t a) { return NULL; } + void * calloc_ (size_t n, size_t a) { return NULL; } + void free_ (void *a) { } +}; + +CCSObjectAllocationInterface failingAllocator = +{ + AllocationInterface::wrapRealloc, + AllocationInterface::wrapMalloc, + AllocationInterface::wrapCalloc, + AllocationInterface::wrapFree, + NULL +}; + +#endif -- GitLab From 97568b0f35e40bcfa2e4bab4e1a3ed1717d9485e Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:28:43 +0800 Subject: [PATCH 341/562] Moved reference counting definitions to ccs-defs.h --- .../libcompizconfig/include/ccs-defs.h | 41 +++++++++++++++++++ compizconfig/libcompizconfig/include/ccs.h | 19 --------- compizconfig/libcompizconfig/src/main.c | 24 ----------- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h b/compizconfig/libcompizconfig/include/ccs-defs.h index 5c1bb43d7..c63c65708 100644 --- a/compizconfig/libcompizconfig/include/ccs-defs.h +++ b/compizconfig/libcompizconfig/include/ccs-defs.h @@ -47,6 +47,47 @@ COMPIZCONFIG_BEGIN_DECLS #define FALSE 0 #endif +/** + * reference counting + * + * ccsSettingRef + * References the settings object so it can be kept in a list and + * unreferenced later with freeObj (mixed with objects that need + * to be freed and need not be freed) + * + * ccsSettingUnref + * Unreferences the settings object, when the reference count reaches + * zero, the object is freed + * + */ + +#define CCSREF_HDR(type,dtype) \ + void ccs##type##Ref (dtype *); \ + void ccs##type##Unref (dtype *); + +#define CCSREF_OBJ(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + ccsObjectRef (d); \ + } \ + \ + void ccs##type##Unref (dtype *d) \ + { \ + ccsObjectUnref (d, ccsFree##type); \ + } \ + +#define CCSREF(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + d->refCount++; \ + } \ + void ccs##type##Unref (dtype *d) \ + { \ + d->refCount--; \ + if (d->refCount == 0) \ + ccsFree##type (d); \ + } \ + COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index dd51544ec..3d595ce70 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -92,25 +92,6 @@ CCSLIST_HDR (IntDesc, CCSIntDesc) CCSLIST_HDR (StrRestriction, CCSStrRestriction) CCSLIST_HDR (StrExtension, CCSStrExtension) - -/** - * reference counting - * - * ccsSettingRef - * References the settings object so it can be kept in a list and - * unreferenced later with freeObj (mixed with objects that need - * to be freed and need not be freed) - * - * ccsSettingUnref - * Unreferences the settings object, when the reference count reaches - * zero, the object is freed - * - */ - -#define CCSREF_HDR(type,dtype) \ - void ccs##type##Ref (dtype *); \ - void ccs##type##Unref (dtype *); - CCSREF_HDR (Plugin, CCSPlugin) CCSREF_HDR (Setting, CCSSetting) CCSREF_HDR (String, CCSString) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index fcb176a87..1f7861182 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -972,19 +972,6 @@ ccsFreeString (CCSString *str) free (str); } -#define CCSREF(type,dtype) \ - void ccs##type##Ref (dtype *d) \ - { \ - d->refCount++; \ - } \ - void ccs##type##Unref (dtype *d) \ - { \ - d->refCount--; \ - if (d->refCount == 0) \ - ccsFree##type (d); \ - } \ - - CCSREF (String, CCSString) CCSREF (Group, CCSGroup) CCSREF (SubGroup, CCSSubGroup) @@ -995,17 +982,6 @@ CCSREF (IntDesc, CCSIntDesc) CCSREF (StrRestriction, CCSStrRestriction) CCSREF (StrExtension, CCSStrExtension) -#define CCSREF_OBJ(type,dtype) \ - void ccs##type##Ref (dtype *d) \ - { \ - ccsObjectRef (d); \ - } \ - \ - void ccs##type##Unref (dtype *d) \ - { \ - ccsObjectUnref (d, ccsFree##type); \ - } \ - CCSREF_OBJ (Plugin, CCSPlugin) CCSREF_OBJ (Setting, CCSSetting) -- GitLab From 77e2788ea0d00de320091f0f7b21ce3e81474461 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 7 Aug 2012 21:31:18 +0800 Subject: [PATCH 342/562] Merge --- .../libcompizconfig/include/ccs-defs.h | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h b/compizconfig/libcompizconfig/include/ccs-defs.h index 1da27ac33..c63c65708 100644 --- a/compizconfig/libcompizconfig/include/ccs-defs.h +++ b/compizconfig/libcompizconfig/include/ccs-defs.h @@ -65,6 +65,29 @@ COMPIZCONFIG_BEGIN_DECLS void ccs##type##Ref (dtype *); \ void ccs##type##Unref (dtype *); +#define CCSREF_OBJ(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + ccsObjectRef (d); \ + } \ + \ + void ccs##type##Unref (dtype *d) \ + { \ + ccsObjectUnref (d, ccsFree##type); \ + } \ + +#define CCSREF(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + d->refCount++; \ + } \ + void ccs##type##Unref (dtype *d) \ + { \ + d->refCount--; \ + if (d->refCount == 0) \ + ccsFree##type (d); \ + } \ + COMPIZCONFIG_END_DECLS #endif -- GitLab From 5dd258ef51227173353d853e79e222a256add47c Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 8 Aug 2012 00:13:32 +0800 Subject: [PATCH 343/562] Use BackendGetInfo --- compizconfig/libcompizconfig/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 37d5197fb..4d921bf8c 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -2709,7 +2709,7 @@ ccsGetBackendDefault (CCSContext * context) if (!cPrivate->backend) return NULL; - return cPrivate->backend->vTable->name; + return ccsBackendGetInfo (cPrivate->backend)->name; } const char * -- GitLab From 2d6e191dcf871bfeaad81f270833fc59054c9f80 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 8 Aug 2012 00:19:59 +0800 Subject: [PATCH 344/562] Re-add removed file --- .../tests/compizconfig_ccs_mocked_allocator.h | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 compizconfig/tests/compizconfig_ccs_mocked_allocator.h diff --git a/compizconfig/tests/compizconfig_ccs_mocked_allocator.h b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h new file mode 100644 index 000000000..dabb25a6a --- /dev/null +++ b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h @@ -0,0 +1,91 @@ +#ifndef _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H +#define _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H +class AllocationInterface +{ + public: + + virtual void * realloc_ (void *, size_t) = 0; + virtual void * malloc_ (size_t) = 0; + virtual void * calloc_ (size_t, size_t) = 0; + virtual void free_ (void *) = 0; + + public: + + static void * wrapRealloc (void *o, void *a , size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->realloc_ (a, b); + } + + static void * wrapMalloc (void *o, size_t a) + { + AllocationInterface *ao = static_cast (o); + return ao->malloc_ (a); + } + + static void * wrapCalloc (void *o, size_t a, size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->calloc_ (a, b); + } + + static void wrapFree (void *o, void *a) + { + AllocationInterface *ao = static_cast (o); + ao->free_ (a); + } +}; + +class ObjectAllocationGMock : + public AllocationInterface +{ + public: + + MOCK_METHOD2 (realloc_, void * (void *, size_t)); + MOCK_METHOD1 (malloc_, void * (size_t)); + MOCK_METHOD2 (calloc_, void * (size_t, size_t)); + MOCK_METHOD1 (free_, void (void *)); + +}; + +class FailingObjectReallocation : + public AllocationInterface +{ + public: + + FailingObjectReallocation (unsigned int sc) : + successCount (sc) + { + } + + void * realloc_ (void *a, size_t b) { unsigned int c = successCount--; if (c) return realloc (a, b); else return NULL; } + void * malloc_ (size_t a) { return malloc (a); } + void * calloc_ (size_t n, size_t a) { return calloc (n, a); } + void free_ (void *a) { free (a); } + + private: + + unsigned int successCount; +}; + +class FailingObjectAllocation : + public AllocationInterface +{ + public: + + void * realloc_ (void *a, size_t b) { return NULL; } + void * malloc_ (size_t a) { return NULL; } + void * calloc_ (size_t n, size_t a) { return NULL; } + void free_ (void *a) { } +}; + +CCSObjectAllocationInterface failingAllocator = +{ + AllocationInterface::wrapRealloc, + AllocationInterface::wrapMalloc, + AllocationInterface::wrapCalloc, + AllocationInterface::wrapFree, + NULL +}; + +#endif -- GitLab From f02e861ba6680a1023973d5327d229086ffff70d Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 8 Aug 2012 01:00:02 +0800 Subject: [PATCH 345/562] Remove code that doesn't belong in this pipe --- .../libcompizconfig/tests/CMakeLists.txt | 18 - ...nfig_test_ccs_mock_backend_conformance.cpp | 643 ------------------ 2 files changed, 661 deletions(-) delete mode 100644 compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index ac4b229b8..fc05d5287 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,11 +1,9 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) -include_directories (${CMAKE_SOURCE_DIR}/tests/shared) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) include_directories (${CMAKE_SOURCE_DIR}/compizconfig/tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../mocks/libcompizconfig) -link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../tests/) add_executable (compizconfig_test_ccs_object ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_object.cpp) @@ -22,9 +20,6 @@ add_executable (compizconfig_test_ccs_setting add_executable (compizconfig_test_ccs_backend ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) -add_executable (compizconfig_test_ccs_mock_backend_conformance - ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp) - if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES ${LIBCOMPIZCONFIG_LIBRARIES} @@ -73,18 +68,6 @@ target_link_libraries (compizconfig_test_ccs_backend compizconfig_ccs_setting_mock compizconfig_ccs_backend_mock) -target_link_libraries (compizconfig_test_ccs_mock_backend_conformance - ${GTEST_BOTH_LIBRARIES} - ${GMOCK_LIBRARY} - ${GMOCK_MAIN_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig - compizconfig_ccs_context_mock - compizconfig_ccs_plugin_mock - compizconfig_ccs_setting_mock - compizconfig_ccs_backend_mock) - target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} @@ -100,4 +83,3 @@ compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig) compiz_discover_tests (compizconfig_test_ccs_context COVERAGE compizconfig_ccs_context_mock) compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock) compiz_discover_tests (compizconfig_test_ccs_setting COVERAGE compizconfig_ccs_setting_mock) -compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance COVERAGE compizconfig_ccs_backend_mock) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp deleted file mode 100644 index 809f4e766..000000000 --- a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp +++ /dev/null @@ -1,643 +0,0 @@ -#include -#include - -#include - -#include -#include - -#include "compizconfig_ccs_backend_mock.h" - -using ::testing::_; -using ::testing::Return; -using ::testing::Invoke; -using ::testing::WithArgs; -using ::testing::Combine; -using ::testing::ValuesIn; -using ::testing::Values; -using ::testing::AtLeast; - -namespace -{ -std::string keynameFromPluginKey (const std::string &plugin, - const std::string &key) -{ - return plugin + "/" + key; -} -} - -template -class ValueForKeyRetreival -{ - public: - - T GetValueForKey (const std::string &key, - const std::map &map) - { - std::map ::const_iterator it = map.find (key); - - if (it != map.end ()) - return boost::get (it->second); - else - throw std::exception (); - } -}; - -namespace -{ - void doNothingWithCCSSetting (CCSSetting *) {}; - - const CCSBackendInfo mockBackendInfo = - { - "mock", - "Mock Backend", - "Mock Backend for libccs", - TRUE, - TRUE - }; -} - -class MockCCSBackendConceptTestEnvironment : - public CCSBackendConceptTestEnvironmentInterface -{ - public: - - CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) - { - mContext = context; - mBackend = ccsMockBackendNew (); - mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); - - ON_CALL (*mBackendGMock, readSetting (_, _)) - .WillByDefault ( - WithArgs<1> ( - Invoke ( - this, - &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); - - ON_CALL (*mBackendGMock, updateSetting (_, _, _)) - .WillByDefault ( - WithArgs<2> ( - Invoke ( - this, - &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); - - ON_CALL (*mBackendGMock, writeSetting (_, _)) - .WillByDefault ( - WithArgs<1> ( - Invoke ( - this, - &MockCCSBackendConceptTestEnvironment::WriteValueToMap))); - - ON_CALL (*mBackendGMock, deleteProfile (_, _)) - .WillByDefault ( - WithArgs <1> ( - Invoke ( - this, - &MockCCSBackendConceptTestEnvironment::DeleteProfile))); - - return mBackend; - } - - const CCSBackendInfo * GetInfo () - { - EXPECT_CALL (*mBackendGMock, getInfo ()).WillOnce (Return (&mockBackendInfo)); - - return &mockBackendInfo; - } - - void TearDown (CCSBackend *backend) - { - ccsFreeMockBackend (backend); - } - - void AddProfile (const std::string &profile) - { - mProfiles.push_back (profile); - } - - void SetGetExistingProfilesExpectation (CCSContext *context, - CCSContextGMock *gmockContext) - { - CCSStringList stringList = NULL; - - CCSString *defaultProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); - CCSString *currentProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); - - EXPECT_CALL (*gmockContext, getProfile ()); - - defaultProfile->value = strdup ("Default"); - currentProfile->value = strdup (ccsGetProfile (context)); - - ccsStringRef (defaultProfile); - ccsStringRef (currentProfile); - - stringList = ccsStringListAppend (stringList, defaultProfile); - stringList = ccsStringListAppend (stringList, currentProfile); - - for (std::vector ::iterator it = mProfiles.begin (); - it != mProfiles.end (); - ++it) - { - if (*it == defaultProfile->value || - *it == currentProfile->value) - continue; - - CCSString *string = reinterpret_cast (calloc (1, sizeof (CCSString))); - - string->value = strdup ((*it).c_str ()); - ccsStringRef (string); - - stringList = ccsStringListAppend (stringList, string); - } - - EXPECT_CALL (*mBackendGMock, getExistingProfiles (context)).WillOnce (Return (stringList)); - } - - void SetDeleteProfileExpectation (const std::string &profileForDeletion, - CCSContext *context, - CCSContextGMock *gmockContext) - { - EXPECT_CALL (*mBackendGMock, deleteProfile (context, - Eq (profileForDeletion))); - } - - void SetReadInitExpectation (CCSContext *context, - CCSContextGMock *gmockContext) - { - EXPECT_CALL (*mBackendGMock, readInit (context)).WillOnce (Return (TRUE)); - } - - void SetReadDoneExpectation (CCSContext *context, - CCSContextGMock *gmockContext) - { - EXPECT_CALL (*mBackendGMock, readDone (context)); - } - - void SetWriteInitExpectation (CCSContext *context, - CCSContextGMock *gmockContext) - { - EXPECT_CALL (*mBackendGMock, writeInit (context)).WillOnce (Return (TRUE)); - } - - void SetWriteDoneExpectation (CCSContext *context, - CCSContextGMock *gmockContext) - { - EXPECT_CALL (*mBackendGMock, writeDone (context)); - } - - void PreWrite (CCSContextGMock *gmockContext, - CCSPluginGMock *gmockPlugin, - CCSSettingGMock *gmockSetting, - CCSSettingType type) - { - EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); - EXPECT_CALL (*gmockPlugin, getName ()); - EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getParent ()); - - if (type == TypeList) - { - EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); - EXPECT_CALL (*gmockSetting, getDefaultValue ()).Times (AtLeast (1)); - } - else - { - EXPECT_CALL (*gmockSetting, getType ()); - } - } - - void PostWrite (CCSContextGMock *gmockContext, - CCSPluginGMock *gmockPlugin, - CCSSettingGMock *gmockSetting, - CCSSettingType type) - { - } - - void WriteBoolAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteIntegerAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteFloatAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteMatchAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteStringAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteColorAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteKeyAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteButtonAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteEdgeAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteBellAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void WriteListAtKey (const std::string &plugin, - const std::string &key, - const VariantTypes &value) - { - mValues[keynameFromPluginKey (plugin, key)] = value; - } - - void PreRead (CCSContextGMock *gmockContext, - CCSPluginGMock *gmockPlugin, - CCSSettingGMock *gmockSetting, - CCSSettingType type) - { - EXPECT_CALL (*mBackendGMock, readSetting (_, _)); - EXPECT_CALL (*gmockPlugin, getName ()); - EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getParent ()); - - if (type == TypeList) - { - EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); - EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); - } - else - { - EXPECT_CALL (*gmockSetting, getType ()); - } - } - - void PostRead (CCSContextGMock *gmockContext, - CCSPluginGMock *gmockPlugin, - CCSSettingGMock *gmockSetting, - CCSSettingType type) - { - } - - virtual Bool ReadBoolAtKey (const std::string &plugin, - const std::string &key) - { - return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); - } - - virtual int ReadIntegerAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual float ReadFloatAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual const char * ReadStringAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual CCSSettingColorValue ReadColorAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual unsigned int ReadEdgeAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual const char * ReadMatchAtKey (const std::string &plugin, - const std::string &key) - { - return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); - } - - virtual Bool ReadBellAtKey (const std::string &plugin, - const std::string &key) - { - return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); - } - - virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, - const std::string &key, - CCSSetting *setting) - { - CCSListWrapper::Ptr lw (ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); - - return ccsCopyList (*lw, lw->setting ().get ()); - } - - void PreUpdate (CCSContextGMock *gmockContext, - CCSPluginGMock *gmockPlugin, - CCSSettingGMock *gmockSetting, - CCSSettingType type) - { - EXPECT_CALL (*mBackendGMock, updateSetting (_, _, _)); - EXPECT_CALL (*gmockPlugin, getName ()); - EXPECT_CALL (*gmockSetting, getName ()); - EXPECT_CALL (*gmockSetting, getParent ()); - - if (type == TypeList) - { - EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); - EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); - } - else - { - EXPECT_CALL (*gmockSetting, getType ()); - } - } - - void PostUpdate (CCSContextGMock *gmockContext, - CCSPluginGMock *gmockPlugin, - CCSSettingGMock *gmockSetting, - CCSSettingType type) - { - } - - bool UpdateSettingAtKey (const std::string &plugin, - const std::string &setting) - { - CCSPlugin *cplugin = ccsFindPlugin (mContext, plugin.c_str ()); - - if (!cplugin) - return false; - - CCSSetting *csetting = ccsFindSetting (cplugin, setting.c_str ()); - - if (!csetting) - return false; - - ccsBackendUpdateSetting (mBackend, mContext, cplugin, csetting); - return true; - } - - protected: - - bool DeleteProfile (const std::string &profileToDelete) - { - std::vector ::iterator it = std::find (mProfiles.begin (), - mProfiles.end (), - profileToDelete); - - if (it != mProfiles.end ()) - { - mProfiles.erase (it); - return true; - } - else - { - return false; - } - - } - - void ReadValueIntoSetting (CCSSetting *setting) - { - std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); - std::string key (ccsSettingGetName (setting)); - - switch (ccsSettingGetType (setting)) - { - case TypeBool: - - ccsSetBool (setting, ReadBoolAtKey (plugin, key), FALSE); - break; - - case TypeInt: - - ccsSetInt (setting, ReadIntegerAtKey (plugin, key), FALSE); - break; - - case TypeFloat: - - ccsSetFloat (setting, ReadFloatAtKey (plugin, key), FALSE); - break; - - case TypeString: - - ccsSetString (setting, ReadStringAtKey (plugin, key), FALSE); - break; - - case TypeMatch: - - ccsSetMatch (setting, ReadMatchAtKey (plugin, key), FALSE); - break; - - case TypeColor: - - ccsSetColor (setting, ReadColorAtKey (plugin, key), FALSE); - break; - - case TypeKey: - - ccsSetKey (setting, ReadKeyAtKey (plugin, key), FALSE); - break; - - case TypeButton: - - ccsSetButton (setting, ReadButtonAtKey (plugin, key), FALSE); - break; - - case TypeEdge: - - ccsSetEdge (setting, ReadEdgeAtKey (plugin, key), FALSE); - break; - - case TypeBell: - - ccsSetBell (setting, ReadBellAtKey (plugin, key), FALSE); - break; - - case TypeList: - ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, setting), - true, - ccsSettingGetInfo (setting)->forList.listType, - boost::shared_ptr (), - boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))), FALSE); - break; - - default: - - throw std::exception (); - } - } - - void WriteValueToMap (CCSSetting *setting) - { - std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); - std::string key (ccsSettingGetName (setting)); - - Bool vBool; - int vInt; - float vFloat; - char *vString; - CCSSettingColorValue vColor; - CCSSettingKeyValue vKey; - CCSSettingButtonValue vButton; - unsigned int vEdge; - CCSSettingValueList vList; - - switch (ccsSettingGetType (setting)) - { - case TypeBool: - - ccsGetBool (setting, &vBool); - WriteBoolAtKey (plugin, key, VariantTypes (vBool ? true : false)); - break; - - case TypeInt: - - ccsGetInt (setting, &vInt); - WriteIntegerAtKey (plugin, key, VariantTypes (vInt)); - break; - - case TypeFloat: - - ccsGetFloat (setting, &vFloat); - WriteFloatAtKey (plugin, key, VariantTypes (vFloat)); - break; - - case TypeString: - - ccsGetString (setting, &vString); - WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); - break; - - case TypeMatch: - - ccsGetMatch (setting, &vString); - WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); - break; - - case TypeColor: - - ccsGetColor (setting, &vColor); - WriteColorAtKey (plugin, key, VariantTypes (vColor)); - break; - - case TypeKey: - - ccsGetKey (setting, &vKey); - WriteKeyAtKey (plugin, key, VariantTypes (vKey)); - break; - - case TypeButton: - - ccsGetButton (setting, &vButton); - WriteButtonAtKey (plugin, key, VariantTypes (vButton)); - break; - - case TypeEdge: - - ccsGetEdge (setting, &vEdge); - WriteEdgeAtKey (plugin, key, VariantTypes (vEdge)); - break; - - case TypeBell: - - ccsGetBell (setting, &vBool); - WriteBellAtKey (plugin, key, VariantTypes (vBool ? true : false)); - break; - - case TypeList: - { - CCSSettingValueList listCopy = NULL; - - ccsGetList (setting, &vList); - listCopy = ccsCopyList (vList, setting); - - WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, - ccsSettingGetInfo (setting)->forList.listType, - boost::shared_ptr (), - boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))))); - break; - } - default: - - throw std::exception (); - } - } - - private: - - CCSBackend *mBackend; - CCSBackendGMock *mBackendGMock; - CCSContext *mContext; - std::map mValues; - std::vector mProfiles; -}; - -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWrite, - compizconfig::test::GenerateTestingParametersForBackendInterface ()); - -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInfo, - compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); - -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInitFiniFuncs, - compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); - -INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestProfileHandling, - compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); -- GitLab From f416e1c92bbe42d2985e1b5bb25d4401c3b453ec Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Wed, 8 Aug 2012 01:01:42 +0800 Subject: [PATCH 346/562] Added mock backend to test the test --- .../libcompizconfig/tests/CMakeLists.txt | 18 + ...nfig_test_ccs_mock_backend_conformance.cpp | 643 ++++++++++++++++++ 2 files changed, 661 insertions(+) create mode 100644 compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index fc05d5287..ac4b229b8 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,9 +1,11 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_SOURCE_DIR}/tests/shared) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) include_directories (${CMAKE_SOURCE_DIR}/compizconfig/tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../mocks/libcompizconfig) +link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../tests/) add_executable (compizconfig_test_ccs_object ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_object.cpp) @@ -20,6 +22,9 @@ add_executable (compizconfig_test_ccs_setting add_executable (compizconfig_test_ccs_backend ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) +add_executable (compizconfig_test_ccs_mock_backend_conformance + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp) + if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES ${LIBCOMPIZCONFIG_LIBRARIES} @@ -68,6 +73,18 @@ target_link_libraries (compizconfig_test_ccs_backend compizconfig_ccs_setting_mock compizconfig_ccs_backend_mock) +target_link_libraries (compizconfig_test_ccs_mock_backend_conformance + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock + compizconfig_ccs_backend_mock) + target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} @@ -83,3 +100,4 @@ compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig) compiz_discover_tests (compizconfig_test_ccs_context COVERAGE compizconfig_ccs_context_mock) compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock) compiz_discover_tests (compizconfig_test_ccs_setting COVERAGE compizconfig_ccs_setting_mock) +compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance COVERAGE compizconfig_ccs_backend_mock) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp new file mode 100644 index 000000000..809f4e766 --- /dev/null +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -0,0 +1,643 @@ +#include +#include + +#include + +#include +#include + +#include "compizconfig_ccs_backend_mock.h" + +using ::testing::_; +using ::testing::Return; +using ::testing::Invoke; +using ::testing::WithArgs; +using ::testing::Combine; +using ::testing::ValuesIn; +using ::testing::Values; +using ::testing::AtLeast; + +namespace +{ +std::string keynameFromPluginKey (const std::string &plugin, + const std::string &key) +{ + return plugin + "/" + key; +} +} + +template +class ValueForKeyRetreival +{ + public: + + T GetValueForKey (const std::string &key, + const std::map &map) + { + std::map ::const_iterator it = map.find (key); + + if (it != map.end ()) + return boost::get (it->second); + else + throw std::exception (); + } +}; + +namespace +{ + void doNothingWithCCSSetting (CCSSetting *) {}; + + const CCSBackendInfo mockBackendInfo = + { + "mock", + "Mock Backend", + "Mock Backend for libccs", + TRUE, + TRUE + }; +} + +class MockCCSBackendConceptTestEnvironment : + public CCSBackendConceptTestEnvironmentInterface +{ + public: + + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) + { + mContext = context; + mBackend = ccsMockBackendNew (); + mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); + + ON_CALL (*mBackendGMock, readSetting (_, _)) + .WillByDefault ( + WithArgs<1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + + ON_CALL (*mBackendGMock, updateSetting (_, _, _)) + .WillByDefault ( + WithArgs<2> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + + ON_CALL (*mBackendGMock, writeSetting (_, _)) + .WillByDefault ( + WithArgs<1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::WriteValueToMap))); + + ON_CALL (*mBackendGMock, deleteProfile (_, _)) + .WillByDefault ( + WithArgs <1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::DeleteProfile))); + + return mBackend; + } + + const CCSBackendInfo * GetInfo () + { + EXPECT_CALL (*mBackendGMock, getInfo ()).WillOnce (Return (&mockBackendInfo)); + + return &mockBackendInfo; + } + + void TearDown (CCSBackend *backend) + { + ccsFreeMockBackend (backend); + } + + void AddProfile (const std::string &profile) + { + mProfiles.push_back (profile); + } + + void SetGetExistingProfilesExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + CCSStringList stringList = NULL; + + CCSString *defaultProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + CCSString *currentProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + + EXPECT_CALL (*gmockContext, getProfile ()); + + defaultProfile->value = strdup ("Default"); + currentProfile->value = strdup (ccsGetProfile (context)); + + ccsStringRef (defaultProfile); + ccsStringRef (currentProfile); + + stringList = ccsStringListAppend (stringList, defaultProfile); + stringList = ccsStringListAppend (stringList, currentProfile); + + for (std::vector ::iterator it = mProfiles.begin (); + it != mProfiles.end (); + ++it) + { + if (*it == defaultProfile->value || + *it == currentProfile->value) + continue; + + CCSString *string = reinterpret_cast (calloc (1, sizeof (CCSString))); + + string->value = strdup ((*it).c_str ()); + ccsStringRef (string); + + stringList = ccsStringListAppend (stringList, string); + } + + EXPECT_CALL (*mBackendGMock, getExistingProfiles (context)).WillOnce (Return (stringList)); + } + + void SetDeleteProfileExpectation (const std::string &profileForDeletion, + CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, deleteProfile (context, + Eq (profileForDeletion))); + } + + void SetReadInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, readInit (context)).WillOnce (Return (TRUE)); + } + + void SetReadDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, readDone (context)); + } + + void SetWriteInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, writeInit (context)).WillOnce (Return (TRUE)); + } + + void SetWriteDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, writeDone (context)); + } + + void PreWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } + } + + void PostWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + + void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteListAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void PreRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } + } + + void PostRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + + virtual Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) + { + return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + } + + virtual int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual float ReadFloatAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) + { + return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + } + + virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key, + CCSSetting *setting) + { + CCSListWrapper::Ptr lw (ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + + return ccsCopyList (*lw, lw->setting ().get ()); + } + + void PreUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, updateSetting (_, _, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } + } + + void PostUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + + bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) + { + CCSPlugin *cplugin = ccsFindPlugin (mContext, plugin.c_str ()); + + if (!cplugin) + return false; + + CCSSetting *csetting = ccsFindSetting (cplugin, setting.c_str ()); + + if (!csetting) + return false; + + ccsBackendUpdateSetting (mBackend, mContext, cplugin, csetting); + return true; + } + + protected: + + bool DeleteProfile (const std::string &profileToDelete) + { + std::vector ::iterator it = std::find (mProfiles.begin (), + mProfiles.end (), + profileToDelete); + + if (it != mProfiles.end ()) + { + mProfiles.erase (it); + return true; + } + else + { + return false; + } + + } + + void ReadValueIntoSetting (CCSSetting *setting) + { + std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); + std::string key (ccsSettingGetName (setting)); + + switch (ccsSettingGetType (setting)) + { + case TypeBool: + + ccsSetBool (setting, ReadBoolAtKey (plugin, key), FALSE); + break; + + case TypeInt: + + ccsSetInt (setting, ReadIntegerAtKey (plugin, key), FALSE); + break; + + case TypeFloat: + + ccsSetFloat (setting, ReadFloatAtKey (plugin, key), FALSE); + break; + + case TypeString: + + ccsSetString (setting, ReadStringAtKey (plugin, key), FALSE); + break; + + case TypeMatch: + + ccsSetMatch (setting, ReadMatchAtKey (plugin, key), FALSE); + break; + + case TypeColor: + + ccsSetColor (setting, ReadColorAtKey (plugin, key), FALSE); + break; + + case TypeKey: + + ccsSetKey (setting, ReadKeyAtKey (plugin, key), FALSE); + break; + + case TypeButton: + + ccsSetButton (setting, ReadButtonAtKey (plugin, key), FALSE); + break; + + case TypeEdge: + + ccsSetEdge (setting, ReadEdgeAtKey (plugin, key), FALSE); + break; + + case TypeBell: + + ccsSetBell (setting, ReadBellAtKey (plugin, key), FALSE); + break; + + case TypeList: + ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, setting), + true, + ccsSettingGetInfo (setting)->forList.listType, + boost::shared_ptr (), + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))), FALSE); + break; + + default: + + throw std::exception (); + } + } + + void WriteValueToMap (CCSSetting *setting) + { + std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); + std::string key (ccsSettingGetName (setting)); + + Bool vBool; + int vInt; + float vFloat; + char *vString; + CCSSettingColorValue vColor; + CCSSettingKeyValue vKey; + CCSSettingButtonValue vButton; + unsigned int vEdge; + CCSSettingValueList vList; + + switch (ccsSettingGetType (setting)) + { + case TypeBool: + + ccsGetBool (setting, &vBool); + WriteBoolAtKey (plugin, key, VariantTypes (vBool ? true : false)); + break; + + case TypeInt: + + ccsGetInt (setting, &vInt); + WriteIntegerAtKey (plugin, key, VariantTypes (vInt)); + break; + + case TypeFloat: + + ccsGetFloat (setting, &vFloat); + WriteFloatAtKey (plugin, key, VariantTypes (vFloat)); + break; + + case TypeString: + + ccsGetString (setting, &vString); + WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); + break; + + case TypeMatch: + + ccsGetMatch (setting, &vString); + WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); + break; + + case TypeColor: + + ccsGetColor (setting, &vColor); + WriteColorAtKey (plugin, key, VariantTypes (vColor)); + break; + + case TypeKey: + + ccsGetKey (setting, &vKey); + WriteKeyAtKey (plugin, key, VariantTypes (vKey)); + break; + + case TypeButton: + + ccsGetButton (setting, &vButton); + WriteButtonAtKey (plugin, key, VariantTypes (vButton)); + break; + + case TypeEdge: + + ccsGetEdge (setting, &vEdge); + WriteEdgeAtKey (plugin, key, VariantTypes (vEdge)); + break; + + case TypeBell: + + ccsGetBell (setting, &vBool); + WriteBellAtKey (plugin, key, VariantTypes (vBool ? true : false)); + break; + + case TypeList: + { + CCSSettingValueList listCopy = NULL; + + ccsGetList (setting, &vList); + listCopy = ccsCopyList (vList, setting); + + WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, + ccsSettingGetInfo (setting)->forList.listType, + boost::shared_ptr (), + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))))); + break; + } + default: + + throw std::exception (); + } + } + + private: + + CCSBackend *mBackend; + CCSBackendGMock *mBackendGMock; + CCSContext *mContext; + std::map mValues; + std::vector mProfiles; +}; + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWrite, + compizconfig::test::GenerateTestingParametersForBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInfo, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInitFiniFuncs, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestProfileHandling, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); -- GitLab From e55217483abb8621cd2988fb04651278bf2eaf2f Mon Sep 17 00:00:00 2001 From: Daniel d'Andrada Date: Wed, 8 Aug 2012 13:34:37 -0300 Subject: [PATCH 347/562] Make ResizeScreen:handleMotionEvent less unwieldy By splitting it into several helper functions. --- plugins/resize/src/resize.cpp | 867 ++++++++++++++++++---------------- plugins/resize/src/resize.h | 13 + 2 files changed, 468 insertions(+), 412 deletions(-) diff --git a/plugins/resize/src/resize.cpp b/plugins/resize/src/resize.cpp index f72959f29..23261d960 100644 --- a/plugins/resize/src/resize.cpp +++ b/plugins/resize/src/resize.cpp @@ -742,134 +742,17 @@ ResizeScreen::handleMotionEvent (int xRoot, int yRoot) BoxRec box; int wi, he, cwi, che; /* size of window contents (c prefix for constrained)*/ int wX, wY, wWidth, wHeight; /* rect. for window contents+borders */ - int workAreaSnapDistance = 15; wi = savedGeometry.width; he = savedGeometry.height; if (!mask) { - int xDist, yDist; - int minPointerOffsetX, minPointerOffsetY; - - CompWindow::Geometry server = w->serverGeometry (); - - xDist = xRoot - (server.x () + (server.width () / 2)); - yDist = yRoot - (server.y () + (server.height () / 2)); - - /* decision threshold is 10% of window size */ - minPointerOffsetX = MIN (20, server.width () / 10); - minPointerOffsetY = MIN (20, server.height () / 10); - - /* if we reached the threshold in one direction, - make the threshold in the other direction smaller - so there is a chance that this threshold also can - be reached (by diagonal movement) */ - if (abs (xDist) > minPointerOffsetX) - minPointerOffsetY /= 2; - else if (abs (yDist) > minPointerOffsetY) - minPointerOffsetX /= 2; - - if (abs (xDist) > minPointerOffsetX) - { - if (xDist > 0) - mask |= ResizeRightMask; - else - mask |= ResizeLeftMask; - } - - if (abs (yDist) > minPointerOffsetY) - { - if (yDist > 0) - mask |= ResizeDownMask; - else - mask |= ResizeUpMask; - } - - /* if the pointer movement was enough to determine a - direction, warp the pointer to the appropriate edge - and set the right cursor */ - if (mask) - { - Cursor cursor; - CompAction *action; - int pointerAdjustX = 0; - int pointerAdjustY = 0; - - action = &optionGetInitiateKey (); - action->setState (action->state () | - CompAction::StateTermButton); - - if (mask & ResizeRightMask) - pointerAdjustX = server.x () + server.width () + - w->border ().right - xRoot; - else if (mask & ResizeLeftMask) - pointerAdjustX = server.x () - w->border ().left - - xRoot; - - if (mask & ResizeDownMask) - pointerAdjustY = server.y () + server.height () + - w->border ().bottom - yRoot; - else if (mask & ResizeUpMask) - pointerAdjustY = server.y () - w->border ().top - yRoot; - - screen->warpPointer (pointerAdjustX, pointerAdjustY); - - cursor = cursorFromResizeMask (mask); - screen->updateGrab (grabIndex, cursor); - } + setUpMask(xRoot, yRoot); } else { - /* only accumulate pointer movement if a mask is - already set as we don't have a use for the - difference information otherwise */ - - if (centered || optionGetResizeFromCenter ()) - { - pointerDx += (xRoot - lastPointerX) * 2; - pointerDy += (yRoot - lastPointerY) * 2; - } - else - { - pointerDx += xRoot - lastPointerX; - pointerDy += yRoot - lastPointerY; - } - - /* If we hit the edge of the screen while resizing - * the window and the adjacent window edge has not hit - * the edge of the screen, then accumulate pointer motion - * in the opposite direction. (So the apparant x / y - * mixup here is intentional) - */ - - if (isConstrained) - { - if (mask == ResizeLeftMask) - { - if (xRoot == 0 && - geometry.x - w->border ().left > grabWindowWorkArea->left ()) - pointerDx += abs (yRoot - lastPointerY) * -1; - } - else if (mask == ResizeRightMask) - { - if (xRoot == screen->width () -1 && - geometry.x + geometry.width + w->border ().right < grabWindowWorkArea->right ()) - pointerDx += abs (yRoot - lastPointerY); - } - if (mask == ResizeUpMask) - { - if (yRoot == 0 && - geometry.y - w->border ().top > grabWindowWorkArea->top ()) - pointerDy += abs (xRoot - lastPointerX) * -1; - } - else if (mask == ResizeDownMask) - { - if (yRoot == screen->height () -1 && - geometry.y + geometry.height + w->border ().bottom < grabWindowWorkArea->bottom ()) - pointerDx += abs (yRoot - lastPointerY); - } - } + accumulatePointerMotion(xRoot, yRoot); } if (mask & ResizeLeftMask) @@ -906,291 +789,21 @@ ResizeScreen::handleMotionEvent (int xRoot, int yRoot) damageRectangle (&box); } - /* constrain to work area */ if (offWorkAreaConstrained) - { - if (mask & ResizeUpMask) - { - int decorTop = savedGeometry.y + savedGeometry.height - - (che + w->border ().top); - - if (grabWindowWorkArea->y () > decorTop) - che -= grabWindowWorkArea->y () - decorTop; - } - if (mask & ResizeDownMask) - { - int decorBottom = savedGeometry.y + che + w->border ().bottom; - - if (decorBottom > - grabWindowWorkArea->y () + grabWindowWorkArea->height ()) - che -= decorBottom - (grabWindowWorkArea->y () + - grabWindowWorkArea->height ()); - } - if (mask & ResizeLeftMask) - { - int decorLeft = savedGeometry.x + savedGeometry.width - - (cwi + w->border ().left); - - if (grabWindowWorkArea->x () > decorLeft) - cwi -= grabWindowWorkArea->x () - decorLeft; - } - if (mask & ResizeRightMask) - { - int decorRight = savedGeometry.x + cwi + w->border ().right; - - if (decorRight > - grabWindowWorkArea->x () + grabWindowWorkArea->width ()) - cwi -= decorRight - (grabWindowWorkArea->x () + - grabWindowWorkArea->width ()); - } - } + constrainToWorkArea(che, cwi); wi = cwi; he = che; /* compute rect. for window + borders */ - wWidth = wi + w->border ().left + w->border ().right; - wHeight = he + w->border ().top + w->border ().bottom; - - if (centered || optionGetResizeFromCenter ()) - { - if (mask & ResizeLeftMask) - wX = geometry.x + geometry.width - - (wi + w->border ().left); - else - wX = geometry.x - w->border ().left; - - if (mask & ResizeUpMask) - wY = geometry.y + geometry.height - - (he + w->border ().top); - else - wY = geometry.y - w->border ().top; - } - else - { - if (mask & ResizeLeftMask) - wX = savedGeometry.x + savedGeometry.width - - (wi + w->border ().left); - else - wX = savedGeometry.x - w->border ().left; - - if (mask & ResizeUpMask) - wY = savedGeometry.y + savedGeometry.height - - (he + w->border ().top); - else - wY = savedGeometry.y - w->border ().top; - } - - /* Check if resized edge(s) are near output work-area boundaries */ - foreach (CompOutput &output, ::screen->outputDevs ()) - { - const CompRect &workArea = output.workArea (); - - /* if window and work-area intersect in x axis */ - if (wX + wWidth > workArea.x () && - wX < workArea.x2 ()) - { - if (mask & ResizeLeftMask) - { - int dw = workArea.x () - wX; - - if (0 < dw && dw < workAreaSnapDistance) - { - wi -= dw; - wWidth -= dw; - wX += dw; - } - } - else if (mask & ResizeRightMask) - { - int dw = wX + wWidth - workArea.x2 (); - - if (0 < dw && dw < workAreaSnapDistance) - { - wi -= dw; - wWidth -= dw; - } - } - } - - /* if window and work-area intersect in y axis */ - if (wY + wHeight > workArea.y () && - wY < workArea.y2 ()) - { - if (mask & ResizeUpMask) - { - int dh = workArea.y () - wY; + computeWindowPlusBordersRect(wX, wY, wWidth, wHeight, /*out*/ + wi, he); /*in*/ - if (0 < dh && dh < workAreaSnapDistance) - { - he -= dh; - wHeight -= dh; - wY += dh; - } - } - else if (mask & ResizeDownMask) - { - int dh = wY + wHeight - workArea.y2 (); - - if (0 < dh && dh < workAreaSnapDistance) - { - he -= dh; - wHeight -= dh; - } - } - } - } + snapWindowToWorkAreaBoundaries(wi, he, wX, wY, wWidth, wHeight); if (isConstrained) - { - int minHeight = 50; - - /* rect. for a minimal height window + borders - (used for the constraining in X axis) */ - int minimalInputHeight = minHeight + - w->border ().top + w->border ().bottom; - - /* small hot-spot square (on window's corner or edge) that is to be - constrained to the combined output work-area region */ - int x, y; - int width = w->border ().top; /* square size = title bar height */ - int height = width; - bool status; /* whether or not hot-spot is in the region */ - - /* compute x & y for constrained hot-spot rect */ - if (mask & ResizeLeftMask) - x = wX; - else if (mask & ResizeRightMask) - x = wX + wWidth - width; - else - x = MIN (MAX (xRoot, wX), wX + wWidth - width); - - if (mask & ResizeUpMask) - y = wY; - else if (mask & ResizeDownMask) - y = wY + wHeight - height; - else - y = MIN (MAX (yRoot, wY), wY + wHeight - height); - - status = constraintRegion.contains (x, y, width, height); - - /* only constrain movement if previous position was valid */ - if (inRegionStatus) - { - bool xStatus = false; - int yForXResize = y; - int nx = x; - int nw = wi; - int nh = he; - int minWidth = 50; - - if (mask & (ResizeLeftMask | ResizeRightMask)) - { - xStatus = status; - - if (mask & ResizeUpMask) - yForXResize = wY + wHeight - minimalInputHeight; - else if (mask & ResizeDownMask) - yForXResize = wY + minimalInputHeight - height; - else - yForXResize = y; - - if (!constraintRegion.contains (x, yForXResize, - width, height)) - { - if (lastGoodHotSpotY >= 0) - yForXResize = lastGoodHotSpotY; - else - yForXResize = y; - } - } - if (mask & ResizeLeftMask) - { - while ((nw > minWidth) && !xStatus) - { - xStatus = constraintRegion.contains (nx, yForXResize, - width, height); - if (!xStatus) - { - nw--; - nx++; - } - } - if (nw > minWidth) - { - x = nx; - wi = nw; - } - } - else if (mask & ResizeRightMask) - { - while ((nw > minWidth) && !xStatus) - { - xStatus = constraintRegion.contains (nx, yForXResize, - width, height); - if (!xStatus) - { - nw--; - nx--; - } - } - if (nw > minWidth) - { - x = nx; - wi = nw; - } - } - - if (mask & ResizeUpMask) - { - while ((nh > minHeight) && !status) - { - status = constraintRegion.contains (x, y, - width, height); - if (!status) - { - nh--; - y++; - } - } - if (nh > minHeight) - he = nh; - } - else if (mask & ResizeDownMask) - { - while ((nh > minHeight) && !status) - { - status = constraintRegion.contains (x, y, - width, height); - if (!status) - { - nh--; - y--; - } - } - if (nh > minHeight) - he = nh; - } - - if (((mask & (ResizeLeftMask | ResizeRightMask)) && xStatus) || - ((mask & (ResizeUpMask | ResizeDownMask)) && status)) - { - /* hot-spot inside work-area region, store good values */ - lastGoodHotSpotY = y; - lastGoodSize = CompSize (wi, he); - } - else - { - /* failed to find a good hot-spot position, restore size */ - wi = lastGoodSize.width (); - he = lastGoodSize.height (); - } - } - else - { - inRegionStatus = status; - } - } + limitMovementToConstraintRegion(wi, he, /*in/out*/ + xRoot, yRoot, wX, wY, wWidth, wHeight); /*in*/ if (mode != ResizeOptions::ModeNormal) { @@ -1202,23 +815,7 @@ ResizeScreen::handleMotionEvent (int xRoot, int yRoot) damageRectangle (&box); } - if (centered || optionGetResizeFromCenter ()) - { - if ((mask & ResizeLeftMask) || (mask & ResizeRightMask)) - geometry.x -= ((wi - geometry.width) / 2); - if ((mask & ResizeUpMask) || (mask & ResizeDownMask)) - geometry.y -= ((he - geometry.height) / 2); - } - else - { - if (mask & ResizeLeftMask) - geometry.x -= wi - geometry.width; - if (mask & ResizeUpMask) - geometry.y -= he - geometry.height; - } - - geometry.width = wi; - geometry.height = he; + computeGeometry(wi, he); if (mode != ResizeOptions::ModeNormal) { @@ -1741,6 +1338,452 @@ ResizeScreen::optionChanged (CompOption *option, resizeMaskValueToKeyMask (valueMask, mask); } +void +ResizeScreen::snapWindowToWorkAreaBoundaries(int &wi, int &he, + int &wX, int &wY, int &wWidth, int &wHeight) +{ + int workAreaSnapDistance = 15; + + /* Check if resized edge(s) are near output work-area boundaries */ + foreach (CompOutput &output, ::screen->outputDevs ()) + { + const CompRect &workArea = output.workArea (); + + /* if window and work-area intersect in x axis */ + if (wX + wWidth > workArea.x () && + wX < workArea.x2 ()) + { + if (mask & ResizeLeftMask) + { + int dw = workArea.x () - wX; + + if (0 < dw && dw < workAreaSnapDistance) + { + wi -= dw; + wWidth -= dw; + wX += dw; + } + } + else if (mask & ResizeRightMask) + { + int dw = wX + wWidth - workArea.x2 (); + + if (0 < dw && dw < workAreaSnapDistance) + { + wi -= dw; + wWidth -= dw; + } + } + } + + /* if window and work-area intersect in y axis */ + if (wY + wHeight > workArea.y () && + wY < workArea.y2 ()) + { + if (mask & ResizeUpMask) + { + int dh = workArea.y () - wY; + + if (0 < dh && dh < workAreaSnapDistance) + { + he -= dh; + wHeight -= dh; + wY += dh; + } + } + else if (mask & ResizeDownMask) + { + int dh = wY + wHeight - workArea.y2 (); + + if (0 < dh && dh < workAreaSnapDistance) + { + he -= dh; + wHeight -= dh; + } + } + } + } +} + +void +ResizeScreen::setUpMask(int xRoot, int yRoot) +{ + int xDist, yDist; + int minPointerOffsetX, minPointerOffsetY; + + CompWindow::Geometry server = w->serverGeometry (); + + xDist = xRoot - (server.x () + (server.width () / 2)); + yDist = yRoot - (server.y () + (server.height () / 2)); + + /* decision threshold is 10% of window size */ + minPointerOffsetX = MIN (20, server.width () / 10); + minPointerOffsetY = MIN (20, server.height () / 10); + + /* if we reached the threshold in one direction, + make the threshold in the other direction smaller + so there is a chance that this threshold also can + be reached (by diagonal movement) */ + if (abs (xDist) > minPointerOffsetX) + minPointerOffsetY /= 2; + else if (abs (yDist) > minPointerOffsetY) + minPointerOffsetX /= 2; + + if (abs (xDist) > minPointerOffsetX) + { + if (xDist > 0) + mask |= ResizeRightMask; + else + mask |= ResizeLeftMask; + } + + if (abs (yDist) > minPointerOffsetY) + { + if (yDist > 0) + mask |= ResizeDownMask; + else + mask |= ResizeUpMask; + } + + /* if the pointer movement was enough to determine a + direction, warp the pointer to the appropriate edge + and set the right cursor */ + if (mask) + { + Cursor cursor; + CompAction *action; + int pointerAdjustX = 0; + int pointerAdjustY = 0; + + action = &optionGetInitiateKey (); + action->setState (action->state () | + CompAction::StateTermButton); + + if (mask & ResizeRightMask) + pointerAdjustX = server.x () + server.width () + + w->border ().right - xRoot; + else if (mask & ResizeLeftMask) + pointerAdjustX = server.x () - w->border ().left - + xRoot; + + if (mask & ResizeDownMask) + pointerAdjustY = server.y () + server.height () + + w->border ().bottom - yRoot; + else if (mask & ResizeUpMask) + pointerAdjustY = server.y () - w->border ().top - yRoot; + + screen->warpPointer (pointerAdjustX, pointerAdjustY); + + cursor = cursorFromResizeMask (mask); + screen->updateGrab (grabIndex, cursor); + } +} + +void +ResizeScreen::accumulatePointerMotion(int xRoot, int yRoot) +{ + /* only accumulate pointer movement if a mask is + already set as we don't have a use for the + difference information otherwise */ + + if (centered || optionGetResizeFromCenter ()) + { + pointerDx += (xRoot - lastPointerX) * 2; + pointerDy += (yRoot - lastPointerY) * 2; + } + else + { + pointerDx += xRoot - lastPointerX; + pointerDy += yRoot - lastPointerY; + } + + /* If we hit the edge of the screen while resizing + * the window and the adjacent window edge has not hit + * the edge of the screen, then accumulate pointer motion + * in the opposite direction. (So the apparant x / y + * mixup here is intentional) + */ + + if (isConstrained) + { + if (mask == ResizeLeftMask) + { + if (xRoot == 0 && + geometry.x - w->border ().left > grabWindowWorkArea->left ()) + pointerDx += abs (yRoot - lastPointerY) * -1; + } + else if (mask == ResizeRightMask) + { + if (xRoot == screen->width () -1 && + geometry.x + geometry.width + w->border ().right < grabWindowWorkArea->right ()) + pointerDx += abs (yRoot - lastPointerY); + } + if (mask == ResizeUpMask) + { + if (yRoot == 0 && + geometry.y - w->border ().top > grabWindowWorkArea->top ()) + pointerDy += abs (xRoot - lastPointerX) * -1; + } + else if (mask == ResizeDownMask) + { + if (yRoot == screen->height () -1 && + geometry.y + geometry.height + w->border ().bottom < grabWindowWorkArea->bottom ()) + pointerDx += abs (yRoot - lastPointerY); + } + } +} + +void +ResizeScreen::constrainToWorkArea(int &che, int &cwi) +{ + if (mask & ResizeUpMask) + { + int decorTop = savedGeometry.y + savedGeometry.height - + (che + w->border ().top); + + if (grabWindowWorkArea->y () > decorTop) + che -= grabWindowWorkArea->y () - decorTop; + } + if (mask & ResizeDownMask) + { + int decorBottom = savedGeometry.y + che + w->border ().bottom; + + if (decorBottom > + grabWindowWorkArea->y () + grabWindowWorkArea->height ()) + che -= decorBottom - (grabWindowWorkArea->y () + + grabWindowWorkArea->height ()); + } + if (mask & ResizeLeftMask) + { + int decorLeft = savedGeometry.x + savedGeometry.width - + (cwi + w->border ().left); + + if (grabWindowWorkArea->x () > decorLeft) + cwi -= grabWindowWorkArea->x () - decorLeft; + } + if (mask & ResizeRightMask) + { + int decorRight = savedGeometry.x + cwi + w->border ().right; + + if (decorRight > + grabWindowWorkArea->x () + grabWindowWorkArea->width ()) + cwi -= decorRight - (grabWindowWorkArea->x () + + grabWindowWorkArea->width ()); + } +} + +void +ResizeScreen::limitMovementToConstraintRegion(int &wi, int &he, + int xRoot, int yRoot, int wX, int wY, int wWidth, int wHeight) +{ + int minHeight = 50; + + /* rect. for a minimal height window + borders + (used for the constraining in X axis) */ + int minimalInputHeight = minHeight + + w->border ().top + w->border ().bottom; + + /* small hot-spot square (on window's corner or edge) that is to be + constrained to the combined output work-area region */ + int x, y; + int width = w->border ().top; /* square size = title bar height */ + int height = width; + bool status; /* whether or not hot-spot is in the region */ + + /* compute x & y for constrained hot-spot rect */ + if (mask & ResizeLeftMask) + x = wX; + else if (mask & ResizeRightMask) + x = wX + wWidth - width; + else + x = MIN (MAX (xRoot, wX), wX + wWidth - width); + + if (mask & ResizeUpMask) + y = wY; + else if (mask & ResizeDownMask) + y = wY + wHeight - height; + else + y = MIN (MAX (yRoot, wY), wY + wHeight - height); + + status = constraintRegion.contains (x, y, width, height); + + /* only constrain movement if previous position was valid */ + if (inRegionStatus) + { + bool xStatus = false; + int yForXResize = y; + int nx = x; + int nw = wi; + int nh = he; + int minWidth = 50; + + if (mask & (ResizeLeftMask | ResizeRightMask)) + { + xStatus = status; + + if (mask & ResizeUpMask) + yForXResize = wY + wHeight - minimalInputHeight; + else if (mask & ResizeDownMask) + yForXResize = wY + minimalInputHeight - height; + else + yForXResize = y; + + if (!constraintRegion.contains (x, yForXResize, + width, height)) + { + if (lastGoodHotSpotY >= 0) + yForXResize = lastGoodHotSpotY; + else + yForXResize = y; + } + } + if (mask & ResizeLeftMask) + { + while ((nw > minWidth) && !xStatus) + { + xStatus = constraintRegion.contains (nx, yForXResize, + width, height); + if (!xStatus) + { + nw--; + nx++; + } + } + if (nw > minWidth) + { + x = nx; + wi = nw; + } + } + else if (mask & ResizeRightMask) + { + while ((nw > minWidth) && !xStatus) + { + xStatus = constraintRegion.contains (nx, yForXResize, + width, height); + if (!xStatus) + { + nw--; + nx--; + } + } + if (nw > minWidth) + { + x = nx; + wi = nw; + } + } + + if (mask & ResizeUpMask) + { + while ((nh > minHeight) && !status) + { + status = constraintRegion.contains (x, y, + width, height); + if (!status) + { + nh--; + y++; + } + } + if (nh > minHeight) + he = nh; + } + else if (mask & ResizeDownMask) + { + while ((nh > minHeight) && !status) + { + status = constraintRegion.contains (x, y, + width, height); + if (!status) + { + nh--; + y--; + } + } + if (nh > minHeight) + he = nh; + } + + if (((mask & (ResizeLeftMask | ResizeRightMask)) && xStatus) || + ((mask & (ResizeUpMask | ResizeDownMask)) && status)) + { + /* hot-spot inside work-area region, store good values */ + lastGoodHotSpotY = y; + lastGoodSize = CompSize (wi, he); + } + else + { + /* failed to find a good hot-spot position, restore size */ + wi = lastGoodSize.width (); + he = lastGoodSize.height (); + } + } + else + { + inRegionStatus = status; + } +} + +void +ResizeScreen::computeWindowPlusBordersRect(int &wX, int &wY, int &wWidth, int &wHeight, + int wi, int he) +{ + wWidth = wi + w->border ().left + w->border ().right; + wHeight = he + w->border ().top + w->border ().bottom; + + if (centered || optionGetResizeFromCenter ()) + { + if (mask & ResizeLeftMask) + wX = geometry.x + geometry.width - + (wi + w->border ().left); + else + wX = geometry.x - w->border ().left; + + if (mask & ResizeUpMask) + wY = geometry.y + geometry.height - + (he + w->border ().top); + else + wY = geometry.y - w->border ().top; + } + else + { + if (mask & ResizeLeftMask) + wX = savedGeometry.x + savedGeometry.width - + (wi + w->border ().left); + else + wX = savedGeometry.x - w->border ().left; + + if (mask & ResizeUpMask) + wY = savedGeometry.y + savedGeometry.height - + (he + w->border ().top); + else + wY = savedGeometry.y - w->border ().top; + } +} + +void +ResizeScreen::computeGeometry(int wi, int he) +{ + if (centered || optionGetResizeFromCenter ()) + { + if ((mask & ResizeLeftMask) || (mask & ResizeRightMask)) + geometry.x -= ((wi - geometry.width) / 2); + if ((mask & ResizeUpMask) || (mask & ResizeDownMask)) + geometry.y -= ((he - geometry.height) / 2); + } + else + { + if (mask & ResizeLeftMask) + geometry.x -= wi - geometry.width; + if (mask & ResizeUpMask) + geometry.y -= he - geometry.height; + } + + geometry.width = wi; + geometry.height = he; +} + ResizeScreen::ResizeScreen (CompScreen *s) : PluginClassHandler (s), gScreen (GLScreen::get (s)), diff --git a/plugins/resize/src/resize.h b/plugins/resize/src/resize.h index 1f0a47739..60a619bb2 100644 --- a/plugins/resize/src/resize.h +++ b/plugins/resize/src/resize.h @@ -150,6 +150,19 @@ class ResizeScreen : bool offWorkAreaConstrained; boost::shared_ptr grabWindowWorkArea; + +private: + /* Helper functions for handleMotionEvent() */ + void snapWindowToWorkAreaBoundaries(int &wi, int &he, + int &wX, int &wY, int &wWidth, int &wHeight); + void setUpMask(int xRoot, int yRoot); + void accumulatePointerMotion(int xRoot, int yRoot); + void constrainToWorkArea(int &che, int &cwi); + void limitMovementToConstraintRegion(int &wi, int &he, + int xRoot, int yRoot, int wX, int wY, int wWidth, int wHeight); + void computeWindowPlusBordersRect(int &wX, int &wY, int &wWidth, int &wHeight, + int wi, int he); + void computeGeometry(int wi, int he); }; class ResizeWindow : -- GitLab From 7be8198e62ed09deb6c78496a09eda06abf5fcb9 Mon Sep 17 00:00:00 2001 From: Daniel d'Andrada Date: Wed, 8 Aug 2012 17:51:01 -0300 Subject: [PATCH 348/562] maximize vertically if pointer reaches top or bottom edges --- plugins/resize/src/resize.cpp | 110 ++++++++++++++++++++++++++++++---- plugins/resize/src/resize.h | 6 ++ 2 files changed, 105 insertions(+), 11 deletions(-) diff --git a/plugins/resize/src/resize.cpp b/plugins/resize/src/resize.cpp index 23261d960..f37f683f4 100644 --- a/plugins/resize/src/resize.cpp +++ b/plugins/resize/src/resize.cpp @@ -527,6 +527,8 @@ resizeInitiate (CompAction *action, rs->constraintRegion += output.workArea (); } } + + rs->maximized_vertically = false; } return false; @@ -582,6 +584,17 @@ resizeTerminate (CompAction *action, xwc.width = rs->savedGeometry.width; xwc.height = rs->savedGeometry.height; + mask = CWX | CWY | CWWidth | CWHeight; + } + else if (rs->maximized_vertically) + { + w->maximize(CompWindowStateMaximizedVertMask); + + xwc.x = rs->geometryWithoutVertMax.x; + xwc.y = rs->geometryWithoutVertMax.y; + xwc.width = rs->geometryWithoutVertMax.width; + xwc.height = rs->geometryWithoutVertMax.height; + mask = CWX | CWY | CWWidth | CWHeight; } } @@ -607,12 +620,22 @@ resizeTerminate (CompAction *action, } else { - xwc.x = geometry.x; - xwc.y = geometry.y; - xwc.width = geometry.width; - xwc.height = geometry.height; + if (rs->maximized_vertically) + { + w->maximize(CompWindowStateMaximizedVertMask); + xwc.x = geometry.x; + xwc.width = geometry.width; + mask = CWX | CWWidth ; + } + else + { + xwc.x = geometry.x; + xwc.y = geometry.y; + xwc.width = geometry.width; + xwc.height = geometry.height; + mask = CWX | CWY | CWWidth | CWHeight; + } - mask = CWX | CWY | CWWidth | CWHeight; } if (rs->mode != ResizeOptions::ModeNormal) @@ -815,6 +838,8 @@ ResizeScreen::handleMotionEvent (int xRoot, int yRoot) damageRectangle (&box); } + enableOrDisableVerticalMaximization(yRoot); + computeGeometry(wi, he); if (mode != ResizeOptions::ModeNormal) @@ -1762,26 +1787,88 @@ ResizeScreen::computeWindowPlusBordersRect(int &wX, int &wY, int &wWidth, int &w } } +void +ResizeScreen::enableOrDisableVerticalMaximization(int yRoot) +{ + /* maximum distance between the pointer and a work area edge (top or bottom) + for a vertical maximization */ + int max_edge_distance = 5; + + if (centered || optionGetResizeFromCenter ()) + { + if (maximized_vertically) + { + geometry = geometryWithoutVertMax; + maximized_vertically = false; + } + } + else if (mask & ResizeUpMask) + { + if (yRoot - grabWindowWorkArea->top() <= max_edge_distance + && !maximized_vertically) + { + maximized_vertically = true; + geometryWithoutVertMax = geometry; + } + else if (yRoot - grabWindowWorkArea->top() > max_edge_distance + && maximized_vertically) + { + geometry = geometryWithoutVertMax; + maximized_vertically = false; + } + } + else if (mask & ResizeDownMask) + { + if (grabWindowWorkArea->bottom() - yRoot <= 5 + && !maximized_vertically) + { + maximized_vertically = true; + geometryWithoutVertMax = geometry; + } + else if (grabWindowWorkArea->bottom() - yRoot > 5 + && maximized_vertically) + { + geometry = geometryWithoutVertMax; + maximized_vertically = false; + } + } +} + void ResizeScreen::computeGeometry(int wi, int he) { + XRectangle *regular_geometry; + if (maximized_vertically) + regular_geometry = &geometryWithoutVertMax; + else + regular_geometry = &geometry; + if (centered || optionGetResizeFromCenter ()) { if ((mask & ResizeLeftMask) || (mask & ResizeRightMask)) - geometry.x -= ((wi - geometry.width) / 2); + regular_geometry->x -= ((wi - regular_geometry->width) / 2); if ((mask & ResizeUpMask) || (mask & ResizeDownMask)) - geometry.y -= ((he - geometry.height) / 2); + regular_geometry->y -= ((he - regular_geometry->height) / 2); } else { if (mask & ResizeLeftMask) - geometry.x -= wi - geometry.width; + regular_geometry->x -= wi - regular_geometry->width; if (mask & ResizeUpMask) - geometry.y -= he - geometry.height; + regular_geometry->y -= he - regular_geometry->height; } - geometry.width = wi; - geometry.height = he; + regular_geometry->width = wi; + regular_geometry->height = he; + + if (maximized_vertically) + { + geometry.x = geometryWithoutVertMax.x; + geometry.width = geometryWithoutVertMax.width; + geometry.y = grabWindowWorkArea->y() + w->border().top; + geometry.height = grabWindowWorkArea->height() - w->border().top + - w->border().bottom; + } } ResizeScreen::ResizeScreen (CompScreen *s) : @@ -1789,6 +1876,7 @@ ResizeScreen::ResizeScreen (CompScreen *s) : gScreen (GLScreen::get (s)), cScreen (CompositeScreen::get (s)), w (NULL), + maximized_vertically(false), outlineMask (0), rectangleMask (0), stretchMask (0), diff --git a/plugins/resize/src/resize.h b/plugins/resize/src/resize.h index 60a619bb2..2a7ebd943 100644 --- a/plugins/resize/src/resize.h +++ b/plugins/resize/src/resize.h @@ -118,6 +118,11 @@ class ResizeScreen : XRectangle savedGeometry; XRectangle geometry; + /* geometry without the vertical maximization. + Its value is undefined when maximized_vertically == false */ + XRectangle geometryWithoutVertMax; + bool maximized_vertically; + int outlineMask; int rectangleMask; int stretchMask; @@ -162,6 +167,7 @@ private: int xRoot, int yRoot, int wX, int wY, int wWidth, int wHeight); void computeWindowPlusBordersRect(int &wX, int &wY, int &wWidth, int &wHeight, int wi, int he); + void enableOrDisableVerticalMaximization(int yRoot); void computeGeometry(int wi, int he); }; -- GitLab From f7d2ca809125fac39adecac582ad7c5699d79cff Mon Sep 17 00:00:00 2001 From: Daniel d'Andrada Date: Wed, 8 Aug 2012 19:55:45 -0300 Subject: [PATCH 349/562] plugins/resize - add a configuration option for vertical maximization --- plugins/resize/resize.xml.in | 5 +++++ plugins/resize/src/resize.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/plugins/resize/resize.xml.in b/plugins/resize/resize.xml.in index 2605c59f1..53067d5db 100644 --- a/plugins/resize/resize.xml.in +++ b/plugins/resize/resize.xml.in @@ -53,6 +53,11 @@ Same as setting 'any' for resize_from_center_match false +