Index: pjproject/trunk/pjlib/include/pj/string_i.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/string_i.h	(revision 117)
+++ pjproject/trunk/pjlib/include/pj/string_i.h	(revision 118)
@@ -130,5 +130,5 @@
     diff = str1->slen - str2->slen;
     if (diff) {
-	return (int)diff;
+	return diff > 0 ? 1 : -1;
     } else if (str1->ptr && str1->slen) {
 	return pj_native_strncmp(str1->ptr, str2->ptr, str1->slen);
@@ -141,7 +141,12 @@
 			 pj_size_t len)
 {
-    return (str1->ptr && str2->ptr) ? 
-	    pj_native_strncmp(str1->ptr, str2->ptr, len) :
-	    (str1->ptr == str2->ptr ? 0 : 1);
+    if (str1->ptr && str2->ptr)
+	return pj_native_strncmp(str1->ptr, str2->ptr, len);
+    else if (str2->ptr)
+	return str2->slen==0 ? 0 : -1;
+    else if (str1->ptr)
+	return str1->slen==0 ? 0 : 1;
+    else
+	return 0;
 }
 
@@ -149,11 +154,22 @@
 			  pj_size_t len)
 {
-    return (str1->ptr && str2) ? pj_native_strncmp(str1->ptr, str2, len) :
-	   (str1->ptr==str2 ? 0 : 1);
+    if (len == 0) 
+	return 0;
+    else if (str1->ptr && str2)
+	return pj_native_strncmp(str1->ptr, str2, len);
+    else if (str1->ptr)
+	return str1->slen==0 ? 0 : 1;
+    else if (str2)
+	return *str2=='\0' ? 0 : -1;
+    else
+	return 0;
 }
 
 PJ_IDEF(int) pj_strcmp2( const pj_str_t *str1, const char *str2 )
 {
-    return pj_strncmp2( str1, str2, str1->slen);
+    if (str1->slen == 0) {
+	return (!str2 || *str2=='\0') ? 0 : -1;
+    } else
+	return pj_strncmp2( str1, str2, str1->slen);
 }
 
@@ -208,5 +224,5 @@
 
     if (len != str2->slen) {
-	return -1;
+	return (len < str2->slen) ? -1 : 1;
     } else if (len == 0) {
 	return 0;
@@ -241,7 +257,12 @@
 PJ_IDEF(int) pj_stricmp2( const pj_str_t *str1, const char *str2)
 {
-    return (str1->ptr && str2) ? 
-	    pj_native_strnicmp(str1->ptr, str2, str1->slen) :
-	    (str1->ptr==str2 ? 0 : 1);
+    if (str1->ptr && str2)
+	return pj_native_strnicmp(str1->ptr, str2, str1->slen);
+    else if (str2)
+	return (*str2=='\0') ? 0 : -1;
+    else if (str1->ptr)
+	return (str1->slen==0) ? 0 : 1;
+    else
+	return 0;
 }
 
@@ -249,7 +270,12 @@
 			  pj_size_t len)
 {
-    return (str1->ptr && str2->ptr) ? 
-	    pj_native_strnicmp(str1->ptr, str2->ptr, len) :
-	    (str1->ptr == str2->ptr ? 0 : 1);
+    if (str1->ptr && str2->ptr)
+	return pj_native_strnicmp(str1->ptr, str2->ptr, len);
+    else if (str2->ptr)
+	return str2->slen==0 ? 0 : -1;
+    else if (str1->ptr)
+	return str1->slen==0 ? 0 : 1;
+    else
+	return 0;
 }
 
@@ -257,7 +283,15 @@
 			   pj_size_t len)
 {
-    return (str1->ptr && str2) ? 
-	    pj_native_strnicmp(str1->ptr, str2, len) :
-	    (str1->ptr == str2 ? 0 : 1);
+    if (len == 0) 
+	return 0;
+    else if (str1->ptr && str2)
+	return pj_native_strnicmp(str1->ptr, str2, len);
+    else if (str1->ptr)
+	return str1->slen==0 ? 0 : 1;
+    else if (str2)
+	return *str2=='\0' ? 0 : -1;
+    else
+	return 0;
+
 }
 
