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:
Sergey Gavrilov
2022-10-06 01:15:23 +10:00
committed by GitHub
parent 0f9ea925d3
commit 4bf29827f8
370 changed files with 5597 additions and 3963 deletions

View File

@@ -58,7 +58,7 @@ static const char* test_data_win = "Filetype: Flipper Format test\r\n"
#define ARRAY_W_BSIZE(x) (x), (sizeof(x))
MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
string_t tmpstr;
FuriString* tmpstr;
uint32_t version;
uint32_t uint32_data[COUNT_OF(test_uint_data)];
int32_t int32_data[COUNT_OF(test_int_data)];
@@ -101,14 +101,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
mu_assert_int_eq(position_before, stream_tell(flipper_format_get_raw_stream(flipper_format)));
// read test
string_init(tmpstr);
tmpstr = furi_string_alloc();
mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
mu_assert_int_eq(test_version, version);
mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
mu_assert_string_eq(test_string_data, string_get_cstr(tmpstr));
mu_assert_string_eq(test_string_data, furi_string_get_cstr(tmpstr));
mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
mu_assert_int_eq(COUNT_OF(test_int_data), count);
@@ -133,7 +133,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
string_clear(tmpstr);
furi_string_free(tmpstr);
// update data
mu_check(flipper_format_rewind(flipper_format));
@@ -155,14 +155,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
uint8_t hex_updated_data[COUNT_OF(test_hex_updated_data)];
mu_check(flipper_format_rewind(flipper_format));
string_init(tmpstr);
tmpstr = furi_string_alloc();
mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
mu_assert_int_eq(test_version, version);
mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
mu_assert_string_eq(test_string_updated_data, string_get_cstr(tmpstr));
mu_assert_string_eq(test_string_updated_data, furi_string_get_cstr(tmpstr));
mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
mu_assert_int_eq(COUNT_OF(test_int_updated_data), count);
@@ -190,7 +190,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
string_clear(tmpstr);
furi_string_free(tmpstr);
// update data
mu_check(flipper_format_rewind(flipper_format));
@@ -214,14 +214,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
uint8_t hex_new_data[COUNT_OF(test_hex_new_data)];
mu_check(flipper_format_rewind(flipper_format));
string_init(tmpstr);
tmpstr = furi_string_alloc();
mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
mu_assert_int_eq(test_version, version);
mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
mu_assert_string_eq(test_string_updated_2_data, string_get_cstr(tmpstr));
mu_assert_string_eq(test_string_updated_2_data, furi_string_get_cstr(tmpstr));
mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
mu_assert_int_eq(COUNT_OF(test_int_updated_2_data), count);
@@ -255,7 +255,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));
string_clear(tmpstr);
furi_string_free(tmpstr);
// delete key test
mu_check(flipper_format_rewind(flipper_format));

View File

