Back to index

unity  6.0.0
test_filesystem_lenses.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <glib-object.h>
00003 #include <UnityCore/FilesystemLenses.h>
00004 
00005 using namespace std;
00006 using namespace unity::dash;
00007 
00008 namespace
00009 {
00010 
00011 void WaitForResult(bool& result)
00012 {
00013   bool timeout_reached;
00014 
00015   auto timeout_cb = [](gpointer data) -> gboolean
00016   {
00017     *(bool*)data = true;
00018     return FALSE;
00019   };
00020 
00021   guint32 timeout_id = g_timeout_add(10000, timeout_cb, &timeout_reached);
00022 
00023   while (!result && !timeout_reached)
00024   {
00025     g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
00026   }
00027   if (result)
00028     g_source_remove(timeout_id);
00029 }
00030 
00031 void WaitForLensesToLoad(FilesystemLenses& lenses)
00032 {
00033   bool result = false;
00034 
00035   auto lenses_loaded_cb = [&result]()
00036   {
00037     result = true;
00038   };
00039   lenses.lenses_loaded.connect(sigc::slot<void>(lenses_loaded_cb));
00040 
00041   WaitForResult(result);
00042   EXPECT_TRUE(result);
00043 }
00044 
00045 TEST(TestFilesystemLenses, TestConstruction)
00046 {
00047   FilesystemLenses lenses0;
00048   LensDirectoryReader::Ptr test_reader(new LensDirectoryReader(TESTDATADIR"/lenses"));
00049   FilesystemLenses lenses1(test_reader);
00050 }
00051 
00052 TEST(TestFilesystemLenses, TestFileLoading)
00053 {
00054   LensDirectoryReader::Ptr test_reader(new LensDirectoryReader(TESTDATADIR"/lenses"));
00055   FilesystemLenses lenses(test_reader);
00056   WaitForLensesToLoad(lenses);
00057 }
00058 
00059 TEST(TestFilesystemLenses, TestLensesAdded)
00060 {
00061   LensDirectoryReader::Ptr test_reader(new LensDirectoryReader(TESTDATADIR"/lenses"));
00062   FilesystemLenses lenses(test_reader);
00063   unsigned int n_lenses = 0;
00064 
00065   auto lens_added_cb = [&n_lenses](Lens::Ptr & p)
00066   {
00067     n_lenses++;
00068   };
00069   lenses.lens_added.connect(sigc::slot<void, Lens::Ptr&>(lens_added_cb));
00070 
00071   WaitForLensesToLoad(lenses);
00072   EXPECT_EQ(n_lenses, (unsigned int)3);
00073   EXPECT_EQ(lenses.count, (unsigned int)3);
00074 }
00075 
00076 TEST(TestFilesystemLenses, TestLensContent)
00077 {
00078   LensDirectoryReader::Ptr test_reader(new LensDirectoryReader(TESTDATADIR"/lenses"));
00079   FilesystemLenses lenses(test_reader);
00080   WaitForLensesToLoad(lenses);
00081 
00082   // Test that the lenses have loaded correctly
00083   Lens::Ptr lens = lenses.GetLens("applications.lens");
00084   EXPECT_TRUE(lens.get());
00085   EXPECT_EQ(lens->dbus_name, "com.canonical.tests.Lens.Applications");
00086   EXPECT_EQ(lens->dbus_path, "/com/canonical/tests/lens/applications");
00087   EXPECT_EQ(lens->name, "Applications");
00088   EXPECT_EQ(lens->icon_hint, "/usr/share/unity-lens-applications/applications.png");
00089   EXPECT_EQ(lens->description, "Search for applications");
00090   EXPECT_EQ(lens->search_hint, "Search Applications");
00091   EXPECT_EQ(lens->visible, true);
00092   EXPECT_EQ(lens->shortcut, "a");
00093 
00094   lens = lenses.GetLens("files.lens");
00095   EXPECT_TRUE(lens.get());
00096   EXPECT_EQ(lens->dbus_name, "com.canonical.tests.Lens.Files");
00097   EXPECT_EQ(lens->dbus_path, "/com/canonical/tests/lens/files");
00098   EXPECT_EQ(lens->name, "Files");
00099   EXPECT_EQ(lens->icon_hint, "/usr/share/unity-lens-files/files.png");
00100   EXPECT_EQ(lens->description, "Search for Files & Folders");
00101   EXPECT_EQ(lens->search_hint, "Search Files & Folders");
00102   EXPECT_EQ(lens->visible, false);
00103   EXPECT_EQ(lens->shortcut, "f");
00104 
00105   lens = lenses.GetLens("social.lens");
00106   EXPECT_TRUE(lens.get());
00107   EXPECT_EQ(lens->dbus_name, "com.canonical.tests.Lens.Social");
00108   EXPECT_EQ(lens->dbus_path, "/com/canonical/tests/lens/social");
00109   EXPECT_EQ(lens->name, "Social");
00110   EXPECT_EQ(lens->icon_hint, "/usr/share/unity-lens-social/social.png");
00111   EXPECT_EQ(lens->description, "");
00112   EXPECT_EQ(lens->search_hint, "");
00113   EXPECT_EQ(lens->visible, true);
00114   EXPECT_EQ(lens->shortcut, "");
00115 }
00116 
00117 }