M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1 * Header stage complete * Source stage complete * Lint & merge fixes * Includes * Documentation step 1 * FBT: output free size considering BT STACK * Documentation step 2 * py lint * Fix music player plugin * unit test stage 1: string allocator, mem, getters, setters, appends, compare, search. * unit test: string equality * unit test: string replace * unit test: string start_with, end_with * unit test: string trim * unit test: utf-8 * Rename * Revert fw_size changes * Simplify CLI backspace handling * Simplify CLI character insert * Merge fixes * Furi: correct filenaming and spelling * Bt: remove furi string include Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
		| @@ -11,7 +11,7 @@ | ||||
| typedef struct { | ||||
|     InfraredDecoderHandler* decoder_handler; | ||||
|     InfraredEncoderHandler* encoder_handler; | ||||
|     string_t file_path; | ||||
|     FuriString* file_path; | ||||
|     FlipperFormat* ff; | ||||
| } InfraredTest; | ||||
|  | ||||
| @@ -23,7 +23,7 @@ static void infrared_test_alloc() { | ||||
|     test->decoder_handler = infrared_alloc_decoder(); | ||||
|     test->encoder_handler = infrared_alloc_encoder(); | ||||
|     test->ff = flipper_format_buffered_file_alloc(storage); | ||||
|     string_init(test->file_path); | ||||
|     test->file_path = furi_string_alloc(); | ||||
| } | ||||
|  | ||||
| static void infrared_test_free() { | ||||
| @@ -31,18 +31,18 @@ static void infrared_test_free() { | ||||
|     infrared_free_decoder(test->decoder_handler); | ||||
|     infrared_free_encoder(test->encoder_handler); | ||||
|     flipper_format_free(test->ff); | ||||
|     string_clear(test->file_path); | ||||
|     furi_string_free(test->file_path); | ||||
|     furi_record_close(RECORD_STORAGE); | ||||
|     free(test); | ||||
|     test = NULL; | ||||
| } | ||||
|  | ||||
| static bool infrared_test_prepare_file(const char* protocol_name) { | ||||
|     string_t file_type; | ||||
|     string_init(file_type); | ||||
|     FuriString* file_type; | ||||
|     file_type = furi_string_alloc(); | ||||
|     bool success = false; | ||||
|  | ||||
|     string_printf( | ||||
|     furi_string_printf( | ||||
|         test->file_path, | ||||
|         "%s%s%s%s", | ||||
|         IR_TEST_FILES_DIR, | ||||
| @@ -52,14 +52,15 @@ static bool infrared_test_prepare_file(const char* protocol_name) { | ||||
|  | ||||
|     do { | ||||
|         uint32_t format_version; | ||||
|         if(!flipper_format_buffered_file_open_existing(test->ff, string_get_cstr(test->file_path))) | ||||
|         if(!flipper_format_buffered_file_open_existing( | ||||
|                test->ff, furi_string_get_cstr(test->file_path))) | ||||
|             break; | ||||
|         if(!flipper_format_read_header(test->ff, file_type, &format_version)) break; | ||||
|         if(string_cmp_str(file_type, "IR tests file") || format_version != 1) break; | ||||
|         if(furi_string_cmp_str(file_type, "IR tests file") || format_version != 1) break; | ||||
|         success = true; | ||||
|     } while(false); | ||||
|  | ||||
|     string_clear(file_type); | ||||
|     furi_string_free(file_type); | ||||
|     return success; | ||||
| } | ||||
|  | ||||
| @@ -68,18 +69,18 @@ static bool infrared_test_load_raw_signal( | ||||
|     const char* signal_name, | ||||
|     uint32_t** timings, | ||||
|     uint32_t* timings_count) { | ||||
|     string_t buf; | ||||
|     string_init(buf); | ||||
|     FuriString* buf; | ||||
|     buf = furi_string_alloc(); | ||||
|     bool success = false; | ||||
|  | ||||
|     do { | ||||
|         bool is_name_found = false; | ||||
|         for(; !is_name_found && flipper_format_read_string(ff, "name", buf); | ||||
|             is_name_found = !string_cmp_str(buf, signal_name)) | ||||
|             is_name_found = !furi_string_cmp(buf, signal_name)) | ||||
|             ; | ||||
|  | ||||
|         if(!is_name_found) break; | ||||
|         if(!flipper_format_read_string(ff, "type", buf) || string_cmp_str(buf, "raw")) break; | ||||
|         if(!flipper_format_read_string(ff, "type", buf) || furi_string_cmp_str(buf, "raw")) break; | ||||
|         if(!flipper_format_get_value_count(ff, "data", timings_count)) break; | ||||
|         if(!*timings_count) break; | ||||
|  | ||||
| @@ -91,18 +92,18 @@ static bool infrared_test_load_raw_signal( | ||||
|         success = true; | ||||
|     } while(false); | ||||
|  | ||||
|     string_clear(buf); | ||||
|     furi_string_free(buf); | ||||
|     return success; | ||||
| } | ||||
|  | ||||
| static bool infrared_test_read_message(FlipperFormat* ff, InfraredMessage* message) { | ||||
|     string_t buf; | ||||
|     string_init(buf); | ||||
|     FuriString* buf; | ||||
|     buf = furi_string_alloc(); | ||||
|     bool success = false; | ||||
|  | ||||
|     do { | ||||
|         if(!flipper_format_read_string(ff, "protocol", buf)) break; | ||||
|         message->protocol = infrared_get_protocol_by_name(string_get_cstr(buf)); | ||||
|         message->protocol = infrared_get_protocol_by_name(furi_string_get_cstr(buf)); | ||||
|         if(!infrared_is_protocol_valid(message->protocol)) break; | ||||
|         if(!flipper_format_read_hex(ff, "address", (uint8_t*)&message->address, sizeof(uint32_t))) | ||||
|             break; | ||||
| @@ -112,7 +113,7 @@ static bool infrared_test_read_message(FlipperFormat* ff, InfraredMessage* messa | ||||
|         success = true; | ||||
|     } while(false); | ||||
|  | ||||
|     string_clear(buf); | ||||
|     furi_string_free(buf); | ||||
|     return success; | ||||
| } | ||||
|  | ||||
| @@ -121,18 +122,19 @@ static bool infrared_test_load_messages( | ||||
|     const char* signal_name, | ||||
|     InfraredMessage** messages, | ||||
|     uint32_t* messages_count) { | ||||
|     string_t buf; | ||||
|     string_init(buf); | ||||
|     FuriString* buf; | ||||
|     buf = furi_string_alloc(); | ||||
|     bool success = false; | ||||
|  | ||||
|     do { | ||||
|         bool is_name_found = false; | ||||
|         for(; !is_name_found && flipper_format_read_string(ff, "name", buf); | ||||
|             is_name_found = !string_cmp_str(buf, signal_name)) | ||||
|             is_name_found = !furi_string_cmp(buf, signal_name)) | ||||
|             ; | ||||
|  | ||||
|         if(!is_name_found) break; | ||||
|         if(!flipper_format_read_string(ff, "type", buf) || string_cmp_str(buf, "parsed_array")) | ||||
|         if(!flipper_format_read_string(ff, "type", buf) || | ||||
|            furi_string_cmp_str(buf, "parsed_array")) | ||||
|             break; | ||||
|         if(!flipper_format_read_uint32(ff, "count", messages_count, 1)) break; | ||||
|         if(!*messages_count) break; | ||||
| @@ -151,7 +153,7 @@ static bool infrared_test_load_messages( | ||||
|         success = true; | ||||
|     } while(false); | ||||
|  | ||||
|     string_clear(buf); | ||||
|     furi_string_free(buf); | ||||
|     return success; | ||||
| } | ||||
|  | ||||
| @@ -213,26 +215,26 @@ static void infrared_test_run_encoder(InfraredProtocol protocol, uint32_t test_i | ||||
|     InfraredMessage* input_messages; | ||||
|     uint32_t input_messages_count; | ||||
|  | ||||
|     string_t buf; | ||||
|     string_init(buf); | ||||
|     FuriString* buf; | ||||
|     buf = furi_string_alloc(); | ||||
|  | ||||
|     const char* protocol_name = infrared_get_protocol_name(protocol); | ||||
|     mu_assert(infrared_test_prepare_file(protocol_name), "Failed to prepare test file"); | ||||
|  | ||||
|     string_printf(buf, "encoder_input%d", test_index); | ||||
|     furi_string_printf(buf, "encoder_input%d", test_index); | ||||
|     mu_assert( | ||||
|         infrared_test_load_messages( | ||||
|             test->ff, string_get_cstr(buf), &input_messages, &input_messages_count), | ||||
|             test->ff, furi_string_get_cstr(buf), &input_messages, &input_messages_count), | ||||
|         "Failed to load messages from file"); | ||||
|  | ||||
|     string_printf(buf, "encoder_expected%d", test_index); | ||||
|     furi_string_printf(buf, "encoder_expected%d", test_index); | ||||
|     mu_assert( | ||||
|         infrared_test_load_raw_signal( | ||||
|             test->ff, string_get_cstr(buf), &expected_timings, &expected_timings_count), | ||||
|             test->ff, furi_string_get_cstr(buf), &expected_timings, &expected_timings_count), | ||||
|         "Failed to load raw signal from file"); | ||||
|  | ||||
|     flipper_format_buffered_file_close(test->ff); | ||||
|     string_clear(buf); | ||||
|     furi_string_free(buf); | ||||
|  | ||||
|     uint32_t j = 0; | ||||
|     timings = malloc(sizeof(uint32_t) * timings_count); | ||||
| @@ -267,22 +269,22 @@ static void infrared_test_run_encoder_decoder(InfraredProtocol protocol, uint32_ | ||||
|     uint32_t input_messages_count; | ||||
|     bool level = false; | ||||
|  | ||||
|     string_t buf; | ||||
|     string_init(buf); | ||||
|     FuriString* buf; | ||||
|     buf = furi_string_alloc(); | ||||
|  | ||||
|     timings = malloc(sizeof(uint32_t) * timings_count); | ||||
|  | ||||
|     const char* protocol_name = infrared_get_protocol_name(protocol); | ||||
|     mu_assert(infrared_test_prepare_file(protocol_name), "Failed to prepare test file"); | ||||
|  | ||||
|     string_printf(buf, "encoder_decoder_input%d", test_index); | ||||
|     furi_string_printf(buf, "encoder_decoder_input%d", test_index); | ||||
|     mu_assert( | ||||
|         infrared_test_load_messages( | ||||
|             test->ff, string_get_cstr(buf), &input_messages, &input_messages_count), | ||||
|             test->ff, furi_string_get_cstr(buf), &input_messages, &input_messages_count), | ||||
|         "Failed to load messages from file"); | ||||
|  | ||||
|     flipper_format_buffered_file_close(test->ff); | ||||
|     string_clear(buf); | ||||
|     furi_string_free(buf); | ||||
|  | ||||
|     for(uint32_t message_counter = 0; message_counter < input_messages_count; ++message_counter) { | ||||
|         const InfraredMessage* message_encoded = &input_messages[message_counter]; | ||||
| @@ -327,25 +329,27 @@ static void infrared_test_run_decoder(InfraredProtocol protocol, uint32_t test_i | ||||
|     InfraredMessage* messages; | ||||
|     uint32_t messages_count; | ||||
|  | ||||
|     string_t buf; | ||||
|     string_init(buf); | ||||
|     FuriString* buf; | ||||
|     buf = furi_string_alloc(); | ||||
|  | ||||
|     mu_assert( | ||||
|         infrared_test_prepare_file(infrared_get_protocol_name(protocol)), | ||||
|         "Failed to prepare test file"); | ||||
|  | ||||
|     string_printf(buf, "decoder_input%d", test_index); | ||||
|     furi_string_printf(buf, "decoder_input%d", test_index); | ||||
|     mu_assert( | ||||
|         infrared_test_load_raw_signal(test->ff, string_get_cstr(buf), &timings, &timings_count), | ||||
|         infrared_test_load_raw_signal( | ||||
|             test->ff, furi_string_get_cstr(buf), &timings, &timings_count), | ||||
|         "Failed to load raw signal from file"); | ||||
|  | ||||
|     string_printf(buf, "decoder_expected%d", test_index); | ||||
|     furi_string_printf(buf, "decoder_expected%d", test_index); | ||||
|     mu_assert( | ||||
|         infrared_test_load_messages(test->ff, string_get_cstr(buf), &messages, &messages_count), | ||||
|         infrared_test_load_messages( | ||||
|             test->ff, furi_string_get_cstr(buf), &messages, &messages_count), | ||||
|         "Failed to load messages from file"); | ||||
|  | ||||
|     flipper_format_buffered_file_close(test->ff); | ||||
|     string_clear(buf); | ||||
|     furi_string_free(buf); | ||||
|  | ||||
|     InfraredMessage message_decoded_check_local; | ||||
|     bool level = 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user