diff options
| author | Tim Penhey <tim.penhey@canonical.com> | 2012-03-28 23:53:08 -0400 |
|---|---|---|
| committer | Tarmac <> | 2012-03-28 23:53:08 -0400 |
| commit | db04e7450f641454bba4b543764b51e5c7a536f8 (patch) | |
| tree | 6866bbd67f8a802e5ae1babf2a93eca60a465bb8 /tests | |
| parent | 7f09958b8f33f101944da79f010993e80dc54bf5 (diff) | |
| parent | d88571cb7c71554cc1a5d6f04cfd07dd415c57e3 (diff) | |
Make the favourite store a bit more robust around empty environments.. Fixes: . Approved by Thomi Richards, Tim Penhey.
(bzr r2185)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_favorite_store_gsettings.cpp | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/tests/test_favorite_store_gsettings.cpp b/tests/test_favorite_store_gsettings.cpp index deed131fd..54cac9ebd 100644 --- a/tests/test_favorite_store_gsettings.cpp +++ b/tests/test_favorite_store_gsettings.cpp @@ -26,15 +26,16 @@ #define G_SETTINGS_ENABLE_BACKEND #include <gio/gsettingsbackend.h> -#include <gtest/gtest.h> +#include <gmock/gmock.h> #include <glib.h> #include "FavoriteStore.h" #include "FavoriteStoreGSettings.h" +#include "FavoriteStorePrivate.h" #include <UnityCore/GLibWrapper.h> - using namespace unity; +using testing::Eq; namespace { @@ -489,4 +490,56 @@ TEST_F(TestFavoriteStoreGSettings, TestFavoriteSignalsMixed3) EXPECT_TRUE(reordered_received); } +TEST(TestFavoriteStorePathDetection, TestEmptyValues) +{ + using internal::impl::get_basename_or_path; + EXPECT_THAT(get_basename_or_path("/some/path/to.desktop", nullptr), + Eq("/some/path/to.desktop")); + EXPECT_THAT(get_basename_or_path("/some/path/to.desktop", { nullptr }), + Eq("/some/path/to.desktop")); + const char* const path[] = { "", nullptr }; + EXPECT_THAT(get_basename_or_path("/some/path/to.desktop", path), + Eq("/some/path/to.desktop")); +} + +TEST(TestFavoriteStorePathDetection, TestPathNeedsApplications) +{ + using internal::impl::get_basename_or_path; + const char* const path[] = { "/this/path", + "/that/path/", + nullptr }; + EXPECT_THAT(get_basename_or_path("/this/path/to.desktop", path), + Eq("/this/path/to.desktop")); + EXPECT_THAT(get_basename_or_path("/that/path/to.desktop", path), + Eq("/that/path/to.desktop")); +} + +TEST(TestFavoriteStorePathDetection, TestStripsPath) +{ + using internal::impl::get_basename_or_path; + const char* const path[] = { "/this/path", + "/that/path/", + nullptr }; + EXPECT_THAT(get_basename_or_path("/this/path/applications/to.desktop", path), + Eq("to.desktop")); + EXPECT_THAT(get_basename_or_path("/that/path/applications/to.desktop", path), + Eq("to.desktop")); + EXPECT_THAT(get_basename_or_path("/some/path/applications/to.desktop", path), + Eq("/some/path/applications/to.desktop")); +} + +TEST(TestFavoriteStorePathDetection, TestSubdirectory) +{ + using internal::impl::get_basename_or_path; + const char* const path[] = { "/this/path", + "/that/path/", + nullptr }; + EXPECT_THAT(get_basename_or_path("/this/path/applications/subdir/to.desktop", path), + Eq("subdir-to.desktop")); + EXPECT_THAT(get_basename_or_path("/that/path/applications/subdir/to.desktop", path), + Eq("subdir-to.desktop")); + EXPECT_THAT(get_basename_or_path("/this/path/applications/subdir1/subdir2/to.desktop", path), + Eq("subdir1-subdir2-to.desktop")); +} + } // anonymous namespace |
