1 // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed
2 // DAI-Labor, TU-Berlin
3 //
4 // This file is part of libSML.
5 //
6 // libSML is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // libSML is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libSML. If not, see <http://www.gnu.org/licenses/>.
18
19 #include "../unity/unity_fixture.h"
20 #include "test_helper.h"
21 #include <sml/sml_time.h>
22
23 TEST_GROUP(sml_time);
24
25 extern sml_buffer *buf;
26
TEST_SETUP(sml_time)27 TEST_SETUP(sml_time) {
28 buf = sml_buffer_init(512);
29 }
30
TEST_TEAR_DOWN(sml_time)31 TEST_TEAR_DOWN(sml_time) {
32 sml_buffer_free(buf);
33 }
34
TEST(sml_time,init)35 TEST(sml_time, init) {
36 sml_time *t = sml_time_init();
37 TEST_ASSERT_NOT_NULL(t);
38 sml_time_free( t );
39 }
40
TEST(sml_time,parse_sec_index)41 TEST(sml_time, parse_sec_index) {
42 hex2binary("72620165000000FF", sml_buf_get_current_buf(buf));
43 sml_time *t = sml_time_parse(buf);
44
45 TEST_ASSERT_NOT_NULL(t);
46 TEST_ASSERT_EQUAL(SML_TIME_SEC_INDEX, *(t->tag));
47 TEST_ASSERT_EQUAL(8, buf->cursor);
48
49 sml_time_free( t );
50 }
51
TEST(sml_time,parse_timestamp)52 TEST(sml_time, parse_timestamp) {
53 hex2binary("72620265000000FF", sml_buf_get_current_buf(buf));
54 sml_time *t = sml_time_parse(buf);
55
56 TEST_ASSERT_NOT_NULL(t);
57 TEST_ASSERT_EQUAL(SML_TIME_TIMESTAMP, *(t->tag));
58 TEST_ASSERT_EQUAL(8, buf->cursor);
59
60 sml_time_free( t );
61 }
62
TEST(sml_time,parse_optional)63 TEST(sml_time, parse_optional) {
64 hex2binary("01", sml_buf_get_current_buf(buf));
65 sml_time *t = sml_time_parse(buf);
66
67 TEST_ASSERT_NULL(t);
68 TEST_ASSERT_EQUAL(1, buf->cursor);
69
70 sml_time_free( t );
71 }
72
TEST(sml_time,write_sec_index)73 TEST(sml_time, write_sec_index) {
74 sml_time *t = sml_time_init();
75 t->data.sec_index = sml_u32_init(255);
76 t->tag = sml_u8_init(SML_TIME_SEC_INDEX);
77
78 sml_time_write(t, buf);
79 expected_buf(buf, "72620165000000FF", 8);
80
81 sml_time_free( t );
82 }
83
TEST(sml_time,write_optional)84 TEST(sml_time, write_optional) {
85 sml_time_write(0, buf);
86 expected_buf(buf, "01", 1);
87 }
88
TEST_GROUP_RUNNER(sml_time)89 TEST_GROUP_RUNNER(sml_time) {
90 RUN_TEST_CASE(sml_time, init);
91 RUN_TEST_CASE(sml_time, parse_sec_index);
92 RUN_TEST_CASE(sml_time, parse_timestamp);
93 RUN_TEST_CASE(sml_time, parse_optional);
94 RUN_TEST_CASE(sml_time, write_sec_index);
95 RUN_TEST_CASE(sml_time, write_optional);
96 }
97
98