aboutsummaryrefslogtreecommitdiff
path: root/src/vdf/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/vdf/tests')
-rw-r--r--src/vdf/tests/CMakeLists.txt22
-rw-r--r--src/vdf/tests/files/registry.vdf47
-rw-r--r--src/vdf/tests/index.c51
-rw-r--r--src/vdf/tests/reparse.c35
4 files changed, 155 insertions, 0 deletions
diff --git a/src/vdf/tests/CMakeLists.txt b/src/vdf/tests/CMakeLists.txt
new file mode 100644
index 0000000..c055c64
--- /dev/null
+++ b/src/vdf/tests/CMakeLists.txt
@@ -0,0 +1,22 @@
+
+add_executable(vdf_reparse reparse.c)
+target_link_libraries(vdf_reparse vdf)
+
+add_test(NAME vdf_reparse_run
+ COMMAND
+ vdf_reparse ${CMAKE_CURRENT_SOURCE_DIR}/files/registry.vdf reparsed_registry.vdf
+ )
+
+add_test(NAME vdf_reparse_compare
+ COMMAND
+ ${CMAKE_COMMAND} -E compare_files --ignore-eol ${CMAKE_CURRENT_SOURCE_DIR}/files/registry.vdf reparsed_registry.vdf
+ )
+
+add_executable(vdf_index index.c)
+target_link_libraries(vdf_index vdf)
+
+add_test(NAME vdf_index_test
+ COMMAND
+ vdf_index ${CMAKE_CURRENT_SOURCE_DIR}/files/registry.vdf HKCU Software Valve Steam steamglobal language
+ )
+
diff --git a/src/vdf/tests/files/registry.vdf b/src/vdf/tests/files/registry.vdf
new file mode 100644
index 0000000..0e400bf
--- /dev/null
+++ b/src/vdf/tests/files/registry.vdf
@@ -0,0 +1,47 @@
+"Registry"
+{
+ "HKCU"
+ {
+ "Software"
+ {
+ "Valve"
+ {
+ "Steam"
+ {
+ "empty"
+ {
+ }
+ "slash-test"
+ {
+ "key\"string" "value\"string"
+ }
+ "steamglobal"
+ {
+ "language" "english"
+ }
+ "Apps"
+ {
+ "10090"
+ {
+ "installed" "1"
+ "Updating" "0"
+ "Running" "0"
+ }
+ "1245040"
+ {
+ "installed" "1"
+ "Updating" "0"
+ "Running" "0"
+ }
+ "287700"
+ {
+ "installed" "1"
+ "Updating" "0"
+ "Running" "0"
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/vdf/tests/index.c b/src/vdf/tests/index.c
new file mode 100644
index 0000000..c3f96b1
--- /dev/null
+++ b/src/vdf/tests/index.c
@@ -0,0 +1,51 @@
+/**
+ * a command line utility that parses a given
+ * vdf file and indexes requested values by key
+ *
+ * Returns 0 if value is a string otherwise 1
+ *
+ * Used for testing to ensure indexing works reliably
+ * on a known file
+ */
+#include <stdio.h>
+
+#include "vdf.h"
+
+int main(int argc, char** argv)
+{
+ if (argc < 2)
+ {
+ puts("vdf_index file index [index...]");
+ return 1;
+ }
+
+ struct vdf_object* o = vdf_parse_file(argv[1]);
+
+ if (!o)
+ {
+ puts("Invalid File");
+ return 1;
+ }
+
+ struct vdf_object* k = o;
+ for (int i = 2; i < argc; ++i)
+ {
+ k = vdf_object_index_array_str(k, argv[i]);
+ if (!k)
+ {
+ printf("Invalid index '%s'\n", argv[i]);
+ break;
+ }
+ }
+
+ int retval = k->type != VDF_TYPE_STRING;
+
+ if (retval)
+ vdf_print_object(k);
+ else
+ puts(k->data.data_string.str);
+
+ vdf_free_object(o);
+
+ return retval;
+} \ No newline at end of file
diff --git a/src/vdf/tests/reparse.c b/src/vdf/tests/reparse.c
new file mode 100644
index 0000000..94da4ca
--- /dev/null
+++ b/src/vdf/tests/reparse.c
@@ -0,0 +1,35 @@
+/**
+ * a command line utility that parses a given
+ * vdf file and and output it pretty printed
+ * onto stdout or a specified file
+ *
+ * Used for testing to ensure we parse a VDF
+ * file correctly and can output the same
+ */
+#include <stdio.h>
+
+#include "vdf.h"
+
+int main(int argc, char** argv)
+{
+ if (argc < 2)
+ {
+ puts("vdf_reparse file [output]");
+ return 1;
+ }
+ else if (argc > 2)
+ {
+ freopen(argv[2], "w", stdout);
+ }
+
+ struct vdf_object* o = vdf_parse_file(argv[1]);
+
+ if (!o)
+ {
+ puts("Invalid File");
+ return 1;
+ }
+ vdf_print_object(o);
+
+ vdf_free_object(o);
+} \ No newline at end of file