[or-cvs] Add code to read configuration lines from a string as well ...

Nick Mathewson nickm at seul.org
Thu Nov 4 22:29:48 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv20541/src/or

Modified Files:
	test.c 
Log Message:
Add code to read configuration lines from a string as well as a file

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- test.c	3 Nov 2004 18:33:07 -0000	1.139
+++ test.c	4 Nov 2004 22:29:45 -0000	1.140
@@ -489,7 +489,7 @@
   int i;
   uint32_t u32;
   uint16_t u16;
-  char *cp;
+  char *cp, *k, *v;
 
   start.tv_sec = 5;
   start.tv_usec = 5000;
@@ -674,6 +674,53 @@
   test_eq(10L, tor_parse_long("10",10,0,100,NULL,NULL));
   test_eq(0L, tor_parse_long("10",10,50,100,NULL,NULL));
 
+  /* Test parse_line_from_str */
+  strlcpy(buf, "k v\n" " key    value with spaces   \n"  "keykey val\n"
+          "k2\n"
+          "k3 \n"  "\n" "   \n" "#comment\n"
+          "k4#a\n" "k5#abc\n" "k6 val #with comment\n", sizeof(buf));
+  cp = buf;
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "k");
+  test_streq(v, "v");
+  test_assert(!strcmpstart(cp, " key    value with"));
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "key");
+  test_streq(v, "value with spaces");
+  test_assert(!strcmpstart(cp, "keykey"));
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "keykey");
+  test_streq(v, "val");
+  test_assert(!strcmpstart(cp, "k2\n"));
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "k2");
+  test_streq(v, "");
+  test_assert(!strcmpstart(cp, "k3 \n"));
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "k3");
+  test_streq(v, "");
+  test_assert(!strcmpstart(cp, "\n   \n"));
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "k4");
+  test_streq(v, "");
+  test_assert(!strcmpstart(cp, "k5#abc"));
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "k5");
+  test_streq(v, "");
+  test_assert(!strcmpstart(cp, "k6"));
+
+  cp = parse_line_from_str(cp, &k, &v);
+  test_streq(k, "k6");
+  test_streq(v, "val");
+  test_streq(cp, "");
+
   /* XXXX test older functions. */
   smartlist_free(sl);
 }



More information about the tor-commits mailing list