summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
Diffstat (limited to 'AK')
-rw-r--r--AK/Tests/.gitignore1
-rw-r--r--AK/Tests/Makefile5
-rw-r--r--AK/Tests/TestJSON.cpp47
3 files changed, 52 insertions, 1 deletions
diff --git a/AK/Tests/.gitignore b/AK/Tests/.gitignore
index c7ff67cd46..a8d8df0d88 100644
--- a/AK/Tests/.gitignore
+++ b/AK/Tests/.gitignore
@@ -2,5 +2,6 @@ TestString
TestQueue
TestVector
TestHashMap
+TestJSON
*.d
*.o
diff --git a/AK/Tests/Makefile b/AK/Tests/Makefile
index a703bb0ea6..ecfc22750e 100644
--- a/AK/Tests/Makefile
+++ b/AK/Tests/Makefile
@@ -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)
diff --git a/AK/Tests/TestJSON.cpp b/AK/Tests/TestJSON.cpp
new file mode 100644
index 0000000000..72fb007de5
--- /dev/null
+++ b/AK/Tests/TestJSON.cpp
@@ -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;
+}