|
| 1 | +/* |
| 2 | + * Copyright (C) EdgeTX |
| 3 | + * |
| 4 | + * Based on code named |
| 5 | + * opentx - https://github.com/opentx/opentx |
| 6 | + * th9x - http://code.google.com/p/th9x |
| 7 | + * er9x - http://code.google.com/p/er9x |
| 8 | + * gruvin9x - http://code.google.com/p/gruvin9x |
| 9 | + * |
| 10 | + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html |
| 11 | + * |
| 12 | + * This program is free software; you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License version 2 as |
| 14 | + * published by the Free Software Foundation. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + */ |
| 21 | + |
| 22 | +#include "gtests.h" |
| 23 | + |
| 24 | +#include <storage/yaml/yaml_node.h> |
| 25 | +#include <storage/yaml/yaml_parser.h> |
| 26 | +#include <storage/yaml/yaml_tree_walker.h> |
| 27 | + |
| 28 | +struct TestStruct { |
| 29 | + uint8_t foo; |
| 30 | + uint8_t bar; |
| 31 | + |
| 32 | + TestStruct() : foo(0), bar(0) {} |
| 33 | +}; |
| 34 | + |
| 35 | +static const struct YamlNode struct_TestStruct[] = { |
| 36 | + YAML_UNSIGNED( "foo", 8 ), |
| 37 | + YAML_UNSIGNED( "bar", 8 ), |
| 38 | + YAML_END |
| 39 | +}; |
| 40 | + |
| 41 | +static const struct YamlNode struct_test[] = { |
| 42 | + YAML_STRUCT("testStruct", sizeof(TestStruct) * 8, struct_TestStruct, NULL), |
| 43 | + YAML_END |
| 44 | +}; |
| 45 | + |
| 46 | +static const struct YamlNode _root_node = YAML_ROOT( struct_test ); |
| 47 | + |
| 48 | +TEST(Yaml, SkipBlankLines) |
| 49 | +{ |
| 50 | + TestStruct t; |
| 51 | + |
| 52 | + YamlTreeWalker tree; |
| 53 | + tree.reset(&_root_node, (uint8_t*)&t); |
| 54 | + |
| 55 | + const char chunk_1[] = "testStruct:\n foo: 12\n"; |
| 56 | + const char chunk_2[] = "\n bar: 34\n\n fo"; |
| 57 | + const char chunk_3[] = "o: 45"; |
| 58 | + |
| 59 | + YamlParser yp; |
| 60 | + yp.init(YamlTreeWalker::get_parser_calls(), &tree); |
| 61 | + EXPECT_EQ(YamlParser::CONTINUE_PARSING, yp.parse(chunk_1, sizeof(chunk_1) - 1)); |
| 62 | + EXPECT_EQ(12, t.foo); |
| 63 | + |
| 64 | + EXPECT_EQ(YamlParser::CONTINUE_PARSING, yp.parse(chunk_2, sizeof(chunk_2) - 1)); |
| 65 | + EXPECT_EQ(34, t.bar); |
| 66 | + |
| 67 | + yp.set_eof(); |
| 68 | + EXPECT_EQ(YamlParser::CONTINUE_PARSING, yp.parse(chunk_3, sizeof(chunk_3) - 1)); |
| 69 | + EXPECT_EQ(45, t.foo); |
| 70 | +} |
0 commit comments