ソースを参照

Setting defualt port to the one written in /etc/services for https.

This way there's the possibility to just write
./qa -r google.com
without having to specify the port. Finally, adding some ore unittests to
test_cmmdline.test, shrinking the old ones and adding some new, requiring the
network.

XXX. using interface wlan0 as default, must be changed.
Michele Orrù 11 年 前
コミット
655399d262
共有3 個のファイルを変更した27 個の追加8 個の削除を含む
  1. 1 0
      src/qa_sock.c
  2. 25 6
      src/tests/test_cmdline.test
  3. 1 2
      src/tests/test_qa_sock.c

+ 1 - 0
src/qa_sock.c

@@ -159,6 +159,7 @@ struct qa_connection* qa_connection_new(char* address)
 
   /* parse input address */
   if (!host_port(address, &host, &port)) goto error;
+  if (!port) port = "https";
 
   c = malloc(sizeof(struct qa_connection));
   if (!c) goto error;

+ 25 - 6
src/tests/test_cmdline.test

@@ -1,8 +1,27 @@
 #!/bin/sh
 
-../qa -a non_existing_test < /dev/null
-if [ $? -ne 1 ]
-then
-    echo "Invalid questions shall raise an error."
-    exit 1
-fi
+## TESTING -a parameter
+../qa -a non_existing_test < /dev/zero
+[[ $? == 1 ]] || exit 1
+
+../qa -a example < /dev/zero
+[[ $? == 1 ]] || exit 1
+
+../qa -a example -f dummy.crt
+[[ $? != 1 ]] || exit 1
+
+../qa  < /dev/zero
+[[ $? == 1 ]] || exit 1
+
+## tests requiring network.
+interface="wlan0"
+[[ $(cat "/sys/class/net/$interface/carrier") == 1 ]] ||  exit 0
+
+../qa -a example -r https://www.esse3.unitn.it
+[[ $? != 1 ]] || exit 1
+
+../qa -a example -r www.esse3.unitn.it
+[[ $? != 1 ]] || exit 1
+
+../qa -a example -r www.esse3.unitn.it:443
+[[ $? != 1 ]] || exit 1

+ 1 - 2
src/tests/test_qa_sock.c

@@ -45,8 +45,7 @@ void test_host_port(void)
   /* uris containing just a hostname shall be recognized */
   strcpy(uri, "queer");
   host_port(uri, &host, &port);
-  assert(!strcmp(host, "queer") &&
-         !port);
+  assert(!strcmp(host, "queer"));
 }
 
 void test_get_remote_cert(void)