@@ -102,8 +102,8 @@ static bool test_read(const char* file_name) {
bool result = false;
FlipperFormat* file = flipper_format_file_alloc(storage);
string_t string_value;
string_init(string_value);
FuriString* string_value;
string_value = furi_string_alloc();
uint32_t uint32_value;
void* scratchpad = malloc(512);
@@ -111,11 +111,11 @@ static bool test_read(const char* file_name) {
if(!flipper_format_file_open_existing(file, file_name)) break;
if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
if(string_cmp_str(string_value, test_filetype) != 0) break;
if(furi_string_cmp_str(string_value, test_filetype) != 0) break;
if(uint32_value != test_version) break;
if(!flipper_format_read_string(file, test_string_key, string_value)) break;
if(string_cmp_str(string_value, test_string_data) != 0) break;
if(furi_string_cmp_str(string_value, test_string_data) != 0) break;
if(!flipper_format_get_value_count(file, test_int_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_int_data)) break;
@@ -150,7 +150,7 @@ static bool test_read(const char* file_name) {
} while(false);
free(scratchpad);
string_clear(string_value);
furi_string_free(string_value);
flipper_format_free(file);
@@ -164,8 +164,8 @@ static bool test_read_updated(const char* file_name) {
bool result = false;
FlipperFormat* file = flipper_format_file_alloc(storage);
string_t string_value;
string_init(string_value);
FuriString* string_value;
string_value = furi_string_alloc();
uint32_t uint32_value;
void* scratchpad = malloc(512);
@@ -173,11 +173,11 @@ static bool test_read_updated(const char* file_name) {
if(!flipper_format_file_open_existing(file, file_name)) break;
if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
if(string_cmp_str(string_value, test_filetype) != 0) break;
if(furi_string_cmp_str(string_value, test_filetype) != 0) break;
if(uint32_value != test_version) break;
if(!flipper_format_read_string(file, test_string_key, string_value)) break;
if(string_cmp_str(string_value, test_string_updated_data) != 0) break;
if(furi_string_cmp_str(string_value, test_string_updated_data) != 0) break;
if(!flipper_format_get_value_count(file, test_int_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_int_updated_data)) break;
@@ -228,7 +228,7 @@ static bool test_read_updated(const char* file_name) {
} while(false);
free(scratchpad);
string_clear(string_value);
furi_string_free(string_value);
flipper_format_free(file);
@@ -401,14 +401,14 @@ static bool test_read_multikey(const char* file_name) {
bool result = false;
FlipperFormat* file = flipper_format_file_alloc(storage);
string_t string_value;
string_init(string_value);
FuriString* string_value;
string_value = furi_string_alloc();
uint32_t uint32_value;
do {
if(!flipper_format_file_open_existing(file, file_name)) break;
if(!flipper_format_read_header(file, string_value, &uint32_value)) break;
if(string_cmp_str(string_value, test_filetype) != 0) break;
if(furi_string_cmp_str(string_value, test_filetype) != 0) break;
if(uint32_value != test_version) break;
bool error = false;
@@ -429,7 +429,7 @@ static bool test_read_multikey(const char* file_name) {
result = true;
} while(false);
string_clear(string_value);
furi_string_free(string_value);
flipper_format_free(file);
furi_record_close(RECORD_STORAGE);

View File

@@ -0,0 +1,469 @@
#include <furi.h>
#include "../minunit.h"
static void test_setup(void) {
}
static void test_teardown(void) {
}
static FuriString* furi_string_alloc_vprintf_test(const char format[], ...) {
va_list args;
va_start(args, format);
FuriString* string = furi_string_alloc_vprintf(format, args);
va_end(args);
return string;
}
MU_TEST(mu_test_furi_string_alloc_free) {
FuriString* tmp;
FuriString* string;
// test alloc and free
string = furi_string_alloc();
mu_check(string != NULL);
mu_check(furi_string_empty(string));
furi_string_free(string);
// test furi_string_alloc_set_str and free
string = furi_string_alloc_set_str("test");
mu_check(string != NULL);
mu_check(!furi_string_empty(string));
mu_check(furi_string_cmp(string, "test") == 0);
furi_string_free(string);
// test furi_string_alloc_set and free
tmp = furi_string_alloc_set("more");
string = furi_string_alloc_set(tmp);
furi_string_free(tmp);
mu_check(string != NULL);
mu_check(!furi_string_empty(string));
mu_check(furi_string_cmp(string, "more") == 0);
furi_string_free(string);
// test alloc_printf and free
string = furi_string_alloc_printf("test %d %s %c 0x%02x", 1, "two", '3', 0x04);
mu_check(string != NULL);
mu_check(!furi_string_empty(string));
mu_check(furi_string_cmp(string, "test 1 two 3 0x04") == 0);
furi_string_free(string);
// test alloc_vprintf and free
string = furi_string_alloc_vprintf_test("test %d %s %c 0x%02x", 4, "five", '6', 0x07);
mu_check(string != NULL);
mu_check(!furi_string_empty(string));
mu_check(furi_string_cmp(string, "test 4 five 6 0x07") == 0);
furi_string_free(string);
// test alloc_move and free
tmp = furi_string_alloc_set("move");
string = furi_string_alloc_move(tmp);
mu_check(string != NULL);
mu_check(!furi_string_empty(string));
mu_check(furi_string_cmp(string, "move") == 0);
furi_string_free(string);
}
MU_TEST(mu_test_furi_string_mem) {
FuriString* string = furi_string_alloc_set("test");
mu_check(string != NULL);
mu_check(!furi_string_empty(string));
// TODO: how to test furi_string_reserve?
// test furi_string_reset
furi_string_reset(string);
mu_check(furi_string_empty(string));
// test furi_string_swap
furi_string_set(string, "test");
FuriString* swap_string = furi_string_alloc_set("swap");
furi_string_swap(string, swap_string);
mu_check(furi_string_cmp(string, "swap") == 0);
mu_check(furi_string_cmp(swap_string, "test") == 0);
furi_string_free(swap_string);
// test furi_string_move
FuriString* move_string = furi_string_alloc_set("move");
furi_string_move(string, move_string);
mu_check(furi_string_cmp(string, "move") == 0);
// move_string is now empty
// and tested by leaked memory check at the end of the tests
furi_string_set(string, "abracadabra");
// test furi_string_hash
mu_assert_int_eq(0xc3bc16d7, furi_string_hash(string));
// test furi_string_size
mu_assert_int_eq(11, furi_string_size(string));
// test furi_string_empty
mu_check(!furi_string_empty(string));
furi_string_reset(string);
mu_check(furi_string_empty(string));
furi_string_free(string);
}
MU_TEST(mu_test_furi_string_getters) {
FuriString* string = furi_string_alloc_set("test");
// test furi_string_get_char
mu_check(furi_string_get_char(string, 0) == 't');
mu_check(furi_string_get_char(string, 1) == 'e');
mu_check(furi_string_get_char(string, 2) == 's');
mu_check(furi_string_get_char(string, 3) == 't');
// test furi_string_get_cstr
mu_assert_string_eq("test", furi_string_get_cstr(string));
furi_string_free(string);
}
static FuriString* furi_string_vprintf_test(FuriString* string, const char format[], ...) {
va_list args;
va_start(args, format);
furi_string_vprintf(string, format, args);
va_end(args);
return string;
}
MU_TEST(mu_test_furi_string_setters) {
FuriString* tmp;
FuriString* string = furi_string_alloc();
// test furi_string_set_str
furi_string_set_str(string, "test");
mu_assert_string_eq("test", furi_string_get_cstr(string));
// test furi_string_set
tmp = furi_string_alloc_set("more");
furi_string_set(string, tmp);
furi_string_free(tmp);
mu_assert_string_eq("more", furi_string_get_cstr(string));
// test furi_string_set_strn
furi_string_set_strn(string, "test", 2);
mu_assert_string_eq("te", furi_string_get_cstr(string));
// test furi_string_set_char
furi_string_set_char(string, 0, 'a');
furi_string_set_char(string, 1, 'b');
mu_assert_string_eq("ab", furi_string_get_cstr(string));
// test furi_string_set_n
tmp = furi_string_alloc_set("dodecahedron");
furi_string_set_n(string, tmp, 4, 5);
furi_string_free(tmp);
mu_assert_string_eq("cahed", furi_string_get_cstr(string));
// test furi_string_printf
furi_string_printf(string, "test %d %s %c 0x%02x", 1, "two", '3', 0x04);
mu_assert_string_eq("test 1 two 3 0x04", furi_string_get_cstr(string));
// test furi_string_vprintf
furi_string_vprintf_test(string, "test %d %s %c 0x%02x", 4, "five", '6', 0x07);
mu_assert_string_eq("test 4 five 6 0x07", furi_string_get_cstr(string));
furi_string_free(string);
}
static FuriString* furi_string_cat_vprintf_test(FuriString* string, const char format[], ...) {
va_list args;
va_start(args, format);
furi_string_cat_vprintf(string, format, args);
va_end(args);
return string;
}
MU_TEST(mu_test_furi_string_appends) {
FuriString* tmp;
FuriString* string = furi_string_alloc();
// test furi_string_push_back
furi_string_push_back(string, 't');
furi_string_push_back(string, 'e');
furi_string_push_back(string, 's');
furi_string_push_back(string, 't');
mu_assert_string_eq("test", furi_string_get_cstr(string));
furi_string_push_back(string, '!');
mu_assert_string_eq("test!", furi_string_get_cstr(string));
// test furi_string_cat_str
furi_string_cat_str(string, "test");
mu_assert_string_eq("test!test", furi_string_get_cstr(string));
// test furi_string_cat
tmp = furi_string_alloc_set("more");
furi_string_cat(string, tmp);
furi_string_free(tmp);
mu_assert_string_eq("test!testmore", furi_string_get_cstr(string));
// test furi_string_cat_printf
furi_string_cat_printf(string, "test %d %s %c 0x%02x", 1, "two", '3', 0x04);
mu_assert_string_eq("test!testmoretest 1 two 3 0x04", furi_string_get_cstr(string));
// test furi_string_cat_vprintf
furi_string_cat_vprintf_test(string, "test %d %s %c 0x%02x", 4, "five", '6', 0x07);
mu_assert_string_eq(
"test!testmoretest 1 two 3 0x04test 4 five 6 0x07", furi_string_get_cstr(string));
furi_string_free(string);
}
MU_TEST(mu_test_furi_string_compare) {
FuriString* string_1 = furi_string_alloc_set("string_1");
FuriString* string_2 = furi_string_alloc_set("string_2");
// test furi_string_cmp
mu_assert_int_eq(0, furi_string_cmp(string_1, string_1));
mu_assert_int_eq(0, furi_string_cmp(string_2, string_2));
mu_assert_int_eq(-1, furi_string_cmp(string_1, string_2));
mu_assert_int_eq(1, furi_string_cmp(string_2, string_1));
// test furi_string_cmp_str
mu_assert_int_eq(0, furi_string_cmp_str(string_1, "string_1"));
mu_assert_int_eq(0, furi_string_cmp_str(string_2, "string_2"));
mu_assert_int_eq(-1, furi_string_cmp_str(string_1, "string_2"));
mu_assert_int_eq(1, furi_string_cmp_str(string_2, "string_1"));
// test furi_string_cmpi
furi_string_set(string_1, "string");
furi_string_set(string_2, "StrIng");
mu_assert_int_eq(0, furi_string_cmpi(string_1, string_1));
mu_assert_int_eq(0, furi_string_cmpi(string_2, string_2));
mu_assert_int_eq(0, furi_string_cmpi(string_1, string_2));
mu_assert_int_eq(0, furi_string_cmpi(string_2, string_1));
furi_string_set(string_1, "string_1");
furi_string_set(string_2, "StrIng_2");
mu_assert_int_eq(32, furi_string_cmp(string_1, string_2));
mu_assert_int_eq(-32, furi_string_cmp(string_2, string_1));
mu_assert_int_eq(-1, furi_string_cmpi(string_1, string_2));
mu_assert_int_eq(1, furi_string_cmpi(string_2, string_1));
// test furi_string_cmpi_str
furi_string_set(string_1, "string");
mu_assert_int_eq(0, furi_string_cmp_str(string_1, "string"));
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "String"));
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STring"));
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRing"));
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRIng"));
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRINg"));
mu_assert_int_eq(32, furi_string_cmp_str(string_1, "STRING"));
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "string"));
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "String"));
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STring"));
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRing"));
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRIng"));
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRINg"));
mu_assert_int_eq(0, furi_string_cmpi_str(string_1, "STRING"));
furi_string_free(string_1);
furi_string_free(string_2);
}
MU_TEST(mu_test_furi_string_search) {
// 012345678901234567
FuriString* haystack = furi_string_alloc_set("test321test123test");
FuriString* needle = furi_string_alloc_set("test");
// test furi_string_search
mu_assert_int_eq(0, furi_string_search(haystack, needle));
mu_assert_int_eq(7, furi_string_search(haystack, needle, 1));
mu_assert_int_eq(14, furi_string_search(haystack, needle, 8));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search(haystack, needle, 15));
FuriString* tmp = furi_string_alloc_set("testnone");
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search(haystack, tmp));
furi_string_free(tmp);
// test furi_string_search_str
mu_assert_int_eq(0, furi_string_search_str(haystack, "test"));
mu_assert_int_eq(7, furi_string_search_str(haystack, "test", 1));
mu_assert_int_eq(14, furi_string_search_str(haystack, "test", 8));
mu_assert_int_eq(4, furi_string_search_str(haystack, "321"));
mu_assert_int_eq(11, furi_string_search_str(haystack, "123"));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_str(haystack, "testnone"));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_str(haystack, "test", 15));
// test furi_string_search_char
mu_assert_int_eq(0, furi_string_search_char(haystack, 't'));
mu_assert_int_eq(1, furi_string_search_char(haystack, 'e'));
mu_assert_int_eq(2, furi_string_search_char(haystack, 's'));
mu_assert_int_eq(3, furi_string_search_char(haystack, 't', 1));
mu_assert_int_eq(7, furi_string_search_char(haystack, 't', 4));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_char(haystack, 'x'));
// test furi_string_search_rchar
mu_assert_int_eq(17, furi_string_search_rchar(haystack, 't'));
mu_assert_int_eq(15, furi_string_search_rchar(haystack, 'e'));
mu_assert_int_eq(16, furi_string_search_rchar(haystack, 's'));
mu_assert_int_eq(13, furi_string_search_rchar(haystack, '3'));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_rchar(haystack, '3', 14));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_search_rchar(haystack, 'x'));
furi_string_free(haystack);
furi_string_free(needle);
}
MU_TEST(mu_test_furi_string_equality) {
FuriString* string = furi_string_alloc_set("test");
FuriString* string_eq = furi_string_alloc_set("test");
FuriString* string_neq = furi_string_alloc_set("test2");
// test furi_string_equal
mu_check(furi_string_equal(string, string_eq));
mu_check(!furi_string_equal(string, string_neq));
// test furi_string_equal_str
mu_check(furi_string_equal_str(string, "test"));
mu_check(!furi_string_equal_str(string, "test2"));
mu_check(furi_string_equal_str(string_neq, "test2"));
mu_check(!furi_string_equal_str(string_neq, "test"));
furi_string_free(string);
furi_string_free(string_eq);
furi_string_free(string_neq);
}
MU_TEST(mu_test_furi_string_replace) {
FuriString* needle = furi_string_alloc_set("test");
FuriString* replace = furi_string_alloc_set("replace");
FuriString* string = furi_string_alloc_set("test123test");
// test furi_string_replace_at
furi_string_replace_at(string, 4, 3, "!biglongword!");
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
// test furi_string_replace
mu_assert_int_eq(17, furi_string_replace(string, needle, replace, 1));
mu_assert_string_eq("test!biglongword!replace", furi_string_get_cstr(string));
mu_assert_int_eq(0, furi_string_replace(string, needle, replace));
mu_assert_string_eq("replace!biglongword!replace", furi_string_get_cstr(string));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_replace(string, needle, replace));
mu_assert_string_eq("replace!biglongword!replace", furi_string_get_cstr(string));
// test furi_string_replace_str
mu_assert_int_eq(20, furi_string_replace_str(string, "replace", "test", 1));
mu_assert_string_eq("replace!biglongword!test", furi_string_get_cstr(string));
mu_assert_int_eq(0, furi_string_replace_str(string, "replace", "test"));
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
mu_assert_int_eq(FURI_STRING_FAILURE, furi_string_replace_str(string, "replace", "test"));
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
// test furi_string_replace_all
furi_string_replace_all(string, needle, replace);
mu_assert_string_eq("replace!biglongword!replace", furi_string_get_cstr(string));
// test furi_string_replace_all_str
furi_string_replace_all_str(string, "replace", "test");
mu_assert_string_eq("test!biglongword!test", furi_string_get_cstr(string));
furi_string_free(string);
furi_string_free(needle);
furi_string_free(replace);
}
MU_TEST(mu_test_furi_string_start_end) {
FuriString* string = furi_string_alloc_set("start_end");
FuriString* start = furi_string_alloc_set("start");
FuriString* end = furi_string_alloc_set("end");
// test furi_string_start_with
mu_check(furi_string_start_with(string, start));
mu_check(!furi_string_start_with(string, end));
// test furi_string_start_with_str
mu_check(furi_string_start_with_str(string, "start"));
mu_check(!furi_string_start_with_str(string, "end"));
// test furi_string_end_with
mu_check(furi_string_end_with(string, end));
mu_check(!furi_string_end_with(string, start));
// test furi_string_end_with_str
mu_check(furi_string_end_with_str(string, "end"));
mu_check(!furi_string_end_with_str(string, "start"));
furi_string_free(string);
furi_string_free(start);
furi_string_free(end);
}
MU_TEST(mu_test_furi_string_trim) {
FuriString* string = furi_string_alloc_set("biglongstring");
// test furi_string_left
furi_string_left(string, 7);
mu_assert_string_eq("biglong", furi_string_get_cstr(string));
// test furi_string_right
furi_string_right(string, 3);
mu_assert_string_eq("long", furi_string_get_cstr(string));
// test furi_string_mid
furi_string_mid(string, 1, 2);
mu_assert_string_eq("on", furi_string_get_cstr(string));
// test furi_string_trim
furi_string_set(string, " \n\r\tbiglongstring \n\r\t ");
furi_string_trim(string);
mu_assert_string_eq("biglongstring", furi_string_get_cstr(string));
furi_string_set(string, "aaaabaaaabbaaabaaaabbtestaaaaaabbaaabaababaa");
furi_string_trim(string, "ab");
mu_assert_string_eq("test", furi_string_get_cstr(string));
furi_string_free(string);
}
MU_TEST(mu_test_furi_string_utf8) {
FuriString* utf8_string = furi_string_alloc_set("イルカ");
// test furi_string_utf8_length
mu_assert_int_eq(9, furi_string_size(utf8_string));
mu_assert_int_eq(3, furi_string_utf8_length(utf8_string));
// test furi_string_utf8_decode
const uint8_t dolphin_emoji_array[4] = {0xF0, 0x9F, 0x90, 0xAC};
FuriStringUTF8State state = FuriStringUTF8StateStarting;
FuriStringUnicodeValue value = 0;
furi_string_utf8_decode(dolphin_emoji_array[0], &state, &value);
mu_assert_int_eq(FuriStringUTF8StateDecoding3, state);
furi_string_utf8_decode(dolphin_emoji_array[1], &state, &value);
mu_assert_int_eq(FuriStringUTF8StateDecoding2, state);
furi_string_utf8_decode(dolphin_emoji_array[2], &state, &value);
mu_assert_int_eq(FuriStringUTF8StateDecoding1, state);
furi_string_utf8_decode(dolphin_emoji_array[3], &state, &value);
mu_assert_int_eq(FuriStringUTF8StateStarting, state);
mu_assert_int_eq(0x1F42C, value);
// test furi_string_utf8_push
furi_string_set(utf8_string, "");
furi_string_utf8_push(utf8_string, value);
mu_assert_string_eq("🐬", furi_string_get_cstr(utf8_string));
furi_string_free(utf8_string);
}
MU_TEST_SUITE(test_suite) {
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
MU_RUN_TEST(mu_test_furi_string_alloc_free);
MU_RUN_TEST(mu_test_furi_string_mem);
MU_RUN_TEST(mu_test_furi_string_getters);
MU_RUN_TEST(mu_test_furi_string_setters);
MU_RUN_TEST(mu_test_furi_string_appends);
MU_RUN_TEST(mu_test_furi_string_compare);
MU_RUN_TEST(mu_test_furi_string_search);
MU_RUN_TEST(mu_test_furi_string_equality);
MU_RUN_TEST(mu_test_furi_string_replace);
MU_RUN_TEST(mu_test_furi_string_start_end);
MU_RUN_TEST(mu_test_furi_string_trim);
MU_RUN_TEST(mu_test_furi_string_utf8);
}
int run_minunit_test_furi_string() {
MU_RUN_SUITE(test_suite);
return MU_EXIT_CODE;
}

