/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2007 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "config.h" #include #include #include #include #ifdef HAVE_UNISTD_H #include #endif /* HAVE_UNISTD_H */ #include #include "pk-debug.h" #include "pk-task-common.h" /** * pk_task_filter_check_part: **/ gboolean pk_task_filter_check_part (const gchar *filter) { if (filter == NULL) { return FALSE; } if (strlen (filter) == 0) { return FALSE; } if (strcmp (filter, "none") == 0) { return TRUE; } if (strcmp (filter, "installed") == 0) { return TRUE; } if (strcmp (filter, "~installed") == 0) { return TRUE; } if (strcmp (filter, "devel") == 0) { return TRUE; } if (strcmp (filter, "~devel") == 0) { return TRUE; } if (strcmp (filter, "gui") == 0) { return TRUE; } if (strcmp (filter, "~gui") == 0) { return TRUE; } return FALSE; } /** * pk_task_filter_check: **/ gboolean pk_task_filter_check (const gchar *filter) { gchar **sections; guint i; guint length; gboolean ret; if (filter == NULL) { pk_warning ("filter null"); return FALSE; } if (strlen (filter) == 0) { pk_warning ("filter zero length"); return FALSE; } /* split by delimeter ';' */ sections = g_strsplit (filter, ";", 0); length = g_strv_length (sections); ret = FALSE; for (i=0; i void libst_task_common (LibSelfTest *test) { gboolean ret; gchar *text; const gchar *temp; if (libst_start (test, "PkTaskCommon", CLASS_AUTO) == FALSE) { return; } /************************************************************ **************** FILTERS ****************** ************************************************************/ temp = NULL; libst_title (test, "test a fail filter (null)"); ret = pk_task_filter_check (temp); if (ret == FALSE) { libst_success (test, NULL); } else { libst_failed (test, "passed the filter '%s'", temp); } /************************************************************/ temp = ""; libst_title (test, "test a fail filter ()"); ret = pk_task_filter_check (temp); if (ret == FALSE) { libst_success (test, NULL); } else { libst_failed (test, "passed the filter '%s'", temp); } /************************************************************/ temp = ";"; libst_title (test, "test a fail filter (;)"); ret = pk_task_filter_check (temp); if (ret == FALSE) { libst_success (test, NULL); } else { libst_failed (test, "passed the filter '%s'", temp); } /************************************************************/ temp = "moo"; libst_title (test, "test a fail filter (invalid)"); ret = pk_task_filter_check (temp); if (ret == FALSE) { libst_success (test, NULL); } else { libst_failed (test, "passed the filter '%s'", temp); } /************************************************************/ temp = "moo;foo"; libst_title (test, "test a fail filter (invalid, multiple)"); ret = pk_task_filter_check (temp); if (ret == FALSE) { libst_success (test, NULL); } else { libst_failed (test, "passed the filter '%s'", temp); } /************************************************************/ temp = "gui;;"; libst_title (test, "test a fail filter (valid then zero length)"); ret = pk_task_filter_check (temp); if (ret == FALSE) { libst_success (test, NULL); } else { libst_failed (test, "passed the filter '%s'", temp); } /************************************************************/ temp = "none"; libst_title (test, "test a pass filter (none)"); ret = pk_task_filter_check (temp); if (ret == TRUE) { libst_success (test, NULL); } else { libst_failed (test, "failed the filter '%s'", temp); } /************************************************************/ temp = "gui"; libst_title (test, "test a pass filter (single)"); ret = pk_task_filter_check (temp); if (ret == TRUE) { libst_success (test, NULL); } else { libst_failed (test, "failed the filter '%s'", temp); } /************************************************************/ temp = "devel;~gui"; libst_title (test, "test a pass filter (multiple)"); ret = pk_task_filter_check (temp); if (ret == TRUE) { libst_success (test, NULL); } else { libst_failed (test, "failed the filter '%s'", temp); } /************************************************************/ temp = "~gui;~installed"; libst_title (test, "test a pass filter (multiple2)"); ret = pk_task_filter_check (temp); if (ret == TRUE) { libst_success (test, NULL); } else { libst_failed (test, "failed the filter '%s'", temp); } libst_end (test); } #endif