20221212
[devspec.git] / devspec.en_US / project / recutils / torture / rec-parser / rec-parse-record-str.c
blobd337a12543bf0c8156d709fc731384c294a5d516
1 /* -*- mode: C -*-
3 * File: rec-parse-record-str.c
4 * Date: Sat Nov 13 20:16:11 2010
6 * GNU recutils - rec_parse_record_str unit tests.
8 */
10 /* Copyright (C) 2010-2015 Jose E. Marchesi */
12 /* This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <config.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <check.h>
31 #include <rec.h>
33 /*-
34 * Test: rec_parse_record_str_nominal
35 * Unit: rec_parse_record_str
36 * Description:
37 * + Parse valid records from strings.
39 START_TEST(rec_parse_record_str_nominal)
41 rec_record_t record;
42 rec_field_t field;
43 char *fname;
45 record = rec_parse_record_str ("foo: bar");
46 fail_if (record == NULL);
47 fname = rec_parse_field_name_str ("foo");
48 fail_if (fname == NULL);
49 field = (rec_field_t) rec_mset_get_at (rec_record_mset (record), MSET_FIELD, 0);
50 fail_if (strcmp (rec_field_value (field), "bar") != 0);
51 fail_if (!rec_field_name_equal_p (fname,
52 rec_field_name (field)));
53 free (fname);
54 rec_record_destroy (record);
56 END_TEST
58 /*-
59 * Test: rec_parse_record_str_invalid
60 * Unit: rec_parse_record_str
61 * Description:
62 * + Try to parse invalid records from strings.
64 START_TEST(rec_parse_record_str_invalid)
66 rec_record_t record;
68 record = rec_parse_record_str ("");
69 fail_if (record != NULL);
71 record = rec_parse_record_str (" ");
72 fail_if (record != NULL);
74 END_TEST
77 * Test creation function.
79 TCase *
80 test_rec_parse_record_str (void)
82 TCase *tc = tcase_create ("rec_parse_record_str");
83 tcase_add_test (tc, rec_parse_record_str_nominal);
84 tcase_add_test (tc, rec_parse_record_str_invalid);
86 return tc;
89 /* End of rec-parse-record-str.c */