Index: pjproject/trunk/pjlib/src/pjlib-test/main.c
===================================================================
--- pjproject/trunk/pjlib/src/pjlib-test/main.c	(revision 117)
+++ pjproject/trunk/pjlib/src/pjlib-test/main.c	(revision 118)
@@ -58,4 +58,5 @@
 {
     int rc;
+    int interractive = 0;
 
     boost();
@@ -65,5 +66,8 @@
         char *arg = argv[--argc];
 
-        if (*arg=='-' && *(arg+1)=='p') {
+	if (*arg=='-' && *(arg+1)=='i') {
+	    interractive = 1;
+
+	} else if (*arg=='-' && *(arg+1)=='p') {
             pj_str_t port = pj_str(argv[--argc]);
 
@@ -89,4 +93,11 @@
     rc = test_main();
 
+    if (interractive) {
+	char s[10];
+	puts("");
+	puts("Press <ENTER> to exit");
+	fgets(s, sizeof(s), stdin);
+    }
+
     return rc;
 }
Index: pjproject/trunk/pjlib/src/pjlib-test/string.c
===================================================================
--- pjproject/trunk/pjlib/src/pjlib-test/string.c	(revision 117)
+++ pjproject/trunk/pjlib/src/pjlib-test/string.c	(revision 118)
@@ -48,5 +48,5 @@
  *  - pj_strtoul()
  *  - pj_create_random_string()
- *
+ *  - ... and mode..
  *
  * This file is <b>pjlib-test/string.c</b>
@@ -67,8 +67,12 @@
 static int stricmp_test(void)
 {
+/* This specificly tests and benchmark pj_stricmp(), pj_stricmp_alnum().
+ * In addition, it also tests pj_stricmp2(), pj_strnicmp(), and 
+ * pj_strnicmp2().
+ */
 #define STRTEST(res,S1,S2,code)	\
 	    do { \
-	        s1.ptr=S1; s1.slen=len; \
-	        s2.ptr=S2; s2.slen=len; \
+		s1.ptr=S1; s1.slen=S1?len:0; \
+		s2.ptr=S2; s2.slen=S2?len:0; \
 		pj_get_timestamp(&t1); \
 	        if (pj_stricmp(&s1,&s2)!=res) return code; \
@@ -81,4 +85,7 @@
 		pj_sub_timestamp(&t2, &t1); \
 		pj_add_timestamp(&e2, &t2); \
+		if (pj_stricmp2(&s1,S2)!=res) return code*10; \
+		if (pj_strnicmp(&s1,&s2,len)!=res) return code*100; \
+		if (pj_strnicmp2(&s1,S2,len)!=res) return code*1000; \
 	    } while (0)
 
@@ -96,4 +103,8 @@
     len=0;
     STRTEST( 0, "","",-500);
+    STRTEST( 0, NULL,"",-502);
+    STRTEST( 0, "",NULL,-504);
+    STRTEST( 0, NULL,NULL,-506);
+    STRTEST( 0, "hello","world",-508);
 
     /* equal, length=1 
@@ -105,4 +116,6 @@
     STRTEST( 0, "a",buf+1,-512);
     STRTEST( -1, "0", "P", -514);
+    STRTEST(-1, NULL, "a", -516);
+    STRTEST(1, "a", NULL, -518);
 
     /* equal, length=2 
@@ -208,4 +221,42 @@
 }
 
+/* This tests pj_strcmp(), pj_strcmp2(), pj_strncmp(), pj_strncmp2() */
+static int strcmp_test(void)
+{
+#define STR_TEST(res,S1,S2,code)    \
+	    do { \
+		s1.ptr=S1; s1.slen=S1?len:0; \
+		s2.ptr=S2; s2.slen=S2?len:0; \
+	        if (pj_strcmp(&s1,&s2)!=res) return code; \
+		if (pj_strcmp2(&s1,S2)!=res) return code-1; \
+		if (pj_strncmp(&s1,&s2,len)!=res) return code-2; \
+		if (pj_strncmp2(&s1,S2,len)!=res) return code-3; \
+	    } while (0)
+
+    pj_str_t s1, s2;
+    int len;
+    
+    /* Test with length == 0 */
+    len=0;
+    STR_TEST(0, "", "", -400);
+    STR_TEST(0, NULL, "", -405);
+    STR_TEST(0, "", NULL, -410);
+    STR_TEST(0, NULL, NULL, -415);
+    STR_TEST(0, "hello", "", -420);
+    STR_TEST(0, "hello", NULL, -425);
+
+    /* Test with length != 0 */
+    len = 2;
+    STR_TEST(0, "12", "12", -430);
+    STR_TEST(1, "12", "1", -435);
+    STR_TEST(-1, "1", "12", -440);
+    STR_TEST(-1, NULL, "12", -445);
+    STR_TEST(1, "12", NULL, -450);
+
+    return 0;
+
+#undef STR_TEST
+}
+
 int string_test(void)
 {
@@ -308,5 +359,15 @@
     pj_pool_release(pool);
 
-    return stricmp_test();
+    /* Case sensitive comparison test. */
+    i = strcmp_test();
+    if (i != 0)
+	return i;
+
+    /* Caseless comparison test. */
+    i = stricmp_test();
+    if (i != 0)
+	return i;
+
+    return 0;
 }
 
