~noskcaj/ubuntu/vivid/gthumb/flickr-https

« back to all changes in this revision

Viewing changes to tests/glib-utils-test.c

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-04-08 06:31:09 UTC
  • mfrom: (1.3.20)
  • Revision ID: package-import@ubuntu.com-20140408063109-tk845map8ji6uxvd
Tags: 3:3.3.1.is.3.2.7-0ubuntu1
* Revert to newest upstream stable release. LP: #1290691
  - Refresh patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
 
 
3
/*
 
4
 *  GThumb
 
5
 *
 
6
 *  Copyright (C) 2008 Free Software Foundation, Inc.
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 2 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
#include <string.h>
 
24
#include "glib-utils.h"
 
25
 
 
26
 
 
27
static void
 
28
test_g_rand_string (void)
 
29
{
 
30
        char *id;
 
31
 
 
32
        id = _g_rand_string (8);
 
33
        g_assert_cmpint (strlen (id), == , 8);
 
34
        g_free (id);
 
35
 
 
36
        id = _g_rand_string (16);
 
37
        g_assert_cmpint (strlen (id), == , 16);
 
38
        g_free (id);
 
39
}
 
40
 
 
41
 
 
42
static void
 
43
test_regexp (void)
 
44
{
 
45
        GRegex   *re;
 
46
        char    **a;
 
47
        int       i, n, j;
 
48
        char    **b;
 
49
        char     *attributes;
 
50
 
 
51
        re = g_regex_new ("%prop\\{([^}]+)\\}", 0, 0, NULL);
 
52
        a = g_regex_split (re, "thunderbird -compose %prop{ Exif::Image::DateTime } %ask %prop{ File::Size }", 0);
 
53
        for (i = 0, n = 0; a[i] != NULL; i += 2)
 
54
                n++;
 
55
 
 
56
        b = g_new (char *, n + 1);
 
57
        for (i = 1, j = 0; a[i] != NULL; i += 2) {
 
58
                b[j++] = g_strstrip (a[i]);
 
59
        }
 
60
        b[j] = NULL;
 
61
        attributes = g_strjoinv (",", b);
 
62
        g_print ("==> %s\n", attributes);
 
63
 
 
64
        g_free (attributes);
 
65
        g_free (b);
 
66
        g_strfreev (a);
 
67
        g_regex_unref (re);
 
68
}
 
69
 
 
70
 
 
71
int
 
72
main (int   argc,
 
73
      char *argv[])
 
74
{
 
75
        g_type_init ();
 
76
        g_test_init (&argc, &argv, NULL);
 
77
 
 
78
        g_test_add_func ("/glib-utils/_g_rand_string/1", test_g_rand_string);
 
79
 
 
80
        test_regexp ();
 
81
 
 
82
        return g_test_run ();
 
83
}