aboutsummaryrefslogtreecommitdiff
path: root/src/vdf/tests/index.c
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-06-28 17:44:01 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-06-28 17:44:01 +0200
commita51036bf447a699511452da773dc4fad02192849 (patch)
tree116b9ec1d527e02db9023c836721bd046fe320ff /src/vdf/tests/index.c
parenta93baa212f3c7b57a08cb9084d38994290195d78 (diff)
downloadOFQT-a51036bf447a699511452da773dc4fad02192849.tar.gz
OFQT-a51036bf447a699511452da773dc4fad02192849.zip
add unit tests for vdf & md5, allow escaped quotesvdf-parser
Diffstat (limited to 'src/vdf/tests/index.c')
-rw-r--r--src/vdf/tests/index.c51
1 files changed, 51 insertions, 0 deletions
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