View File

@@ -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;

View File

@@ -53,14 +53,15 @@ static bool nfc_test_read_signal_from_file(const char* file_name) {
bool success = false;
FlipperFormat* file = flipper_format_file_alloc(nfc_test->storage);
string_t file_type;
string_init(file_type);
FuriString* file_type;
file_type = furi_string_alloc();
uint32_t file_version = 0;
do {
if(!flipper_format_file_open_existing(file, file_name)) break;
if(!flipper_format_read_header(file, file_type, &file_version)) break;
if(string_cmp_str(file_type, nfc_test_file_type) || file_version != nfc_test_file_version)
if(furi_string_cmp_str(file_type, nfc_test_file_type) ||
file_version != nfc_test_file_version)
break;
if(!flipper_format_read_uint32(file, "Data length", &nfc_test->test_data_len, 1)) break;
if(nfc_test->test_data_len > NFC_TEST_DATA_MAX_LEN) break;
@@ -76,7 +77,7 @@ static bool nfc_test_read_signal_from_file(const char* file_name) {
success = true;
} while(false);
string_clear(file_type);
furi_string_free(file_type);
flipper_format_free(file);
return success;
@@ -174,8 +175,8 @@ MU_TEST(nfc_digital_signal_test) {
MU_TEST(mf_classic_dict_test) {
MfClassicDict* instance = NULL;
uint64_t key = 0;
string_t temp_str;
string_init(temp_str);
FuriString* temp_str;
temp_str = furi_string_alloc();
instance = mf_classic_dict_alloc(MfClassicDictTypeUnitTest);
mu_assert(instance != NULL, "mf_classic_dict_alloc\r\n");
@@ -184,7 +185,7 @@ MU_TEST(mf_classic_dict_test) {
mf_classic_dict_get_total_keys(instance) == 0,
"mf_classic_dict_get_total_keys == 0 assert failed\r\n");
string_set(temp_str, "2196FAD8115B");
furi_string_set(temp_str, "2196FAD8115B");
mu_assert(
mf_classic_dict_add_key_str(instance, temp_str),
"mf_classic_dict_add_key == true assert failed\r\n");
@@ -199,7 +200,7 @@ MU_TEST(mf_classic_dict_test) {
mf_classic_dict_get_key_at_index_str(instance, temp_str, 0),
"mf_classic_dict_get_key_at_index_str == true assert failed\r\n");
mu_assert(
string_cmp(temp_str, "2196FAD8115B") == 0,
furi_string_cmp(temp_str, "2196FAD8115B") == 0,
"string_cmp(temp_str, \"2196FAD8115B\") == 0 assert failed\r\n");
mu_assert(mf_classic_dict_rewind(instance), "mf_classic_dict_rewind == 1 assert failed\r\n");
@@ -216,7 +217,7 @@ MU_TEST(mf_classic_dict_test) {
"mf_classic_dict_delete_index == true assert failed\r\n");
mf_classic_dict_free(instance);
string_clear(temp_str);
furi_string_free(temp_str);
}
MU_TEST_SUITE(nfc) {

View File

@@ -75,7 +75,7 @@ typedef struct {
bool visited;
} StorageTestPath;
DICT_DEF2(StorageTestPathDict, string_t, STRING_OPLIST, StorageTestPath, M_POD_OPLIST)
DICT_DEF2(StorageTestPathDict, FuriString*, FURI_STRING_OPLIST, StorageTestPath, M_POD_OPLIST)
static StorageTestPathDict_t*
storage_test_paths_alloc(const StorageTestPathDesc paths[], size_t paths_count) {
@@ -83,15 +83,15 @@ static StorageTestPathDict_t*
StorageTestPathDict_init(*data);
for(size_t i = 0; i < paths_count; i++) {
string_t key;
string_init_set(key, paths[i].path);
FuriString* key;
key = furi_string_alloc_set(paths[i].path);
StorageTestPath value = {
.is_dir = paths[i].is_dir,
.visited = false,
};
StorageTestPathDict_set_at(*data, key, value);
string_clear(key);
furi_string_free(key);
}
return data;
@@ -102,7 +102,7 @@ static void storage_test_paths_free(StorageTestPathDict_t* data) {
free(data);
}
static bool storage_test_paths_mark(StorageTestPathDict_t* data, string_t path, bool is_dir) {
static bool storage_test_paths_mark(StorageTestPathDict_t* data, FuriString* path, bool is_dir) {
bool found = false;
StorageTestPath* record = StorageTestPathDict_get(*data, path);
@@ -148,27 +148,27 @@ static bool write_file_13DA(Storage* storage, const char* path) {
}
static void storage_dirs_create(Storage* storage, const char* base) {
string_t path;
string_init(path);
FuriString* path;
path = furi_string_alloc();
storage_common_mkdir(storage, base);
for(size_t i = 0; i < COUNT_OF(storage_test_dirwalk_paths); i++) {
string_printf(path, "%s/%s", base, storage_test_dirwalk_paths[i]);
storage_common_mkdir(storage, string_get_cstr(path));
furi_string_printf(path, "%s/%s", base, storage_test_dirwalk_paths[i]);
storage_common_mkdir(storage, furi_string_get_cstr(path));
}
for(size_t i = 0; i < COUNT_OF(storage_test_dirwalk_files); i++) {
string_printf(path, "%s/%s", base, storage_test_dirwalk_files[i]);
write_file_13DA(storage, string_get_cstr(path));
furi_string_printf(path, "%s/%s", base, storage_test_dirwalk_files[i]);
write_file_13DA(storage, furi_string_get_cstr(path));
}
string_clear(path);
furi_string_free(path);
}
MU_TEST_1(test_dirwalk_full, Storage* storage) {
string_t path;
string_init(path);
FuriString* path;
path = furi_string_alloc();
FileInfo fileinfo;
StorageTestPathDict_t* paths =
@@ -178,12 +178,12 @@ MU_TEST_1(test_dirwalk_full, Storage* storage) {
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
string_right(path, strlen(EXT_PATH("dirwalk/")));
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
string_clear(path);
furi_string_free(path);
mu_check(storage_test_paths_check(paths) == false);
@@ -191,8 +191,8 @@ MU_TEST_1(test_dirwalk_full, Storage* storage) {
}
MU_TEST_1(test_dirwalk_no_recursive, Storage* storage) {
string_t path;
string_init(path);
FuriString* path;
path = furi_string_alloc();
FileInfo fileinfo;
StorageTestPathDict_t* paths = storage_test_paths_alloc(
@@ -203,12 +203,12 @@ MU_TEST_1(test_dirwalk_no_recursive, Storage* storage) {
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
string_right(path, strlen(EXT_PATH("dirwalk/")));
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
string_clear(path);
furi_string_free(path);
mu_check(storage_test_paths_check(paths) == false);
@@ -230,8 +230,8 @@ static bool test_dirwalk_filter_no_folder_ext(const char* name, FileInfo* filein
}
MU_TEST_1(test_dirwalk_filter, Storage* storage) {
string_t path;
string_init(path);
FuriString* path;
path = furi_string_alloc();
FileInfo fileinfo;
StorageTestPathDict_t* paths = storage_test_paths_alloc(
@@ -242,12 +242,12 @@ MU_TEST_1(test_dirwalk_filter, Storage* storage) {
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
string_right(path, strlen(EXT_PATH("dirwalk/")));
furi_string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
string_clear(path);
furi_string_free(path);
mu_check(storage_test_paths_check(paths) == false);

View File

@@ -211,22 +211,22 @@ static bool check_file_13DA(Storage* storage, const char* path) {
}
static void storage_dir_create(Storage* storage, const char* base) {
string_t path;
string_init(path);
FuriString* path;
path = furi_string_alloc();
storage_common_mkdir(storage, base);
for(size_t i = 0; i < COUNT_OF(storage_copy_test_paths); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
storage_common_mkdir(storage, string_get_cstr(path));
furi_string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
storage_common_mkdir(storage, furi_string_get_cstr(path));
}
for(size_t i = 0; i < COUNT_OF(storage_copy_test_files); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
write_file_13DA(storage, string_get_cstr(path));
furi_string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
write_file_13DA(storage, furi_string_get_cstr(path));
}
string_clear(path);
furi_string_free(path);
}
static void storage_dir_remove(Storage* storage, const char* base) {
@@ -235,15 +235,15 @@ static void storage_dir_remove(Storage* storage, const char* base) {
static bool storage_dir_rename_check(Storage* storage, const char* base) {
bool result = false;
string_t path;
string_init(path);
FuriString* path;
path = furi_string_alloc();
result = (storage_common_stat(storage, base, NULL) == FSE_OK);
if(result) {
for(size_t i = 0; i < COUNT_OF(storage_copy_test_paths); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
result = (storage_common_stat(storage, string_get_cstr(path), NULL) == FSE_OK);
furi_string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
result = (storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK);
if(!result) {
break;
}
@@ -252,15 +252,15 @@ static bool storage_dir_rename_check(Storage* storage, const char* base) {
if(result) {
for(size_t i = 0; i < COUNT_OF(storage_copy_test_files); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
result = check_file_13DA(storage, string_get_cstr(path));
furi_string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
result = check_file_13DA(storage, furi_string_get_cstr(path));
if(!result) {
break;
}
}
}
string_clear(path);
furi_string_free(path);
return result;
}

View File

@@ -18,8 +18,8 @@ static const char* stream_test_right_data =
MU_TEST_1(stream_composite_subtest, Stream* stream) {
const size_t data_size = 128;
uint8_t data[data_size];
string_t string_lee;
string_init_set(string_lee, "lee");
FuriString* string_lee;
string_lee = furi_string_alloc_set("lee");
// test that stream is empty
// "" -> ""
@@ -267,7 +267,7 @@ MU_TEST_1(stream_composite_subtest, Stream* stream) {
mu_assert_int_eq(9, stream_tell(stream));
mu_check(stream_eof(stream));
string_clear(string_lee);
furi_string_free(string_lee);
}
MU_TEST(stream_composite_test) {
@@ -416,10 +416,10 @@ MU_TEST(stream_buffered_write_after_read_test) {
}
MU_TEST(stream_buffered_large_file_test) {
string_t input_data;
string_t output_data;
string_init(input_data);
string_init(output_data);
FuriString* input_data;
FuriString* output_data;
input_data = furi_string_alloc();
output_data = furi_string_alloc();
Storage* storage = furi_record_open(RECORD_STORAGE);
@@ -429,7 +429,7 @@ MU_TEST(stream_buffered_large_file_test) {
const size_t rep_count = data_size / line_size + 1;
for(size_t i = 0; i < rep_count; ++i) {
string_cat_printf(input_data, "%s\n", stream_test_data);
furi_string_cat_printf(input_data, "%s\n", stream_test_data);
}
// write test data to file
@@ -437,8 +437,8 @@ MU_TEST(stream_buffered_large_file_test) {
mu_check(buffered_file_stream_open(
stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
mu_assert_int_eq(0, stream_size(stream));
mu_assert_int_eq(string_size(input_data), stream_write_string(stream, input_data));
mu_assert_int_eq(string_size(input_data), stream_size(stream));
mu_assert_int_eq(furi_string_size(input_data), stream_write_string(stream, input_data));
mu_assert_int_eq(furi_string_size(input_data), stream_size(stream));
const size_t substr_start = 8;
const size_t substr_len = 11;
@@ -475,23 +475,23 @@ MU_TEST(stream_buffered_large_file_test) {
// read the whole file
mu_check(stream_rewind(stream));
string_t tmp;
string_init(tmp);
FuriString* tmp;
tmp = furi_string_alloc();
while(stream_read_line(stream, tmp)) {
string_cat(output_data, tmp);
furi_string_cat(output_data, tmp);
}
string_clear(tmp);
furi_string_free(tmp);
// check against generated data
mu_assert_int_eq(string_size(input_data), string_size(output_data));
mu_check(string_equal_p(input_data, output_data));
mu_assert_int_eq(furi_string_size(input_data), furi_string_size(output_data));
mu_check(furi_string_equal(input_data, output_data));
mu_check(stream_eof(stream));
stream_free(stream);
furi_record_close(RECORD_STORAGE);
string_clear(input_data);
string_clear(output_data);
furi_string_free(input_data);
furi_string_free(output_data);
}
MU_TEST_SUITE(stream_suite) {

View File

@@ -28,12 +28,12 @@ static void subghz_test_rx_callback(
void* context) {
UNUSED(receiver);
UNUSED(context);
string_t text;
string_init(text);
FuriString* text;
text = furi_string_alloc();
subghz_protocol_decoder_base_get_string(decoder_base, text);
subghz_receiver_reset(receiver_handler);
FURI_LOG_T(TAG, "\r\n%s", string_get_cstr(text));
string_clear(text);
FURI_LOG_T(TAG, "\r\n%s", furi_string_get_cstr(text));
furi_string_free(text);
subghz_test_decoder_count++;
}
@@ -141,8 +141,8 @@ static bool subghz_decode_random_test(const char* path) {
static bool subghz_encoder_test(const char* path) {
subghz_test_decoder_count = 0;
uint32_t test_start = furi_get_tick();
string_t temp_str;
string_init(temp_str);
FuriString* temp_str;
temp_str = furi_string_alloc();
bool file_load = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
@@ -167,11 +167,11 @@ static bool subghz_encoder_test(const char* path) {
} while(false);
if(file_load) {
SubGhzTransmitter* transmitter =
subghz_transmitter_alloc_init(environment_handler, string_get_cstr(temp_str));
subghz_transmitter_alloc_init(environment_handler, furi_string_get_cstr(temp_str));
subghz_transmitter_deserialize(transmitter, fff_data_file);
SubGhzProtocolDecoderBase* decoder = subghz_receiver_search_decoder_base_by_name(
receiver_handler, string_get_cstr(temp_str));
receiver_handler, furi_string_get_cstr(temp_str));
if(decoder) {
LevelDuration level_duration;
@@ -192,10 +192,11 @@ static bool subghz_encoder_test(const char* path) {
flipper_format_free(fff_data_file);
FURI_LOG_T(TAG, "\r\n Decoder count parse \033[0;33m%d\033[0m ", subghz_test_decoder_count);
if(furi_get_tick() - test_start > TEST_TIMEOUT) {
printf("\033[0;31mTest encoder %s ERROR TimeOut\033[0m\r\n", string_get_cstr(temp_str));
printf(
"\033[0;31mTest encoder %s ERROR TimeOut\033[0m\r\n", furi_string_get_cstr(temp_str));
subghz_test_decoder_count = 0;
}
string_clear(temp_str);
furi_string_free(temp_str);
return subghz_test_decoder_count ? true : false;
}

View File

@@ -1,5 +1,3 @@
#include "m-string.h"
#include <stdio.h>
#include <furi.h>
#include <furi_hal.h>
@@ -11,6 +9,7 @@
#define TAG "UnitTests"
int run_minunit_test_furi();
int run_minunit_test_furi_string();
int run_minunit_test_infrared();
int run_minunit_test_rpc();
int run_minunit_test_flipper_format();
@@ -33,6 +32,7 @@ typedef struct {
const UnitTest unit_tests[] = {
{.name = "furi", .entry = run_minunit_test_furi},
{.name = "furi_string", .entry = run_minunit_test_furi_string},
{.name = "storage", .entry = run_minunit_test_storage},
{.name = "stream", .entry = run_minunit_test_stream},
{.name = "dirwalk", .entry = run_minunit_test_dirwalk},
@@ -63,7 +63,7 @@ void minunit_print_fail(const char* str) {
printf(FURI_LOG_CLR_E "%s\r\n" FURI_LOG_CLR_RESET, str);
}
void unit_tests_cli(Cli* cli, string_t args, void* context) {
void unit_tests_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(cli);
UNUSED(args);
UNUSED(context);
@@ -91,8 +91,8 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
break;
}
if(string_size(args)) {
if(string_cmp_str(args, unit_tests[i].name) == 0) {
if(furi_string_size(args)) {
if(furi_string_cmp_str(args, unit_tests[i].name) == 0) {
failed_tests += unit_tests[i].entry();
} else {
printf("Skipping %s\r\n", unit_tests[i].name);