Sync with tizen 2.4 39/52439/2 accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_tv accepted/tizen_3.0.m2_wearable accepted/tizen_3.0_common accepted/tizen_3.0_ivi accepted/tizen_3.0_mobile accepted/tizen_3.0_tv accepted/tizen_3.0_wearable accepted/tizen_4.0_unified accepted/tizen_5.0_unified accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix accepted/tizen_ivi accepted/tizen_mobile accepted/tizen_tv accepted/tizen_wearable tizen_3.0 tizen_3.0.m2 tizen_3.0_tv tizen_4.0 tizen_4.0_tv tizen_5.0 tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix accepted/tizen/3.0.m2/mobile/20170105.024726 accepted/tizen/3.0.m2/tv/20170105.024904 accepted/tizen/3.0.m2/wearable/20170105.025031 accepted/tizen/3.0/common/20161114.111001 accepted/tizen/3.0/ivi/20161011.044320 accepted/tizen/3.0/mobile/20161015.033533 accepted/tizen/3.0/tv/20161016.004931 accepted/tizen/3.0/wearable/20161015.083222 accepted/tizen/4.0/unified/20170816.012325 accepted/tizen/4.0/unified/20170828.222800 accepted/tizen/5.0/unified/20181102.030131 accepted/tizen/5.5/unified/20191031.011337 accepted/tizen/5.5/unified/mobile/hotfix/20201027.074002 accepted/tizen/5.5/unified/wearable/hotfix/20201027.100311 accepted/tizen/ivi/20160218.025234 accepted/tizen/mobile/20151224.061922 accepted/tizen/tv/20151224.062024 accepted/tizen/unified/20170309.040057 accepted/tizen/wearable/20151224.062054 submit/tizen/20151223.035755 submit/tizen_3.0.m2/20170104.093753 submit/tizen_3.0_common/20161104.104000 submit/tizen_3.0_ivi/20161010.000003 submit/tizen_3.0_mobile/20161015.000003 submit/tizen_3.0_tv/20161015.000003 submit/tizen_3.0_wearable/20161015.000003 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170828.100006 submit/tizen_5.0/20181101.000007 submit/tizen_5.5/20191031.000007 submit/tizen_5.5_mobile_hotfix/20201026.185107 submit/tizen_5.5_wearable_hotfix/20201026.184307 submit/tizen_common/20151229.142028 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718 submit/tizen_ivi/20160217.000000 submit/tizen_ivi/20160217.000006 submit/tizen_unified/20170308.100414 tizen_4.0.IoT.p1_release tizen_4.0.IoT.p2_release tizen_4.0.m1_release tizen_4.0.m2_release tizen_5.5.m2_release
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 23 Nov 2015 11:19:50 +0000 (20:19 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 23 Nov 2015 11:21:42 +0000 (20:21 +0900)
Change-Id: I76254d79a90abef9f1e9dda14c6449cac8838cda
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
libiri/parse.c
packaging/libiri.spec
run_test.sh [new file with mode: 0755]
tests/iridump.ans [new file with mode: 0644]

index 6f4e556..642e4aa 100644 (file)
  * or promote products derived from this software without specific prior
  * written permission.
  *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
@@ -76,7 +76,7 @@ static inline const char *
 iri__copychar_decode(char **dest, const char *src, int convert_space)
 {
        unsigned char *p = (unsigned char *) (*dest);
-       
+
        if(1 == convert_space && '+' == *src)
        {
                **dest = ' ';
@@ -194,9 +194,9 @@ iri_parse(const char *src)
 {
        iri_t *p;
        char *bufstart, *endp, *bufp, **sl;
-       const char *at, *colon, *slash, *t;
+    const char *at, *colon, *slash, *t, *slash3rd;
        size_t buflen, sc, cp;
-       
+
        if(NULL == (p = (iri_t *) calloc(1, sizeof(iri_t))))
        {
                return NULL;
@@ -216,6 +216,24 @@ iri_parse(const char *src)
                /* We can disregard the colon if a slash appears before it */
                colon = NULL;
        }
+    // "@" is valid character in hierarchical part of IRI
+    if(slash && colon && (colon[1] != '/' || colon[2] != '/'))
+    {
+        //if scheme not suffixed with ://, there is not autority
+        //therefore autority(and user within) is not set
+        at = NULL;
+    }
+    else if(at && slash && slash[1] && slash[2])
+    {
+        slash3rd = strchr(slash + 2, '/');
+        //here we know scheme suffix is "://" so autority can exist
+        //3rd slash should match start of hierarchical part if exists
+        //@ after that is valid character
+        if(slash3rd && slash3rd < at)
+        {
+            at = NULL;
+        }
+    }
        if(colon && !at)
        {
                /* Definitely a scheme */
@@ -438,7 +456,7 @@ iri_parse(const char *src)
        if(*src == '#')
        {
                bufp = ALIGN(bufp);
-               p->iri.anchor = bufp; 
+               p->iri.anchor = bufp;
                while(*src)
                {
                        src = iri__copychar_decode(&bufp, src, 0);
@@ -450,7 +468,7 @@ iri_parse(const char *src)
        {
                /* Still stuff left? It must be a path... of sorts */
                bufp = ALIGN(bufp);
-               p->iri.path = bufp; 
+               p->iri.path = bufp;
                while(*src && *src != '?' && *src != '#')
                {
                        src = iri__copychar_decode(&bufp, src, 0);
index 41bc5a8..2e9da68 100644 (file)
@@ -1,6 +1,12 @@
+%define run_tests 0
+%if %{run_tests}
+    # check is defined off at .rpmmacros file.
+    %undefine check
+%endif
+
 Name:       libiri
 Version:    1.1
-Release:    0
+Release:    1
 License:    BSD-3-Clause
 Summary:    An IRI parsing library
 Url:        http://code.google.com/p/libiri/
@@ -39,6 +45,13 @@ cp %{S:1001} .
 %reconfigure
 make %{?_smp_mflags}
 
+%check
+%if %{run_tests}
+    %__make check || exit 0
+    chmod +x ./run_test.sh
+    ./run_test.sh %{name} %{version}
+%endif
+
 %install
 %make_install
 
diff --git a/run_test.sh b/run_test.sh
new file mode 100755 (executable)
index 0000000..c6f1ce4
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/bash
+
+PACKAGE_NAME=$1
+PACKAGE_VERSION=$2
+
+TEST_LOG="/tmp/${PACKAGE_NAME}_test"
+export TEST_LOG
+rm -f ${TEST_LOG}
+
+# Color
+Color_Off='\e[0m'       # Text Reset
+
+# Regular Colors
+Red='\e[0;31m'          # Red
+Green='\e[0;32m'        # Green
+Cyan='\e[0;36m'         # Cyank
+
+# Bold
+BWhite='\e[1;37m'       # White
+
+result_check() {
+    result=$?
+    test_case=$1
+    if [ $result -eq 0 ]
+    then
+        echo -e "${Green}PASS${Color_Off}: $test_case"
+        echo "TEST: PASS: $test_case" >> ${TEST_LOG}
+    else
+        echo -e "${Red}FAIL${Color_Off}: $test_case"
+        echo -e "TEST: FAIL: $test_case" >> ${TEST_LOG}
+    fi
+}
+
+skip_test() {
+    test_case=$1
+    echo -e "${Cyan}SKIP${Color_Off}: $test_case"
+    echo "TEST: SKIP: $test_case" >> ${TEST_LOG}
+}
+
+run_test() {
+    test_case=$1
+    test_arg=$2
+    pushd tests
+    ./${test_case} ${test_arg} > ${test_case}.ref 2>&1
+    diff ${test_case}.ans ${test_case}.ref
+    result_check "diff ${test_case}.ans ${test_case}.ref"
+    popd
+
+}
+
+run_test_sort() {
+    test_case=$1
+    test_arg=$2
+    pushd tests
+    ./${test_case} ${test_arg} 2>&1 | sort > ${test_case}.ref
+    diff ${test_case}.ans ${test_case}.ref
+    result_check "diff ${test_case}.ans ${test_case}.ref"
+    popd
+
+}
+
+    run_test iridump "abc://username:password@example.com:123/path/data?key=value#fragid1"
+
+TOTAL_CNT=`grep "TEST:" ${TEST_LOG} | wc -l`
+PASS_CNT=`grep "PASS:" ${TEST_LOG} | wc -l`
+FAIL_CNT=`grep "FAIL:" ${TEST_LOG} | wc -l`
+SKIP_CNT=`grep "SKIP:" ${TEST_LOG} | wc -l`
+
+
+br='==================='; br=$br$br$br$br;
+
+echo -e "${Green}$br ${Color_Off}"
+echo -e "${Green}Testsuite summary for ${PACKAGE_NAME} ${PACKAGE_VERSION}${Color_Off}"
+echo -e "${Green}$br ${Color_Off}"
+echo -e "#${BWhite} TOTAL: $TOTAL_CNT ${Color_Off}"
+echo -e "#${Green} PASS${Color_Off} : $PASS_CNT"
+echo -e "#${Red} FAIL${Color_Off} : $FAIL_CNT"
+echo -e "#${Cyan} SKIP${Color_Off} : $SKIP_CNT"
+echo -e "${Green}$br ${Color_Off}"
+
+rm -f ${TEST_LOG}
+exit 0
+
diff --git a/tests/iridump.ans b/tests/iridump.ans
new file mode 100644 (file)
index 0000000..c49eb09
--- /dev/null
@@ -0,0 +1,12 @@
+Colon occurs before at
+Found user
+  scheme: abc
+       0: abc
+    user: username
+    auth: (null)
+password: password
+    host: example.com
+    port: 123
+    path: /path/data
+   query: key=value
+  anchor: #fragid1