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_boolean.h>
22 
23 TEST_GROUP(sml_boolean);
24 
25 extern sml_buffer *buf;
26 
TEST_SETUP(sml_boolean)27 TEST_SETUP(sml_boolean) {
28 	buf = sml_buffer_init(512);
29 }
30 
TEST_TEAR_DOWN(sml_boolean)31 TEST_TEAR_DOWN(sml_boolean) {
32 	sml_buffer_free(buf);
33 }
34 
TEST(sml_boolean,init)35 TEST(sml_boolean, init) {
36 	sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE);
37 	TEST_ASSERT_NOT_NULL(b);
38 	TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b);
39 	sml_boolean_free( b );
40 }
41 
TEST(sml_boolean,parse_true)42 TEST(sml_boolean, parse_true) {
43 	hex2binary("420F", sml_buf_get_current_buf(buf));
44 	sml_boolean *b = sml_boolean_parse(buf);
45 	TEST_ASSERT_NOT_NULL(b);
46 	TEST_ASSERT_EQUAL(SML_BOOLEAN_TRUE, *b);
47 	sml_boolean_free( b );
48 }
49 
TEST(sml_boolean,parse_false)50 TEST(sml_boolean, parse_false) {
51 	hex2binary("4200", sml_buf_get_current_buf(buf));
52 	sml_boolean *b = sml_boolean_parse(buf);
53 	TEST_ASSERT_NOT_NULL(b);
54 	TEST_ASSERT_EQUAL(SML_BOOLEAN_FALSE, *b);
55 	TEST_ASSERT_EQUAL(2, buf->cursor);
56 	sml_boolean_free( b );
57 }
58 
TEST(sml_boolean,parse_optional)59 TEST(sml_boolean, parse_optional) {
60 	hex2binary("01", sml_buf_get_current_buf(buf));
61 	sml_boolean *b = sml_boolean_parse(buf);
62 	TEST_ASSERT_NULL(b);
63 	TEST_ASSERT_FALSE(sml_buf_has_errors(buf));
64 	sml_boolean_free( b );
65 }
66 
TEST(sml_boolean,write_true)67 TEST(sml_boolean, write_true) {
68 	sml_boolean *b = sml_boolean_init(SML_BOOLEAN_TRUE);
69 	sml_boolean_write(b, buf);
70 	expected_buf(buf, "42FF", 2);
71 	sml_boolean_free( b );
72 }
73 
TEST(sml_boolean,write_false)74 TEST(sml_boolean, write_false) {
75 	sml_boolean *b = sml_boolean_init(SML_BOOLEAN_FALSE);
76 	sml_boolean_write(b, buf);
77 	expected_buf(buf, "4200", 2);
78 	sml_boolean_free( b );
79 }
80 
TEST(sml_boolean,write_optional)81 TEST(sml_boolean, write_optional) {
82 	sml_boolean_write(0, buf);
83 	expected_buf(buf, "01", 1);
84 }
85 
86 
TEST_GROUP_RUNNER(sml_boolean)87 TEST_GROUP_RUNNER(sml_boolean) {
88 	RUN_TEST_CASE(sml_boolean, init);
89 	RUN_TEST_CASE(sml_boolean, parse_true);
90 	RUN_TEST_CASE(sml_boolean, parse_false);
91 	RUN_TEST_CASE(sml_boolean, parse_optional);
92 	RUN_TEST_CASE(sml_boolean, write_true);
93 	RUN_TEST_CASE(sml_boolean, write_false);
94 	RUN_TEST_CASE(sml_boolean, write_optional);
95 }
96 
97