From c54ae3afd67a991287731f56a28c96e07da8b2dc Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sat, 31 Jul 2021 14:13:38 -0700 Subject: [PATCH] Tests: Fix AK/TestJSON.cpp by not relying on disk resources The following commit broke Tests/AK/TestJSON.cpp as it removed the file that the test loaded from disk to validate JSON parsing. commit ad141a228696d4e0f80add20d3e40a1fa3e82972 Author: Andreas Kling Date: Sat Jul 31 15:26:14 2021 +0200 Base: Remove "test.frm" from HackStudio test project Instead of restoring the file, lets just embed a bit of JSON in the test case to avoid using external resources, as they obviously are surprising and make the test less portable across environments. --- Tests/AK/CMakeLists.txt | 3 --- Tests/AK/TestJSON.cpp | 35 ++++++++++++++++++++++------------- Tests/AK/test.frm | 1 - 3 files changed, 22 insertions(+), 17 deletions(-) delete mode 120000 Tests/AK/test.frm diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index 3598f480fe..61cb63a14e 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -71,6 +71,3 @@ set(AK_TEST_SOURCES foreach(source ${AK_TEST_SOURCES}) serenity_test(${source} AK) endforeach() - -get_filename_component(TEST_FRM_RESOLVED ./test.frm REALPATH) -install(FILES ${TEST_FRM_RESOLVED} DESTINATION usr/Tests/AK) diff --git a/Tests/AK/TestJSON.cpp b/Tests/AK/TestJSON.cpp index 86d4dce2ce..7f8da710c0 100644 --- a/Tests/AK/TestJSON.cpp +++ b/Tests/AK/TestJSON.cpp @@ -15,20 +15,29 @@ TEST_CASE(load_form) { - FILE* fp = fopen("test.frm", "r"); - VERIFY(fp); + String raw_form_json = R"( + { + "name": "Form1", + "widgets": [ + { + "enabled": true, + "forecolor": "#000000ff", + "ruler_visible": false, + "autofill": false, + "x": 155, + "tooltip": null, + "height": 121, + "width": 126, + "y": 10, + "class": "GTextEditor", + "text": "Hi", + "backcolor": "#c0c0c0ff", + "visible":true + } + ] + })"; - StringBuilder builder; - for (;;) { - char buffer[1024]; - if (!fgets(buffer, sizeof(buffer), fp)) - break; - builder.append(buffer); - } - - fclose(fp); - - JsonValue form_json = JsonValue::from_string(builder.to_string()).value(); + JsonValue form_json = JsonValue::from_string(raw_form_json).value(); EXPECT(form_json.is_object()); diff --git a/Tests/AK/test.frm b/Tests/AK/test.frm deleted file mode 120000 index b01e93f4ee..0000000000 --- a/Tests/AK/test.frm +++ /dev/null @@ -1 +0,0 @@ -../../Base/home/anon/Source/little/test.frm \ No newline at end of file