AK: Make a tiny JSON unit test based on a saved VisualBuilder form.
This commit is contained in:
parent
c9826bb429
commit
b1d113e32a
Notes:
sideshowbarker
2024-07-19 13:27:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b1d113e32ab
4 changed files with 53 additions and 1 deletions
1
AK/Tests/.gitignore
vendored
1
AK/Tests/.gitignore
vendored
|
@ -2,5 +2,6 @@ TestString
|
|||
TestQueue
|
||||
TestVector
|
||||
TestHashMap
|
||||
TestJSON
|
||||
*.d
|
||||
*.o
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
PROGRAMS = TestString TestQueue TestVector TestHashMap
|
||||
PROGRAMS = TestString TestQueue TestVector TestHashMap TestJSON
|
||||
|
||||
all: $(PROGRAMS)
|
||||
|
||||
|
@ -16,5 +16,8 @@ TestVector: TestVector.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp
|
|||
TestHashMap: TestHashMap.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h
|
||||
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestHashMap.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
|
||||
|
||||
TestJSON: TestJSON.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h ../JsonObject.cpp ../JsonValue.cpp ../JsonArray.cpp ../JsonParser.cpp
|
||||
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestJSON.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp ../JsonObject.cpp ../JsonValue.cpp ../JsonArray.cpp ../JsonParser.cpp
|
||||
|
||||
clean:
|
||||
rm -f $(PROGRAMS)
|
||||
|
|
47
AK/Tests/TestJSON.cpp
Normal file
47
AK/Tests/TestJSON.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "TestHelpers.h"
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
typedef HashMap<int, int> IntIntMap;
|
||||
|
||||
int main()
|
||||
{
|
||||
FILE* fp = fopen("../../Base/home/anon/test.frm", "r");
|
||||
ASSERT(fp);
|
||||
|
||||
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());
|
||||
|
||||
EXPECT(form_json.is_object());
|
||||
|
||||
auto name = form_json.as_object().get("name").to_string();
|
||||
|
||||
EXPECT_EQ(name, "Form1");
|
||||
|
||||
auto widgets = form_json.as_object().get("widgets").as_array();
|
||||
|
||||
widgets.for_each([&](const JsonValue& widget_value) {
|
||||
auto& widget_object = widget_value.as_object();
|
||||
auto widget_class = widget_object.get("class").as_string();
|
||||
widget_object.for_each_member([&](auto& property_name, const JsonValue& property_value) {
|
||||
(void)property_name;
|
||||
(void)property_value;
|
||||
//dbgprintf("Set property %s.%s to '%s'\n", widget_class.characters(), property_name.characters(), property_value.serialized().characters());
|
||||
});
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
1
Base/home/anon/test.frm
Normal file
1
Base/home/anon/test.frm
Normal file
|
@ -0,0 +1 @@
|
|||
{"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},{"tooltip":null,"backcolor":"#c0c0c0ff","forecolor":"#000000ff","text":"Okydoky","class":"GButton","autofill":false,"enabled":true,"visible":true,"x":10,"height":21,"y":70,"width":81},{"tooltip":null,"backcolor":"#c0c0c0ff","forecolor":"#000000ff","class":"GGroupBox","autofill":true,"enabled":true,"visible":true,"title":"groupie","x":10,"height":71,"y":100,"width":141},{"tooltip":null,"forecolor":"#000000ff","y":10,"max":100,"autofill":false,"x":10,"min":0,"class":"GProgressBar","backcolor":"#c0c0c0ff","height":21,"enabled":true,"visible":true,"width":136,"value":50},{"tooltip":null,"backcolor":"#c0c0c0ff","forecolor":"#000000ff","text":"Looks like success!","class":"GLabel","autofill":true,"enabled":true,"visible":true,"x":10,"height":26,"y":35,"width":136},{"enabled":true,"forecolor":"#000000ff","checked":false,"autofill":false,"x":160,"tooltip":null,"height":26,"width":91,"y":140,"class":"GCheckBox","text":"checkbox_1","backcolor":"#c0c0c0ff","visible":true},{"enabled":true,"forecolor":"#000000ff","checked":false,"autofill":false,"x":160,"tooltip":null,"height":26,"width":61,"y":160,"class":"GRadioButton","text":"radio_1","backcolor":"#c0c0c0ff","visible":true},{"tooltip":null,"forecolor":"#000000ff","y":125,"max":100,"autofill":false,"x":25,"min":0,"class":"GSlider","backcolor":"#c0c0c0ff","height":26,"enabled":true,"visible":true,"width":116,"value":"60"}]}
|
Loading…
Add table
Reference in a new issue