File: test-cut-test-data.c

package info (click to toggle)
cutter-testing-framework 1.1.7-1.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 18,556 kB
  • sloc: ansic: 79,864; xml: 38,680; sh: 10,266; makefile: 2,324; ruby: 845; cpp: 697
file content (138 lines) | stat: -rw-r--r-- 3,365 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <gcutter.h>
#include <cutter/cut-test-data.h>
#include "../lib/cuttest-utils.h"

void test_new (void);
void test_new_empty (void);
void test_new_and_destroy (void);
void test_set_name (void);
void test_to_xml (void);
void test_to_xml_empty (void);
void test_to_xml_string (void);

static CutTestData *test_data;
static gboolean destroy_called;
static gchar *destroyed_string;
static GString *string;

void
cut_setup (void)
{
    test_data = NULL;
    destroy_called = FALSE;
    destroyed_string = NULL;
    string = NULL;
}

void
cut_teardown (void)
{
    if (test_data)
        g_object_unref(test_data);

    if (destroyed_string)
        g_free(destroyed_string);

    if (string)
        g_string_free(string, TRUE);
}

void
test_new (void)
{
    const gchar name[] = "sample test data";
    gchar value[] = "sample test value";

    test_data = cut_test_data_new(name, value, NULL);
    cut_assert_equal_string(name, cut_test_data_get_name(test_data));
    cut_assert_equal_string(value, cut_test_data_get_value(test_data));
}

void
test_new_empty (void)
{
    test_data = cut_test_data_new_empty();
    cut_assert_equal_string(NULL, cut_test_data_get_name(test_data));
    cut_assert_equal_string(NULL, cut_test_data_get_value(test_data));
}

static void
string_data_free (gpointer data)
{
    destroy_called = TRUE;
    destroyed_string = data;
}

void
test_new_and_destroy (void)
{
    const gchar name[] = "sample test data";
    const gchar value[] = "sample test value";

    test_data = cut_test_data_new(name, g_strdup(value), string_data_free);
    cut_assert_false(destroy_called);
    cut_assert_equal_string(NULL, destroyed_string);
    g_object_unref(test_data);
    test_data = NULL;
    cut_assert_true(destroy_called);
    cut_assert_equal_string(value, destroyed_string);
}

void
test_set_name (void)
{
    const gchar name[] = "sample test data";
    const gchar changed_name[] = "changed name";

    test_data = cut_test_data_new(name, NULL, NULL);
    cut_assert_equal_string(name, cut_test_data_get_name(test_data));

    cut_test_data_set_name(test_data, changed_name);
    cut_assert_equal_string(changed_name, cut_test_data_get_name(test_data));
}

void
test_to_xml (void)
{
    const gchar name[] = "sample test data";
    const gchar value[] = "sample test value";
    const gchar expected[] =
        "<test-data>\n"
        "  <name>sample test data</name>\n"
        "</test-data>\n";

    test_data = cut_test_data_new(name, g_strdup(value), g_free);
    cut_assert_equal_string_with_free(expected, cut_test_data_to_xml(test_data));
}

void
test_to_xml_empty (void)
{
    const gchar expected[] =
        "<test-data>\n"
        "</test-data>\n";

    test_data = cut_test_data_new_empty();
    cut_assert_equal_string_with_free(expected, cut_test_data_to_xml(test_data));
}

void
test_to_xml_string (void)
{
    const gchar name[] = "sample test data";
    const gchar value[] = "sample test value";
    const gchar expected[] =
        "before content\n"
        "  <test-data>\n"
        "    <name>sample test data</name>\n"
        "  </test-data>\n";

    test_data = cut_test_data_new(name, g_strdup(value), g_free);
    string = g_string_new("before content\n");
    cut_test_data_to_xml_string(test_data, string, 2);
    cut_assert_equal_string(expected, string->str);
}

/*
vi:ts=4:nowrap:ai:expandtab:sw=4
*/