Skip to content

Commit 8904cbe

Browse files
authored
Merge pull request #12 from tobozo/atmega-tests
Atmega tests
2 parents 9f0988b + 4ba933f commit 8904cbe

File tree

9 files changed

+430
-101
lines changed

9 files changed

+430
-101
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
lint:
2323
runs-on: ubuntu-latest
2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v3
2626
- uses: arduino/arduino-lint-action@v1
2727
with:
2828
project-type: library
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#pragma GCC diagnostic ignored "-Wunused-variable"
2+
3+
#include <ArduinoJson.h>
4+
#include <YAMLDuino.h>
5+
6+
const char* yaml_sample_str = R"_YAML_STRING_(
7+
first: true
8+
blah:
9+
nope: ["n","o","p","e"]
10+
integer: 12345
11+
float: 12.3323
12+
last: true
13+
14+
)_YAML_STRING_";
15+
16+
// exact JSON representation of yaml_sample_str
17+
const char* json_sample_str = R"_JSON_STRING_(
18+
{
19+
"first": true,
20+
"blah": { "nope": [ "n", "o", "p", "e" ] },
21+
"integer": 12345,
22+
"float": 12.3323,
23+
"last": true
24+
}
25+
26+
)_JSON_STRING_";
27+
28+
29+
const size_t yaml_str_size = strlen(yaml_sample_str);
30+
const size_t json_str_size = strlen(json_sample_str);
31+
int test_number = 1;
32+
33+
34+
// uncomment/comment as needed
35+
36+
#define TEST_YAML_Stream_To_ArduinoJsonObject
37+
#define TEST_YAML_String_To_ArduinoJsonObject
38+
#define TEST_YAML_Stream_To_ArduinoJsonDocument
39+
#define TEST_YAML_String_To_ArduinoJsonDocument
40+
41+
42+
43+
void test_deserializeYml_JsonObject_YamlStream()
44+
{
45+
#if defined TEST_YAML_Stream_To_ArduinoJsonObject
46+
String yaml_str = String( yaml_sample_str );
47+
StringStream yaml_stream( yaml_str );
48+
StaticJsonDocument<128> json_doc;
49+
JsonObject json_obj = json_doc.to<JsonObject>();
50+
auto err = deserializeYml( json_obj, yaml_stream ); // deserialize yaml stream to JsonObject
51+
if( err ) {
52+
Serial.printf("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
53+
return;
54+
}
55+
const size_t bytes_out = serializeJsonPretty( json_obj, Serial ); // print deserialized JsonObject
56+
#endif
57+
}
58+
59+
60+
void test_deserializeYml_JsonObject_YamlString()
61+
{
62+
#if defined TEST_YAML_String_To_ArduinoJsonObject
63+
StaticJsonDocument<128> json_doc;
64+
JsonObject json_obj = json_doc.to<JsonObject>();
65+
auto err = deserializeYml( json_obj, yaml_sample_str ); // deserialize yaml string to JsonObject
66+
if( err ) {
67+
Serial.printf("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
68+
return;
69+
}
70+
const size_t bytes_out = serializeJsonPretty( json_obj, Serial ); // print deserialized JsonObject
71+
#endif
72+
}
73+
74+
75+
void test_deserializeYml_JsonDocument_YamlStream()
76+
{
77+
#if defined TEST_YAML_Stream_To_ArduinoJsonDocument
78+
StaticJsonDocument<128> json_doc;
79+
String yaml_str = String( yaml_sample_str );
80+
StringStream yaml_stream( yaml_str );
81+
auto err = deserializeYml( json_doc, yaml_stream ); // deserialize yaml stream to JsonDocument
82+
if( err ) {
83+
Serial.printf("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
84+
return;
85+
}
86+
const size_t bytes_out = serializeJsonPretty( json_doc, Serial ); // print deserialized JsonObject
87+
#endif
88+
}
89+
90+
91+
void test_deserializeYml_JsonDocument_YamlString()
92+
{
93+
#if defined TEST_YAML_String_To_ArduinoJsonDocument
94+
String yaml_str( yaml_sample_str );
95+
StaticJsonDocument<128> json_doc;
96+
auto err = deserializeYml( json_doc, yaml_str.c_str() ); // deserialize yaml string to JsonDocument
97+
if( err ) {
98+
Serial.printf("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
99+
return;
100+
}
101+
JsonObject json_obj = json_doc.as<JsonObject>();
102+
const size_t bytes_out = serializeJsonPretty( json_obj, Serial ); // print deserialized JsonObject
103+
#endif
104+
}
105+
106+
107+
108+
void setup()
109+
{
110+
Serial.begin(115200);
111+
delay(5000);
112+
Serial.printf("Welcome to the YAML Test sketch\nRam free: %d bytes", HEAP_AVAILABLE() );
113+
114+
// YAML::setLogLevel( YAML::LogLevelDebug ); // override sketch debug level (otherwise inherited)
115+
// YAML::setJSONIndent(" ", 8 ); // JSON -> two spaces per indent level, unfold objets up to 8 nesting levels
116+
// YAML::setYAMLIndent( 3 ); // annoy your friends with 3 spaces indentation
117+
118+
test_deserializeYml_JsonDocument_YamlStream();
119+
test_deserializeYml_JsonDocument_YamlString();
120+
test_deserializeYml_JsonObject_YamlString();
121+
test_deserializeYml_JsonObject_YamlStream();
122+
123+
}
124+
125+
126+
void loop()
127+
{
128+
129+
}
130+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#include <ArduinoJson.h>
2+
//#define YAML_DISABLE_ARDUINOJSON
3+
#include <YAMLDuino.h>
4+
5+
const char* yaml_sample_str = R"_YAML_STRING_(
6+
first: true
7+
blah:
8+
nope: ["n","o","p","e"]
9+
integer: 12345
10+
float: 12.3323
11+
last: true
12+
13+
)_YAML_STRING_";
14+
15+
// exact JSON representation of yaml_sample_str
16+
const char* json_sample_str = R"_JSON_STRING_(
17+
{
18+
"first": true,
19+
"blah": { "nope": [ "n", "o", "p", "e" ] },
20+
"integer": 12345,
21+
"float": 12.3323,
22+
"last": true
23+
}
24+
25+
)_JSON_STRING_";
26+
27+
28+
const size_t yaml_str_size = strlen(yaml_sample_str);
29+
const size_t json_str_size = strlen(json_sample_str);
30+
31+
32+
int test_number = 1;
33+
34+
35+
// uncomment/comment as needed
36+
37+
#define TEST_YAML_TO_JSON
38+
#define TEST_YAML_TO_JSON_PRETTY
39+
#define TEST_JSON_TO_YAML
40+
#define TEST_ArduinoJsonObject_TO_YAML_Stream
41+
#define TEST_ArduinoJsonObject_TO_YAML_String
42+
43+
44+
void test_Yaml2JsonPretty()
45+
{
46+
#if defined TEST_YAML_TO_JSON
47+
String yaml_str = String( yaml_sample_str );
48+
StringStream yaml_stream( yaml_str );
49+
serializeYml( yaml_stream, Serial, YAMLParser::OUTPUT_JSON_PRETTY );
50+
#endif
51+
}
52+
53+
void test_Yaml2Json()
54+
{
55+
#if defined TEST_YAML_TO_JSON_PRETTY
56+
String yaml_str = String( yaml_sample_str );
57+
StringStream yaml_stream( yaml_str );
58+
serializeYml( yaml_stream, Serial, YAMLParser::OUTPUT_JSON );
59+
#endif
60+
}
61+
62+
63+
void test_Json2Yaml()
64+
{
65+
#if defined TEST_JSON_TO_YAML
66+
String yaml_str = String( yaml_sample_str );
67+
StringStream yaml_stream( yaml_str );
68+
serializeYml( yaml_stream, Serial, YAMLParser::OUTPUT_YAML );
69+
#endif
70+
}
71+
72+
73+
void test_serializeYml_JsonObject_YamlStream()
74+
{
75+
#if defined TEST_ArduinoJsonObject_TO_YAML_Stream
76+
// Convert JsonObject to yaml
77+
String json_str = String( json_sample_str );
78+
DynamicJsonDocument doc(128); // create and populate a JsonObject
79+
auto err = deserializeJson( doc, json_str.c_str() );
80+
if( err ) {
81+
Serial.printf("Unable to deserialize demo JSON to JsonObject: %s", err.c_str() );
82+
return;
83+
}
84+
JsonObject json_obj = doc.as<JsonObject>();
85+
const size_t bytes_out = serializeYml( json_obj, Serial );
86+
#endif
87+
}
88+
89+
90+
void test_serializeYml_JsonObject_YamlString()
91+
{
92+
#if defined TEST_ArduinoJsonObject_TO_YAML_String
93+
// Convert JsonObject to yaml
94+
String str_yaml_out = ""; // YAML output string
95+
String json_str = String( json_sample_str );
96+
DynamicJsonDocument doc(128); // create and populate a JsonObject
97+
auto err = deserializeJson( doc, json_str.c_str() );
98+
if( err ) {
99+
Serial.printf("Unable to deserialize demo JSON to JsonObject: %s", err.c_str() );
100+
return;
101+
}
102+
JsonObject json_obj = doc.as<JsonObject>();
103+
const size_t bytes_out = serializeYml( json_obj, str_yaml_out );
104+
Serial.println( str_yaml_out );
105+
#endif
106+
}
107+
108+
109+
110+
111+
void setup()
112+
{
113+
Serial.begin(115200);
114+
delay(5000);
115+
Serial.printf("Welcome to the YAML Test sketch\nRam free: %d bytes", HEAP_AVAILABLE() );
116+
117+
// YAML::setLogLevel( YAML::LogLevelDebug ); // override sketch debug level (otherwise inherited)
118+
// YAML::setJSONIndent(" ", 8 ); // JSON -> two spaces per indent level, unfold objets up to 8 nesting levels
119+
// YAML::setYAMLIndent( 3 ); // annoy your friends with 3 spaces indentation
120+
121+
test_Yaml2JsonPretty();
122+
test_Yaml2Json();
123+
test_Json2Yaml();
124+
test_serializeYml_JsonObject_YamlString();
125+
test_serializeYml_JsonObject_YamlStream();
126+
}
127+
128+
129+
void loop()
130+
{
131+
132+
}
133+

examples/test/platformio.ini

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ src_dir = src
88
framework = arduino
99
lib_deps =
1010
bblanchon/ArduinoJson @ ^6
11-
tobozo/YAMLDuino @ ^1.2
11+
; tobozo/YAMLDuino @ ^1.2
12+
YAMLDuino
1213
lib_ldf_mode = deep
1314

1415

@@ -18,3 +19,13 @@ platform = espressif32
1819
; or alternate platform/package:
1920
;platform = https://github.com/tasmota/platform-espressif32
2021
;platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32/releases/download/2.0.5/esp32-2.0.5.zip
22+
23+
24+
[env:rp2040_pico]
25+
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
26+
platform_packages = framework-arduinopico @ https://github.com/earlephilhower/arduino-pico/releases/download/2.6.1/rp2040-2.6.1.zip
27+
board = generic
28+
framework = arduino
29+
board_build.filesystem_size = 0.5m ; adjust if needed
30+
board_upload.maximum_size = 16777216
31+
board_build.arduino.earlephilhower.boot2_source = boot2_w25q080_4_padded_checksum.S

examples/test/src/test.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void test_Yaml_Stream_Loader()
227227
String yaml_str = String( yaml_sample_str );
228228
StringStream yaml_stream( yaml_str );
229229
DynamicJsonDocument json_doc(2048);
230-
JsonObject json_obj = json_doc.as<JsonObject>();
230+
JsonObject json_obj = json_doc.to<JsonObject>();
231231
auto err = deserializeYml( json_obj, yaml_stream ); // deserialize yaml stream to JsonObject
232232
if( err ) {
233233
YAML_LOG_n("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
@@ -244,7 +244,7 @@ void test_Yaml_Stream_Loader()
244244
{
245245
YAML_LOG_n( "[TEST #%d] YAML string to JsonObject -> deserializeYml(json_obj, yaml_sample_str):", test_number++ );
246246
DynamicJsonDocument json_doc(2048);
247-
JsonObject json_obj = json_doc.as<JsonObject>();
247+
JsonObject json_obj = json_doc.to<JsonObject>();
248248
auto err = deserializeYml( json_obj, yaml_sample_str ); // deserialize yaml string to JsonObject
249249
if( err ) {
250250
YAML_LOG_n("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
@@ -456,12 +456,16 @@ void setup()
456456
#pragma message "Enabling ArduinoJson tests"
457457
Serial.println("\n");
458458
YAML_LOG_n("### YAML=>JSON and JSON=>YAML using ArduinoJson\n");
459-
test_deserializeYml_JsonObject_YamlString();
459+
#if !defined ARDUINO_ARCH_AVR
460+
test_deserializeYml_JsonDocument_YamlStream();
461+
test_deserializeYml_JsonDocument_YamlString();
462+
test_deserializeYml_JsonObject_YamlString();
463+
test_serializeYml_JsonObject_YamlString();
464+
#endif
460465
test_deserializeYml_JsonObject_YamlStream();
461-
test_deserializeYml_JsonDocument_YamlStream();
462-
test_deserializeYml_JsonDocument_YamlString();
463466
test_serializeYml_JsonObject_YamlStream();
464-
test_serializeYml_JsonObject_YamlString();
467+
468+
465469
YAML_LOG_n("### ArduinoJson tests complete\n");
466470
#endif
467471

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=YAMLDuino
2-
version=1.2.8
2+
version=1.2.9
33
author=tobozo <[email protected]>
44
maintainer=tobozo <[email protected]>
55
sentence=A simple and efficient YAML library for embedded C++

0 commit comments

Comments
 (0)