~jbicha/ubuntu/oneiric/gjs/1.29.18

« back to all changes in this revision

Viewing changes to test/gjs-unit.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-02-06 13:01:02 UTC
  • mfrom: (1.3.10 experimental)
  • Revision ID: james.westby@ubuntu.com-20110206130102-69xpqq0gql9fob01
Tags: 0.7.10-1
* New upstream release.
* debian/control.in:
  - Drop build-depend on libmozjs-dev
  - Make libgjs-dev depend on xulrunner-dev and libdbus-1-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    int code;
48
48
    char *filename;
49
49
    char *search_path[2];
 
50
    const char *test_filename = test_data;
 
51
    const char *js_version;
 
52
 
 
53
    js_version = gjs_context_scan_file_for_js_version(test_filename);
50
54
 
51
55
    search_path[0] = g_build_filename(top_srcdir, "test", "modules", NULL);
52
56
    search_path[1] = NULL;
53
57
 
54
 
    fix->context = gjs_context_new_with_search_path(search_path);
 
58
    fix->context = g_object_new (GJS_TYPE_CONTEXT,
 
59
                                 "search-path", search_path,
 
60
                                 "js-version", js_version,
 
61
                                 NULL);
55
62
    g_free(search_path[0]);
56
63
 
57
64
    /* Load jsUnit.js directly into global scope, rather than
111
118
    return result;
112
119
}
113
120
 
 
121
/* Always return an absolute filename and treat all absolute path elements as
 
122
 * absolute, not just the first one, e.g.
 
123
 *     ("/foo", "/bar", NULL) returns "/bar"
 
124
 * (g_build_filename would return "/foo/bar")
 
125
 * Returned path may still include '..' path elements.
 
126
 */
 
127
static char *
 
128
build_absolute_filename(const char *first_element,
 
129
                        ...)
 
130
{
 
131
    const char *element;
 
132
    va_list ap;
 
133
    char *cwd;
 
134
    char *path;
 
135
    GPtrArray *array;
 
136
 
 
137
    cwd = g_get_current_dir();
 
138
 
 
139
    array = g_ptr_array_new();
 
140
 
 
141
    g_ptr_array_add(array, cwd);
 
142
 
 
143
    va_start(ap, first_element);
 
144
 
 
145
    element = first_element;
 
146
    while (element != NULL) {
 
147
        if (g_path_is_absolute(element))
 
148
            g_ptr_array_set_size(array, 0);
 
149
 
 
150
        g_ptr_array_add(array, (char*)element);
 
151
 
 
152
        element = va_arg(ap, const char *);
 
153
    }
 
154
    va_end(ap);
 
155
 
 
156
    g_ptr_array_add(array, NULL);
 
157
 
 
158
    path = g_build_filenamev((char **)array->pdata);
 
159
 
 
160
    g_ptr_array_free(array, TRUE);
 
161
 
 
162
    g_free(cwd);
 
163
 
 
164
    return path;
 
165
}
 
166
 
114
167
int
115
168
main(int argc, char **argv)
116
169
{
117
 
    /* These are relative to top_builddir */
 
170
    /* These may be absolute or relative to top_builddir, depending whether
 
171
     * GJS_TOP_SRCDIR is absolute or not */
118
172
    const char * const path_directories[] = {
119
173
        GJS_TOP_SRCDIR"/modules",
120
174
        GJS_TOP_SRCDIR"/test/js/modules",
134
188
 
135
189
    working_dir = g_get_current_dir();
136
190
 
137
 
    if(g_path_is_absolute(argv[0]))
138
 
        gjs_unit_path = g_strdup(argv[0]);
139
 
    else
140
 
        gjs_unit_path = g_build_filename(working_dir, argv[0], NULL);
 
191
    gjs_unit_path = build_absolute_filename(argv[0], NULL);
141
192
 
142
193
    gjs_unit_dir = g_path_get_dirname(gjs_unit_path);
143
194
    /* the gjs-unit executable will be in <top_builddir>/.libs */
144
 
    top_builddir = g_build_filename(gjs_unit_dir, "..", NULL);
145
 
    top_srcdir = g_build_filename(top_builddir, GJS_TOP_SRCDIR, NULL);
 
195
    top_builddir = g_path_get_dirname(gjs_unit_dir);
 
196
    top_srcdir = build_absolute_filename(top_builddir, GJS_TOP_SRCDIR, NULL);
146
197
 
147
198
    /* Normalize, not strictly necessary */
148
199
    g_chdir(top_builddir);
166
217
        if (i != 0)
167
218
            g_string_append_c(path, ':');
168
219
 
169
 
        directory = g_build_filename(top_builddir, path_directories[i], NULL);
 
220
        directory = build_absolute_filename(top_builddir, path_directories[i], NULL);
170
221
        g_string_append(path, directory);
171
222
        g_free(directory);
172
223
    }