@@ -3190,6 +3190,8 @@ ZTEST(devicetree_api, test_string_unquoted)
3190
3190
#define XA 12.0
3191
3191
#define XB 34.0
3192
3192
#define XPLUS +
3193
+ #define XSTR1 "one"
3194
+ #define XSTR2 "two"
3193
3195
const double f0_expected = 0.1234 ;
3194
3196
const double f1_expected = 0.9e-3 ;
3195
3197
const double delta = 0.1e-4 ;
@@ -3201,19 +3203,31 @@ ZTEST(devicetree_api, test_string_unquoted)
3201
3203
f1_expected , delta , "" );
3202
3204
zassert_within (DT_STRING_UNQUOTED (DT_NODELABEL (test_str_unquoted_t ), val ),
3203
3205
XA XPLUS XB , delta , "" );
3206
+ zassert_within (DT_STRING_UNQUOTED (DT_NODELABEL (test_str_unquoted_esc_t ), val ), XA XPLUS XB ,
3207
+ delta , "" );
3208
+ zassert_str_equal (DT_STRING_UNQUOTED (DT_NODELABEL (test_str_unquoted_esc_s ), val ),
3209
+ "one plus two" );
3204
3210
/* Test DT_STRING_UNQUOTED_OR */
3205
3211
zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f0 ), val , (0.0 )),
3206
3212
f0_expected , delta , "" );
3207
3213
zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f1 ), val , (0.0 )),
3208
3214
f1_expected , delta , "" );
3209
3215
zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_t ), val , (0.0 )),
3210
3216
XA XPLUS XB , delta , "" );
3217
+ zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_t ), val , (0.0 )),
3218
+ XA XPLUS XB , delta , "" );
3219
+ zassert_str_equal (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_s ), val , "nak" ),
3220
+ "one plus two" );
3211
3221
zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f0 ), nak , (0.0 )),
3212
3222
0.0 , delta , "" );
3213
3223
zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_f1 ), nak , (0.0 )),
3214
3224
0.0 , delta , "" );
3215
3225
zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_t ), nak , (0.0 )),
3216
3226
0.0 , delta , "" );
3227
+ zassert_within (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_t ), nak , (0.0 )),
3228
+ 0.0 , delta , "" );
3229
+ zassert_str_equal (DT_STRING_UNQUOTED_OR (DT_NODELABEL (test_str_unquoted_esc_s ), nak , "nak" ),
3230
+ "nak" );
3217
3231
/* Test DT_INST_STRING_UNQUOTED */
3218
3232
#define STRING_UNQUOTED_VAR (node_id ) _CONCAT(var_, node_id)
3219
3233
#define STRING_UNQUOTED_TEST_INST_EXPANSION (inst ) \
@@ -3226,6 +3240,8 @@ ZTEST(devicetree_api, test_string_unquoted)
3226
3240
f1_expected , delta , "" );
3227
3241
zassert_within (STRING_UNQUOTED_VAR (DT_NODELABEL (test_str_unquoted_t )), XA XPLUS XB ,
3228
3242
delta , "" );
3243
+ zassert_within (STRING_UNQUOTED_VAR (DT_NODELABEL (test_str_unquoted_esc_t )), XA XPLUS XB ,
3244
+ delta , "" );
3229
3245
3230
3246
/* Test DT_INST_STRING_UNQUOTED_OR */
3231
3247
#define STRING_UNQUOTED_OR_VAR (node_id ) _CONCAT(var_or_, node_id)
@@ -3242,15 +3258,21 @@ ZTEST(devicetree_api, test_string_unquoted)
3242
3258
f1_expected , delta , "" );
3243
3259
zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_t ))[0 ],
3244
3260
XA XPLUS XB , delta , "" );
3261
+ zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_esc_t ))[0 ],
3262
+ XA XPLUS XB , delta , "" );
3245
3263
zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_f0 ))[1 ],
3246
3264
1.0e10 , delta , "" );
3247
3265
zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_f1 ))[1 ],
3248
3266
1.0e10 , delta , "" );
3249
3267
zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_t ))[1 ],
3250
3268
1.0e10 , delta , "" );
3269
+ zassert_within (STRING_UNQUOTED_OR_VAR (DT_NODELABEL (test_str_unquoted_esc_t ))[1 ], 1.0e10 ,
3270
+ delta , "" );
3251
3271
#undef XA
3252
3272
#undef XB
3253
3273
#undef XPLUS
3274
+ #undef XSTR1
3275
+ #undef XSTR2
3254
3276
}
3255
3277
3256
3278
#undef DT_DRV_COMPAT
@@ -3263,6 +3285,8 @@ ZTEST(devicetree_api, test_string_idx_unquoted)
3263
3285
#define XD 78.0
3264
3286
#define XPLUS +
3265
3287
#define XMINUS -
3288
+ #define XSTR1 "one"
3289
+ #define XSTR2 "two"
3266
3290
const double delta = 0.1e-4 ;
3267
3291
3268
3292
/* DT_STRING_UNQUOTED_BY_IDX */
@@ -3293,6 +3317,11 @@ ZTEST(devicetree_api, test_string_idx_unquoted)
3293
3317
zassert_within (DT_STRING_UNQUOTED_BY_IDX (DT_NODELABEL (test_stra_unquoted_t ), val , 3 ),
3294
3318
XC XMINUS XD , delta , "" );
3295
3319
3320
+ zassert_within (DT_STRING_UNQUOTED_BY_IDX (DT_NODELABEL (test_stra_unquoted_esc ), val , 0 ),
3321
+ XA XPLUS XB , delta , "" );
3322
+ zassert_str_equal (DT_STRING_UNQUOTED_BY_IDX (DT_NODELABEL (test_stra_unquoted_esc ), val , 1 ),
3323
+ "one plus two" );
3324
+
3296
3325
#define STRING_UNQUOTED_BY_IDX_VAR (node_id ) _CONCAT(var_, node_id)
3297
3326
#define STRING_UNQUOTED_BY_IDX_TEST_INST_EXPANSION (inst ) \
3298
3327
double STRING_UNQUOTED_BY_IDX_VAR(DT_DRV_INST(inst))[] = { \
@@ -3335,6 +3364,26 @@ ZTEST(devicetree_api, test_string_idx_unquoted)
3335
3364
#undef XD
3336
3365
#undef XPLUS
3337
3366
#undef XMINUS
3367
+ #undef XSTR1
3368
+ #undef XSTR2
3369
+ }
3370
+
3371
+ #undef DT_DRV_COMPAT
3372
+ ZTEST (devicetree_api , test_string_escape )
3373
+ {
3374
+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_0 ), val ), "\a\b\f\n\r\t\v" );
3375
+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_1 ), val ), "\'single\' \"double\"" );
3376
+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_2 ), val ), "first\nsecond" );
3377
+ zassert_str_equal (DT_PROP (DT_NODELABEL (test_str_escape_3 ), val ), "\x01\x7F" );
3378
+ }
3379
+
3380
+ ZTEST (devicetree_api , test_string_array_escape )
3381
+ {
3382
+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 0 ), "\a\b\f\n\r\t\v" );
3383
+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 1 ),
3384
+ "\'single\' \"double\"" );
3385
+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 2 ), "first\nsecond" );
3386
+ zassert_str_equal (DT_PROP_BY_IDX (DT_NODELABEL (test_stra_escape ), val , 3 ), "\x01\x7F" );
3338
3387
}
3339
3388
3340
3389
#undef DT_DRV_COMPAT
0 commit comments