File: check_amf.c

package info (click to toggle)
flvmeta 1.2.2-2~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,000 kB
  • sloc: ansic: 14,457; xml: 120; makefile: 5
file content (178 lines) | stat: -rw-r--r-- 4,997 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
    FLVMeta - FLV Metadata Editor

    Copyright (C) 2007-2016 Marc Noirot <marc.noirot AT gmail.com>

    This file is part of FLVMeta.

    FLVMeta 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.

    FLVMeta 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 FLVMeta; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <check.h>
#include <stdlib.h>
#include <string.h>
#include "src/amf.h"

amf_data * data;

void teardown(void) {
    amf_data_free(data);
}

/**
    AMF number
*/
void setup_amf_number(void) {
    data = amf_number_new(0);
}

START_TEST(test_amf_number_new) {
    ck_assert_ptr_nonnull(data);
    ck_assert_int_eq(amf_data_get_type(data), AMF_TYPE_NUMBER);
    /* AMF number size == 1(header) + 8(data) -> 9 bytes */
    ck_assert_int_eq(amf_data_size(data), 9);
    ck_assert_int_eq(amf_number_get_value(data), 0);
}
END_TEST

START_TEST(test_amf_number_set_value) {
    amf_number_set_value(data, -512.78);
    ck_assert_double_eq(amf_number_get_value(data), -512.78);
}
END_TEST

START_TEST(test_amf_number_null) {
    ck_assert_int_eq(amf_number_get_value(NULL), 0);
    /* just making sure we don't core dump */
    amf_number_set_value(NULL, 12);
}
END_TEST

/**
    AMF boolean
*/
void setup_amf_boolean(void) {
    data = amf_boolean_new(1);
}

START_TEST(test_amf_boolean_new) {
    ck_assert_ptr_nonnull(data);
    ck_assert_int_eq(amf_data_get_type(data), AMF_TYPE_BOOLEAN);
    /* AMF boolean size == 1(header) + 1(data) -> 2 bytes */
    ck_assert_int_eq(amf_data_size(data), 2);
    ck_assert_int_eq(amf_boolean_get_value(data), 1);
}
END_TEST

START_TEST(test_amf_boolean_set_value) {
    amf_boolean_set_value(data, 0);
    ck_assert_int_eq(amf_boolean_get_value(data), 0);
}
END_TEST

START_TEST(test_amf_boolean_null) {
    ck_assert_int_eq(amf_boolean_get_value(NULL), 0);
    /* just making sure we don't core dump */
    amf_boolean_set_value(NULL, 12);
}
END_TEST

/**
    AMF string
*/
START_TEST(test_amf_str) {
    char * str = "hello world";
    int length = strlen(str);
    data = amf_str(str);

    ck_assert_ptr_nonnull(data);
    ck_assert_int_eq(amf_data_get_type(data), AMF_TYPE_STRING);
    /* AMF string size == 1(header) + 2(string length) + length */
    ck_assert_int_eq(amf_data_size(data), 3 + length);
    ck_assert_int_eq(amf_string_get_size(data), length);
    ck_assert_str_eq(amf_string_get_bytes(data), str);
}
END_TEST

START_TEST(test_amf_str_null) {
    data = amf_str(NULL);

    ck_assert_int_eq(amf_string_get_size(data), 0);
    ck_assert_str_eq(amf_string_get_bytes(data), "");

    amf_data_free(data);
}
END_TEST

START_TEST(test_amf_string_new) {
    char * str = "hello world";
    data = amf_string_new(str, 5);

    ck_assert_int_eq(amf_string_get_size(data), 5);
    ck_assert_str_eq(amf_string_get_bytes(data), "hello");

    amf_data_free(data);
}
END_TEST

START_TEST(test_amf_string_new_null) {
    data = amf_string_new(NULL, 12);

    ck_assert_ptr_nonnull(data);
    ck_assert_int_eq(amf_string_get_size(data), 0);
    ck_assert_str_eq(amf_string_get_bytes(data), "");

    amf_data_free(data);
}
END_TEST

START_TEST(test_amf_string_null) {
    ck_assert_int_eq(amf_string_get_size(NULL), 0);
    ck_assert_ptr_null(amf_string_get_bytes(NULL));
}
END_TEST

/**
    AMF Types Suite
*/
Suite * amf_types_suite(void) {
    Suite * s = suite_create("AMF types");

    /* AMF number test case */
    TCase * tc_number = tcase_create("AMF number");
    tcase_add_checked_fixture(tc_number, setup_amf_number, teardown);
    tcase_add_test(tc_number, test_amf_number_new);
    tcase_add_test(tc_number, test_amf_number_set_value);
    tcase_add_test(tc_number, test_amf_number_null);
    suite_add_tcase(s, tc_number);

    /* AMF boolean test case */
    TCase * tc_boolean = tcase_create("AMF boolean");
    tcase_add_checked_fixture(tc_boolean, setup_amf_boolean, teardown);
    tcase_add_test(tc_boolean, test_amf_boolean_new);
    tcase_add_test(tc_boolean, test_amf_boolean_set_value);
    tcase_add_test(tc_boolean, test_amf_boolean_null);
    suite_add_tcase(s, tc_boolean);

    /* AMF string test case */
    TCase * tc_string = tcase_create("AMF string");
    tcase_add_test(tc_string, test_amf_str);
    tcase_add_test(tc_string, test_amf_str_null);
    tcase_add_test(tc_string, test_amf_string_new);
    tcase_add_test(tc_string, test_amf_string_new_null);
    tcase_add_test(tc_string, test_amf_string_null);
    suite_add_tcase(s, tc_string);

    return s;
}