summaryrefslogtreecommitdiff
path: root/src/tests/eet
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <gustavo.barbieri@intel.com>2014-03-13 22:00:27 -0300
committerGustavo Sverzut Barbieri <gustavo.barbieri@intel.com>2014-03-13 22:08:44 -0300
commitf2a1f14abd51946c75b96730a989ec334194ed76 (patch)
treec554132bd76c4e5c67eb8e3cf71edcb502994ea7 /src/tests/eet
parent6242271e74eca2b483f603b72e170e049e07aa18 (diff)
eet: fix tokenizer's escape logic.
Tokenizer's approach of looking back is horrible and breaks the following simple case (bug I had that lead to this patch): "string\\" As the parser would get the end quote and check the previous character if it was a backslash and it was, but it was not escaping the quote, but being escaped by the previous backslash. The best approach is to first check for escape and then go to quote. Escape is simple and only the following byte, so we enter escape, process the byte and then are back to regular mode (be it quote or unquote). Added testcase so we avoid breaking it again. @bugfix cherry-pick
Diffstat (limited to 'src/tests/eet')
-rw-r--r--src/tests/eet/eet_suite.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/tests/eet/eet_suite.c b/src/tests/eet/eet_suite.c
index 6bc5687180..5b56cf95fd 100644
--- a/src/tests/eet/eet_suite.c
+++ b/src/tests/eet/eet_suite.c
@@ -920,6 +920,47 @@ START_TEST(eet_test_data_type_dump_undump)
920 eet_shutdown(); 920 eet_shutdown();
921} 921}
922END_TEST 922END_TEST
923
924static void
925append_strbuf_string(void *data, const char *string)
926{
927 Eina_Strbuf *strbuf = data;
928 eina_strbuf_append(strbuf, string);
929}
930
931START_TEST(eet_test_data_type_escape_dump_undump)
932{
933 void *blob;
934 int blob_len;
935 int ret = 0;
936 const char *outputstr;
937 Eina_Strbuf *strbuf;
938 const char inputstr[] = ""
939 "group \"\\\\My\\\"Group\\\\\" struct {\n"
940 " value \"\\\\My\\\\BackSlash\\\\\" string: \"\\\\\";\n"
941 " value \"\\\\My\\\\DoubleQuote\\\\\" string: \"\\\"\";\n"
942 " value \"\\\\My\\\\NewLine\\\\\" string: \"\\n\";\n"
943 "}\n";
944
945 eet_init();
946
947 blob = eet_data_text_undump(inputstr, strlen(inputstr), &blob_len);
948 fail_if(!blob);
949
950 strbuf = eina_strbuf_new();
951 ret = eet_data_text_dump(blob, blob_len, append_strbuf_string, strbuf);
952 ck_assert_int_eq(ret, 1);
953
954 outputstr = eina_strbuf_string_get(strbuf);
955 fail_if(!outputstr);
956 ck_assert_str_eq(inputstr, outputstr);
957
958 eina_strbuf_free(strbuf);
959 free(blob);
960
961 eet_shutdown();
962}
963END_TEST
923START_TEST(eet_file_simple_write) 964START_TEST(eet_file_simple_write)
924{ 965{
925 const char *buffer = "Here is a string of data to save !"; 966 const char *buffer = "Here is a string of data to save !";
@@ -2724,6 +2765,7 @@ eet_suite(void)
2724 tcase_add_test(tc, eet_test_basic_data_type_encoding_decoding); 2765 tcase_add_test(tc, eet_test_basic_data_type_encoding_decoding);
2725 tcase_add_test(tc, eet_test_data_type_encoding_decoding); 2766 tcase_add_test(tc, eet_test_data_type_encoding_decoding);
2726 tcase_add_test(tc, eet_test_data_type_dump_undump); 2767 tcase_add_test(tc, eet_test_data_type_dump_undump);
2768 tcase_add_test(tc, eet_test_data_type_escape_dump_undump);
2727 tcase_add_test(tc, eet_fp); 2769 tcase_add_test(tc, eet_fp);
2728 tcase_add_test(tc, eet_test_union); 2770 tcase_add_test(tc, eet_test_union);
2729 tcase_add_test(tc, eet_test_variant); 2771 tcase_add_test(tc, eet_test_variant);