Jelajahi Sumber

Fix another TODO in the unit test

bel 11 tahun lalu
induk
melakukan
61c52a6fb9
3 mengubah file dengan 38 tambahan dan 8 penghapusan
  1. 3 0
      src/civetweb.c
  2. 28 0
      test/page5.lua
  3. 7 8
      test/unit_test.c

+ 3 - 0
src/civetweb.c

@@ -1187,6 +1187,9 @@ static char *skip_quoted(char **buf, const char *delimiters,
     if (end_word > begin_word) {
         p = end_word - 1;
         while (*p == quotechar) {
+            /* TODO (bel): it seems this code is never reached, so quotechar is actually
+               not needed - check if this code may be droped */
+
             /* If there is anything beyond end_word, copy it */
             if (*end_word == '\0') {
                 *p = '\0';

+ 28 - 0
test/page5.lua

@@ -0,0 +1,28 @@
+-- This test checks the Lua functions:
+-- get_var, get_cookie, md5, url_encode
+
+now = os.time()
+cookie_name = "civetweb-test-page4"
+
+if mg.request_info.http_headers.Cookie then
+   cookie_value = tonumber(mg.get_cookie(mg.request_info.http_headers.Cookie, cookie_name))
+end
+
+mg.write("HTTP/1.0 200 OK\r\n")
+mg.write("Connection: close\r\n")
+mg.write("Content-Type: text/html; charset=utf-8\r\n")
+mg.write("Cache-Control: max-age=0, must-revalidate\r\n")
+if not cookie_value then
+    mg.write("Set-Cookie: " .. cookie_name .. "=" .. tostring(now) .. "\r\n")
+end
+mg.write("\r\n")
+
+mg.write("<html>\r\n<head><title>Civetweb Lua script test page 5</title></head>\r\n<body>\r\n")
+mg.write("<p>Test of Civetweb Lua Import Functions:</p>\r\n");
+mg.write("<pre>\r\n");
+-- begin of page
+
+require 'lxp'
+
+-- end of page
+mg.write("</pre>\r\n</body>\r\n</html>\r\n")

+ 7 - 8
test/unit_test.c

@@ -727,7 +727,7 @@ static void test_mg_stat(void) {
 }
 
 static void test_skip_quoted(void) {
-    char x[] = "a=1, b=2  c='hi \' there'", *s = x, *p;
+    char x[] = "a=1, b=2, c='hi \' there', d='here\\, there'", *s = x, *p;
 
     p = skip_quoted(&s, ", ", ", ", 0);
     ASSERT(p != NULL && !strcmp(p, "a=1"));
@@ -735,13 +735,12 @@ static void test_skip_quoted(void) {
     p = skip_quoted(&s, ", ", ", ", 0);
     ASSERT(p != NULL && !strcmp(p, "b=2"));
 
-    /* TODO(lsm): fix this */
-#if 0
-    p = skip_quoted(&s, "'", ", ", '\\');
-    p = skip_quoted(&s, "'", ", ", '\\');
-    printf("[%s]\n", p);
-    ASSERT(p != NULL && !strcmp(p, "hi ' there"));
-#endif
+    p = skip_quoted(&s, ",", " ", 0);
+    ASSERT(p != NULL && !strcmp(p, "c='hi \' there'"));
+
+    p = skip_quoted(&s, ",", " ", '\\');
+    ASSERT(p != NULL && !strcmp(p, "d='here, there'"));
+    ASSERT(*s == 0);
 }
 
 static void test_alloc_vprintf(void) {