./ 0000755 0000041 0000041 00000000000 12735444523 011254 5 ustar www-data www-data ./autogen.sh 0000755 0000041 0000041 00000000307 12735444523 013255 0 ustar www-data www-data #!/bin/sh
srcdir=`dirname $0`
PKG_NAME="unity-place-applications"
which gnome-autogen.sh || {
echo "You need gnome-common from GNOME SVN"
exit 1
}
USE_GNOME2_MACROS=1 \
. gnome-autogen.sh "$@"
./Makefile.am.coverage 0000644 0000041 0000041 00000002505 12735444523 015104 0 ustar www-data www-data
# Coverage targets
.PHONY: clean-gcno clean-gcda \
coverage-html generate-coverage-html clean-coverage-html \
coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
if HAVE_GCOV
clean-gcno:
@echo Removing old coverage instrumentation
-find -name '*.gcno' -print | xargs -r rm
clean-gcda:
@echo Removing old coverage results
-find -name '*.gcda' -print | xargs -r rm
coverage-html: clean-gcda
-$(MAKE) $(AM_MAKEFLAGS) -k check
$(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
generate-coverage-html:
@echo Collecting coverage data
$(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
clean-coverage-html: clean-gcda
-$(LCOV) --directory $(top_builddir) -z
-rm -rf coverage.info coveragereport
if HAVE_GCOVR
coverage-gcovr: clean-gcda
-$(MAKE) $(AM_MAKEFLAGS) -k check
$(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
generate-coverage-gcovr:
@echo Generating coverage GCOVR report
$(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
clean-coverage-gcovr: clean-gcda
-rm -rf $(top_builddir)/coverage.xml
endif # HAVE_GCOVR
endif # HAVE_GCOV
./tests/ 0000755 0000041 0000041 00000000000 12735444523 012416 5 ustar www-data www-data ./tests/test-keyword-relevancy.sh 0000755 0000041 0000041 00000000557 12735444523 017413 0 ustar www-data www-data #!/bin/sh
# This test is pretty flaky, feel free to remove if it starts failing... :(
# Search for display, print the results, make sure first is:
# gnome-display-panel.desktop
unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/applications -s "display" --no-search-reply -r | head -n1 | grep -q gnome-display-panel.desktop || exit 1
./tests/test-3-categories.sh 0000755 0000041 0000041 00000000503 12735444523 016215 0 ustar www-data www-data #!/bin/sh
# Do empty search, print the results, look at category id field, make sure
# there are exactly 3 different values for it
unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/applications -s "" --no-search-reply -r | awk -F "\t" ' { print $3; } ' | uniq | wc -l | grep -q 3 || exit 1
./tests/test-common.sh 0000755 0000041 0000041 00000000367 12735444523 015230 0 ustar www-data www-data #!/bin/sh
# Common tests for emitting finished signal
unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/applications -c
unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/commands -c
./tests/test-no-results.sh 0000755 0000041 0000041 00000000362 12735444523 016046 0 ustar www-data www-data #!/bin/sh
# Check that a non-sensical search string returns reply with "no-results-hint"
# set.
unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/applications -s asdfqwer | grep -q "no-results-hint" || exit 1
./tests/unit/ 0000755 0000041 0000041 00000000000 12735444523 013375 5 ustar www-data www-data ./tests/unit/test-xapian-utils.vala 0000644 0000041 0000041 00000015206 12735444523 017641 0 ustar www-data www-data /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by Pawel Stolowski
*/
namespace Unity.ApplicationsLens
{
public static int main (string[] args)
{
Test.init (ref args);
Test.add_data_func ("/Unit/EmptySearchQuery", test_empty_search_query);
Test.add_data_func ("/Unit/EmptySearchWithSingleCategoryFilter", test_empty_search_with_single_cat_filter);
Test.add_data_func ("/Unit/EmptySearchWithMultipleCategoryFilter", test_empty_search_with_multi_cat_filter);
Test.add_data_func ("/Unit/SearchQueryWithNoFilters", test_search_query_no_filters);
Test.add_data_func ("/Unit/SearchQueryWithSingleCategoryFilter", test_search_query_with_single_cat_filter);
Test.add_data_func ("/Unit/SearchQueryWithMultipleCategoryFilter", test_search_query_with_multi_cat_filter);
Test.add_data_func ("/Unit/ZgEmptySearchQuery", test_zg_empty_search_query);
Test.add_data_func ("/Unit/ZgEmptySearchWithSingleCategoryFilter", test_zg_empty_search_with_single_cat_filter);
Test.add_data_func ("/Unit/ZgEmptySearchWithMultipleCategoryFilter", test_zg_empty_search_with_multi_cat_filter);
Test.add_data_func ("/Unit/ZgSearchQuery", test_zg_search_query_no_filters);
Test.add_data_func ("/Unit/ZgSearchQueryWithSingleCategoryFilter", test_zg_search_query_with_single_cat_filter);
Test.add_data_func ("/Unit/ZgSearchQueryWithMultipleCategoryFilter", test_zg_search_query_with_multi_cat_filter);
Test.run ();
return 0;
}
internal static void test_empty_search_query ()
{
var query = XapianUtils.prepare_pkg_search_string ("", null);
assert (query == "(type:Application OR type:Scope)");
}
internal static void test_empty_search_with_single_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null).active = true;
filter.add_option ("internet", "Internet", null);
var query = XapianUtils.prepare_pkg_search_string ("", filter);
assert (query == "(type:Application OR type:Scope) AND (category:AudioVideo)");
}
internal static void test_empty_search_with_multi_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null).active = true;
filter.add_option ("internet", "Internet", null);
filter.add_option ("game", "Game", null).active = true;
var query = XapianUtils.prepare_pkg_search_string ("", filter);
assert (query == "(type:Application OR type:Scope) AND (category:Game OR category:AudioVideo)");
}
internal static void test_search_query_no_filters ()
{
var query = XapianUtils.prepare_pkg_search_string (" foo ", null);
assert (query == "(type:Application OR type:Scope) AND foo");
query = XapianUtils.prepare_pkg_search_string ("foo", null);
assert (query == "(type:Application OR type:Scope) AND foo");
}
internal static void test_search_query_with_single_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null);
filter.add_option ("internet", "Internet", null).active = true;
var query = XapianUtils.prepare_pkg_search_string ("foo", filter);
assert (query == "(type:Application OR type:Scope) AND (category:Network) AND foo");
}
internal static void test_search_query_with_multi_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null);
filter.add_option ("internet", "Internet", null).active = true;
filter.add_option ("game", "Game", null).active = true;
var query = XapianUtils.prepare_pkg_search_string ("foo", filter);
assert (query == "(type:Application OR type:Scope) AND (category:Game OR category:Network) AND foo");
}
internal static void test_zg_empty_search_query ()
{
var query = XapianUtils.prepare_zg_search_string ("", null);
assert (query == "NOT category:XYZ");
}
internal static void test_zg_empty_search_with_single_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null);
filter.add_option ("office", "Office", null).active = true;
var query = XapianUtils.prepare_zg_search_string ("", filter);
assert (query == "(category:Office)");
}
internal static void test_zg_empty_search_with_multi_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null);
filter.add_option ("office", "Office", null).active = true;
filter.add_option ("customization", "Customization", null).active = true;
var query = XapianUtils.prepare_zg_search_string ("", filter);
assert (query == "(category:Office OR category:Settings)");
}
internal static void test_zg_search_query_no_filters ()
{
var query = XapianUtils.prepare_zg_search_string (" foo ", null);
assert (query == "app:(foo*)");
query = XapianUtils.prepare_zg_search_string (" foo*", null);
assert (query == "app:(foo*)");
}
internal static void test_zg_search_query_with_single_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null);
filter.add_option ("internet", "Internet", null).active = true;
var query = XapianUtils.prepare_zg_search_string (" foo* ", filter);
assert (query == "app:(foo*) AND (category:Network)");
}
internal static void test_zg_search_query_with_multi_cat_filter ()
{
var filter = new Unity.CheckOptionFilter ("filter", "Filter");
filter.filtering = true;
filter.add_option ("media", "Media", null);
filter.add_option ("internet", "Internet", null).active = true;
filter.add_option ("game", "Game", null).active = true;
var query = XapianUtils.prepare_zg_search_string (" foo* ", filter);
assert (query == "app:(foo*) AND (category:Game OR category:Network)");
}
}
./tests/unit/test-purchase-info-helper.vala 0000644 0000041 0000041 00000006335 12735444523 021246 0 ustar www-data www-data /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by Pawel Stolowski
*/
namespace Unity.ApplicationsLens
{
public static int main (string[] args)
{
Test.init (ref args);
Test.add_data_func ("/Unit/Find", test_find);
Test.add_data_func ("/Unit/CreatePkgSearchQuery", test_pkgsearch_query);
Test.run ();
return 0;
}
public Unity.Package.SearchResult create_search_result ()
{
Unity.Package.SearchResult search_results = new Unity.Package.SearchResult ();
var pi = new Unity.Package.PackageInfo ();
pi.application_name = "Evince";
pi.package_name = "evince";
pi.needs_purchase = false;
search_results.results.append ((owned) pi);
pi = new Unity.Package.PackageInfo ();
pi.application_name = "Commercial App1";
pi.package_name = "commercial_app1";
pi.price = "10 EUR";
pi.needs_purchase = true;
search_results.results.append ((owned) pi);
pi = new Unity.Package.PackageInfo ();
pi.application_name = "Commercial App2";
pi.package_name = "commercial_app2";
pi.price = "20 EUR";
pi.needs_purchase = false;
search_results.results.append ((owned) pi);
search_results.num_hits = 3;
return search_results;
}
internal static void test_find ()
{
// populate search results
var search_results = create_search_result ();
var phelper = new PurchaseInfoHelper ();
phelper.from_pkgresults (search_results);
assert (phelper.find ("FooApp", "foopkg") == null);
var appinfo = phelper.find ("Evince", "evince");
assert (appinfo != null);
assert (appinfo.formatted_price == "");
assert (appinfo.paid == false);
appinfo = phelper.find ("Commercial App1", "commercial_app1");
assert (appinfo != null);
assert (appinfo.formatted_price == "10 EUR");
assert (appinfo.paid == false);
appinfo = phelper.find ("Commercial App2", "commercial_app2");
assert (appinfo != null);
assert (appinfo.formatted_price == "20 EUR");
assert (appinfo.paid == true);
}
internal static void test_pkgsearch_query ()
{
SoftwareCenterData.AppInfo?[] data = new SoftwareCenterData.AppInfo?[2] {
SoftwareCenterData.AppInfo () { package_name = "evince", application_name = "Evince" },
SoftwareCenterData.AppInfo () { package_name = "skype", application_name = "Skype" }
};
var phelper = new PurchaseInfoHelper ();
var query = phelper.create_pkgsearch_query (data);
assert (query.length () == 4);
assert (query.nth_data (0) == "Evince");
assert (query.nth_data (1) == "evince");
assert (query.nth_data (2) == "Skype");
assert (query.nth_data (3) == "skype");
}
} ./tests/unit/Makefile.am 0000644 0000041 0000041 00000012451 12735444523 015434 0 ustar www-data www-data include $(top_srcdir)/Makefile.decl
check_PROGRAMS = \
test-software-center-data-cache \
test-purchase-info-helper \
test-software-center-utils \
test-software-center-details \
test-xapian-utils \
test-utils
TEST_PROGS += $(check_PROGRAMS)
AM_VALAFLAGS = \
--vapidir $(top_srcdir)/vapi \
--pkg glib-2.0 \
--pkg posix \
--pkg dee-1.0 \
--pkg gio-2.0 \
--pkg gee-0.8 \
--pkg gio-unix-2.0 \
--pkg unity-package-search \
--pkg unity \
--target-glib=2.26 \
$(MAINTAINER_VALAFLAGS) \
$(NULL)
UNITY_PACKAGE_SEARCH_LIBS = -lxapian -lstdc++
LDADD = $(LENS_DAEMON_LIBS) \
$(test_libs) \
$(UNITY_PACKAGE_SEARCH_LIBS)
LDFLAGS += -rpath $(PROTOCOLPRIVATELIBDIR)
AM_CPPFLAGS = \
$(LENS_DAEMON_CFLAGS) \
-I$(srcdir) \
-I$(top_srcdir)/src \
-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
-DGMENU_I_KNOW_THIS_IS_UNSTABLE \
$(COVERAGE_CFLAGS) \
$(NULL)
if !ENABLE_C_WARNINGS
AM_CPPFLAGS += -w
endif
AM_LDFLAGS = $(COVERAGE_LDFLAGS)
test_software_center_data_cache_VALASOURCES = \
test-software-center-data-cache.vala \
$(top_srcdir)/src/software-center-data-cache.vala \
$(top_srcdir)/src/software-center-app-details.vala \
software-center-data-provider-mock.vala \
$(NULL)
nodist_test_software_center_data_cache_SOURCES = $(test_software_center_data_cache_VALASOURCES:.vala=.c)
test_purchase_info_helper_VALASOURCES = \
test-purchase-info-helper.vala \
$(top_srcdir)/src/purchase-info-helper.vala \
$(top_srcdir)/src/software-center-app-details.vala \
$(top_srcdir)/src/utils.vala \
$(NULL)
nodist_test_purchase_info_helper_SOURCES = $(test_purchase_info_helper_VALASOURCES:.vala=.c)
test_purchase_info_helper_LDADD = \
$(LDADD) \
unity-package-search.o \
unity-ratings-db.o \
-ldb
test_software_center_utils_VALASOURCES = \
test-software-center-utils.vala \
$(top_srcdir)/src/software-center-utils.vala \
$(NULL)
nodist_test_software_center_utils_SOURCES = $(test_software_center_utils_VALASOURCES:.vala=.c)
test_xapian_utils_VALASOURCES = \
test-xapian-utils.vala \
$(top_srcdir)/src/xapian-utils.vala \
$(top_srcdir)/src/utils.vala \
$(NULL)
nodist_test_xapian_utils_SOURCES = $(test_xapian_utils_VALASOURCES:.vala=.c)
# Also includes source files that don't have proper tests
# so they show up in coverage reports.
test_utils_VALASOURCES = \
test-utils.vala \
$(top_srcdir)/src/utils.vala \
$(top_srcdir)/src/app-watcher.vala \
$(top_srcdir)/src/aptd-client.vala \
$(top_srcdir)/src/schemas.vala \
$(top_srcdir)/src/xapian-utils.vala \
$(NULL)
nodist_test_utils_SOURCES = $(test_utils_VALASOURCES:.vala=.c)
test_software_center_details_VALASOURCES = \
test-software-center-app-details.vala \
$(top_srcdir)/src/software-center-app-details.vala \
$(NULL)
nodist_test_software_center_details_SOURCES = $(test_software_center_details_VALASOURCES:.vala=.c)
unity-package-search.o : $(top_srcdir)/src/unity-package-search.cc $(top_srcdir)/src/unity-package-search.h
$(AM_V_GEN)$(CXX) --std=c++11 -g $(COVERAGE_CFLAGS) $(UNITY_PACKAGE_SEARCH_LIBS) -DGMENU_I_KNOW_THIS_IS_UNSTABLE `pkg-config --cflags --libs glib-2.0 libgnome-menu-3.0 unity gee-0.8 libcolumbus` -c $(top_srcdir)/src/unity-package-search.cc
unity-ratings-db.o : $(top_srcdir)/src/unity-ratings-db.c $(top_srcdir)/src/unity-ratings-db.h
$(AM_V_CC)$(CC) -g $(COVERAGE_CFLAGS) $(unity_ratings_db_libs) `pkg-config --cflags --libs glib-2.0` -c $(top_srcdir)/src/unity-ratings-db.c
CLEANFILES = *.stamp \
$(test_software_center_data_cache_VALASOURCES:.vala=.c) \
$(test_purchase_info_helper_VALASOURCES:.vala=.c) \
$(test_software_center_utils_VALASOURCES:.vala=.c) \
$(test_xapian_utils_VALASOURCES:.vala=.c) \
$(test_utils_VALASOURCES:.vala=.c) \
$(test_software_center_details_VALASOURCES:.vala=.c) \
$(NULL)
BUILT_SOURCES = \
test-software-center-data-cache.vala.stamp \
test-purchase-info-helper.vala.stamp \
test-software-center-utils.vala.stamp \
test-software-center-details.vala.stamp \
test-xapian-utils.vala.stamp \
test-utils.vala.stamp \
$(NULL)
test-software-center-data-cache.vala.stamp: $(test_software_center_data_cache_VALASOURCES)
$(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
@touch $@
test-purchase-info-helper.vala.stamp: $(test_purchase_info_helper_VALASOURCES)
$(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
@touch $@
test-software-center-utils.vala.stamp: $(test_software_center_utils_VALASOURCES)
$(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
@touch $@
test-software-center-details.vala.stamp: $(test_software_center_details_VALASOURCES)
$(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
@touch $@
test-xapian-utils.vala.stamp: $(test_xapian_utils_VALASOURCES)
$(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
@touch $@
test-utils.vala.stamp: $(test_utils_VALASOURCES)
$(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
@touch $@
# START HEADLESS TESTS
if ENABLE_HEADLESS_TESTS
DISPLAY = :27
LOG_PATH = headless-logs
test-headless:
set -e; \
export DISPLAY=$(DISPLAY); \
rm -rf $(LOG_PATH); \
mkdir $(LOG_PATH); \
$(XVFB) $(DISPLAY) -screen 0 1024x768x8 > $(LOG_PATH)/Xvfb.out 2>&1 & \
sleep 1; \
\
$(DBUS_LAUNCH) > $(LOG_PATH)/sessionbus.sh; \
source $(LOG_PATH)/sessionbus.sh; \
sleep 1; \
\
make test; \
sleep 1; \
\
kill `grep DBUS_SESSION_BUS_PID $(LOG_PATH)/sessionbus.sh | grep -oE '[0-9]+'`; \
pkill Xvfb;
endif
# END HEADLESS TESTS
./tests/unit/test-software-center-data-cache.vala 0000644 0000041 0000041 00000006266 12735444523 022311 0 ustar www-data www-data /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by Pawel Stolowski
*/
namespace Unity.ApplicationsLens
{
public static const string TOP_RATED = "unity-top-rated";
public static int main (string[] args)
{
Test.init (ref args);
Test.add_data_func ("/Unit/ItemsForCategoryCache", test_category_cache);
Test.run ();
return 0;
}
public bool has_app (SoftwareCenterData.AppInfo?[] items, string appname, string pkgname)
{
foreach (var item in items)
{
if (item.application_name == appname && item.package_name == pkgname)
return true;
}
return false;
}
internal static bool run_with_timeout (MainLoop ml, uint timeout_ms = 5000)
{
bool timeout_reached = false;
var t_id = Timeout.add (timeout_ms, () =>
{
timeout_reached = true;
debug ("Timeout reached");
ml.quit ();
return false;
});
ml.run ();
if (!timeout_reached) Source.remove (t_id);
return !timeout_reached;
}
internal static SoftwareCenterData.AppInfo?[] get_items (SoftwareCenterDataCache cache, string category)
{
var ml = new MainLoop ();
SoftwareCenterData.AppInfo?[] items = null;
cache.get_items_for_category.begin (category, (obj, result) =>
{
items = cache.get_items_for_category.end (result);
ml.quit ();
});
assert (run_with_timeout (ml));
return items;
}
internal static void test_category_cache ()
{
var cache = new SoftwareCenterDataCache (1); // lifetime of cache items = 1s
// add items to mock base class
cache.mock_add (TOP_RATED, "Evince", "evince");
// at this point items are fetched by cache and kept for 1s
var items = get_items (cache, TOP_RATED);
assert (items.length == 1);
// remove & add new items to the mock, but get_items_for_category should still
// return old cached values.
cache.mock_clear (TOP_RATED);
cache.mock_add (TOP_RATED, "Blender", "blender");
cache.mock_add (TOP_RATED, "Firefox", "firefox");
cache.mock_add (TOP_RATED, "Thunderbird", "thunderbird");
var items_2 = get_items (cache, TOP_RATED);
assert (items_2.length == 1);
assert (has_app (items_2, "Evince", "evince") == true);
// wait 3s for cache items to expire
GLib.Thread.usleep (2 * 1000000);
// cache will fetch new items now.
var items_3 = get_items (cache, TOP_RATED);
assert (items_3.length == 3);
assert (has_app (items_3, "Blender", "blender") == true);
assert (has_app (items_3, "Firefox", "firefox") == true);
assert (has_app (items_3, "Thunderbird", "thunderbird") == true);
}
}
./tests/unit/test-software-center-app-details.vala 0000644 0000041 0000041 00000010324 12735444523 022530 0 ustar www-data www-data /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by Pawel Stolowski
*/
namespace Unity.ApplicationsLens
{
public static int main (string[] args)
{
Test.init (ref args);
Test.add_data_func ("/Unit/AppDetailsCtor", test_app_details_ctor);
Test.add_data_func ("/Unit/AppDetailsPkgStates", test_app_details_pkg_states);
Test.run ();
return 0;
}
internal HashTable create_sc_app_details_data ()
{
var data = new HashTable (str_hash, str_equal);
data.insert ("name", "Foo");
data.insert ("summary", "Foobar application");
data.insert ("description", "Completly useless application");
data.insert ("version", "1.0");
var bld = new GLib.VariantBuilder (new VariantType ("aa{sv}"));
bld.open (new VariantType ("a{sv}"));
bld.add ("{sv}", "large_image_url", new Variant.string ("http://foo-bar.org/screenshot.png"));
bld.add ("{sv}", "small_image_url", new Variant.string ("http://foo-bar.org/screenshot_small.png"));
bld.close ();
data.insert ("screenshots", bld.end ());
data.insert ("signing_key_id", "");
data.insert ("region_requirements_satisfied", true);
data.insert ("desktop_file", "foo.desktop");
data.insert ("license", "GPL");
data.insert ("icon_file_name", "foo.png");
data.insert ("icon_url", "http://foo-bar.org/icon.png");
data.insert ("price", "1 EUR");
data.insert ("raw_price", "1");
data.insert ("installation_date", "01-01-2012");
data.insert ("website", "http://foo-bar.org");
data.insert ("hardware_requirements", "PC");
data.insert ("size", "10000");
data.insert ("is_desktop_dependency", true);
data.insert ("pkg_state", "installed");
return data;
}
internal static void test_app_details_ctor ()
{
var data = create_sc_app_details_data ();
var app_details = new SoftwareCenterData.AppDetailsData (data);
assert (app_details.name == "Foo");
assert (app_details.summary == "Foobar application");
assert (app_details.description == "Completly useless application");
assert (app_details.version == "1.0");
assert (app_details.screenshot == "http://foo-bar.org/screenshot.png");
assert (app_details.desktop_file == "foo.desktop");
assert (app_details.license == "GPL");
assert (app_details.icon == "foo.png");
assert (app_details.icon_url == "http://foo-bar.org/icon.png");
assert (app_details.price == "1 EUR");
assert (app_details.raw_price == "1");
assert (app_details.installation_date == "01-01-2012");
assert (app_details.website == "http://foo-bar.org");
assert (app_details.size == 10000);
assert (app_details.hardware_requirements == "PC");
assert (app_details.is_desktop_dependency == true);
assert (app_details.pkg_state == SoftwareCenterData.PackageState.INSTALLED);
}
internal static void test_app_details_pkg_states ()
{
var data = create_sc_app_details_data ();
var app_details = new SoftwareCenterData.AppDetailsData (data);
assert (app_details.pkg_state == SoftwareCenterData.PackageState.INSTALLED);
data.replace ("pkg_state", "uninstalled");
app_details = new SoftwareCenterData.AppDetailsData (data);
assert (app_details.pkg_state == SoftwareCenterData.PackageState.UNINSTALLED);
data.replace ("pkg_state", "needs_purchase");
app_details = new SoftwareCenterData.AppDetailsData (data);
assert (app_details.pkg_state == SoftwareCenterData.PackageState.NEEDS_PURCHASE);
data.replace ("pkg_state", "");
app_details = new SoftwareCenterData.AppDetailsData (data);
assert (app_details.pkg_state == SoftwareCenterData.PackageState.UNKNOWN);
}
} ./tests/unit/software-center-data-provider-mock.vala 0000644 0000041 0000041 00000003342 12735444523 023042 0 ustar www-data www-data /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by Pawel Stolowski
*/
namespace Unity.ApplicationsLens
{
public class SoftwareCenterDataProviderProxy: GLib.Object
{
private HashTable> data;
public SoftwareCenterDataProviderProxy ()
{
data = new HashTable> (str_hash, str_equal);
data["unity-top-rated"] = new Gee.ArrayList ();
data["unity-whats-new"] = new Gee.ArrayList ();
}
public void mock_add (string category, string appname, string pkgname)
{
var app = SoftwareCenterData.AppInfo () {
application_name = appname,
package_name = pkgname,
icon = null,
desktop_file = null
};
data[category].add (app);
}
public void mock_clear (string category)
{
data[category].clear ();
}
public virtual async SoftwareCenterData.AppInfo?[] get_items_for_category (string category_name) throws Error
{
return data[category_name].to_array ();
}
}
}
./tests/unit/test-utils.vala 0000644 0000041 0000041 00000005766 12735444523 016375 0 ustar www-data www-data /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by Pawel Stolowski
*/
namespace Unity.ApplicationsLens
{
public static int main (string[] args)
{
Test.init (ref args);
Test.add_data_func ("/Unit/GetDesktopIdForActor", test_get_desktop_id_for_actor);
Test.add_data_func ("/Unit/IsSearchEmpty", test_is_search_empty);
Test.add_data_func ("/Unit/PreprocessString", test_preprocess_string);
Test.add_data_func ("/Unit/Uncamelcase", test_uncamelcase);
Test.add_data_func ("/Unit/SubstTilde", test_subst_tilde);
Test.run ();
return 0;
}
internal static void test_get_desktop_id_for_actor ()
{
assert (Utils.get_desktop_id_for_actor ("application://foobar") == "foobar");
assert (Utils.get_desktop_id_for_actor ("app://foobar") == "foobar");
assert (Utils.get_desktop_id_for_actor ("/etc/passwd") == "passwd");
assert (Utils.get_desktop_id_for_actor ("foo.desktop") == "foo.desktop");
assert (Utils.get_desktop_id_for_actor ("foo") == "foo");
}
internal static void test_is_search_empty ()
{
assert (Utils.is_search_empty (null) == true);
assert (Utils.is_search_empty ("") == true);
assert (Utils.is_search_empty (" ") == false);
}
internal static void test_preprocess_string ()
{
assert (Utils.preprocess_string ("AisleRiot Solitaire") == "AisleRiot Solitaire\nAisle Riot Solitaire");
assert (Utils.preprocess_string ("FooBar") == "FooBar\nFoo Bar");
assert (Utils.preprocess_string ("Foo Bar") == "Foo Bar");
}
internal static void test_uncamelcase ()
{
assert (Utils.uncamelcase ("FooBar") == "Foo Bar");
assert (Utils.uncamelcase ("fooBar") == "foo Bar");
assert (Utils.uncamelcase ("Foo Bar") == "Foo Bar");
assert (Utils.uncamelcase ("foobar") == "foobar");
assert (Utils.uncamelcase ("FOoBar") == "FOo Bar");
}
internal static void test_subst_tilde ()
{
assert (Utils.subst_tilde ("foo") == "foo");
var home = Environment.get_home_dir ();
var path = Utils.subst_tilde ("~");
assert (path == home);
path = Utils.subst_tilde ("~/foo/bar.txt");
assert (path == home + "/foo/bar.txt");
// test ~username expansion
var username = GLib.Environment.get_user_name ();
assert (username.length > 0); // sanity check to ensure we're really testing ~username expansion
path = Utils.subst_tilde ("~" + GLib.Environment.get_user_name ());
assert (path == home);
}
} ./tests/unit/test-software-center-utils.vala 0000644 0000041 0000041 00000003521 12735444523 021466 0 ustar www-data www-data /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by Pawel Stolowski
*/
namespace Unity.ApplicationsLens
{
public static int main (string[] args)
{
Test.init (ref args);
Test.add_data_func ("/Unit/DesktopIdLookupWithMangling", test_desktop_file_lookup_with_unmangling);
Test.add_data_func ("/Unit/DesktopIdLookupWithoutMangling", test_desktop_file_lookup_without_unmangling);
Test.run ();
return 0;
}
internal static void test_desktop_file_lookup_with_unmangling ()
{
var lookup = new SoftwareCenterUtils.MangledDesktopFileLookup ();
string desktop_file = "/foo/bar/kde4:kde4__KCharSelect.desktop";
var result = lookup.extract_desktop_id (desktop_file, true /* unmangle */);
assert (result == "kde4-KCharSelect.desktop");
assert (lookup.contains (result) == true);
assert (lookup.get (result) == "kde4__KCharSelect.desktop");
}
internal static void test_desktop_file_lookup_without_unmangling ()
{
var lookup = new SoftwareCenterUtils.MangledDesktopFileLookup ();
string desktop_file = "/foo/bar/evince.desktop";
var result = lookup.extract_desktop_id (desktop_file, false);
assert (result == "evince.desktop");
assert (lookup.contains (result) == false);
}
} ./tests/test-6-recent-results.sh 0000755 0000041 0000041 00000000472 12735444523 017057 0 ustar www-data www-data #!/bin/sh
# Do empty search, print the results, look at the number of items
# for the recent category, make sure there are max 6
test `unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/applications -s "" --no-search-reply -r | awk -F "\t" ' { print $3; } ' | grep 0 | wc -l` -le 6
./tests/mock-winstack.py 0000755 0000041 0000041 00000013746 12735444523 015560 0 ustar www-data www-data #!/usr/bin/env python3
#
# Copyright (C) 2013 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Authored by Pawel Stolowski
#
#
# This is a simple simulator/mock of com.canonical.Unity.WindowStack DBus service,
# meant for testing of unity-scope-runningapps. It doesn't implement all the API calls -
# only what's needed by the scope.
#
# Usage:
# - to run indefinitely, with window events every 2 secs.
# ./mock-winstack.py
#
# - to run with specific number of simulation steps and given interval:
# ./mock-winstack.py
# (where interval is in seconds; use steps = 0 for infinity).
#
import dbus
import dbus.service
import sys
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib, GObject
WINSTACK_DBUS_IFACE = "com.canonical.Unity.WindowStack"
WINSTACK_DBUS_NAME = "com.canonical.Unity.WindowStack"
WINSTACK_DBUS_PATH = "/com/canonical/Unity/WindowStack"
START = 0
FOCUS = 1
CLOSE = 2
APP_WEB = 'org.mozilla.firefox'
APP_EDITOR = 'org.gnome.gedit'
APP_NOTES = 'com.canonical.notes'
APP_GALLERY = 'com.canonical.gallery'
main_loop = GLib.MainLoop()
class WinStackSim (GObject.GObject):
__gsignals__ = {
'window_created': (GObject.SIGNAL_RUN_FIRST, None, (int, str,)),
'window_destroyed': (GObject.SIGNAL_RUN_FIRST, None, (int, str,)),
'focused_window_changed': (GObject.SIGNAL_RUN_FIRST, None, (int, str, int))
}
#
# window events to be generated in every simulation step;
# every step contains at least one event.
_SIM_STEPS = (
(
(START, APP_WEB),
(START, APP_NOTES),
(FOCUS, APP_WEB)
),
(
(START, APP_EDITOR),
),
(
(FOCUS, APP_NOTES),
),
(
(FOCUS, APP_WEB),
),
(
(CLOSE, APP_WEB),
(FOCUS, APP_NOTES)
),
(
(CLOSE, APP_NOTES),
),
(
(START, APP_GALLERY),
(FOCUS, APP_GALLERY)
),
(
(FOCUS, APP_EDITOR),
),
(
(CLOSE, APP_EDITOR),
(FOCUS, APP_GALLERY),
(CLOSE, APP_GALLERY)
)
# make sure that the last step leaves window stack in a state
# that makes sense when all the steps are repeated
# in infinite loop.
)
def __init__(self):
GObject.GObject.__init__(self)
self._windows = []
self._total_step = 0
self._sim_step = 0
self._steps = 0
self._focused = None
def start_sim(self, interval_secs, steps = 0):
self._sim_step = 0
self._steps = steps
GLib.timeout_add_seconds(interval_secs, self.do_sim_step)
def do_sim_step(self):
sim_data = self._SIM_STEPS[self._sim_step]
for s in sim_data:
if s[0] == START:
self.emit('window_created', 0, s[1])
self._windows.append(s[1])
elif s[0] == CLOSE:
self.emit('window_destroyed', 0, s[1])
self._windows.remove(s[1])
elif s[0] == FOCUS:
self._focused = s[1]
self.emit('focused_window_changed', 0, s[1], 0)
self._total_step += 1
self._sim_step = (self._sim_step + 1) % len(self._SIM_STEPS)
if self._steps > 0 and self._total_step >= self._steps:
main_loop.quit()
return True
def get_window_stack(self):
return [(0, win, self._focused == win, 0) for win in self._windows]
class WinStackServiceMock (dbus.service.Object):
def __init__(self, sim):
dbus.service.Object.__init__(self)
self._sim = sim
self._sim.connect('window_created', self.on_window_created)
self._sim.connect('window_destroyed', self.on_window_destroyed)
self._sim.connect('focused_window_changed', self.on_focused_window_changed)
bus_name = dbus.service.BusName(WINSTACK_DBUS_NAME, bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, WINSTACK_DBUS_PATH)
def on_window_created(self, sim, window_id, app_id):
self.WindowCreated(window_id, app_id)
def on_window_destroyed(self, sim, window_id, app_id):
self.WindowDestroyed(window_id, app_id)
def on_focused_window_changed(self, sim, window_id, app_id, stage):
self.FocusedWindowChanged(window_id, app_id, stage)
@dbus.service.signal(dbus_interface=WINSTACK_DBUS_IFACE, signature='us')
def WindowCreated(self, window_id, app_id):
pass
@dbus.service.signal(dbus_interface=WINSTACK_DBUS_IFACE, signature='us')
def WindowDestroyed(self, window_id, app_id):
pass
@dbus.service.signal(dbus_interface=WINSTACK_DBUS_IFACE, signature='usu')
def FocusedWindowChanged(self, window_id, app_id, stage):
pass
@dbus.service.method(WINSTACK_DBUS_NAME, out_signature='a(usbu)')
def GetWindowStack(self):
return self._sim.get_window_stack()
##################################################### main #######################################################
interval = 2
steps = 0
if len(sys.argv) > 2:
(interval, steps) = int(sys.argv[1]), int(sys.argv[2])
print("Starting WinStack mock service with interval = %d and %s simulation steps" % (interval, steps if steps > 0 else 'unlimited'))
sim = WinStackSim()
DBusGMainLoop(set_as_default=True)
myservice = WinStackServiceMock(sim)
sim.start_sim(interval, steps)
main_loop.run()
./tests/test-full-and-partial.sh 0000755 0000041 0000041 00000000667 12735444523 017077 0 ustar www-data www-data #!/bin/sh
# Search for "ls", print the results, this search should only include both
# "ls", not "ls.+"
test `unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/commands -s "ls" --no-search-reply -r | grep "\\" | wc -l` -eq 1 || exit 1
test `unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/commands -s "ls" --no-search-reply -r | grep "\\