File: test_main.cpp

package info (click to toggle)
libdnf 0.75.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,468 kB
  • sloc: cpp: 48,297; xml: 1,638; python: 1,537; ansic: 1,223; sql: 227; sh: 54; makefile: 39
file content (90 lines) | stat: -rw-r--r-- 2,757 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (C) 2012-2014 Red Hat, Inc.
 *
 * Licensed under the GNU Lesser General Public License Version 2.1
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "fixtures.h"
#include "test_suites.h"
#include "testsys.h"

#include <solv/util.h>

#include <assert.h>
#include <check.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

#define TESTREPODATADIR TESTDATADIR "/hawkey"

static int
init_test_globals(struct TestGlobals_s *tg, const char *repo_dir)
{
    int const len = strlen(repo_dir);
    if (repo_dir[len -1] != '/')
        tg->repo_dir = solv_dupjoin(repo_dir, "/", NULL);
    else
        tg->repo_dir = g_strdup(repo_dir);
    tg->tmpdir = g_strdup(UNITTEST_DIR);
    if (mkdtemp(tg->tmpdir) == NULL)
        return 1;
    tg->sack = NULL;
    return 0;
}

static void
free_test_globals(struct TestGlobals_s *tg)
{
    g_free(tg->tmpdir);
    g_free(tg->repo_dir);
}

int
main(int argc, const char **argv)
{
    int number_failed;

    if (init_test_globals(&test_globals, TESTREPODATADIR)) {
        fprintf(stderr, "failed initializing test engine.\n");
        exit(1);
    }
    printf("Tests using directory: %s\n", test_globals.tmpdir);

    SRunner *sr = srunner_create(sack_suite());
    srunner_add_suite(sr, iutil_suite());
    srunner_add_suite(sr, util_suite());
    srunner_add_suite(sr, reldep_suite());
    srunner_add_suite(sr, repo_suite());
    srunner_add_suite(sr, package_suite());
    srunner_add_suite(sr, packagelist_suite());
    srunner_add_suite(sr, packageset_suite());
    srunner_add_suite(sr, query_suite());
    srunner_add_suite(sr, selector_suite());
    srunner_add_suite(sr, subject_suite());
    srunner_add_suite(sr, goal_suite());
    srunner_add_suite(sr, advisory_suite());
    srunner_add_suite(sr, advisorypkg_suite());
    srunner_add_suite(sr, advisoryref_suite());
    srunner_run_all(sr, CK_NORMAL);
    number_failed = srunner_ntests_failed(sr);
    srunner_free(sr);

    free_test_globals(&test_globals);
    return (number_failed == 0) ? 0 : 1;
}