19750e409Sopenharmony_ci/* 29750e409Sopenharmony_ci Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 39750e409Sopenharmony_ci 49750e409Sopenharmony_ci Permission is hereby granted, free of charge, to any person obtaining a copy 59750e409Sopenharmony_ci of this software and associated documentation files (the "Software"), to deal 69750e409Sopenharmony_ci in the Software without restriction, including without limitation the rights 79750e409Sopenharmony_ci to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 89750e409Sopenharmony_ci copies of the Software, and to permit persons to whom the Software is 99750e409Sopenharmony_ci furnished to do so, subject to the following conditions: 109750e409Sopenharmony_ci 119750e409Sopenharmony_ci The above copyright notice and this permission notice shall be included in 129750e409Sopenharmony_ci all copies or substantial portions of the Software. 139750e409Sopenharmony_ci 149750e409Sopenharmony_ci THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 159750e409Sopenharmony_ci IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 169750e409Sopenharmony_ci FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 179750e409Sopenharmony_ci AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 189750e409Sopenharmony_ci LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 199750e409Sopenharmony_ci OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 209750e409Sopenharmony_ci THE SOFTWARE. 219750e409Sopenharmony_ci*/ 229750e409Sopenharmony_ci 239750e409Sopenharmony_ci#include <stdio.h> 249750e409Sopenharmony_ci#include <stdlib.h> 259750e409Sopenharmony_ci#include <string.h> 269750e409Sopenharmony_ci 279750e409Sopenharmony_ci#include "unity/examples/unity_config.h" 289750e409Sopenharmony_ci#include "unity/src/unity.h" 299750e409Sopenharmony_ci#include "common.h" 309750e409Sopenharmony_ci 319750e409Sopenharmony_cistatic void parse_hex4_should_parse_all_combinations(void) 329750e409Sopenharmony_ci{ 339750e409Sopenharmony_ci unsigned int number = 0; 349750e409Sopenharmony_ci unsigned char digits_lower[6]; 359750e409Sopenharmony_ci unsigned char digits_upper[6]; 369750e409Sopenharmony_ci /* test all combinations */ 379750e409Sopenharmony_ci for (number = 0; number <= 0xFFFF; number++) 389750e409Sopenharmony_ci { 399750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_lower, "%.4x", number), "sprintf failed."); 409750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_upper, "%.4X", number), "sprintf failed."); 419750e409Sopenharmony_ci 429750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT_MESSAGE(number, parse_hex4(digits_lower), "Failed to parse lowercase digits."); 439750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT_MESSAGE(number, parse_hex4(digits_upper), "Failed to parse uppercase digits."); 449750e409Sopenharmony_ci } 459750e409Sopenharmony_ci} 469750e409Sopenharmony_ci 479750e409Sopenharmony_cistatic void parse_hex4_should_parse_mixed_case(void) 489750e409Sopenharmony_ci{ 499750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beef")); 509750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beeF")); 519750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beEf")); 529750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"beEF")); 539750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEef")); 549750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEeF")); 559750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEEf")); 569750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"bEEF")); 579750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"Beef")); 589750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BeeF")); 599750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BeEf")); 609750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BeEF")); 619750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEef")); 629750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEeF")); 639750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEEf")); 649750e409Sopenharmony_ci TEST_ASSERT_EQUAL_INT(0xBEEF, parse_hex4((const unsigned char*)"BEEF")); 659750e409Sopenharmony_ci} 669750e409Sopenharmony_ci 679750e409Sopenharmony_ciint CJSON_CDECL main(void) 689750e409Sopenharmony_ci{ 699750e409Sopenharmony_ci UNITY_BEGIN(); 709750e409Sopenharmony_ci RUN_TEST(parse_hex4_should_parse_all_combinations); 719750e409Sopenharmony_ci RUN_TEST(parse_hex4_should_parse_mixed_case); 729750e409Sopenharmony_ci return UNITY_END(); 739750e409Sopenharmony_ci} 74